From 8416fd1031489f3e0d99592ad5aa1bc10135ec65 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Wed, 3 Apr 2024 17:54:22 +1100 Subject: [PATCH] tweak(experimental): getCallsStatus -> getCallsReceipt --- ...getCallsStatus.mdx => getCallsReceipt.mdx} | 8 +++--- .../experimental/actions/getCapabilities.mdx | 2 +- site/pages/experimental/actions/sendCalls.mdx | 6 ++-- .../experimental/actions/writeContracts.mdx | 6 ++-- site/pages/experimental/client.mdx | 2 +- site/sidebar.ts | 4 +-- src/CHANGELOG.md | 2 +- ...Status.test.ts => getCallsReceipt.test.ts} | 10 +++---- .../{getCallsStatus.ts => getCallsReceipt.ts} | 28 +++++++++---------- .../actions/writeContracts.test.ts | 10 +++---- src/experimental/decorators/eip5792.test.ts | 10 ++++--- src/experimental/decorators/eip5792.ts | 24 ++++++++-------- src/experimental/index.ts | 10 +++---- src/index.ts | 4 +-- src/types/eip1193.ts | 12 ++++---- 15 files changed, 70 insertions(+), 68 deletions(-) rename site/pages/experimental/actions/{getCallsStatus.mdx => getCallsReceipt.mdx} (78%) rename src/experimental/actions/{getCallsStatus.test.ts => getCallsReceipt.test.ts} (93%) rename src/experimental/actions/{getCallsStatus.ts => getCallsReceipt.ts} (63%) diff --git a/site/pages/experimental/actions/getCallsStatus.mdx b/site/pages/experimental/actions/getCallsReceipt.mdx similarity index 78% rename from site/pages/experimental/actions/getCallsStatus.mdx rename to site/pages/experimental/actions/getCallsReceipt.mdx index b30c386919..16c5454a38 100644 --- a/site/pages/experimental/actions/getCallsStatus.mdx +++ b/site/pages/experimental/actions/getCallsReceipt.mdx @@ -2,11 +2,11 @@ description: Returns the status and receipts of a call batch. --- -# getCallsStatus +# getCallsReceipt Returns the status and receipts of a call batch that was sent via `sendCalls`. -[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_getcallsstatus) +[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_getcallsreceipt) :::warning[Warning] This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production. @@ -19,7 +19,7 @@ This is an experimental action that is not supported in most wallets. It is reco ```ts twoslash [example.ts] import { walletClient } from './config' -const { status, receipts } = await walletClient.getCallsStatus({ // [!code focus:99] +const { status, receipts } = await walletClient.getCallsReceipt({ // [!code focus:99] id: '0x1234567890abcdef', }) ``` @@ -43,7 +43,7 @@ export const [account] = await walletClient.getAddresses() ## Returns -`WalletGetCallsStatusReturnType` +`WalletGetCallsReceiptReturnType` Status and receipts of the calls. diff --git a/site/pages/experimental/actions/getCapabilities.mdx b/site/pages/experimental/actions/getCapabilities.mdx index 617fd85224..abc33944a2 100644 --- a/site/pages/experimental/actions/getCapabilities.mdx +++ b/site/pages/experimental/actions/getCapabilities.mdx @@ -6,7 +6,7 @@ description: Extract capabilities that a connected wallet supports. Extract capabilities (grouped by chain ID) that a connected wallet supports (e.g. paymasters, session keys, etc). -[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_getcapabilities) +[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_getcapabilities) :::warning[Warning] This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production. diff --git a/site/pages/experimental/actions/sendCalls.mdx b/site/pages/experimental/actions/sendCalls.mdx index 6b3968b0d7..7a7dd9530f 100644 --- a/site/pages/experimental/actions/sendCalls.mdx +++ b/site/pages/experimental/actions/sendCalls.mdx @@ -6,7 +6,7 @@ description: Sign and broadcast a batch of calls to the network. Requests for the wallet to sign and broadcast a batch of calls (transactions) to the network. -[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls) +[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls) :::warning[Warning] This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production. @@ -56,7 +56,7 @@ Notes: - `account` and `chain` are top level properties as all calls should be sent by the same account and chain. - Properties of `calls` items are only those shared by all transaction types (e.g. `data`, `to`, `value`). The Wallet should handle other required properties like gas & fees. -- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls) +- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls) ### Account Hoisting @@ -105,7 +105,7 @@ export const walletClient = createWalletClient({ `string` -The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsStatus` with this identifier to retreive a batch call status and call receipts. +The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsReceipt` with this identifier to retreive a batch call status and call receipts. ## Parameters diff --git a/site/pages/experimental/actions/writeContracts.mdx b/site/pages/experimental/actions/writeContracts.mdx index 76edef8f26..124b934de5 100644 --- a/site/pages/experimental/actions/writeContracts.mdx +++ b/site/pages/experimental/actions/writeContracts.mdx @@ -6,7 +6,7 @@ description: Sign and broadcast a batch of write contract calls to the network. Requests for the wallet to sign and broadcast a batch of write contract calls (transactions) to the network. -[Read more.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls) +[Read more.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls) :::warning[Warning] This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production. @@ -72,7 +72,7 @@ Notes: - Internally calls [`sendCalls`](/experimental/actions/writeContracts) - `account` and `chain` are top level properties as all calls should be sent by the same account and chain. -- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md#wallet_sendcalls) +- [Read `wallet_sendCalls` on EIP-5792.](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md#wallet_sendcalls) ### Account Hoisting @@ -138,7 +138,7 @@ export const walletClient = createWalletClient({ `string` -The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsStatus` with this identifier to retreive a batch call status and call receipts. +The identifier can be any arbitrary string. The only requirement is that for a given session, consumers should be able to call `getCallsReceipt` with this identifier to retreive a batch call status and call receipts. ## Parameters diff --git a/site/pages/experimental/client.mdx b/site/pages/experimental/client.mdx index aaf0b77980..8c63a63987 100644 --- a/site/pages/experimental/client.mdx +++ b/site/pages/experimental/client.mdx @@ -6,7 +6,7 @@ To use the experimental functionality of Viem, you must extend your existing (or ### `walletActionsEip5792` -A suite of [EIP-5792 Wallet Actions](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md) for suited for development with wallet's that support batch transactions. +A suite of [EIP-5792 Wallet Actions](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md) for suited for development with wallet's that support batch transactions. ```ts import { createPublicClient, createWalletClient, http } from 'viem' diff --git a/site/sidebar.ts b/site/sidebar.ts index d28ab5c194..8f5ce908c8 100644 --- a/site/sidebar.ts +++ b/site/sidebar.ts @@ -1013,8 +1013,8 @@ export const sidebar = { text: 'EIP-5792', items: [ { - text: 'getCallsStatus', - link: '/experimental/actions/getCallsStatus', + text: 'getCallsReceipt', + link: '/experimental/actions/getCallsReceipt', }, { text: 'getCapabilities', diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 6716fe8324..6d12025af6 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -10,7 +10,7 @@ ### Patch Changes -- [#2053](https://github.com/wevm/viem/pull/2053) [`e53fe120b9c15dde3e50eda794e261f320bf52bc`](https://github.com/wevm/viem/commit/e53fe120b9c15dde3e50eda794e261f320bf52bc) Thanks [@jxom](https://github.com/jxom)! - Added experimental support for [EIP-5792 `wallet_` methods](https://github.com/ethereum/EIPs/blob/1d759f24e6552a516091bb1fe3361d9ca44d085c/EIPS/eip-5792.md). +- [#2053](https://github.com/wevm/viem/pull/2053) [`e53fe120b9c15dde3e50eda794e261f320bf52bc`](https://github.com/wevm/viem/commit/e53fe120b9c15dde3e50eda794e261f320bf52bc) Thanks [@jxom](https://github.com/jxom)! - Added experimental support for [EIP-5792 `wallet_` methods](https://github.com/ethereum/EIPs/blob/815028dc634463e1716fc5ce44c019a6040f0bef/EIPS/eip-5792.md). - [#2052](https://github.com/wevm/viem/pull/2052) [`445ec244c7be329eb26048102d282bac9bf23506`](https://github.com/wevm/viem/commit/445ec244c7be329eb26048102d282bac9bf23506) Thanks [@maggo](https://github.com/maggo)! - Added WebSocket RPC URL on Degen chain. diff --git a/src/experimental/actions/getCallsStatus.test.ts b/src/experimental/actions/getCallsReceipt.test.ts similarity index 93% rename from src/experimental/actions/getCallsStatus.test.ts rename to src/experimental/actions/getCallsReceipt.test.ts index 994cc7e5b1..751de71f3d 100644 --- a/src/experimental/actions/getCallsStatus.test.ts +++ b/src/experimental/actions/getCallsReceipt.test.ts @@ -6,11 +6,11 @@ import { mainnet } from '../../chains/index.js' import { createClient } from '../../clients/createClient.js' import { custom } from '../../clients/transports/custom.js' import { RpcRequestError } from '../../errors/request.js' -import type { WalletGetCallsStatusReceipt } from '../../types/eip1193.js' +import type { WalletCallReceipt } from '../../types/eip1193.js' import type { Hex } from '../../types/misc.js' import { getHttpRpcClient, parseEther } from '../../utils/index.js' import { uid } from '../../utils/uid.js' -import { getCallsStatus } from './getCallsStatus.js' +import { getCallsReceipt } from './getCallsReceipt.js' import { sendCalls } from './sendCalls.js' type Uid = string @@ -27,7 +27,7 @@ const getClient = ({ const rpcClient = getHttpRpcClient(localHttpUrl) - if (method === 'wallet_getCallsStatus') { + if (method === 'wallet_getCallsReceipt') { const hashes = calls.get(params) if (!hashes) return null const receipts = await Promise.all( @@ -52,7 +52,7 @@ const getClient = ({ logs: result.logs, status: result.status, transactionHash: result.transactionHash, - } satisfies WalletGetCallsStatusReceipt + } satisfies WalletCallReceipt }), ) return { status: 'CONFIRMED', receipts } @@ -118,7 +118,7 @@ test('default', async () => { await mine(testClient, { blocks: 1 }) - const { status, receipts } = await getCallsStatus(client, { id }) + const { status, receipts } = await getCallsReceipt(client, { id }) expect(status).toMatchInlineSnapshot(`"CONFIRMED"`) expect(receipts![0].blockHash).toBeDefined() expect( diff --git a/src/experimental/actions/getCallsStatus.ts b/src/experimental/actions/getCallsReceipt.ts similarity index 63% rename from src/experimental/actions/getCallsStatus.ts rename to src/experimental/actions/getCallsReceipt.ts index 544fb4d058..ce921d4308 100644 --- a/src/experimental/actions/getCallsStatus.ts +++ b/src/experimental/actions/getCallsReceipt.ts @@ -3,50 +3,50 @@ import type { Transport } from '../../clients/transports/createTransport.js' import type { ErrorType } from '../../errors/utils.js' import type { Account } from '../../types/account.js' import type { Chain } from '../../types/chain.js' -import type { WalletGetCallsStatusReturnType } from '../../types/eip1193.js' +import type { WalletGetCallsReceiptReturnType } from '../../types/eip1193.js' import type { Prettify } from '../../types/utils.js' import type { RequestErrorType } from '../../utils/buildRequest.js' import { hexToBigInt } from '../../utils/encoding/fromHex.js' import { receiptStatuses } from '../../utils/formatters/transactionReceipt.js' -export type GetCallsStatusParameters = { id: string } +export type GetCallsReceiptParameters = { id: string } -export type GetCallsStatusReturnType = Prettify< - WalletGetCallsStatusReturnType +export type GetCallsReceiptReturnType = Prettify< + WalletGetCallsReceiptReturnType > -export type GetCallsStatusErrorType = RequestErrorType | ErrorType +export type GetCallsReceiptErrorType = RequestErrorType | ErrorType /** * Returns the status of a call batch that was sent via `sendCalls`. * - * - Docs: https://viem.sh/experimental/actions/getCallsStatus - * - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792) + * - Docs: https://viem.sh/experimental/actions/getCallsReceipt + * - JSON-RPC Methods: [`wallet_getCallsReceipt`](https://eips.ethereum.org/EIPS/eip-5792) * * @param client - Client to use - * @returns Status of the calls. {@link GetCallsStatusReturnType} + * @returns Status of the calls. {@link GetCallsReceiptReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { getCallsStatus } from 'viem/wallet' + * import { getCallsReceipt } from 'viem/wallet' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) - * const { receipts, status } = await getCallsStatus(client, { id: '0xdeadbeef' }) + * const { receipts, status } = await getCallsReceipt(client, { id: '0xdeadbeef' }) */ -export async function getCallsStatus< +export async function getCallsReceipt< chain extends Chain | undefined, account extends Account | undefined = undefined, >( client: Client, - parameters: GetCallsStatusParameters, -): Promise { + parameters: GetCallsReceiptParameters, +): Promise { const { id } = parameters const { receipts, status } = await client.request({ - method: 'wallet_getCallsStatus', + method: 'wallet_getCallsReceipt', params: id, }) return { diff --git a/src/experimental/actions/writeContracts.test.ts b/src/experimental/actions/writeContracts.test.ts index 8ca5721288..65b24dbecb 100644 --- a/src/experimental/actions/writeContracts.test.ts +++ b/src/experimental/actions/writeContracts.test.ts @@ -7,11 +7,11 @@ import { mainnet } from '../../chains/index.js' import { createClient } from '../../clients/createClient.js' import { custom } from '../../clients/transports/custom.js' import { RpcRequestError } from '../../errors/request.js' -import type { WalletGetCallsStatusReceipt } from '../../types/eip1193.js' +import type { WalletCallReceipt } from '../../types/eip1193.js' import type { Hex } from '../../types/misc.js' import { getHttpRpcClient } from '../../utils/index.js' import { uid } from '../../utils/uid.js' -import { getCallsStatus } from './getCallsStatus.js' +import { getCallsReceipt } from './getCallsReceipt.js' import { writeContracts } from './writeContracts.js' type Uid = string @@ -28,7 +28,7 @@ const getClient = ({ const rpcClient = getHttpRpcClient(localHttpUrl) - if (method === 'wallet_getCallsStatus') { + if (method === 'wallet_getCallsReceipt') { const hashes = calls.get(params) if (!hashes) return null const receipts = await Promise.all( @@ -54,7 +54,7 @@ const getClient = ({ logs: result.logs, status: result.status, transactionHash: result.transactionHash, - } satisfies WalletGetCallsStatusReceipt + } satisfies WalletCallReceipt }), ) return { status: 'CONFIRMED', receipts } @@ -158,7 +158,7 @@ test('default', async () => { await mine(testClient, { blocks: 3 }) - const { receipts } = await getCallsStatus(client, { id: id_ }) + const { receipts } = await getCallsReceipt(client, { id: id_ }) expect( receipts?.map((receipt) => ({ diff --git a/src/experimental/decorators/eip5792.test.ts b/src/experimental/decorators/eip5792.test.ts index ae3b3688d4..e7b2efb715 100644 --- a/src/experimental/decorators/eip5792.test.ts +++ b/src/experimental/decorators/eip5792.test.ts @@ -26,7 +26,7 @@ const client = createClient({ }, } if (method === 'wallet_sendCalls') return '0x1' - if (method === 'wallet_getCallsStatus') + if (method === 'wallet_getCallsReceipt') return { status: 'CONFIRMED', receipts: [ @@ -50,7 +50,7 @@ const client = createClient({ test('default', async () => { expect(walletActionsEip5792()(client)).toMatchInlineSnapshot(` { - "getCallsStatus": [Function], + "getCallsReceipt": [Function], "getCapabilities": [Function], "sendCalls": [Function], "writeContracts": [Function], @@ -79,8 +79,10 @@ describe('smoke test', () => { `) }) - test('getCallsStatus', async () => { - expect(await client.getCallsStatus({ id: '0x123' })).toMatchInlineSnapshot(` + test('getCallsReceipt', async () => { + expect( + await client.getCallsReceipt({ id: '0x123' }), + ).toMatchInlineSnapshot(` { "receipts": [ { diff --git a/src/experimental/decorators/eip5792.ts b/src/experimental/decorators/eip5792.ts index 5f80f7158c..50ce8f1f22 100644 --- a/src/experimental/decorators/eip5792.ts +++ b/src/experimental/decorators/eip5792.ts @@ -3,10 +3,10 @@ import type { Transport } from '../../clients/transports/createTransport.js' import type { Account } from '../../types/account.js' import type { Chain } from '../../types/chain.js' import { - type GetCallsStatusParameters, - type GetCallsStatusReturnType, - getCallsStatus, -} from '../actions/getCallsStatus.js' + type GetCallsReceiptParameters, + type GetCallsReceiptReturnType, + getCallsReceipt, +} from '../actions/getCallsReceipt.js' import { type GetCapabilitiesReturnType, getCapabilities, @@ -29,11 +29,11 @@ export type WalletActionsEip5792< /** * Returns the status of a call batch that was sent via `sendCalls`. * - * - Docs: https://viem.sh/experimental/actions/getCallsStatus - * - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792) + * - Docs: https://viem.sh/experimental/actions/getCallsReceipt + * - JSON-RPC Methods: [`wallet_getCallsReceipt`](https://eips.ethereum.org/EIPS/eip-5792) * * @param client - Client to use - * @returns Status of the calls. {@link GetCallsStatusReturnType} + * @returns Status of the calls. {@link GetCallsReceiptReturnType} * * @example * import { createWalletClient, custom } from 'viem' @@ -45,11 +45,11 @@ export type WalletActionsEip5792< * transport: custom(window.ethereum), * }).extend(walletActionsEip5792()) * - * const { receipts, status } = await client.getCallsStatus({ id: '0xdeadbeef' }) + * const { receipts, status } = await client.getCallsReceipt({ id: '0xdeadbeef' }) */ - getCallsStatus: ( - parameters: GetCallsStatusParameters, - ) => Promise + getCallsReceipt: ( + parameters: GetCallsReceiptParameters, + ) => Promise /** * Extract capabilities that a connected wallet supports (e.g. paymasters, session keys, etc). * @@ -191,7 +191,7 @@ export function walletActionsEip5792() { client: Client, ): WalletActionsEip5792 => { return { - getCallsStatus: (parameters) => getCallsStatus(client, parameters), + getCallsReceipt: (parameters) => getCallsReceipt(client, parameters), getCapabilities: () => getCapabilities(client), sendCalls: (parameters) => sendCalls(client, parameters), writeContracts: (parameters) => writeContracts(client, parameters), diff --git a/src/experimental/index.ts b/src/experimental/index.ts index b2f5841797..89caddfdf6 100644 --- a/src/experimental/index.ts +++ b/src/experimental/index.ts @@ -10,11 +10,11 @@ export { sendCalls, } from './actions/sendCalls.js' export { - type GetCallsStatusErrorType, - type GetCallsStatusParameters, - type GetCallsStatusReturnType, - getCallsStatus, -} from './actions/getCallsStatus.js' + type GetCallsReceiptErrorType, + type GetCallsReceiptParameters, + type GetCallsReceiptReturnType, + getCallsReceipt, +} from './actions/getCallsReceipt.js' export { type WriteContractsErrorType, type WriteContractsParameters, diff --git a/src/index.ts b/src/index.ts index a6909c1b0e..fe3973f74c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1001,8 +1001,8 @@ export type { TestRpcSchema, WalletCapabilities, WalletCapabilitiesRecord, - WalletGetCallsStatusReceipt, - WalletGetCallsStatusReturnType, + WalletCallReceipt, + WalletGetCallsReceiptReturnType, WalletSendCallsParameters, WalletPermissionCaveat, WalletPermission, diff --git a/src/types/eip1193.ts b/src/types/eip1193.ts index 156797e61b..f080a675af 100644 --- a/src/types/eip1193.ts +++ b/src/types/eip1193.ts @@ -118,7 +118,7 @@ export type WalletCapabilitiesRecord< [chainId in id]: capabilities } -export type WalletGetCallsStatusReceipt = { +export type WalletCallReceipt = { logs: { address: Hex data: Hex @@ -131,9 +131,9 @@ export type WalletGetCallsStatusReceipt = { transactionHash: Hex } -export type WalletGetCallsStatusReturnType = { +export type WalletGetCallsReceiptReturnType = { status: 'PENDING' | 'CONFIRMED' - receipts?: WalletGetCallsStatusReceipt[] | undefined + receipts?: WalletCallReceipt[] | undefined } export type WalletPermissionCaveat = { @@ -1319,13 +1319,13 @@ export type WalletRpcSchema = [ * @description Returns the status of a call batch that was sent via `wallet_sendCalls`. * @link https://eips.ethereum.org/EIPS/eip-5792 * @example - * provider.request({ method: 'wallet_getCallsStatus' }) + * provider.request({ method: 'wallet_getCallsReceipt' }) * // => { ... } */ { - Method: 'wallet_getCallsStatus' + Method: 'wallet_getCallsReceipt' Parameters?: string - ReturnType: WalletGetCallsStatusReturnType + ReturnType: WalletGetCallsReceiptReturnType }, /** * @description Gets the connected wallet's capabilities.