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

fix: display sent and received txs in a single table #1167

Merged
merged 29 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
10bcf63
merged withdrawals
brtkx Sep 22, 2023
c83002e
fix event logs and tests
brtkx Sep 25, 2023
505e444
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Sep 25, 2023
4adabd9
nit comment
brtkx Sep 25, 2023
1a20798
fix for scw
brtkx Sep 29, 2023
ff7382a
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Sep 29, 2023
f20bbe1
fix tests
brtkx Oct 2, 2023
e840d6c
clean up
brtkx Oct 2, 2023
5e48957
Merge branch 'master' into or-condition-subgraph
fionnachan Oct 4, 2023
47e3bc1
address comments
brtkx Oct 5, 2023
f825dfd
address comments
brtkx Oct 5, 2023
e0b9240
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Oct 5, 2023
413931b
Merge branch 'or-condition-subgraph' of github.com:OffchainLabs/arbit…
brtkx Oct 5, 2023
35fc325
review changes
brtkx Oct 6, 2023
17d26e3
tsdoc fix
brtkx Oct 6, 2023
54ae273
review comments and clean up
brtkx Oct 10, 2023
1638fc5
revert filters
brtkx Oct 10, 2023
bad1695
clean up
brtkx Oct 10, 2023
40c13ee
move dedupe events
brtkx Oct 10, 2023
86a25d4
sorting
brtkx Oct 10, 2023
241706d
is token withdrawal method
brtkx Oct 10, 2023
c637e43
better types
brtkx Oct 11, 2023
e4de9e7
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Oct 11, 2023
d97d2a3
remove type casting
brtkx Oct 11, 2023
6dfcedb
comments clean up
brtkx Oct 11, 2023
9cd8b14
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx Oct 12, 2023
075d571
Merge branch 'master' into or-condition-subgraph
spsjvc Oct 17, 2023
4a17adb
Merge branch 'master' into or-condition-subgraph
fionnachan Oct 18, 2023
b1190f5
Merge branch 'master' into or-condition-subgraph
fionnachan Oct 18, 2023
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
22 changes: 0 additions & 22 deletions packages/arb-token-bridge-ui/src/components/App/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type AppContextState = {
isTransferPanelVisible: boolean
isTransferring: boolean
isTransactionHistoryPanelVisible: boolean
isTransactionHistoryShowingSentTx: boolean
isTransactionHistoryShowingCctpDeposits: boolean
transactionHistorySelectedTab: TransactionHistoryTab
}
Expand All @@ -27,7 +26,6 @@ const initialState: AppContextState = {
isTransferPanelVisible: true,
isTransferring: false,
isTransactionHistoryPanelVisible: false,
isTransactionHistoryShowingSentTx: true,
isTransactionHistoryShowingCctpDeposits: true,
transactionHistorySelectedTab: TransactionHistoryTab.DEPOSITS
}
Expand All @@ -42,7 +40,6 @@ type Action =
| { type: 'layout.set_is_transfer_panel_visible'; payload: boolean }
| { type: 'layout.set_is_transferring'; payload: boolean }
| { type: 'layout.set_txhistory_panel_visible'; payload: boolean }
| { type: 'layout.set_txhistory_show_sent_tx'; payload: boolean }
| { type: 'layout.set_txhistory_show_cctp_deposits'; payload: boolean }
| { type: 'layout.set_txhistory_tab'; payload: TransactionHistoryTab }

Expand All @@ -63,15 +60,6 @@ function reducer(state: AppContextState, action: Action) {
}
}

case 'layout.set_txhistory_show_sent_tx':
return {
...state,
layout: {
...state.layout,
isTransactionHistoryShowingSentTx: action.payload
}
}

case 'layout.set_txhistory_show_cctp_deposits':
return {
...state,
Expand Down Expand Up @@ -145,14 +133,6 @@ export const useAppContextActions = (dispatchOverride?: Dispatch<Action>) => {
})
}, [dispatch])

const showSentTransactions = useCallback(() => {
dispatch({ type: 'layout.set_txhistory_show_sent_tx', payload: true })
}, [dispatch])

