Skip to content

Commit

Permalink
fix: prepareTransactionRequest using unsupported wallet RPC methods. (
Browse files Browse the repository at this point in the history
#3869)

* fix: resolves #3865

* chore: update snapshot
  • Loading branch information
jxom committed Apr 30, 2024
1 parent 51ec9e4 commit d4a78eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 46 deletions.
6 changes: 6 additions & 0 deletions .changeset/loud-avocados-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wagmi/core": patch
"wagmi": patch
---

Fixed issue where `prepareTransactionRequest` would internally call unsupported wallet RPC methods.
30 changes: 1 addition & 29 deletions packages/core/src/actions/prepareTransactionRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test('default', async () => {
} = request
expect(rest).toMatchInlineSnapshot(`
{
"account": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"chainId": 1,
"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
Expand Down Expand Up @@ -67,35 +68,6 @@ test('parameters: account', async () => {
await disconnect(config, { connector })
})

test('parameters: connector', async () => {
await connect(config, { connector })

const request = await prepareTransactionRequest(config, {
connector,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
})

const {
gas: _gas,
maxFeePerGas: _mfpg,
maxPriorityFeePerGas: _mpfpg,
nonce: _nonce,
...rest
} = request
expect(rest).toMatchInlineSnapshot(`
{
"chainId": 1,
"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
"type": "eip1559",
"value": 1000000000000000000n,
}
`)

await disconnect(config, { connector })
})

test('behavior: local account', async () => {
const account = privateKeyToAccount(privateKey)

Expand Down
26 changes: 9 additions & 17 deletions packages/core/src/actions/prepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ import { prepareTransactionRequest as viem_prepareTransactionRequest } from 'vie

import { type Config } from '../createConfig.js'
import { type SelectChains } from '../types/chain.js'
import {
type ChainIdParameter,
type ConnectorParameter,
} from '../types/properties.js'
import { type ChainIdParameter } from '../types/properties.js'
import {
type Evaluate,
type IsNarrowable,
type UnionEvaluate,
type UnionOmit,
} from '../types/utils.js'
import { getAction } from '../utils/getAction.js'
import { getConnectorClient } from './getConnectorClient.js'
import { getAccount } from './getAccount.js'

export type PrepareTransactionRequestParameters<
config extends Config = Config,
Expand Down Expand Up @@ -55,8 +52,7 @@ export type PrepareTransactionRequestParameters<
>,
'chain'
> &
ChainIdParameter<config, chainId> &
ConnectorParameter & {
ChainIdParameter<config, chainId> & {
to: Address
}
>
Expand Down Expand Up @@ -90,10 +86,9 @@ export type PrepareTransactionRequestReturnType<
? request
: never
>
> &
ConnectorParameter & {
chainId: chains[key]['id']
}
> & {
chainId: chains[key]['id']
}
}[number]

export type PrepareTransactionRequestErrorType =
Expand All @@ -111,13 +106,10 @@ export async function prepareTransactionRequest<
config: config,
parameters: PrepareTransactionRequestParameters<config, chainId, request>,
): Promise<PrepareTransactionRequestReturnType<config, chainId, request>> {
const { account, chainId, connector, ...rest } = parameters
const { account: account_, chainId, ...rest } = parameters

let client
if (typeof account === 'object' && account.type === 'local')
client = config.getClient({ chainId })
else
client = await getConnectorClient(config, { account, chainId, connector })
const account = account_ ?? getAccount(config).address
const client = config.getClient({ chainId })

const action = getAction(
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test('default', async () => {

expect(data).toMatchInlineSnapshot(`
{
"account": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"chainId": 1,
"from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
Expand Down

0 comments on commit d4a78eb

Please sign in to comment.