-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
175 additions
and
203 deletions.
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
93 changes: 93 additions & 0 deletions
93
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,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 = ({ | ||
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 | ||
|
||
const href = createBlockExplorerUrlForToken({ | ||
explorerLink: networks.sourceChain.blockExplorers?.default.url, | ||
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} | ||
</Tooltip> | ||
) | ||
} |
66 changes: 66 additions & 0 deletions
66
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,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 | ||
]) | ||
|
||
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
79 changes: 0 additions & 79 deletions
79
packages/arb-token-bridge-ui/src/components/TransferPanel/TransferPanelMain/TokenBalance.tsx
This file was deleted.
Oops, something went wrong.
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.