From 8bd7d0ad595ee7842f5d298e4690130f1aeb4d1c Mon Sep 17 00:00:00 2001 From: Petar Todorovic Date: Mon, 14 Apr 2025 15:08:06 +0200 Subject: [PATCH 1/2] feat: add txMeta arg to external provider sendTransaction --- .changeset/afraid-rats-sell.md | 5 +++++ .../widget/src/domain/types/external-providers.ts | 12 ++++++++---- packages/widget/src/domain/types/wallet.ts | 2 ++ .../src/domain/types/wallets/generic-wallet.ts | 6 +++++- .../src/pages/steps/hooks/use-steps-machine.hook.ts | 8 ++++++++ .../widget/src/pages/steps/hooks/use-steps.hook.ts | 1 + packages/widget/src/providers/sk-wallet/index.tsx | 7 +++++-- 7 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 .changeset/afraid-rats-sell.md diff --git a/.changeset/afraid-rats-sell.md b/.changeset/afraid-rats-sell.md new file mode 100644 index 00000000..2a8c1653 --- /dev/null +++ b/.changeset/afraid-rats-sell.md @@ -0,0 +1,5 @@ +--- +"@stakekit/widget": patch +--- + +feat: add txMeta arg to external provider sendTransaction diff --git a/packages/widget/src/domain/types/external-providers.ts b/packages/widget/src/domain/types/external-providers.ts index adb4b6f9..42206cda 100644 --- a/packages/widget/src/domain/types/external-providers.ts +++ b/packages/widget/src/domain/types/external-providers.ts @@ -1,3 +1,4 @@ +import type { ActionDto, TransactionDto } from "@stakekit/api-hooks"; import { EitherAsync, Left } from "purify-ts"; import type { RefObject } from "react"; import type { SKExternalProviders } from "./wallets"; @@ -10,15 +11,18 @@ export class ExternalProvider { return EitherAsync.liftEither(Left(new Error("Invalid provider type"))); } - sendTransaction(tx: EVMTx) { - const sendTransaction = + sendTransaction( + tx: EVMTx, + txMeta: { txId: TransactionDto["id"]; actionId: ActionDto["id"] } + ) { + const _sendTransaction = this.variantProvider.current.provider.sendTransaction; - if (!sendTransaction) { + if (!_sendTransaction) { return this.invalidProviderType(); } - return EitherAsync(() => sendTransaction(tx)).mapLeft((e) => { + return EitherAsync(() => _sendTransaction(tx, txMeta)).mapLeft((e) => { console.log(e); return new Error("Failed to send transaction"); }); diff --git a/packages/widget/src/domain/types/wallet.ts b/packages/widget/src/domain/types/wallet.ts index 65b6f035..f4f6740e 100644 --- a/packages/widget/src/domain/types/wallet.ts +++ b/packages/widget/src/domain/types/wallet.ts @@ -1,5 +1,6 @@ import type { Account } from "@ledgerhq/wallet-api-client"; import type { + ActionDto, AddressWithTokenDtoAdditionalAddresses, TransactionDto, } from "@stakekit/api-hooks"; @@ -19,6 +20,7 @@ export type SKWallet = { disconnect: () => Promise; signTransaction: (args: { tx: NonNullable; + txMeta: { txId: TransactionDto["id"]; actionId: ActionDto["id"] }; ledgerHwAppId: Nullable; }) => EitherAsync< TransactionDecodeError | SendTransactionError, diff --git a/packages/widget/src/domain/types/wallets/generic-wallet.ts b/packages/widget/src/domain/types/wallets/generic-wallet.ts index c3e647a2..da365168 100644 --- a/packages/widget/src/domain/types/wallets/generic-wallet.ts +++ b/packages/widget/src/domain/types/wallets/generic-wallet.ts @@ -1,3 +1,4 @@ +import type { ActionDto, TransactionDto } from "@stakekit/api-hooks"; import type { Hex } from "viem"; export enum TxType { @@ -27,5 +28,8 @@ export type EVMWallet = { signMessage: (message: string) => Promise; switchChain: (chainId: string) => Promise; getTransactionReceipt?(txHash: string): Promise<{ transactionHash?: string }>; - sendTransaction(tx: EVMTx): Promise; + sendTransaction( + tx: EVMTx, + txMeta: { txId: TransactionDto["id"]; actionId: ActionDto["id"] } + ): Promise; }; diff --git a/packages/widget/src/pages/steps/hooks/use-steps-machine.hook.ts b/packages/widget/src/pages/steps/hooks/use-steps-machine.hook.ts index 07354b80..77e2cdf9 100644 --- a/packages/widget/src/pages/steps/hooks/use-steps-machine.hook.ts +++ b/packages/widget/src/pages/steps/hooks/use-steps-machine.hook.ts @@ -58,9 +58,11 @@ type SignRes = export const useStepsMachine = ({ transactions, integrationId, + actionId, }: { transactions: ActionDto["transactions"]; integrationId: ActionDto["integrationId"]; + actionId: ActionDto["id"]; }) => { const { signTransaction, signMessage, isLedgerLive } = useSKWallet(); @@ -78,6 +80,7 @@ export const useStepsMachine = ({ trackEvent, signMessage, signTransaction, + actionId, }); return useMachine(useState(() => getMachine(machineParams))[0]); @@ -92,6 +95,7 @@ const getMachine = ( trackEvent: ReturnType; signMessage: ReturnType["signMessage"]; signTransaction: ReturnType["signTransaction"]; + actionId: ActionDto["id"]; }> > ) => { @@ -260,6 +264,10 @@ const getMachine = ( .signTransaction({ tx: constructedTx.unsignedTransaction, ledgerHwAppId: constructedTx.ledgerHwAppId, + txMeta: { + actionId: ref.current.actionId, + txId: constructedTx.id, + }, }) .map((val) => ({ ...val, diff --git a/packages/widget/src/pages/steps/hooks/use-steps.hook.ts b/packages/widget/src/pages/steps/hooks/use-steps.hook.ts index 7c15df1a..b6ce2e8e 100644 --- a/packages/widget/src/pages/steps/hooks/use-steps.hook.ts +++ b/packages/widget/src/pages/steps/hooks/use-steps.hook.ts @@ -24,6 +24,7 @@ export const useSteps = ({ const [machineState, send, actorRef] = useStepsMachine({ transactions: session.transactions, integrationId: session.integrationId, + actionId: session.id, }); /** diff --git a/packages/widget/src/providers/sk-wallet/index.tsx b/packages/widget/src/providers/sk-wallet/index.tsx index e58bc7c7..b547e9a0 100644 --- a/packages/widget/src/providers/sk-wallet/index.tsx +++ b/packages/widget/src/providers/sk-wallet/index.tsx @@ -158,7 +158,7 @@ export const SKWalletProvider = ({ children }: PropsWithChildren) => { ); const signTransaction = useCallback( - ({ tx, ledgerHwAppId }) => + ({ tx, ledgerHwAppId, txMeta }) => connectorDetails.chain< TransactionDecodeError | SendTransactionError | NotSupportedFlowError, { signedTx: string; broadcasted: boolean } @@ -254,7 +254,10 @@ export const SKWalletProvider = ({ children }: PropsWithChildren) => { }) ) .chain((val) => - conn.sendTransaction(prepareEVMTx({ address, decodedTx: val })) + conn.sendTransaction( + prepareEVMTx({ address, decodedTx: val }), + txMeta + ) ) .map((val) => ({ signedTx: val, broadcasted: true })); } From 9f2683dddbc85662942066126b0b979af7b5dd3f Mon Sep 17 00:00:00 2001 From: Petar Todorovic Date: Mon, 14 Apr 2025 15:09:23 +0200 Subject: [PATCH 2/2] fix: revert motion for useAnimate --- .changeset/flat-walls-jog.md | 5 +++++ packages/widget/package.json | 2 +- pnpm-lock.yaml | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/flat-walls-jog.md diff --git a/.changeset/flat-walls-jog.md b/.changeset/flat-walls-jog.md new file mode 100644 index 00000000..c7b25ec1 --- /dev/null +++ b/.changeset/flat-walls-jog.md @@ -0,0 +1,5 @@ +--- +"@stakekit/widget": patch +--- + +fix: revert motion for useAnimate diff --git a/packages/widget/package.json b/packages/widget/package.json index 18596d21..57eee749 100644 --- a/packages/widget/package.json +++ b/packages/widget/package.json @@ -111,7 +111,7 @@ "jsdom": "^26.1.0", "lodash.merge": "^4.6.2", "mixpanel-browser": "^2.63.0", - "motion": "^12.6.5", + "motion": "12.6.2", "msw": "^2.7.4", "postcss": "^8.5.3", "purify-ts": "2.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a55a603..e711fd60 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -305,8 +305,8 @@ importers: specifier: ^2.63.0 version: 2.63.0 motion: - specifier: ^12.6.5 - version: 12.6.5(react-dom@19.1.0(react@19.1.0))(react@19.1.0) + specifier: 12.6.2 + version: 12.6.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0) msw: specifier: ^2.7.4 version: 2.7.4(@types/node@22.14.1)(typescript@5.8.3) @@ -4618,8 +4618,8 @@ packages: motion@10.16.2: resolution: {integrity: sha512-p+PurYqfUdcJZvtnmAqu5fJgV2kR0uLFQuBKtLeFVTrYEVllI99tiOTSefVNYuip9ELTEkepIIDftNdze76NAQ==} - motion@12.6.5: - resolution: {integrity: sha512-X3IIy76nxyk4I87xQEm5Ah8ojQ4qisd+/H592eXF14ha+xqpbDJcWOSf9PEKCOCC0K4PN/0UBaz+MvSQUkIeXQ==} + motion@12.6.2: + resolution: {integrity: sha512-8OBjjuC59WuWHKmPzVWT5M0t5kDxtkfMfHF1M7Iey6F/nvd0AI15YlPnpGlcagW/eOfkdWDO90U/K5LF/k55Yw==} peerDependencies: '@emotion/is-prop-valid': '*' react: ^18.0.0 || ^19.0.0 @@ -12144,7 +12144,7 @@ snapshots: '@motionone/utils': 10.18.0 '@motionone/vue': 10.16.4 - motion@12.6.5(react-dom@19.1.0(react@19.1.0))(react@19.1.0): + motion@12.6.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0): dependencies: framer-motion: 12.6.5(react-dom@19.1.0(react@19.1.0))(react@19.1.0) tslib: 2.8.1