-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
135 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { config } from '@wagmi/test' | ||
import { parseEther } from 'viem' | ||
import { expect, test } from 'vitest' | ||
|
||
import { connect } from './connect.js' | ||
import { disconnect } from './disconnect.js' | ||
import { prepareSendTransaction } from './prepareSendTransaction.js' | ||
import { sendTransaction } from './sendTransaction.js' | ||
|
||
const connector = config.connectors[0]! | ||
|
||
test('default', async () => { | ||
await connect(config, { connector }) | ||
await expect( | ||
sendTransaction(config, { | ||
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', | ||
value: parseEther('0.01'), | ||
}), | ||
).resolves.toMatchObject({ | ||
hash: expect.any(String), | ||
}) | ||
await disconnect(config, { connector }) | ||
}) | ||
|
||
test('default', async () => { | ||
await connect(config, { connector }) | ||
const result = await prepareSendTransaction(config, { | ||
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B', | ||
value: parseEther('0.01'), | ||
}) | ||
await expect(sendTransaction(config, result)).resolves.toMatchObject({ | ||
hash: expect.any(String), | ||
}) | ||
await disconnect(config, { connector }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { | ||
Account, | ||
Chain, | ||
SendTransactionParameters as viem_SendTransactionParameters, | ||
SendTransactionReturnType as viem_SendTransactionReturnType, | ||
} from 'viem' | ||
import { sendTransaction as viem_sendTransaction } from 'viem/actions' | ||
|
||
import type { Config } from '../config.js' | ||
import { ConnectorNotFoundError } from '../errors/config.js' | ||
import type { ChainId } from '../types/properties.js' | ||
import type { Evaluate } from '../types/utils.js' | ||
import { assertActiveChain } from '../utils/assertActiveChain.js' | ||
import { getConnectorClient } from './getConnectorClient.js' | ||
|
||
export type SendTransactionParameters< | ||
config extends Config = Config, | ||
chainId extends | ||
| config['chains'][number]['id'] | ||
| undefined = config['chains'][number]['id'], | ||
> = Evaluate< | ||
Omit< | ||
viem_SendTransactionParameters< | ||
Extract< | ||
config['chains'][number], | ||
{ id: chainId } | ||
> extends infer chain extends Chain | ||
? chain | ||
: config['chains'][number], | ||
Account | ||
>, | ||
'account' | 'chain' | ||
> & | ||
ChainId<config, chainId> & { | ||
mode?: 'prepared' | ||
} | ||
> | ||
|
||
export type SendTransactionReturnType = { | ||
hash: viem_SendTransactionReturnType | ||
} | ||
|
||
export type SendTransactionError = Error | ||
|
||
export async function sendTransaction< | ||
config extends Config, | ||
chainId extends config['chains'][number]['id'] | undefined, | ||
>( | ||
config: config, | ||
parameters: SendTransactionParameters<config, chainId>, | ||
): Promise<SendTransactionReturnType> | ||
|
||
/** https://wagmi.sh/core/actions/sendTransaction */ | ||
export async function sendTransaction( | ||
config: Config, | ||
parameters: SendTransactionParameters, | ||
): Promise<SendTransactionReturnType> { | ||
const { chainId, ...rest } = parameters | ||
|
||
const client = await getConnectorClient(config, { chainId }) | ||
if (!client) throw new ConnectorNotFoundError() | ||
if (chainId) assertActiveChain(config, { chainId }) | ||
|
||
const hash = await viem_sendTransaction(client, { | ||
...(rest as viem_SendTransactionParameters), | ||
chain: null, | ||
}) | ||
|
||
return { hash } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4d1bd3a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
wagmi-v2 – ./docs
wagmi-v2.vercel.app
wagmi-v2-wagmi-dev.vercel.app
wagmi-v2-git-tmm-v2-wagmi-dev.vercel.app