Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto-import erc20 tokens after fork #75

Merged
merged 3 commits into from
Oct 10, 2023

Conversation

ditto-eth
Copy link
Contributor

Fixes #56

Works but there are a few things I'm not sure about (feel free to just fix and merge as well)

  • GetLogsParameters typing is painful (only figured it out by copying the same idea from another one relating to blocks)
  • useGetLogs should probably be cached in a different way (or does it matter if it querys the same logs from fork to latest when it doesn't need to, technically one could save another cache of the last fetched block per chain per user but might be too much to save/invalidate later)
  • when should this useImportTransferredTokens be called? right now it's just called whenever the account details screen is rendered (this also has the effect that if you are already on the screen it won't refresh until you go back to it?)
  • for future: event Transfer(address indexed from, address indexed to, uint256) is the same event for both erc20/erc721? I'm not sure how that will be saved, like if it should be in the same store (all tokens, with an extra field to say whether it's erc20 or 721, or etc), since you don't know it based on the address ahead of time

function Tokens({ accountAddress }: { accountAddress: Address }) {
const { tokens } = useTokensStore()
useImportTransferredTokens()
Copy link
Member

@jxom jxom Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this might be better invoked from within a "sync component" in src/index.ts, and only called once (see SyncBlockNumber for prior art).

After initial sync, we should then keep track of transferred tokens from within usePendingBlock, and make the block range fromBlock = prevBlock.number, and toBlock = block.number (still using useGetLogs). This will solve your issue of tokens not invalidating until you return to the account details screen.

const client = useClient()

return queryOptions({
enabled: Boolean(parameters),
Copy link
Member

@jxom jxom Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also add gcTime: Infinity and staleTime: Infinity (ONLY IF fromBlock and toBlock are numbers, not tags) as we know that logs are immutable when queried against a block number.

@jxom jxom merged commit f9dc5c2 into paradigmxyz:main Oct 10, 2023
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Auto-import ERC20 tokens after fork
2 participants