forked from paradigmxyz/rivet
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
220 additions
and
65 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,21 @@ | ||
import { useMutation } from '@tanstack/react-query' | ||
import type { RevertParameters } from 'viem' | ||
|
||
import { queryClient } from '~/react-query' | ||
|
||
import { useClient } from './useClient' | ||
import { usePendingBlockQueryOptions } from './usePendingBlock' | ||
|
||
export function useRevert() { | ||
const client = useClient() | ||
const pendingBlockQueryOptions = usePendingBlockQueryOptions() | ||
|
||
return useMutation({ | ||
mutationFn: async ({ id }: RevertParameters) => { | ||
await client.revert({ | ||
id, | ||
}) | ||
queryClient.invalidateQueries(pendingBlockQueryOptions) | ||
}, | ||
}) | ||
} |
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,37 @@ | ||
import { queryOptions, useQuery } from '@tanstack/react-query' | ||
import type { Client } from 'viem' | ||
|
||
import { createQueryKey } from '~/react-query' | ||
|
||
import { useClient } from './useClient' | ||
|
||
type UseSnapshotParameters = { | ||
blockNumber?: bigint | null | ||
enabled?: boolean | ||
} | ||
|
||
export const getSnapshotQueryKey = createQueryKey< | ||
'snapshot', | ||
[key: Client['key'], blockNumber: string] | ||
>('snapshot') | ||
|
||
export function useSnapshotQueryOptions({ | ||
blockNumber, | ||
enabled = true, | ||
}: UseSnapshotParameters) { | ||
const client = useClient() | ||
return queryOptions({ | ||
gcTime: Infinity, | ||
staleTime: 0, | ||
enabled: Boolean(enabled && blockNumber), | ||
queryKey: getSnapshotQueryKey([client.key, (blockNumber || '').toString()]), | ||
async queryFn() { | ||
return (await client.snapshot()) || null | ||
}, | ||
}) | ||
} | ||
|
||
export function useSnapshot({ blockNumber, enabled }: UseSnapshotParameters) { | ||
const queryOptions = useSnapshotQueryOptions({ blockNumber, enabled }) | ||
return useQuery(queryOptions) | ||
} |
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