-
Notifications
You must be signed in to change notification settings - Fork 202
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: add multi-chain transaction history hooks #1233
Conversation
…e into or-condition-subgraph
…e into or-condition-subgraph
…e into or-condition-subgraph
…rum-token-bridge into or-condition-subgraph
…e into multi-chain-hooks
@@ -117,6 +117,9 @@ function parseTransferToMergedTransaction( | |||
tokenAddress: getUsdcTokenAddressFromSourceChainId(sourceChainId), | |||
depositStatus: DepositStatus.CCTP_DEFAULT_STATE, | |||
isCctp: true, | |||
// TODO: Fix those when adding CCTP |
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.
What about this?
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.
As discussed, this will be added in another PR
@@ -132,7 +132,7 @@ export default async function handler( | |||
l1Token, | |||
tokenAmount, | |||
isClassic, | |||
l2BlockTimestamp, | |||
timestamp: l2BlockTimestamp, |
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 would keep this as it is in the subgraph, as it could cause confusion
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.
done
l2TxHash: string | ||
l2BlockNum: string | ||
parentChainId: number | ||
chainId: number |
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.
Let's do childChainId
everywhere. Christophe's useNetworksRelationship
hook will give us parentChain
and childChain
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.
done
@@ -84,6 +85,64 @@ export const transformDeposits = ( | |||
}) | |||
} | |||
|
|||
export const transformDeposit = (tx: Deposit): MergedTransaction => { |
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 think extracting transformDeposit
and transformWithdrawal
as a separate PR (before this one) might make the diff smaller
Edit: #1310
export interface Transaction extends TransactionBase { | ||
export interface Transaction | ||
extends TransactionBase, | ||
AdditionalTransferProperties { |
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.
Can we just add these fields directly to Transaction
?
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.
done
const finalTransactions: Transaction[] = await Promise.all( | ||
ethDepositsFromSubgraph.map(depositTx => | ||
updateAdditionalDepositData(depositTx, l1Provider, l2Provider) | ||
) | ||
) |
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.
Let's move this out of fetchDeposits
and into useDeposits
in a separate PR. That way we could reuse the current fetchDeposits
for the new transaction history and reduce the diff. Same thing for withdrawals.
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.
return tx.direction === 'deposit' | ||
} | ||
|
||
async function transformTransaction(tx: DepositOrWithdrawal) { |
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.
Let's add a return type to be safe it's always good
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.
done
const [page, setPage] = useState(0) | ||
const [loading, setLoading] = useState(true) | ||
|
||
const { address } = useAccount() |
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.
Make this a prop for the hook. Reasoning: we want to keep this independent of the connected wallet, e.g. if we ever wanna have a separate transaction history page that you can provide the address for through a query param
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.
done
[page, transactions] | ||
) | ||
|
||
const { data, error } = 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.
Maybe there's a way to replace this with https://swr.vercel.app/docs/pagination.en-US#infinite-loading
* Fetches transaction history only, without mapping additional info that would require a lot of RPC calls. | ||
* The data is collected for multiple chain pairs, and sorted by date. | ||
*/ | ||
const useMultiChainTransactionList = () => { |
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 feel like this should belong to the useTransactionListByDirection
so it gives us merged deposits & withdrawals, sorted and everything. We can remove the direction
prop.
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.
Then we end up with 2 hooks instead of 3.
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.
done
* Fetches transaction history only, and only for a specific direction. | ||
* The query could be e.g. deposits or withdrawals. | ||
*/ | ||
const useTransactionListByDirection = ( |
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.
const useTransactionListByDirection = ( | |
const useTransactionHistoryWithoutStatuses = ( |
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.
done
* Maps additional info to previously fetches transaction history, starting with the earliest data. | ||
* This is done in small batches to safely meet RPC limits. | ||
*/ | ||
export const useCompleteMultiChainTransactions = () => { |
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.
export const useCompleteMultiChainTransactions = () => { | |
export const useTransactionHistory = () => { |
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.
done
const [paused, setPaused] = useState(false) | ||
|
||
const { data, loading, error } = useMultiChainTransactionList() | ||
const { address } = useAccount() |
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.
make it a prop
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.
done
…e into new-tx-history-hooks
|
||
if (withdrawal) { | ||
return transformWithdrawal(withdrawal) | ||
} |
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.
hm what's the default case here? why can it be undefined? tbh I'd rather we throw if this is unexpected
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.
now it will throw an error if the tx is undefined
Closes #1212
Closes #1210
NewTransactionHistory
useCompleteMultiChainTransactions
that control the whole logicIn the next PR, the new logic will be integrated with the existing tx history