-
Notifications
You must be signed in to change notification settings - Fork 211
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ad09d9d
token tooltip
brtkx a29ac4b
comment
brtkx a60d266
unused code
brtkx 40aae6f
address comments
brtkx 3d1e35e
Merge branch 'master' of github.com:OffchainLabs/arbitrum-token-bridg…
brtkx 91a4de4
fix
brtkx ae69dd0
clean up
brtkx 48d20ed
Merge branch 'master' into token-tooltip
brtkx 5c5a955
Merge branch 'master' into token-tooltip
spsjvc bc5fd94
address comments
brtkx c7bbeb9
Merge branch 'token-tooltip' of github.com:OffchainLabs/arbitrum-toke…
brtkx f4dd4bc
change
brtkx 033e51f
Merge branch 'master' into token-tooltip
douglance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/arb-token-bridge-ui/src/components/TransferPanel/TokenInfoTooltip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ERC20BridgeToken } from '../../hooks/arbTokenBridge.types' | ||
import { useNetworks } from '../../hooks/useNetworks' | ||
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship' | ||
import { Tooltip } from '../common/Tooltip' | ||
import { TokenLogo } from './TokenLogo' | ||
import { useNativeCurrency } from '../../hooks/useNativeCurrency' | ||
import { ExternalLink } from '../common/ExternalLink' | ||
import { shortenAddress } from '../../util/CommonUtils' | ||
import { getExplorerUrl } from '../../util/networks' | ||
import { ChainId } from '../../types/ChainId' | ||
import { isTokenNativeUSDC } from '../../util/TokenUtils' | ||
|
||
export function BlockExplorerTokenLink({ | ||
chainId, | ||
address | ||
}: { | ||
chainId: ChainId | ||
address: string | undefined | ||
}) { | ||
douglance marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (typeof address === 'undefined') { | ||
return null | ||
} | ||
|
||
return ( | ||
<ExternalLink | ||
href={`${getExplorerUrl(chainId)}/token/${address}`} | ||
className="arb-hover text-xs underline" | ||
onClick={e => e.stopPropagation()} | ||
> | ||
{shortenAddress(address).toLowerCase()} | ||
</ExternalLink> | ||
) | ||
} | ||
|
||
export const TokenInfoTooltip = ({ | ||
token | ||
}: { | ||
token: ERC20BridgeToken | null | ||
}) => { | ||
const [networks] = useNetworks() | ||
const { isDepositMode, childChainProvider } = | ||
useNetworksRelationship(networks) | ||
const childChainNativeCurrency = useNativeCurrency({ | ||
provider: childChainProvider | ||
}) | ||
|
||
if (!token || isTokenNativeUSDC(token.address)) { | ||
return <span>{token?.symbol ?? childChainNativeCurrency.symbol}</span> | ||
} | ||
|
||
const tokenAddress = isDepositMode ? token.l2Address : token.address | ||
|
||
return ( | ||
<Tooltip | ||
wrapperClassName="underline cursor-pointer" | ||
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> | ||
<BlockExplorerTokenLink | ||
chainId={networks.destinationChain.id} | ||
address={tokenAddress} | ||
/> | ||
</div> | ||
</div> | ||
} | ||
tippyProps={{ | ||
arrow: false, | ||
interactive: true | ||
}} | ||
> | ||
{token.symbol} | ||
fionnachan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Tooltip> | ||
) | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/arb-token-bridge-ui/src/components/TransferPanel/TokenLogo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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 | ||
* @param {string | undefined} [props.className] - Class name override | ||
*/ | ||
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)} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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