-
Notifications
You must be signed in to change notification settings - Fork 218
feat: indexer poc #2545
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
base: bump-react-19
Are you sure you want to change the base?
feat: indexer poc #2545
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@@ -0,0 +1,30 @@ | |||
import { createClient } from '@ponder/client' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check with @douglance what we actually need here
const { isFeatureDisabled } = useDisabledFeatures() | ||
const isTxHistoryEnabled = !isFeatureDisabled(DisabledFeatures.TX_HISTORY) | ||
|
||
const indexerResult = useIndexerHistory(address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to only run indexer with the feature flag enabled. We return indexerResult
if indexer
flag is true, otherwise legacy results.
We also use the indexer
flag when fetching indexer and legacy results so that:
- we only fetch legacy if
indexer === false
||indexer === undefined
- we only fetch indexer if
indexer === true
parentChainId: number | ||
} | ||
|
||
type EthIndexerTransfer = PartialTransfer & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mirrored whatever indexer was returning, but maybe we can now get types from some package @douglance?
If not then we have to keep them defined here.
|
||
type IndexerTransfer = EthIndexerTransfer | Erc20IndexerTransfer | ||
|
||
function getIndexerTransferStatus(tx: IndexerTransfer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took from indexer some time ago but these may have changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to map them to whatever we use in our UI
} | ||
} | ||
|
||
function getIndexerDepositStatus(tx: IndexerTransfer): DepositStatus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, may have changed
} | ||
} | ||
|
||
type TokenDetails = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indexer only gives us token address because it would take a long time to fetch token data and store it. We need to fetch the token data ourselves.
see L162
decimals: number | ||
} | ||
|
||
function transformIndexerTransfer(params: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some overrides for ETH or ERC20
async ([_indexerTransactions, _tokensFromLists]) => { | ||
const result: { [key in string]: TokenDetails } = {} | ||
|
||
for (let i = 0; i < _indexerTransactions.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not great but I did it just for PoC to work.
Basically as mentioned before, indexer is not giving us ERC20 data, so we fetch ourselves. We need to do it for each ERC20 transaction we get from indexer. We may be able to do something smarter here.
}, [pendingTransfers, completedTransfers]) | ||
|
||
// todo: cache | ||
const { data: tokenDetailsMap } = useSWRImmutable( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERC20 data because indexer doesn't have it.
} | ||
) | ||
|
||
const { data: transactions = [] } = useSWR( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final data which includes token data for ERC20 transactions
([_indexerTransactions, _tokenDetailsMap]) => { | ||
return _indexerTransactions.map(tx => { | ||
if (tx.type === 'ETH') { | ||
return transformIndexerTransfer({ tx }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With overrides we can use the same function for ETH and ERC20. The only difference is if it's ERC20 then tokenDetails
is required, otherwise it needs to be skipped for ETH.
const isIndexerEnabled = isExperimentalFeatureEnabled('indexer') | ||
|
||
if (isIndexerEnabled) { | ||
return { ...indexerResult, addPendingTransaction, updatePendingTransaction } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addPendingTransaction
and updatePendingTransaction
stays as is because it's a different useSWR key with it's own mutator
'addPendingTransaction' | 'updatePendingTransaction' | ||
> => { | ||
const isIndexerEnabled = isExperimentalFeatureEnabled('indexer') | ||
// todo: allow undefined in indexer and return empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useArbitrumIndexer
doesn't allow undefined address so we need to pass empty string. Would be nice if indexer let us pass undefined, but it's just nice to have
loading: isLoading, | ||
// TODO: This will need to be based on pagination | ||
completed: !isLoading, | ||
failedChainPairs: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't really do failedChainPairs
with indexer
completed: !isLoading, | ||
failedChainPairs: [], | ||
error, | ||
pause: () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pause
and resume
N/A for indexer
return { | ||
transactions, | ||
loading: isLoading, | ||
// TODO: This will need to be based on pagination |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to do any pagination for v1. We can just fetch first 1000 results like we do for CCTP, and it should be sufficient for vast majority of users for now.
packages/arb-token-bridge-ui/src/components/App/AppProviders.tsx
Outdated
Show resolved
Hide resolved
a2f8cac
to
9e7a288
Compare
No description provided.