Skip to content

Commit

Permalink
chore: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Nov 5, 2024
1 parent 9461ded commit cdd5e67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
14 changes: 12 additions & 2 deletions src/actions/wallet/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ describe('args: chain', async () => {
const originalError = new InvalidInputRpcError(new Error())

const request = client.request
client.request = (parameters: any) => {
client.request = async (parameters: any) => {
if (parameters.method === 'eth_sendTransaction') throw originalError
if (parameters.method === 'wallet_sendTransaction')
throw new MethodNotSupportedRpcError(new Error())
Expand All @@ -652,7 +652,17 @@ describe('args: chain', async () => {
to: targetAccount.address,
value: 0n,
}),
).rejects.toThrowError(originalError)
).rejects.toThrowErrorMatchingInlineSnapshot(`
[TransactionExecutionError: Missing or invalid parameters.
Double check you have provided the correct parameters.
Request Arguments:
from: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
to: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8
value: 0 ETH
Version: [email protected]]
`)
})

test('behavior: nullish account', async () => {
Expand Down
18 changes: 9 additions & 9 deletions src/actions/wallet/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ export async function sendTransaction<
} catch (e) {
if (isWalletNamespaceSupported === false) throw e

const originalError = e as BaseError
const error = e as BaseError
// If the transport does not support the method or input, attempt to use the
// `wallet_sendTransaction` method.
if (
originalError.name === 'InvalidInputRpcError' ||
originalError.name === 'InvalidParamsRpcError' ||
originalError.name === 'MethodNotFoundRpcError' ||
originalError.name === 'MethodNotSupportedRpcError'
error.name === 'InvalidInputRpcError' ||
error.name === 'InvalidParamsRpcError' ||
error.name === 'MethodNotFoundRpcError' ||
error.name === 'MethodNotSupportedRpcError'
) {
return await client
.request(
Expand All @@ -268,21 +268,21 @@ export async function sendTransaction<
supportsWalletNamespace.set(client.uid, true)
return hash
})
.catch((err) => {
const walletNamespaceError = err as BaseError
.catch((e) => {
const walletNamespaceError = e as BaseError
if (
walletNamespaceError.name === 'MethodNotFoundRpcError' ||
walletNamespaceError.name === 'MethodNotSupportedRpcError'
) {
supportsWalletNamespace.set(client.uid, false)
throw originalError
throw error
}

throw walletNamespaceError
})
}

throw originalError
throw error
}
}

Expand Down

0 comments on commit cdd5e67

Please sign in to comment.