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

feat: show token tooltip in transfer summary #2202

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useTokensFromLists, useTokensFromUser } from './TokenSearchUtils'

export type TokenButtonOptions = {
symbol?: string
logoSrc?: string
logoSrc?: string | null
Copy link
Contributor Author

Choose a reason for hiding this comment

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

null is used if we want to show native currency, otherwise selected token is show as the token logo

disabled?: boolean
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { ERC20BridgeToken } from '../../hooks/arbTokenBridge.types'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { shortenAddress } from '../../util/CommonUtils'
import { captureSentryErrorWithExtraData } from '../../util/SentryUtils'
import { ExternalLink } from '../common/ExternalLink'
import { Tooltip } from '../common/Tooltip'
import { TokenLogo } from './TokenLogo'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'

const createBlockExplorerUrlForToken = ({
fionnachan marked this conversation as resolved.
Show resolved Hide resolved
explorerLink,
tokenAddress
}: {
explorerLink: string | undefined
tokenAddress: string | undefined
}): string | undefined => {
if (!explorerLink) {
return undefined
}
if (!tokenAddress) {
return undefined
}
try {
const url = new URL(explorerLink)
url.pathname += `token/${tokenAddress}`
return url.toString()
} catch (error) {
captureSentryErrorWithExtraData({
error,
originFunction: 'createBlockExplorerUrlForToken'
})
return undefined
}
}

export const TokenInfoTooltip = ({
token
}: {
token: ERC20BridgeToken | null
}) => {
const [networks] = useNetworks()
const { isDepositMode, childChainProvider } =
useNetworksRelationship(networks)
const childChainNativeCurrency = useNativeCurrency({
provider: childChainProvider
})

if (!token) {
return <span>{childChainNativeCurrency.symbol}</span>
}

const tokenAddress = isDepositMode ? token.address : token.l2Address
fionnachan marked this conversation as resolved.
Show resolved Hide resolved

const href = createBlockExplorerUrlForToken({
explorerLink: networks.sourceChain.blockExplorers?.default.url,
fionnachan marked this conversation as resolved.
Show resolved Hide resolved
tokenAddress
})

return (
<Tooltip
wrapperClassName="underline"
theme="dark"
content={
<div className="flex items-center space-x-2">
<TokenLogo srcOverride={token.logoURI} className="h-7 w-7" />
<div className="flex flex-col">
<div className="flex space-x-1">
<span className="text-lg font-normal">{token.symbol}</span>
<span className="pt-[4px] text-xs font-normal text-gray-400">
{token.name}
</span>
</div>
{href && tokenAddress && (
<ExternalLink
className="arb-hover text-xs text-gray-300 underline"
href={href}
>
<span>{shortenAddress(tokenAddress)}</span>
</ExternalLink>
)}
</div>
</div>
}
tippyProps={{
arrow: false,
interactive: true
}}
>
{token.symbol}
fionnachan marked this conversation as resolved.
Show resolved Hide resolved
</Tooltip>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useMemo } from 'react'

import { useAppState } from '../../state'
import { useTokensFromLists, useTokensFromUser } from './TokenSearchUtils'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
import { SafeImage } from '../common/SafeImage'
import { twMerge } from 'tailwind-merge'

/**
* Shows the selected token logo by default.
* @param {Object} props
* @param {string | null} [props.srcOverride] - Optional URL to override default token logo source
*/
export const TokenLogo = ({
srcOverride,
className
}: {
srcOverride?: string | null
className?: string
}) => {
const {
app: { selectedToken }
} = useAppState()
const tokensFromLists = useTokensFromLists()
const tokensFromUser = useTokensFromUser()

const [networks] = useNetworks()
const { childChainProvider } = useNetworksRelationship(networks)
const nativeCurrency = useNativeCurrency({ provider: childChainProvider })

const src = useMemo(() => {
// Override to show the native currency logo
if (srcOverride === null) {
return nativeCurrency.logoUrl
}

if (typeof srcOverride !== 'undefined') {
return srcOverride
}

if (selectedToken) {
return (
tokensFromLists[selectedToken.address]?.logoURI ??
tokensFromUser[selectedToken.address]?.logoURI
)
}

return nativeCurrency.logoUrl
}, [
nativeCurrency.logoUrl,
selectedToken,
srcOverride,
tokensFromLists,
tokensFromUser
])
fionnachan marked this conversation as resolved.
Show resolved Hide resolved

return (
<SafeImage
src={src}
alt="Token logo"
className={twMerge('h-5 w-5 shrink-0', className)}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ export function SourceNetworkBox() {
)
)
: undefined,
logoSrc: nativeCurrency.logoUrl
logoSrc: null
}),
[
nativeCurrency.symbol,
nativeCurrency.logoUrl,
nativeCurrencyBalances.sourceBalance,
nativeCurrencyDecimalsOnSourceChain
]
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file hasn't been used anywhere at all

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import { twMerge } from 'tailwind-merge'
import Image from 'next/image'

import { formatAmount } from '../../util/NumberUtils'
import { getNetworkName, isNetwork } from '../../util/networks'
import { getNetworkName } from '../../util/networks'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
import { useGasSummary } from '../../hooks/TransferPanel/useGasSummary'
import { useArbQueryParams } from '../../hooks/useArbQueryParams'
import { TokenSymbolWithExplorerLink } from '../common/TokenSymbolWithExplorerLink'
import { ERC20BridgeToken } from '../../hooks/arbTokenBridge.types'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'
import { NativeCurrencyPrice, useIsBridgingEth } from './NativeCurrencyPrice'
import { useAppState } from '../../state'
import { Loader } from '../common/atoms/Loader'
import { Tooltip } from '../common/Tooltip'
import { isTokenNativeUSDC } from '../../util/TokenUtils'
import { NoteBox } from '../common/NoteBox'
import { DISABLED_CHAIN_IDS } from './useTransferReadiness'
import { useIsBatchTransferSupported } from '../../hooks/TransferPanel/useIsBatchTransferSupported'
import { getConfirmationTime } from '../../util/WithdrawalUtils'
import LightningIcon from '@/images/LightningIcon.svg'
import { TokenInfoTooltip } from './TokenInfoTooltip'

export type TransferPanelSummaryToken = {
symbol: string
Expand Down Expand Up @@ -190,16 +189,6 @@ export function TransferPanelSummary({ token }: TransferPanelSummaryProps) {
const [{ amount, amount2 }] = useArbQueryParams()
const isBatchTransferSupported = useIsBatchTransferSupported()

const {
isArbitrumOne: isDestinationChainArbitrumOne,
isArbitrumSepolia: isDestinationChainArbitrumSepolia
} = isNetwork(networks.destinationChain.id)

const isDepositingUSDCtoArbOneOrArbSepolia =
isTokenNativeUSDC(token?.address) &&
isDepositMode &&
(isDestinationChainArbitrumOne || isDestinationChainArbitrumSepolia)

if (gasSummaryStatus === 'unavailable') {
return (
<TransferPanelSummaryContainer>
Expand Down Expand Up @@ -242,16 +231,9 @@ export function TransferPanelSummary({ token }: TransferPanelSummaryProps) {
<span>
You will receive on {getNetworkName(networks.destinationChain.id)}:
</span>
<span className="font-medium">
<span className="flex space-x-1 font-medium">
<span className="tabular-nums">{formatAmount(Number(amount))}</span>{' '}
{isDepositingUSDCtoArbOneOrArbSepolia ? (
<>USDC</>
) : (
<TokenSymbolWithExplorerLink
token={token}
isParentChain={!isDepositMode}
/>
)}
<TokenInfoTooltip token={token} />
{isBridgingEth && (
<NativeCurrencyPrice amount={Number(amount)} showBrackets />
)}
Expand Down
Loading
Loading