Skip to content

Commit

Permalink
feat: transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jul 13, 2023
1 parent 051e72c commit ed7f230
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
strategy:
matrix:
typescript-version: ['5.0.4', 'latest']
# TODO: Run against multiple viem versions (need to update patchedDependencies in package.json)
# TODO: Run against multiple viem versions
# viem-version: ['1.2.0', 'latest']

steps:
Expand Down Expand Up @@ -92,6 +92,7 @@ jobs:

# TODO: Run against multiple viem versions
# - run: pnpm add -D -w viem@${{ matrix.viem-version }}
# - run: pnpm test:update:viem

- name: Run tests
uses: nick-fields/retry@v2
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/query/getTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function getTransactionQueryOptions<
async queryFn({ queryKey }) {
const { blockHash, blockNumber, blockTag, hash, ...parameters } =
queryKey[1]
if (!(blockHash && blockNumber && blockTag && hash))
if (!blockHash && !blockNumber && !blockTag && !hash)
throw new Error('blockHash, blockNumber, blockTag, or hash is required')

let params
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/hooks/useToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from 'vitest'

import { useToken } from './useToken.js'

test('mounts', async () => {
test('default', async () => {
const { result } = renderHook(() =>
useToken({
address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/hooks/useTransaction.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expectTypeOf, test } from 'vitest'

import { useTransaction } from './useTransaction.js'

test('select data', async () => {
const result = useTransaction({
select(data) {
return data?.nonce
},
})
expectTypeOf(result.data).toEqualTypeOf<number | undefined>()
})
64 changes: 64 additions & 0 deletions packages/react/src/hooks/useTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { renderHook, waitFor } from '@wagmi/test/react'
import { expect, test } from 'vitest'

import { useTransaction } from './useTransaction.js'

test('default', async () => {
const { result } = renderHook(() =>
useTransaction({
hash: '0x60668ed8c2dc110d61d945a936fcd45b8f13654e5c78481c8c825d1148c7ef30',
}),
)

await waitFor(() => expect(result.current.isSuccess).toBeTruthy())

expect(result.current).toMatchInlineSnapshot(`
{
"data": {
"accessList": [],
"blockHash": "0xd725a38b51e5ceec8c5f6c9ccfdb2cc423af993bb650af5eedca5e4be7156ba7",
"blockNumber": 15189204n,
"chainId": 1,
"from": "0xa0cf798816d4b9b9866b5330eea46a18382f251e",
"gas": 21000n,
"gasPrice": 9371645552n,
"hash": "0x60668ed8c2dc110d61d945a936fcd45b8f13654e5c78481c8c825d1148c7ef30",
"input": "0x",
"maxFeePerGas": 13644824566n,
"maxPriorityFeePerGas": 1500000000n,
"nonce": 86,
"r": "0x40174f9a38df876c1a7ce2587848819d4082ccd6d67a88aa5cabe59bf594e14f",
"s": "0x7c0c82f62a8a5a9b0e9cf30a54a72fdae8fc54b5b79ddafef0acd30e94e83872",
"to": "0xd2135cfb216b74109775236e36d4b433f1df507b",
"transactionIndex": 144,
"type": "eip1559",
"typeHex": "0x2",
"v": 0n,
"value": 100000000000000000n,
},
"dataUpdatedAt": 1675209600000,
"error": null,
"errorUpdateCount": 0,
"errorUpdatedAt": 0,
"failureCount": 0,
"failureReason": null,
"fetchStatus": "idle",
"isError": false,
"isFetched": true,
"isFetchedAfterMount": true,
"isFetching": false,
"isInitialLoading": false,
"isLoading": false,
"isLoadingError": false,
"isPaused": false,
"isPending": false,
"isPlaceholderData": false,
"isRefetchError": false,
"isRefetching": false,
"isStale": true,
"isSuccess": true,
"refetch": [Function],
"status": "success",
}
`)
})

1 comment on commit ed7f230

@vercel
Copy link

@vercel vercel bot commented on ed7f230 Jul 13, 2023

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

Please sign in to comment.