Skip to content

Commit 5a74f0f

Browse files
committed
✨ support eip-5792 calls
1 parent f93cb5e commit 5a74f0f

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default defineConfig({
2727
"@eslint-react/dom/no-missing-iframe-sandbox": "off",
2828
"@typescript-eslint/no-deprecated": "warn",
2929
"unicorn/filename-case": "off",
30+
"unicorn/no-await-expression-member": "off",
3031
"unicorn/no-null": "off",
3132
"unicorn/prefer-global-this": "off",
3233
"unicorn/prevent-abbreviations": ["error", { allowList: { params: true } }],

src/App.tsx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import { SequenceConnect, useOpenConnectModal } from "@0xsequence/connect";
2-
import { getAccount, getChainId, signMessage, switchChain } from "@wagmi/core";
1+
import { sendTransactions, SequenceConnect, useOpenConnectModal } from "@0xsequence/connect";
2+
import { SequenceIndexer } from "@0xsequence/indexer";
3+
import {
4+
getAccount,
5+
getCallsStatus,
6+
getChainId,
7+
getPublicClient,
8+
getWalletClient,
9+
signMessage,
10+
switchChain,
11+
} from "@wagmi/core";
312
import { useLayoutEffect, useRef } from "react";
13+
import { concat, numberToHex } from "viem";
414
import { useAccount, useDisconnect } from "wagmi";
515

16+
import { ChainId, networks } from "@0xsequence/network";
617
import hostExaApp from "./hostExaApp"; // host SDK: expose APIs to the iframe
718
import { connectConfig, wagmiConfig } from "./sequence";
819

@@ -38,6 +49,36 @@ function App() {
3849
if (!Array.isArray(params) || params.length !== 2) throw new Error("bad params");
3950
if (params[1] !== getAccount(wagmiConfig).address) throw new Error("bad account");
4051
return signMessage(wagmiConfig, { message: { raw: params[0] } });
52+
case "wallet_sendCalls": {
53+
if (!Array.isArray(params) || params.length !== 1) throw new Error("bad params");
54+
const { address, chainId, connector } = getAccount(wagmiConfig);
55+
if (!address || !chainId || !connector) throw new Error("not connected");
56+
if (params[0].from && params[0].from !== address) throw new Error("bad account");
57+
if (params[0].chainId && Number(params[0].chainId) !== chainId) throw new Error("bad chain id");
58+
const hashes = await Promise.all(
59+
(
60+
await sendTransactions({
61+
chainId,
62+
connector,
63+
senderAddress: address,
64+
publicClient: getPublicClient(wagmiConfig)!,
65+
walletClient: await getWalletClient(wagmiConfig)!,
66+
indexerClient: new SequenceIndexer(
67+
`https://${networks[chainId as ChainId]!.name}-indexer.sequence.app`,
68+
connectConfig.projectAccessKey,
69+
),
70+
transactions: (
71+
params[0].calls as { to: `0x${string}`; data?: `0x${string}`; value?: `0x${string}` }[]
72+
).map(({ to, data, value }) => ({ to, data, value: value && BigInt(value) })),
73+
waitConfirmationForLastTransaction: false,
74+
})
75+
).map((send) => send() as Promise<`0x${string}`>),
76+
);
77+
return { id: concat([...hashes, numberToHex(chainId, { size: 32 }), TX_MAGIC_ID]) };
78+
}
79+
case "wallet_getCallsStatus":
80+
if (!Array.isArray(params) || params.length !== 1 || typeof params[0] !== "string") throw new Error("bad");
81+
return getCallsStatus(wagmiConfig, { id: params[0] });
4182
default:
4283
throw new Error(`${method} not supported`);
4384
}
@@ -75,3 +116,5 @@ export default function Layout() {
75116
</SequenceConnect>
76117
);
77118
}
119+
120+
const TX_MAGIC_ID = "0x5792579257925792579257925792579257925792579257925792579257925792" as const;

0 commit comments

Comments
 (0)