Skip to content

Commit

Permalink
Merge branch 'master' into perf-optimize-withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Dec 19, 2024
2 parents 6d64595 + b569ef1 commit bcd2617
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useCallback } from 'react'
import { useAccount, useNetwork } from 'wagmi'

import { GET_HELP_LINK } from '../../constants'
import { useClaimWithdrawal } from '../../hooks/useClaimWithdrawal'
import { useClaimCctp } from '../../state/cctpState'
Expand All @@ -13,7 +15,6 @@ import { getNetworkName } from '../../util/networks'
import { errorToast } from '../common/atoms/Toast'
import { Button } from '../common/Button'
import { useSwitchNetworkWithConfig } from '../../hooks/useSwitchNetworkWithConfig'
import { useNetwork } from 'wagmi'
import { isDepositReadyToRedeem } from '../../state/app/utils'
import { useRedeemRetryable } from '../../hooks/useRedeemRetryable'
import { TransferCountdown } from '../common/TransferCountdown'
Expand All @@ -23,6 +24,7 @@ import { useRedeemTeleporter } from '../../hooks/useRedeemTeleporter'
import { sanitizeTokenSymbol } from '../../util/TokenUtils'
import { formatAmount } from '../../util/NumberUtils'
import { useTransactionHistoryAddressStore } from './TransactionHistorySearchBar'
import { Tooltip } from '../common/Tooltip'

export function TransactionsTableRowAction({
tx,
Expand All @@ -33,10 +35,17 @@ export function TransactionsTableRowAction({
isError: boolean
type: 'deposits' | 'withdrawals'
}) {
const { address: connectedAddress } = useAccount()
const { chain } = useNetwork()
const { switchNetworkAsync } = useSwitchNetworkWithConfig()
const networkName = getNetworkName(chain?.id ?? 0)
const { sanitizedAddress } = useTransactionHistoryAddressStore()
const { sanitizedAddress: searchedAddress } =
useTransactionHistoryAddressStore()

const isViewingAnotherAddress =
connectedAddress &&
searchedAddress &&
connectedAddress.toLowerCase() !== searchedAddress.toLowerCase()

const tokenSymbol = sanitizeTokenSymbol(tx.asset, {
erc20L1Address: tx.tokenAddress,
Expand All @@ -47,10 +56,10 @@ export function TransactionsTableRowAction({
const { claim: claimCctp, isClaiming: isClaimingCctp } = useClaimCctp(tx)
const { redeem, isRedeeming: isRetryableRedeeming } = useRedeemRetryable(
tx,
sanitizedAddress
searchedAddress
)
const { redeem: teleporterRedeem, isRedeeming: isTeleporterRedeeming } =
useRedeemTeleporter(tx, sanitizedAddress)
useRedeemTeleporter(tx, searchedAddress)

const isRedeeming = isRetryableRedeeming || isTeleporterRedeeming

Expand Down Expand Up @@ -162,16 +171,25 @@ export function TransactionsTableRowAction({
return isClaiming || isClaimingCctp ? (
<span className="my-2 animate-pulse text-xs">Claiming...</span>
) : (
<Button
aria-label={`Claim ${formatAmount(Number(tx.value), {
symbol: tokenSymbol
})}`}
variant="primary"
className="w-14 rounded bg-green-400 p-2 text-xs text-black"
onClick={handleClaim}
<Tooltip
content={
<span>{`Funds will arrive at ${searchedAddress} on ${getNetworkName(
tx.destinationChainId
)} once the claim transaction succeeds.`}</span>
}
show={isViewingAnotherAddress}
>
Claim
</Button>
<Button
aria-label={`Claim ${formatAmount(Number(tx.value), {
symbol: tokenSymbol
})}`}
variant="primary"
className="w-14 rounded bg-green-400 p-2 text-xs text-black"
onClick={handleClaim}
>
Claim
</Button>
</Tooltip>
)
}

Expand Down
6 changes: 5 additions & 1 deletion packages/arb-token-bridge-ui/src/hooks/useClaimWithdrawal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { fetchErc20Data } from '../util/TokenUtils'
import { fetchNativeCurrency } from './useNativeCurrency'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'
import { captureSentryErrorWithExtraData } from '../util/SentryUtils'
import { useTransactionHistoryAddressStore } from '../components/TransactionHistory/TransactionHistorySearchBar'

export type UseClaimWithdrawalResult = {
claim: () => Promise<void>
Expand All @@ -28,8 +29,11 @@ export function useClaimWithdrawal(
app: { arbTokenBridge }
} = useAppState()
const { address } = useAccount()
const { sanitizedAddress } = useTransactionHistoryAddressStore()
const { data: signer } = useSigner({ chainId: tx.parentChainId })
const { updatePendingTransaction } = useTransactionHistory(address)
const { updatePendingTransaction } = useTransactionHistory(
sanitizedAddress ?? address
)
const [isClaiming, setIsClaiming] = useState(false)

const claim = useCallback(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ export const useTransactionHistory = (

if (isLoadingTxsWithoutStatus || error) {
return {
transactions: [],
transactions: newTransactionsData || [],
loading: isLoadingTxsWithoutStatus,
error,
failedChainPairs: [],
Expand Down
7 changes: 3 additions & 4 deletions packages/arb-token-bridge-ui/src/util/wagmi/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ export function getProps(targetChainKey: string | null) {
chains
})

wallets[0]?.wallets.push(okxWallet({ chains, projectId }))

const connectors = connectorsForWallets([
...wallets,
{
groupName: 'More',
wallets: [
trustWallet({ chains, projectId }),
okxWallet({ chains, projectId })
]
wallets: [trustWallet({ chains, projectId })]
}
])

Expand Down

0 comments on commit bcd2617

Please sign in to comment.