Skip to content

Commit 940ee07

Browse files
committed
chore: clean up
1 parent faac513 commit 940ee07

5 files changed

Lines changed: 63 additions & 14 deletions

File tree

demo/wagmi-react-app/src/components/Main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ const Main = () => {
254254
{
255255
calls: [
256256
{
257-
to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" as `0x${string}`,
257+
to: address as `0x${string}`,
258258
value: parseEther("0.0001"),
259259
},
260260
{
261-
to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" as `0x${string}`,
261+
to: address as `0x${string}`,
262262
value: parseEther("0.0002"),
263263
},
264264
],

packages/no-modal/src/connectors/wallet-connect-v2-connector/walletConnectV2Utils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { bs58 as base58 } from "@toruslabs/bs58";
2-
import { EIP_5792_METHODS, Eip5792GetCapabilitiesParams, Eip5792SendCallsParams } from "@toruslabs/ethereum-controllers";
2+
import {
3+
EIP_5792_METHODS,
4+
Eip5792GetCapabilitiesParams,
5+
Eip5792SendCallsParams,
6+
Eip5792ShowCallsStatusParams,
7+
} from "@toruslabs/ethereum-controllers";
38
import type { ISignClient, SessionTypes } from "@walletconnect/types";
49
import { getAccountsFromNamespaces, parseAccountId } from "@walletconnect/utils";
510
import { type JRPCRequest, providerErrors, rpcErrors } from "@web3auth/auth";
611
import { EVM_METHOD_TYPES, SOLANA_METHOD_TYPES } from "@web3auth/ws-embed";
7-
import { GetCapabilitiesReturnType, isHex, SendCallsReturnType, WalletGetCallsStatusReturnType } from "viem";
12+
import type { GetCapabilitiesReturnType, SendCallsReturnType, WalletGetCallsStatusReturnType } from "viem";
813

914
import { AddEthereumChainConfig, SOLANA_CAIP_CHAIN_MAP, WalletLoginError } from "../../base";
1015
import type { IEthProviderHandlers, MessageParams, TransactionParams, TypedMessageParams } from "../../providers/ethereum-provider";
@@ -137,10 +142,6 @@ export function getEthProviderHandlers({ connector, chainId }: { connector: ISig
137142
},
138143
// EIP-5792: wallet_getCallsStatus
139144
processGetCallsStatus: async (batchId: string) => {
140-
if (!isHex(batchId)) {
141-
throw rpcErrors.invalidParams("Invalid batchId");
142-
}
143-
144145
const results = await sendJrpcRequest<WalletGetCallsStatusReturnType, string[]>(
145146
connector,
146147
`eip155:${chainId}`,
@@ -149,6 +150,10 @@ export function getEthProviderHandlers({ connector, chainId }: { connector: ISig
149150
);
150151
return results;
151152
},
153+
// EIP-5792: wallet_showCallsStatus
154+
processShowCallsStatus: async (batchId: Eip5792ShowCallsStatusParams) => {
155+
await sendJrpcRequest<void, string[]>(connector, `eip155:${chainId}`, EIP_5792_METHODS.WALLET_SHOW_CALLS_STATUS, [batchId]);
156+
},
152157
};
153158
}
154159

packages/no-modal/src/providers/ethereum-provider/rpc/ethRpcMiddlewares.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function createEthMiddleware(providerHandlers: IEthProviderHandlers): JRP
2525
processGetCapabilities,
2626
processSendCalls,
2727
processGetCallsStatus,
28+
processShowCallsStatus,
2829
} = providerHandlers;
2930
const ethMiddleware = mergeMiddleware([
3031
createScaffoldMiddleware({
@@ -42,6 +43,7 @@ export function createEthMiddleware(providerHandlers: IEthProviderHandlers): JRP
4243
processGetCapabilities,
4344
processSendCalls,
4445
processGetCallsStatus,
46+
processShowCallsStatus,
4547
}) as JRPCMiddleware<unknown, unknown>,
4648
]);
4749
return ethMiddleware;

packages/no-modal/src/providers/ethereum-provider/rpc/interfaces.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Eip5792GetCapabilitiesParams, Eip5792SendCallsParams } from "@toruslabs/ethereum-controllers";
1+
import { Eip5792GetCapabilitiesParams, Eip5792SendCallsParams, Eip5792ShowCallsStatusParams } from "@toruslabs/ethereum-controllers";
22
import type { JRPCRequest } from "@web3auth/auth";
33
import type { TransactionLike, TypedDataDomain, TypedDataField } from "ethers";
4-
import { GetCapabilitiesReturnType, SendCallsReturnType, WalletGetCallsStatusReturnType } from "viem";
4+
import type { GetCapabilitiesReturnType, SendCallsReturnType, WalletGetCallsStatusReturnType } from "viem";
55

66
import { AddEthereumChainConfig } from "../../../base";
77
export interface IEthAccountHandlers {
@@ -60,6 +60,7 @@ export interface WalletMiddlewareOptions {
6060
processGetCapabilities?: (req: Eip5792GetCapabilitiesParams) => Promise<GetCapabilitiesReturnType>;
6161
processSendCalls?: (params: Eip5792SendCallsParams) => Promise<SendCallsReturnType>;
6262
processGetCallsStatus?: (batchId: string) => Promise<WalletGetCallsStatusReturnType>;
63+
processShowCallsStatus?: (batchId: Eip5792ShowCallsStatusParams) => Promise<void>;
6364
}
6465

6566
export type IEthProviderHandlers = WalletMiddlewareOptions;

packages/no-modal/src/providers/ethereum-provider/rpc/walletMidddleware.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Eip5792GetCapabilitiesParams, Eip5792SendCallsParams } from "@toruslabs/ethereum-controllers";
1+
import { Eip5792GetCapabilitiesParams, Eip5792SendCallsParams, SUPPORTED_EIP_5792_VERSIONS } from "@toruslabs/ethereum-controllers";
22
import { createAsyncMiddleware, createScaffoldMiddleware, JRPCMiddleware, JRPCRequest, JRPCResponse, rpcErrors } from "@web3auth/auth";
33
import { isHex, toHex } from "viem";
44

@@ -16,6 +16,7 @@ export function createWalletMiddleware({
1616
processGetCapabilities,
1717
processSendCalls,
1818
processGetCallsStatus,
19+
processShowCallsStatus,
1920
}: WalletMiddlewareOptions): JRPCMiddleware<string, unknown> {
2021
if (!getAccounts) {
2122
throw new Error("opts.getAccounts is required");
@@ -221,6 +222,28 @@ export function createWalletMiddleware({
221222
}
222223

223224
const params = Array.isArray(req.params) ? req.params[0] : req.params;
225+
if (!params || typeof params !== "object") {
226+
throw rpcErrors.invalidParams("Missing or invalid params for wallet_sendCalls");
227+
}
228+
229+
if (!params.version || !SUPPORTED_EIP_5792_VERSIONS.includes(params.version)) {
230+
throw rpcErrors.invalidParams(
231+
`Invalid version: expected one of ${SUPPORTED_EIP_5792_VERSIONS.join(", ")}, got "${params.version || "undefined"}"`
232+
);
233+
}
234+
235+
if (!params.chainId) {
236+
throw rpcErrors.invalidParams("Missing required field: chainId");
237+
}
238+
239+
if (!Array.isArray(params.calls) || params.calls.length === 0) {
240+
throw rpcErrors.invalidParams("calls must be a non-empty array");
241+
}
242+
243+
const from = params.from as string | undefined;
244+
if (from) {
245+
await validateAndNormalizeKeyholder(from, req);
246+
}
224247

225248
const walletSendCallsParams: Eip5792SendCallsParams = {
226249
...params,
@@ -236,10 +259,27 @@ export function createWalletMiddleware({
236259
}
237260

238261
const batchId = Array.isArray(req.params) ? req.params[0] : (req.params as string);
262+
if (!batchId || typeof batchId !== "string") {
263+
throw rpcErrors.invalidParams("Missing or invalid batchId");
264+
}
239265

240266
res.result = await processGetCallsStatus(batchId);
241267
}
242268

269+
async function walletShowCallsStatusMiddleware(req: JRPCRequest<unknown>, res: JRPCResponse<unknown>): Promise<void> {
270+
if (!processShowCallsStatus) {
271+
throw rpcErrors.methodNotSupported();
272+
}
273+
274+
const batchId = Array.isArray(req.params) ? req.params[0] : (req.params as string);
275+
if (!batchId || typeof batchId !== "string") {
276+
throw rpcErrors.invalidParams("Missing or invalid batchId");
277+
}
278+
279+
await processShowCallsStatus(batchId);
280+
res.result = true;
281+
}
282+
243283
return createScaffoldMiddleware({
244284
// account lookups
245285
eth_accounts: createAsyncMiddleware(lookupAccounts),
@@ -256,8 +296,9 @@ export function createWalletMiddleware({
256296
eth_signTypedData_v4: createAsyncMiddleware(signTypedDataV4),
257297
personal_sign: createAsyncMiddleware(personalSign),
258298
// EIP-5792
259-
wallet_getCapabilities: createAsyncMiddleware(getWalletCapabilitiesMiddleware), // EIP-5792: Wallet Capabilities
260-
wallet_sendCalls: createAsyncMiddleware(walletSendCallsMiddleware), // EIP-5792: Send Batch Calls
261-
wallet_getCallsStatus: createAsyncMiddleware(walletBatchCallStatusMiddleware), // EIP-5792: Batch Call Status
299+
wallet_getCapabilities: createAsyncMiddleware(getWalletCapabilitiesMiddleware),
300+
wallet_sendCalls: createAsyncMiddleware(walletSendCallsMiddleware),
301+
wallet_getCallsStatus: createAsyncMiddleware(walletBatchCallStatusMiddleware),
302+
wallet_showCallsStatus: createAsyncMiddleware(walletShowCallsStatusMiddleware),
262303
});
263304
}

0 commit comments

Comments
 (0)