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

refactor: extract status mapping methods #1311

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/arb-token-bridge-ui/src/hooks/useDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
shouldIncludeSentTxs,
shouldIncludeReceivedTxs
} from '../util/SubgraphUtils'
import { updateAdditionalDepositData } from '../util/deposits/helpers'

export type CompleteDepositData = {
deposits: Transaction[]
Expand All @@ -27,7 +28,19 @@ export const fetchCompleteDepositData = async (
depositParams: FetchDepositParams
): Promise<CompleteDepositData> => {
// get the original deposits
const deposits = await fetchDeposits(depositParams)

const depositsWithoutStatuses = await fetchDeposits(depositParams)

const deposits = await Promise.all(
depositsWithoutStatuses.map(depositTx =>
updateAdditionalDepositData(
depositTx,
depositParams.l1Provider,
depositParams.l2Provider
)
)
)

// filter out pending deposits
const pendingDepositsMap = new Map<string, boolean>()
// get their complete transformed data (so that we get their exact status)
Expand Down
13 changes: 12 additions & 1 deletion packages/arb-token-bridge-ui/src/hooks/useWithdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
shouldIncludeSentTxs,
shouldIncludeReceivedTxs
} from '../util/SubgraphUtils'
import { updateAdditionalWithdrawalData } from '../util/withdrawals/helpers'

export type CompleteWithdrawalData = {
withdrawals: L2ToL1EventResultPlus[]
Expand All @@ -27,7 +28,17 @@ const fetchCompleteWithdrawalData = async (
params: FetchWithdrawalsParams
): Promise<CompleteWithdrawalData> => {
// get the original deposits
const withdrawals = await fetchWithdrawals(params)
const withdrawalsWithoutStatuses = await fetchWithdrawals(params)

const withdrawals: L2ToL1EventResultPlus[] = await Promise.all(
withdrawalsWithoutStatuses.map(withdrawal =>
updateAdditionalWithdrawalData(
withdrawal,
params.l1Provider,
params.l2Provider
)
)
)

// filter out pending withdrawals
const pendingWithdrawalMap = new Map<string, boolean>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Provider } from '@ethersproject/providers'
import { utils } from 'ethers'
import { updateAdditionalDepositData } from './helpers'
import {
fetchDepositsFromSubgraph,
FetchDepositsFromSubgraphResult
Expand Down Expand Up @@ -126,11 +125,5 @@ export const fetchDeposits = async ({
}
)

const finalTransactions: Transaction[] = await Promise.all(
ethDepositsFromSubgraph.map(depositTx =>
updateAdditionalDepositData(depositTx, l1Provider, l2Provider)
)
)

return finalTransactions
return ethDepositsFromSubgraph
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this is just a misnomer and this actually includes token deposits, too?

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
isTokenWithdrawal,
mapETHWithdrawalToL2ToL1EventResult,
mapTokenWithdrawalFromEventLogsToL2ToL1EventResult,
mapWithdrawalToL2ToL1EventResult,
updateAdditionalWithdrawalData
mapWithdrawalToL2ToL1EventResult
} from './helpers'
import { fetchWithdrawalsFromSubgraph } from './fetchWithdrawalsFromSubgraph'
import { tryFetchLatestSubgraphBlockNumber } from '../SubgraphUtils'
Expand Down Expand Up @@ -177,13 +176,7 @@ export const fetchWithdrawals = async ({
.filter((msg): msg is L2ToL1EventResultPlus => typeof msg !== 'undefined')
.sort(sortByTimestampDescending)

const finalL2ToL1Txns: L2ToL1EventResultPlus[] = await Promise.all(
l2ToL1Txns.map(withdrawal =>
updateAdditionalWithdrawalData(withdrawal, l1Provider, l2Provider)
)
)

return finalL2ToL1Txns.map(tx => ({
return l2ToL1Txns.map(tx => ({
...tx,

// attach the chain ids to the withdrawal object
Expand Down
Loading