const showReceivedTransactions = useCallback(() => {
dispatch({ type: 'layout.set_txhistory_show_sent_tx', payload: false })
}, [dispatch])

const closeTransactionHistoryPanel = () => {
dispatch({ type: 'layout.set_txhistory_panel_visible', payload: false })
}
Expand All @@ -168,8 +148,6 @@ export const useAppContextActions = (dispatchOverride?: Dispatch<Action>) => {
setTransferring,
openTransactionHistoryPanel,
closeTransactionHistoryPanel,
showSentTransactions,
showReceivedTransactions,
showCctpDepositsTransactions,
showCctpWithdrawalsTransactions,
setTransactionHistoryTab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export const TransactionHistory = ({
const { l1, l2 } = useNetworksAndSigners()
const { isSmartContractWallet } = useAccountType()
const {
showSentTransactions,
showReceivedTransactions,
showCctpDepositsTransactions,
showCctpWithdrawalsTransactions,
setTransactionHistoryTab
Expand Down Expand Up @@ -147,31 +145,10 @@ export const TransactionHistory = ({
if (!isSmartContractWallet || !chain) {
return
}
const isDepositsTab = index === TransactionHistoryTab.DEPOSITS
const isWithdrawalsTab = index === TransactionHistoryTab.WITHDRAWALS
const isCctpTab = index === TransactionHistoryTab.CCTP
const isConnectedToArbitrum = isNetwork(chain.id).isArbitrum
// SCW address is tied to a specific network, so we must ensure that:
if (isDepositsTab) {
// if showing deposits, we always show:
if (isConnectedToArbitrum) {
// - received txs if connected to L2
showReceivedTransactions()
} else {
// - sent txs if connected to L1
showSentTransactions()
}
} else if (isWithdrawalsTab) {
// Withdrawal tab
// if showing withdrawals, we always show:
if (isConnectedToArbitrum) {
// - sent txs if connected to L2
showSentTransactions()
} else {
// - received txs if connected to L1
showReceivedTransactions()
}
} else {
// Cctp tab

if (isCctpTab) {
if (isConnectedToArbitrum) {
showCctpDepositsTransactions()
} else {
Expand All @@ -183,9 +160,7 @@ export const TransactionHistory = ({
chain,
isSmartContractWallet,
showCctpDepositsTransactions,
showCctpWithdrawalsTransactions,
showReceivedTransactions,
showSentTransactions
showCctpWithdrawalsTransactions
]
)

Expand Down Expand Up @@ -300,7 +275,6 @@ export const TransactionHistory = ({
pageParams={depositsPageParams}
setPageParams={setDepositsPageParams}
transactions={depositsData.transformedDeposits}
isSmartContractWallet={isSmartContractWallet}
loading={depositsLoading}
error={depositsError}
/>
Expand All @@ -317,7 +291,6 @@ export const TransactionHistory = ({
pageParams={withdrawalsPageParams}
setPageParams={setWithdrawalsPageParams}
transactions={withdrawalsData.transformedWithdrawals}
isSmartContractWallet={isSmartContractWallet}
loading={withdrawalsLoading}
error={withdrawalsError}
/>
Expand Down

This file was deleted.

fionnachan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { NoDataOverlay } from './NoDataOverlay'
import { TableBodyLoading } from './TableBodyLoading'
import { TableBodyError } from './TableBodyError'
import { TableActionHeader } from './TableActionHeader'
import { TableSentOrReceivedFundsSwitch } from './TableSentOrReceivedFundsSwitch'
import { useAppState } from '../../../state'
import { useAppContextState } from '../../App/AppContext'
import { useNetworksAndSigners } from '../../../hooks/useNetworksAndSigners'
import { ExternalLink } from '../../common/ExternalLink'
import { getExplorerUrl } from '../../../util/networks'
Expand Down Expand Up @@ -166,7 +164,6 @@ export type TransactionsTableProps = {
pageParams: PageParams
setPageParams: Dispatch<SetStateAction<PageParams>>
transactions: MergedTransaction[]
isSmartContractWallet?: boolean
loading: boolean
error: boolean
}
Expand All @@ -176,17 +173,12 @@ export function TransactionsTable({
pageParams,
setPageParams,
transactions,
isSmartContractWallet,
loading,
error
}: TransactionsTableProps) {
const {
app: { mergedTransactions: locallyStoredTransactions }
} = useAppState()
const {
layout: { isTransactionHistoryShowingSentTx }
} = useAppContextState()
const { address } = useAccount()

// don't want to update hooks on useAppState reference change. Just the exact value of localTransactions
const localTransactionsKey = JSON.stringify(locallyStoredTransactions || [])
Expand Down Expand Up @@ -235,18 +227,6 @@ export function TransactionsTable({
return [...newerTransactions.reverse(), ...subgraphTransactions]
}, [transactions, localTransactionsKey])
Copy link
Member

Choose a reason for hiding this comment

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

React Hook useMemo has missing dependencies: 'locallyStoredTransactions', 'pageParams.pageNumber', 'pageParams.searchString', and 'type'. Either include them or remove the dependency array.eslintreact-hooks/exhaustive-deps

do we need the other deps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We haven't had them before but I will have a look.

Maybe @dewanshparashar can have a look as well as I don't believe I've made any changes here before.

Copy link
Contributor

Choose a reason for hiding this comment

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

In dependencies,

  • we don't need locallyStoredTransactions since this state object mutates very frequently and localTransactionsKey (string) is derived from it to keep things under control.
  • pageNumber and searchString can be added, but we only need this memo function to run for the very first page so adding these doesn't make a difference to the logic / result. Just that it will recalculate and do an early return for each update. It's optional.

If we go ahead with it, I'd suggest a different PR to isolate it's impact.

Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need locallyStoredTransactions since this state object mutates very frequently and localTransactionsKey (string) is derived from it to keep things under control.

Then we should either memo it, or not having it as a dependencies, otherwise it make things unpredictable

pageNumber and searchString can be added, but we only need this memo function to run for the very first page so adding these doesn't make a difference to the logic / result. Just that it will recalculate and do an early return for each update. It's optional.

If they are part of the callback of useEffect, then they should be included, even if they never change


const transactionsBySentOrReceivedFunds = useMemo(() => {
if (!address) return []
// both sent and received PENDING txs are stored together
// here we make sure we display a correct tx (sent or received)
return _transactions.filter(tx => {
if (isTransactionHistoryShowingSentTx) {
return tx.sender?.toLowerCase() === address.toLowerCase()
}
return tx.sender?.toLowerCase() !== address.toLowerCase()
})
}, [_transactions, address])

const locallyStoredTransactionsMap = useMemo(() => {
// map of all the locally-stored transactions (pending + recently executed)
// so that tx rows can easily subscribe to live-local status without refetching table data
Expand All @@ -271,14 +251,12 @@ export function TransactionsTable({

return (
<>
{!isSmartContractWallet && <TableSentOrReceivedFundsSwitch />}
chrstph-dvx marked this conversation as resolved.
Show resolved Hide resolved

{/* search and pagination buttons */}
<TableActionHeader
type={type}
pageParams={pageParams}
setPageParams={setPageParams}
transactions={transactionsBySentOrReceivedFunds}
transactions={_transactions}
loading={loading}
showSearch
/>
Expand All @@ -299,7 +277,7 @@ export function TransactionsTable({
{/* when there are no transactions present */}
{status === TableStatus.SUCCESS &&
!noSearchResults &&
!transactionsBySentOrReceivedFunds.length && (
_transactions.length === 0 && (
<EmptyTableRow>
<span className="text-sm font-medium">No transactions</span>
</EmptyTableRow>
Expand All @@ -308,9 +286,8 @@ export function TransactionsTable({
{/* finally, when transactions are present, show rows */}
{status === TableStatus.SUCCESS &&
!noSearchResults &&
transactionsBySentOrReceivedFunds.map((tx, index) => {
const isLastRow =
index === transactionsBySentOrReceivedFunds.length - 1
_transactions.map((tx, index) => {
const isLastRow = index === _transactions.length - 1

// if transaction is present in local (pending + recently executed) transactions, subscribe to that in this row,
// this will make sure the row updates with any updates in the local app state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type L2ToL1EventResultPlus = L2ToL1EventResult & {

export type WithdrawalInitiated = EventArgs<WithdrawalInitiatedEvent> & {
txHash: string
timestamp?: BigNumber
}

export interface PendingWithdrawalsMap {
Expand Down
47 changes: 33 additions & 14 deletions packages/arb-token-bridge-ui/src/hooks/useDeposits.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useMemo } from 'react'
import useSWRImmutable from 'swr/immutable'
import { useAccount } from 'wagmi'
import { useAccount, useChainId } from 'wagmi'

import { PageParams } from '../components/TransactionHistory/TransactionsTable/TransactionsTable'
import { useAppContextState } from '../components/App/AppContext'
import { MergedTransaction } from '../state/app/state'
import { isPending, transformDeposits } from '../state/app/utils'
import {
Expand All @@ -12,9 +11,10 @@ import {
} from '../util/deposits/fetchDeposits'
import { useNetworksAndSigners } from './useNetworksAndSigners'
import { Transaction } from './useTransactions'
import { useAccountType } from './useAccountType'
import {
getQueryParamsForFetchingReceivedFunds,
getQueryParamsForFetchingSentFunds
shouldIncludeSentTxs,
shouldIncludeReceivedTxs
} from '../util/SubgraphUtils'

export type CompleteDepositData = {
Expand Down Expand Up @@ -46,16 +46,37 @@ export const fetchCompleteDepositData = async (

export const useDeposits = (depositPageParams: PageParams) => {
const { l1, l2 } = useNetworksAndSigners()
const { isSmartContractWallet, isLoading: isAccountTypeLoading } =
useAccountType()
const chainId = useChainId()

const isConnectedToParentChain = l1.network.id === chainId

// only change l1-l2 providers (and hence, reload deposits) when the connected chain id changes
// otherwise tx-history unnecessarily reloads on l1<->l2 network switch as well (#847)
const l1Provider = useMemo(() => l1.provider, [l1.network.id])
const l2Provider = useMemo(() => l2.provider, [l2.network.id])

const { address: walletAddress } = useAccount()
const {
layout: { isTransactionHistoryShowingSentTx }
} = useAppContextState()

// SCW address is tied to a specific network
// that's why we need to limit shown txs either to sent or received funds
// otherwise we'd display funds for a different network, which could be someone else's account
const includeSentTxs = isAccountTypeLoading
? false
: shouldIncludeSentTxs({
type: 'deposit',
isSmartContractWallet,
isConnectedToParentChain
})

const includeReceivedTxs = isAccountTypeLoading
? false
: shouldIncludeReceivedTxs({
type: 'deposit',
isSmartContractWallet,
isConnectedToParentChain
})

/* return the cached response for the complete pending transactions */
return useSWRImmutable(
Expand All @@ -65,31 +86,29 @@ export const useDeposits = (depositPageParams: PageParams) => {
walletAddress,
l1Provider,
l2Provider,
isTransactionHistoryShowingSentTx,
depositPageParams.pageNumber,
depositPageParams.pageSize,
depositPageParams.searchString
depositPageParams.searchString,
isAccountTypeLoading
]
: null,
([
,
_walletAddress,
_l1Provider,
_l2Provider,
_isTransactionHistoryShowingSentTx,
_pageNumber,
_pageSize,
_searchString
]) =>
fetchCompleteDepositData({
sender: includeSentTxs ? _walletAddress : undefined,
receiver: includeReceivedTxs ? _walletAddress : undefined,
l1Provider: _l1Provider,
l2Provider: _l2Provider,
pageNumber: _pageNumber,
pageSize: _pageSize,
searchString: _searchString,
...(_isTransactionHistoryShowingSentTx
? getQueryParamsForFetchingSentFunds(_walletAddress)
: getQueryParamsForFetchingReceivedFunds(_walletAddress))
searchString: _searchString
})
)
}
Loading
Loading