Skip to content

Commit 2778745

Browse files
committed
SDK: token details screen UI tweaks (#8612)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on improving the user interface of the `TokenInfoScreen` component in the `select-token-ui.tsx` file by enhancing loading states, adjusting layout heights, and refining token display logic. ### Detailed summary - Removed initial loading and token not found states. - Increased `Container` minHeight from `350px` to `450px`. - Refactored conditional rendering for token details. - Maintained structure for displaying token name, symbol, price, market cap, volume, and contract address. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Consolidated rendering logic for the token information view to centralize pending, not-found, and content states. * Reorganized layout so detailed token sections render only when token data is present. * Adjusted minimum container height for token information screens in the bridge swap widget. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 4fc02b3 commit 2778745

File tree

1 file changed

+119
-136
lines changed

1 file changed

+119
-136
lines changed

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx

Lines changed: 119 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -506,34 +506,6 @@ function TokenInfoScreen(props: {
506506
});
507507
const token = tokenQuery.data;
508508

509-
if (tokenQuery.isPending) {
510-
return (
511-
<Container
512-
flex="column"
513-
center="both"
514-
expand
515-
style={{ minHeight: "350px" }}
516-
>
517-
<Spinner size="lg" color="secondaryText" />
518-
</Container>
519-
);
520-
}
521-
522-
if (!token) {
523-
return (
524-
<Container
525-
flex="column"
526-
center="both"
527-
expand
528-
style={{ minHeight: "350px" }}
529-
>
530-
<Text size="sm" color="secondaryText">
531-
Token not found
532-
</Text>
533-
</Container>
534-
);
535-
}
536-
537509
const isNativeToken = isNativeTokenAddress(props.tokenAddress);
538510
const explorerLink = isNativeToken
539511
? `https://thirdweb.com/${props.chainId}`
@@ -543,7 +515,7 @@ function TokenInfoScreen(props: {
543515
<Container
544516
flex="column"
545517
expand
546-
style={{ minHeight: "350px" }}
518+
style={{ minHeight: "450px" }}
547519
animate="fadein"
548520
>
549521
{/* Header */}
@@ -552,125 +524,136 @@ function TokenInfoScreen(props: {
552524
</Container>
553525
<Line dashed />
554526

555-
{/* Content */}
556-
<Container flex="column" gap="md" px="md" py="lg">
557-
{/* name + icon */}
558-
<Container
559-
flex="row"
560-
style={{
561-
justifyContent: "space-between",
562-
alignItems: "center",
563-
}}
564-
>
527+
{tokenQuery.isPending ? (
528+
<Container flex="column" center="both" expand>
529+
<Spinner size="lg" color="secondaryText" />
530+
</Container>
531+
) : !token ? (
532+
<Container flex="column" center="both" expand>
565533
<Text size="sm" color="secondaryText">
566-
Name
534+
Token not found
567535
</Text>
568-
569-
<Container flex="row" gap="xxs" center="y">
570-
<Img
571-
src={token.iconUri || ""}
572-
client={props.client}
573-
width={iconSize.sm}
574-
height={iconSize.sm}
575-
style={{
576-
borderRadius: radius.full,
577-
}}
578-
fallback={
579-
<Container
580-
style={{
581-
background: `linear-gradient(45deg, white, ${theme.colors.accentText})`,
582-
borderRadius: radius.full,
583-
width: `${iconSize.sm}px`,
584-
height: `${iconSize.sm}px`,
585-
}}
586-
/>
587-
}
588-
/>
589-
<Text
590-
size="sm"
591-
color="primaryText"
592-
weight={500}
593-
style={{
594-
maxWidth: "200px",
595-
whiteSpace: "nowrap",
596-
}}
597-
>
598-
{token.name}
536+
</Container>
537+
) : (
538+
<Container flex="column" gap="md" px="md" py="lg">
539+
{/* name + icon */}
540+
<Container
541+
flex="row"
542+
style={{
543+
justifyContent: "space-between",
544+
alignItems: "center",
545+
}}
546+
>
547+
<Text size="sm" color="secondaryText">
548+
Name
599549
</Text>
550+
551+
<Container flex="row" gap="xxs" center="y">
552+
<Img
553+
src={token.iconUri || ""}
554+
client={props.client}
555+
width={iconSize.sm}
556+
height={iconSize.sm}
557+
style={{
558+
borderRadius: radius.full,
559+
}}
560+
fallback={
561+
<Container
562+
style={{
563+
background: `linear-gradient(45deg, white, ${theme.colors.accentText})`,
564+
borderRadius: radius.full,
565+
width: `${iconSize.sm}px`,
566+
height: `${iconSize.sm}px`,
567+
}}
568+
/>
569+
}
570+
/>
571+
<Text
572+
size="sm"
573+
color="primaryText"
574+
weight={500}
575+
style={{
576+
maxWidth: "200px",
577+
whiteSpace: "nowrap",
578+
}}
579+
>
580+
{token.name}
581+
</Text>
582+
</Container>
600583
</Container>
601-
</Container>
602584

603-
{/* symbol */}
604-
<TokenInfoRow label="Symbol" value={token.symbol} />
605-
606-
{/* price */}
607-
{"prices" in token && (
608-
<TokenInfoRow
609-
label="Price"
610-
value={
611-
token.prices[props.currency]
612-
? formatCurrencyAmount(
613-
props.currency,
614-
token.prices[props.currency] as number,
615-
)
616-
: "N/A"
617-
}
618-
/>
619-
)}
585+
{/* symbol */}
586+
<TokenInfoRow label="Symbol" value={token.symbol} />
587+
588+
{/* price */}
589+
{"prices" in token && (
590+
<TokenInfoRow
591+
label="Price"
592+
value={
593+
token.prices[props.currency]
594+
? formatCurrencyAmount(
595+
props.currency,
596+
token.prices[props.currency] as number,
597+
)
598+
: "N/A"
599+
}
600+
/>
601+
)}
620602

621-
{/* market cap */}
622-
{!!token.marketCapUsd && (
623-
<TokenInfoRow
624-
label="Market Cap"
625-
value={formatCurrencyAmount(props.currency, token.marketCapUsd)}
626-
/>
627-
)}
603+
{/* market cap */}
604+
{!!token.marketCapUsd && (
605+
<TokenInfoRow
606+
label="Market Cap"
607+
value={formatCurrencyAmount(props.currency, token.marketCapUsd)}
608+
/>
609+
)}
628610

629-
{/* volume 24h */}
630-
{!!token.volume24hUsd && (
631-
<TokenInfoRow
632-
label="Volume (24h)"
633-
value={formatCurrencyAmount(props.currency, token.volume24hUsd)}
634-
/>
635-
)}
611+
{/* volume 24h */}
612+
{!!token.volume24hUsd && (
613+
<TokenInfoRow
614+
label="Volume (24h)"
615+
value={formatCurrencyAmount(props.currency, token.volume24hUsd)}
616+
/>
617+
)}
636618

637-
{/* address + link */}
638-
<Container
639-
flex="row"
640-
style={{
641-
justifyContent: "space-between",
642-
alignItems: "center",
643-
}}
644-
>
645-
<Text size="sm" color="secondaryText">
646-
Contract Address
647-
</Text>
619+
{/* address + link */}
620+
<Container
621+
flex="row"
622+
style={{
623+
justifyContent: "space-between",
624+
alignItems: "center",
625+
}}
626+
>
627+
<Text size="sm" color="secondaryText">
628+
Contract Address
629+
</Text>
648630

649-
<Container flex="row" gap="3xs" center="y">
650-
{!isNativeToken && (
651-
<CopyIcon
652-
text={props.tokenAddress}
653-
iconSize={13}
654-
tip="Copy Address"
655-
/>
656-
)}
631+
<Container flex="row" gap="3xs" center="y">
632+
{!isNativeToken && (
633+
<CopyIcon
634+
text={props.tokenAddress}
635+
iconSize={13}
636+
tip="Copy Address"
637+
/>
638+
)}
657639

658-
<Link
659-
href={explorerLink}
660-
target="_blank"
661-
rel="noreferrer"
662-
color="accentText"
663-
hoverColor="primaryText"
664-
weight={500}
665-
size="sm"
666-
>
667-
{isNativeToken
668-
? "Native Currency"
669-
: shortenAddress(props.tokenAddress)}
670-
</Link>
640+
<Link
641+
href={explorerLink}
642+
target="_blank"
643+
rel="noreferrer"
644+
color="accentText"
645+
hoverColor="primaryText"
646+
weight={500}
647+
size="sm"
648+
>
649+
{isNativeToken
650+
? "Native Currency"
651+
: shortenAddress(props.tokenAddress)}
652+
</Link>
653+
</Container>
671654
</Container>
672655
</Container>
673-
</Container>
656+
)}
674657
</Container>
675658
);
676659
}

0 commit comments

Comments
 (0)