-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto-import erc20 tokens after fork
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { queryOptions, useQuery } from '@tanstack/react-query' | ||
import { | ||
type BlockNumber, | ||
type BlockTag, | ||
type Client, | ||
type GetLogsParameters, | ||
stringify, | ||
} from 'viem' | ||
|
||
import { createQueryKey } from '~/react-query' | ||
|
||
import type { AbiEvent } from 'abitype' | ||
import { useClient } from './useClient' | ||
|
||
type UseLogsParameters< | ||
TAbiEvent extends AbiEvent, | ||
TFromBlock extends BlockNumber | BlockTag, | ||
TToBlock extends BlockNumber | BlockTag, | ||
> = GetLogsParameters<TAbiEvent, TAbiEvent[], undefined, TFromBlock, TToBlock> | ||
|
||
export const getLogsQueryKey = createQueryKey< | ||
'get-logs', | ||
[key: Client['key'], args: string] | ||
>('get-logs') | ||
|
||
export function useGetLogsQueryOptions< | ||
TAbiEvent extends AbiEvent, | ||
TFromBlock extends BlockNumber | BlockTag, | ||
TToBlock extends BlockNumber | BlockTag, | ||
>(parameters: UseLogsParameters<TAbiEvent, TFromBlock, TToBlock>) { | ||
const client = useClient() | ||
|
||
return queryOptions({ | ||
enabled: Boolean(parameters), | ||
queryKey: getLogsQueryKey([client.key, stringify(parameters)]), | ||
async queryFn() { | ||
return await client.getLogs(parameters) | ||
}, | ||
}) | ||
} | ||
|
||
export function useGetLogs< | ||
TAbiEvent extends AbiEvent, | ||
TFromBlock extends BlockNumber | BlockTag, | ||
TToBlock extends BlockNumber | BlockTag, | ||
>(parameters: UseLogsParameters<TAbiEvent, TFromBlock, TToBlock>) { | ||
const queryOptions = useGetLogsQueryOptions(parameters) | ||
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
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