Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-rats-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stakekit/widget": patch
---

feat: add txMeta arg to external provider sendTransaction
5 changes: 5 additions & 0 deletions .changeset/flat-walls-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stakekit/widget": patch
---

fix: revert motion for useAnimate
2 changes: 1 addition & 1 deletion packages/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions packages/widget/src/domain/types/external-providers.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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");
});
Expand Down
2 changes: 2 additions & 0 deletions packages/widget/src/domain/types/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Account } from "@ledgerhq/wallet-api-client";
import type {
ActionDto,
AddressWithTokenDtoAdditionalAddresses,
TransactionDto,
} from "@stakekit/api-hooks";
Expand All @@ -19,6 +20,7 @@ export type SKWallet = {
disconnect: () => Promise<void>;
signTransaction: (args: {
tx: NonNullable<TransactionDto["unsignedTransaction"]>;
txMeta: { txId: TransactionDto["id"]; actionId: ActionDto["id"] };
ledgerHwAppId: Nullable<string>;
}) => EitherAsync<
TransactionDecodeError | SendTransactionError,
Expand Down
6 changes: 5 additions & 1 deletion packages/widget/src/domain/types/wallets/generic-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ActionDto, TransactionDto } from "@stakekit/api-hooks";
import type { Hex } from "viem";

export enum TxType {
Expand Down Expand Up @@ -27,5 +28,8 @@ export type EVMWallet = {
signMessage: (message: string) => Promise<string>;
switchChain: (chainId: string) => Promise<void>;
getTransactionReceipt?(txHash: string): Promise<{ transactionHash?: string }>;
sendTransaction(tx: EVMTx): Promise<string>;
sendTransaction(
tx: EVMTx,
txMeta: { txId: TransactionDto["id"]; actionId: ActionDto["id"] }
): Promise<string>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -78,6 +80,7 @@ export const useStepsMachine = ({
trackEvent,
signMessage,
signTransaction,
actionId,
});

return useMachine(useState(() => getMachine(machineParams))[0]);
Expand All @@ -92,6 +95,7 @@ const getMachine = (
trackEvent: ReturnType<typeof useTrackEvent>;
signMessage: ReturnType<typeof useSKWallet>["signMessage"];
signTransaction: ReturnType<typeof useSKWallet>["signTransaction"];
actionId: ActionDto["id"];
}>
>
) => {
Expand Down Expand Up @@ -260,6 +264,10 @@ const getMachine = (
.signTransaction({
tx: constructedTx.unsignedTransaction,
ledgerHwAppId: constructedTx.ledgerHwAppId,
txMeta: {
actionId: ref.current.actionId,
txId: constructedTx.id,
},
})
.map((val) => ({
...val,
Expand Down
1 change: 1 addition & 0 deletions packages/widget/src/pages/steps/hooks/use-steps.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const useSteps = ({
const [machineState, send, actorRef] = useStepsMachine({
transactions: session.transactions,
integrationId: session.integrationId,
actionId: session.id,
});

/**
Expand Down
7 changes: 5 additions & 2 deletions packages/widget/src/providers/sk-wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const SKWalletProvider = ({ children }: PropsWithChildren) => {
);

const signTransaction = useCallback<SKWallet["signTransaction"]>(
({ tx, ledgerHwAppId }) =>
({ tx, ledgerHwAppId, txMeta }) =>
connectorDetails.chain<
TransactionDecodeError | SendTransactionError | NotSupportedFlowError,
{ signedTx: string; broadcasted: boolean }
Expand Down Expand Up @@ -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 }));
}
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

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