Skip to content

Commit

Permalink
✨ (sample) [DSDK-423]: Implement Sign transaction in the Ethereum Key…
Browse files Browse the repository at this point in the history
…ring (#230)
  • Loading branch information
aussedatlo authored Sep 3, 2024
2 parents 8bfaa71 + 3e91677 commit 37bd3f8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-gifts-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-sdk-sample": patch
---

Implement SignTransactionUseCase in the Ethereum Keyring part
1 change: 1 addition & 0 deletions apps/sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@ledgerhq/keyring-eth": "workspace:*",
"@ledgerhq/react-ui": "^0.15.3",
"@sentry/nextjs": "^8.27.0",
"ethers": "^6.13.2",
"next": "14.2.6",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export function DeviceActionDrawer<
{responses.map((response, index, arr) => {
const isLatest = index === arr.length - 1;
return (
<React.Fragment key={response.date.toISOString()}>
<React.Fragment
key={`${response.date.toISOString()}-index-${index}`}
>
<DeviceActionResponse {...response} isLatest={isLatest} />
<div hidden={isLatest}>
{/** if I just unmount it, all dividers are glitching out */}
Expand Down
36 changes: 35 additions & 1 deletion apps/sample/src/components/KeyringEthView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ import {
SignTypedDataDAOutput,
KeyringEthBuilder,
TypedData,
SignTransactionDAOutput,
SignTransactionDAError,
SignTransactionDAIntermediateValue,
} from "@ledgerhq/keyring-eth";
import {
DeviceAction,
DeviceActionProps,
} from "@/components/DeviceActionsView/DeviceAction";
import { PageWithHeader } from "@/components/PageWithHeader";
import { ethers } from "ethers";

export const KeyringEthView: React.FC<{ sessionId: string }> = ({
sessionId,
Expand Down Expand Up @@ -60,7 +64,7 @@ export const KeyringEthView: React.FC<{ sessionId: string }> = ({
GetAddressDAIntermediateValue
>,
{
title: "Sign Message",
title: "Sign message",
description:
"Perform all the actions necessary to sign a message with the device",
executeDeviceAction: ({ derivationPath, message }) => {
Expand All @@ -79,6 +83,36 @@ export const KeyringEthView: React.FC<{ sessionId: string }> = ({
SignPersonalMessageDAError,
SignPersonalMessageDAIntermediateValue
>,
{
title: "Sign transaction",
description:
"Perform all the actions necessary to sign a transaction with the device",
executeDeviceAction: ({
derivationPath,
transaction,
recipientDomain,
}) => {
return keyring.signTransaction(
derivationPath,
ethers.Transaction.from(transaction),
{ domain: recipientDomain },
);
},
initialValues: {
derivationPath: "44'/60'/0'/0/0",
transaction: "",
recipientDomain: "",
},
} satisfies DeviceActionProps<
SignTransactionDAOutput,
{
derivationPath: string;
transaction: string;
recipientDomain: string;
},
SignTransactionDAError,
SignTransactionDAIntermediateValue
>,
{
title: "Sign typed message",
description:
Expand Down
20 changes: 4 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37bd3f8

Please sign in to comment.