Skip to content

Commit

Permalink
Merge branch 'master' into extract-status-mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
fionnachan authored Nov 28, 2023
2 parents dd1efea + 33d0fcd commit 457614b
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 88 deletions.
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"react-use": "^17.2.4",
"react-virtualized": "^9.22.3",
"swr": "^2.1.2",
"tailwind-merge": "^0.9.0",
"tailwind-merge": "^2.0.0",
"use-query-params": "^2.1.1",
"wagmi": "^0.12.18",
"zod": "^3.22.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAccount, useChainId } from 'wagmi'

import { PageParams } from '../components/TransactionHistory/TransactionsTable/TransactionsTable'
import { MergedTransaction } from '../state/app/state'
import { isPending, transformDeposits } from '../state/app/utils'
import { isPending, transformDeposit } from '../state/app/utils'
import {
FetchDepositParams,
fetchDeposits
Expand Down Expand Up @@ -44,7 +44,7 @@ export const fetchCompleteDepositData = async (
// filter out pending deposits
const pendingDepositsMap = new Map<string, boolean>()
// get their complete transformed data (so that we get their exact status)
const completeDepositData = transformDeposits(deposits)
const completeDepositData = deposits.map(transformDeposit)
completeDepositData.forEach(completeTxData => {
if (isPending(completeTxData)) {
pendingDepositsMap.set(completeTxData.txId, true)
Expand Down
8 changes: 4 additions & 4 deletions packages/arb-token-bridge-ui/src/hooks/useWithdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAccount, useChainId } from 'wagmi'

import { PageParams } from '../components/TransactionHistory/TransactionsTable/TransactionsTable'
import { MergedTransaction } from '../state/app/state'
import { isPending, transformWithdrawals } from '../state/app/utils'
import { isPending, transformWithdrawal } from '../state/app/utils'
import {
FetchWithdrawalsParams,
fetchWithdrawals
Expand Down Expand Up @@ -42,9 +42,9 @@ const fetchCompleteWithdrawalData = async (

// filter out pending withdrawals
const pendingWithdrawalMap = new Map<string, boolean>()
const completeWithdrawalData = transformWithdrawals(
withdrawals.sort((msgA, msgB) => +msgB.timestamp - +msgA.timestamp)
)
const completeWithdrawalData = withdrawals
.sort((msgA, msgB) => +msgB.timestamp - +msgA.timestamp)
.map(transformWithdrawal)

completeWithdrawalData.forEach(completeTxData => {
if (isPending(completeTxData)) {
Expand Down
12 changes: 6 additions & 6 deletions packages/arb-token-bridge-ui/src/state/app/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import dayjs from 'dayjs'

import {
filterTransactions,
transformDeposits,
transformWithdrawals
transformDeposit,
transformWithdrawal
} from './utils'

import {
Expand Down Expand Up @@ -150,19 +150,19 @@ export const defaultState: AppState = {
)
}),
depositsTransformed: derived((s: AppState) => {
return transformDeposits(
s.sortedTransactions.filter(
return s.sortedTransactions
.filter(
// only take the deposit transactions, rest `outbox`, `approve` etc should not come
tx => tx.type === 'deposit' || tx.type === 'deposit-l1'
)
)
.map(transformDeposit)
}),
withdrawalsTransformed: derived((s: AppState) => {
const withdrawals = Object.values(
s.arbTokenBridge?.pendingWithdrawalsMap || []
) as L2ToL1EventResultPlus[]

return transformWithdrawals(withdrawals)
return withdrawals.map(transformWithdrawal)
}),
mergedTransactions: derived((s: AppState) => {
return _reverse(
Expand Down
124 changes: 59 additions & 65 deletions packages/arb-token-bridge-ui/src/state/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,70 +54,64 @@ export const getDepositStatus = (tx: Transaction) => {
}
}

export const transformDeposits = (
deposits: Transaction[]
): MergedTransaction[] => {
return deposits.map(tx => {
return {
sender: tx.sender,
destination: tx.destination,
direction: tx.type,
status: tx.status,
createdAt: tx.timestampCreated
? getStandardizedTimestamp(tx.timestampCreated)
: null,
resolvedAt: tx.timestampResolved
? getStandardizedTimestamp(tx.timestampResolved)
: null,
txId: tx.txID,
asset: tx.assetName || '',
assetType: tx.assetType,
value: tx.value,
uniqueId: null, // not needed
isWithdrawal: false,
blockNum: tx.blockNumber || null,
tokenAddress: tx.tokenAddress || null,
l1ToL2MsgData: tx.l1ToL2MsgData,
l2ToL1MsgData: tx.l2ToL1MsgData,
depositStatus: getDepositStatus(tx),
chainId: Number(tx.l2NetworkID),
parentChainId: Number(tx.l1NetworkID)
}
})
export const transformDeposit = (tx: Transaction): MergedTransaction => {
return {
sender: tx.sender,
destination: tx.destination,
direction: tx.type,
status: tx.status,
createdAt: tx.timestampCreated
? getStandardizedTimestamp(tx.timestampCreated)
: null,
resolvedAt: tx.timestampResolved
? getStandardizedTimestamp(tx.timestampResolved)
: null,
txId: tx.txID,
asset: tx.assetName || '',
assetType: tx.assetType,
value: tx.value,
uniqueId: null, // not needed
isWithdrawal: false,
blockNum: tx.blockNumber || null,
tokenAddress: tx.tokenAddress || null,
l1ToL2MsgData: tx.l1ToL2MsgData,
l2ToL1MsgData: tx.l2ToL1MsgData,
depositStatus: getDepositStatus(tx),
chainId: Number(tx.l2NetworkID),
parentChainId: Number(tx.l1NetworkID)
}
}

export const transformWithdrawals = (
withdrawals: L2ToL1EventResultPlus[]
): MergedTransaction[] => {
return withdrawals.map(tx => {
const uniqueIdOrHash = getUniqueIdOrHashFromEvent(tx)

return {
sender: tx.sender,
destination: tx.destinationAddress,
direction: 'outbox',
status:
tx.nodeBlockDeadline ===
NodeBlockDeadlineStatusTypes.EXECUTE_CALL_EXCEPTION
? 'Failure'
: outgoingStateToString[tx.outgoingMessageState],
createdAt: getStandardizedTimestamp(
String(BigNumber.from(tx.timestamp).toNumber() * 1000)
),
resolvedAt: null,
txId: tx.l2TxHash || 'l2-tx-hash-not-found',
asset: tx.symbol || '',
assetType: tx.type,
value: ethers.utils.formatUnits(tx.value?.toString(), tx.decimals),
uniqueId: uniqueIdOrHash,
isWithdrawal: true,
blockNum: tx.ethBlockNum.toNumber(),
tokenAddress: tx.tokenAddress || null,
nodeBlockDeadline: tx.nodeBlockDeadline,
chainId: tx.chainId,
parentChainId: tx.parentChainId
}
})
export const transformWithdrawal = (
tx: L2ToL1EventResultPlus
): MergedTransaction => {
const uniqueIdOrHash = getUniqueIdOrHashFromEvent(tx)

return {
sender: tx.sender,
destination: tx.destinationAddress,
direction: 'outbox',
status:
tx.nodeBlockDeadline ===
NodeBlockDeadlineStatusTypes.EXECUTE_CALL_EXCEPTION
? 'Failure'
: outgoingStateToString[tx.outgoingMessageState],
createdAt: getStandardizedTimestamp(
String(BigNumber.from(tx.timestamp).toNumber() * 1000)
),
resolvedAt: null,
txId: tx.l2TxHash || 'l2-tx-hash-not-found',
asset: tx.symbol || '',
assetType: tx.type,
value: ethers.utils.formatUnits(tx.value?.toString(), tx.decimals),
uniqueId: uniqueIdOrHash,
isWithdrawal: true,
blockNum: tx.ethBlockNum.toNumber(),
tokenAddress: tx.tokenAddress || null,
nodeBlockDeadline: tx.nodeBlockDeadline,
chainId: tx.chainId,
parentChainId: tx.parentChainId
}
}

// filter the transactions based on current wallet address and network ID's
Expand Down Expand Up @@ -234,9 +228,9 @@ export const findMatchingL1TxForWithdrawal = (
const cachedTransactions: Transaction[] = JSON.parse(
window.localStorage.getItem('arbTransactions') || '[]'
)
const outboxTransactions = transformDeposits(
cachedTransactions.filter(tx => tx.type === 'outbox')
)
const outboxTransactions = cachedTransactions
.filter(tx => tx.type === 'outbox')
.map(transformDeposit)

return outboxTransactions.find(_tx => {
const l2ToL1MsgData = _tx.l2ToL1MsgData
Expand Down
27 changes: 17 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@
dependencies:
regenerator-runtime "^0.13.11"

"@babel/runtime@^7.23.1":
version "7.23.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.4.tgz#36fa1d2b36db873d25ec631dcc4923fdc1cf2e2e"
integrity sha512-2Yv65nlWnWlSpe3fXEyX5i7fx5kIKo4Qbcj+hMO0odwaneFjfXw5fdum+4yL20O0QiaHpia0cYQ9xpNMqrBwHg==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/template@^7.22.15":
version "7.22.15"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38"
Expand Down Expand Up @@ -6578,11 +6585,6 @@ hasha@^5.0.0:
is-stream "^2.0.0"
type-fest "^0.8.0"

hashlru@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/hashlru/-/hashlru-2.3.0.tgz#5dc15928b3f6961a2056416bb3a4910216fdfb51"
integrity sha512-0cMsjjIC8I+D3M44pOQdsy0OHXGLVz6Z0beRuufhKa0KfaD2wGwAev6jILzXsd3/vpnNQJmWyZtIILqM1N+n5A==

he@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
Expand Down Expand Up @@ -9672,6 +9674,11 @@ regenerator-runtime@^0.13.11:
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz#f6dca3e7ceec20590d07ada785636a90cdca17f9"
integrity sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==

regenerator-runtime@^0.14.0:
version "0.14.0"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz#5e19d68eb12d486f797e15a3c6a918f7cec5eb45"
integrity sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==

regexp.prototype.flags@^1.4.3, regexp.prototype.flags@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.0.tgz#fe7ce25e7e4cca8db37b6634c8a2c7009199b9cb"
Expand Down Expand Up @@ -10674,12 +10681,12 @@ table@^6.0.9:
string-width "^4.2.3"
strip-ansi "^6.0.1"

tailwind-merge@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/tailwind-merge/-/tailwind-merge-0.9.0.tgz#3c7df4983515d291cc1136dd9269c7e8d8d37c7e"
integrity sha512-nHI0CoAAais8+0lwIiDposkhmdr4ejRVZxJH8bzZFbB7d6/jkciyl9lgHmkNpCJ0MMYi4Xg8JjHXZX7/67g3Tw==
tailwind-merge@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/tailwind-merge/-/tailwind-merge-2.0.0.tgz#a0f3a8c874ebae5feec5595614d08245a5f88a39"
integrity sha512-WO8qghn9yhsldLSg80au+3/gY9E4hFxIvQ3qOmlpXnqpDKoMruKfi/56BbbMg6fHTQJ9QD3cc79PoWqlaQE4rw==
dependencies:
hashlru "^2.3.0"
"@babel/runtime" "^7.23.1"

tailwindcss@^3.2.4:
version "3.3.2"
Expand Down

0 comments on commit 457614b

Please sign in to comment.