-
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.
Attempt to run on load and usePendingBlock
- Loading branch information
Showing
6 changed files
with
120 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { parseAbiItem } from 'abitype' | ||
import type { BlockTag } from 'viem' | ||
import { useAccountStore, useNetworkStore } from '~/zustand' | ||
import { useGetLogs } from './useGetLogs' | ||
|
||
type UseImportTransferredTokensParameters = { | ||
fromBlock?: bigint | BlockTag | ||
toBlock?: bigint | BlockTag | ||
} | ||
|
||
export function useImportTransferredTokens({ | ||
fromBlock, | ||
toBlock, | ||
}: UseImportTransferredTokensParameters = {}) { | ||
const { account } = useAccountStore() | ||
const { network } = useNetworkStore() | ||
|
||
const { data: transfersFrom } = useGetLogs({ | ||
event: parseAbiItem( | ||
'event Transfer(address indexed from, address indexed to, uint256)', | ||
), | ||
args: { | ||
from: account?.address, | ||
}, | ||
fromBlock: fromBlock || network.forkBlockNumber, | ||
toBlock: toBlock || 'latest', | ||
}) | ||
const { data: transfersTo } = useGetLogs({ | ||
event: parseAbiItem( | ||
'event Transfer(address indexed from, address indexed to, uint256)', | ||
), | ||
args: { | ||
to: account?.address, | ||
}, | ||
fromBlock: fromBlock || network.forkBlockNumber, | ||
toBlock: toBlock || 'latest', | ||
}) | ||
|
||
if (account?.address) { | ||
return [ | ||
...new Set([ | ||
...(transfersFrom?.map((t) => t.address) || []), | ||
...(transfersTo?.map((t) => t.address) || []), | ||
]), | ||
] | ||
} | ||
|
||
return [] | ||
} |
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