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: add multi-chain transaction history hooks #1233

Merged
merged 52 commits into from
Dec 4, 2023

Conversation

brtkx
Copy link
Contributor

@brtkx brtkx commented Oct 19, 2023

Closes #1212
Closes #1210

  • A lot of files removed (that's why so many files changed)
  • Removes things that aren't needed anymore
  • Adds hooks to fetch data from multiple chains (CCTP not included yet)
  • Added minimal UI for tx history for testing, do not review NewTransactionHistory
  • The main feature are hooks in useCompleteMultiChainTransactions that control the whole logic

In the next PR, the new logic will be integrated with the existing tx history

@cla-bot cla-bot bot added the cla-signed label Oct 19, 2023
@@ -117,6 +117,9 @@ function parseTransferToMergedTransaction(
tokenAddress: getUsdcTokenAddressFromSourceChainId(sourceChainId),
depositStatus: DepositStatus.CCTP_DEFAULT_STATE,
isCctp: true,
// TODO: Fix those when adding CCTP
Copy link
Member

Choose a reason for hiding this comment

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

What about this?

Copy link
Contributor Author

@brtkx brtkx Nov 23, 2023

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,
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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 => {
Copy link
Member

@spsjvc spsjvc Nov 23, 2023

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 {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 129 to 133
const finalTransactions: Transaction[] = await Promise.all(
ethDepositsFromSubgraph.map(depositTx =>
updateAdditionalDepositData(depositTx, l1Provider, l2Provider)
)
)
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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

Copy link
Contributor Author

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()
Copy link
Member

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

Copy link
Contributor Author

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(
Copy link
Member

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 = () => {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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 = (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const useTransactionListByDirection = (
const useTransactionHistoryWithoutStatuses = (

Copy link
Contributor Author

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 = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export const useCompleteMultiChainTransactions = () => {
export const useTransactionHistory = () => {

Copy link
Contributor Author

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()
Copy link
Member

Choose a reason for hiding this comment

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

make it a prop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


if (withdrawal) {
return transformWithdrawal(withdrawal)
}
Copy link
Member

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

Copy link
Contributor Author

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

@spsjvc spsjvc changed the title feat: multi chain transactions hooks feat: add multi-chain transaction history hooks Dec 4, 2023
@spsjvc spsjvc merged commit 673446e into new-transaction-history-base Dec 4, 2023
3 checks passed
@spsjvc spsjvc deleted the new-tx-history-hooks branch December 4, 2023 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

load deposit & withdrawal history across multiple L2 chains
4 participants