Skip to content

Commit

Permalink
Merge branch 'master' into network-box-redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
fionnachan committed Sep 20, 2024
2 parents d76e933 + efcc7bd commit 988dfa1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ enum DestinationAddressWarnings {
}

type DestinationAddressStore = {
error: DestinationAddressErrors | null
destinationAddress: string | undefined
setError: (error: DestinationAddressErrors | null) => void
setDestinationAddress: (destinationAddress: string | undefined) => void
}

export const useDestinationAddressStore = create<DestinationAddressStore>(
set => ({
error: null,
destinationAddress: undefined,
setError: error => set(() => ({ error })),
setDestinationAddress: destinationAddress =>
set(() => ({ destinationAddress }))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ import { useBalances } from '../../hooks/useBalances'
import { captureSentryErrorWithExtraData } from '../../util/SentryUtils'
import { useIsBatchTransferSupported } from '../../hooks/TransferPanel/useIsBatchTransferSupported'
import { normalizeTimestamp } from '../../state/app/utils'
import { getDestinationAddressError } from './hooks/useDestinationAddressError'
import { useDestinationAddressError } from './hooks/useDestinationAddressError'
import { useIsCctpTransfer } from './hooks/useIsCctpTransfer'

const signerUndefinedError = 'Signer is undefined'

export function TransferPanel() {
const { tokenFromSearchParams, setTokenQueryParam } =
useTokenFromSearchParams()
Expand Down Expand Up @@ -172,6 +174,8 @@ export function TransferPanel() {

const { transferReady } = useTransferReadiness()

const { destinationAddressError } = useDestinationAddressError()

const { color: destinationChainUIcolor } = getBridgeUiConfigForChain(
networks.destinationChain.id
)
Expand Down Expand Up @@ -389,11 +393,6 @@ export function TransferPanel() {
if (!withdrawalConfirmation) return
}

const destinationAddressError = await getDestinationAddressError({
destinationAddress,
isSenderSmartContractWallet: isSmartContractWallet,
isTeleportMode
})
if (destinationAddressError) {
console.error(destinationAddressError)
return
Expand Down Expand Up @@ -535,9 +534,20 @@ export function TransferPanel() {
}
}

const transfer = async () => {
const signerUndefinedError = 'Signer is undefined'
const isTransferAllowed = useMemo(() => {
if (!isConnected) {
return false
}
if (!walletAddress) {
return false
}
if (!!destinationAddressError) {
return false
}
return true
}, [destinationAddressError, isConnected, walletAddress])

const transfer = async () => {
try {
setTransferring(true)
if (chainId !== networks.sourceChain.id) {
Expand All @@ -547,10 +557,7 @@ export function TransferPanel() {
setTransferring(false)
}

if (!isConnected) {
return
}
if (!walletAddress) {
if (!isTransferAllowed) {
return
}

Expand All @@ -559,16 +566,6 @@ export function TransferPanel() {
throw signerUndefinedError
}

const destinationAddressError = await getDestinationAddressError({
destinationAddress,
isSenderSmartContractWallet: isSmartContractWallet,
isTeleportMode
})
if (destinationAddressError) {
console.error(destinationAddressError)
return
}

// SC ETH transfers aren't enabled yet. Safety check, shouldn't be able to get here.
if (isSmartContractWallet && !selectedToken) {
console.error("ETH transfers aren't enabled for smart contract wallets.")
Expand Down Expand Up @@ -716,12 +713,6 @@ export function TransferPanel() {
return
}

// if destination address is added, validate it
const destinationAddressError = await getDestinationAddressError({
destinationAddress,
isSenderSmartContractWallet: isSmartContractWallet,
isTeleportMode
})
if (destinationAddressError) {
console.error(destinationAddressError)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
isTokenArbitrumOneNativeUSDC
} from '../../util/TokenUtils'
import { useAppContextState } from '../App/AppContext'
import { useDestinationAddressStore } from './AdvancedSettings'
import {
TransferReadinessRichErrorMessage,
getInsufficientFundsErrorMessage,
Expand All @@ -32,6 +31,7 @@ import { useBalances } from '../../hooks/useBalances'
import { useArbQueryParams } from '../../hooks/useArbQueryParams'
import { formatAmount } from '../../util/NumberUtils'
import { useSelectedTokenIsWithdrawOnly } from './hooks/useSelectedTokenIsWithdrawOnly'
import { useDestinationAddressError } from './hooks/useDestinationAddressError'

// Add chains IDs that are currently down or disabled
// It will block transfers and display an info box in the transfer panel
Expand Down Expand Up @@ -151,7 +151,7 @@ export function useTransferReadiness(): UseTransferReadinessResult {
parentWalletAddress: walletAddress,
childWalletAddress: walletAddress
})
const { error: destinationAddressError } = useDestinationAddressStore()
const { destinationAddressError } = useDestinationAddressError()

const ethL1BalanceFloat = ethParentBalance
? parseFloat(utils.formatEther(ethParentBalance))
Expand Down Expand Up @@ -571,6 +571,8 @@ export function useTransferReadiness(): UseTransferReadinessResult {
childChain.id,
parentChain.id,
networks.sourceChain.name,
isTeleportMode
isTeleportMode,
isSelectedTokenWithdrawOnly,
isSelectedTokenWithdrawOnlyLoading
])
}

0 comments on commit 988dfa1

Please sign in to comment.