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

Playground: Headless components #5535

Open
wants to merge 1 commit into
base: kien/account-balance-in-usd
Choose a base branch
from

Conversation

kien-ngo
Copy link
Contributor

@kien-ngo kien-ngo commented Nov 28, 2024

Problem solved

Short description of the bug fixed or feature added


PR-Codex overview

This PR introduces new UI components and updates existing ones for enhanced account and NFT functionalities in a web application. It adds new sections and examples for Headless UI components, improving the overall user experience in connecting wallets and displaying account information.

Detailed summary

  • Added ArticleCardIndex for "Headless UI" in page.tsx.
  • Expanded navigation links in navLinks.ts.
  • Enhanced account avatar queries with additional parameters in avatar.tsx and name.tsx.
  • Created new NFT components (NftMediaBasic, NftNameBasic, NftDescriptionBasic, NftCardDemo) in nft-examples.tsx.
  • Implemented new account components (AccountAddressBasic, AccountAvatarBasic, etc.) in account-examples.tsx.
  • Updated metadata in various components for better description and titles.
  • Wrapped new components with ThirdwebProvider for context management in UI pages.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Nov 28, 2024

⚠️ No Changeset found

Latest commit: 39f870d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel vercel bot temporarily deployed to Preview – docs-v2 November 28, 2024 13:10 Inactive
Copy link

vercel bot commented Nov 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2024 10:36pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2024 10:36pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2024 10:36pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 28, 2024 10:36pm

Copy link

graphite-app bot commented Nov 28, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@vercel vercel bot temporarily deployed to Preview – wallet-ui November 28, 2024 13:10 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb-www November 28, 2024 13:10 Inactive
Copy link
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the Playground Changes involving the Playground codebase. label Nov 28, 2024
@kien-ngo kien-ngo changed the title update Playground: Headless components Nov 28, 2024
@kien-ngo kien-ngo marked this pull request as ready for review November 28, 2024 13:11
AccountBalance
</h2>
<p className="max-w-[600px] text-lg">
Display the current native of the wallet.
Copy link

Choose a reason for hiding this comment

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

There appears to be a word missing in this description text. It should read either "Display the current native balance of the wallet" or "Display the current native token of the wallet" to properly convey the component's purpose.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Contributor

github-actions bot commented Nov 28, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 47.92 KB (0%) 959 ms (0%) 2.6 s (-23.48% 🔽) 3.6 s
thirdweb (cjs) 107.43 KB (0%) 2.2 s (0%) 5.7 s (-8.38% 🔽) 7.8 s
thirdweb (minimal + tree-shaking) 5.58 KB (0%) 112 ms (0%) 162 ms (-6.68% 🔽) 274 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 40 ms (-3.05% 🔽) 50 ms
thirdweb/react (minimal + tree-shaking) 18.28 KB (0%) 366 ms (0%) 606 ms (+50.26% 🔺) 971 ms

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Nov 28, 2024
Comment on lines 324 to 421
<AccountBalance
chain={ethereum}
showFiatValue="USD"
loadingComponent={<span>Loading...</span>}
/>
Copy link

Choose a reason for hiding this comment

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

The code example is inconsistent with the preview component shown above it. The example is missing the formatFn={formatAccountBalanceForButton} prop that's demonstrated in the preview. Adding this prop would make the example match the actual implementation and help developers understand how to properly format balance values.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.18%. Comparing base (5b02ff0) to head (39f870d).

Additional details and impacted files
@@                       Coverage Diff                       @@
##           kien/account-balance-in-usd    #5535      +/-   ##
===============================================================
+ Coverage                        46.16%   46.18%   +0.01%     
===============================================================
  Files                             1085     1084       -1     
  Lines                            58871    58846      -25     
  Branches                          3949     3949              
===============================================================
- Hits                             27180    27178       -2     
+ Misses                           31007    30985      -22     
+ Partials                           684      683       -1     
Flag Coverage Δ *Carryforward flag
legacy_packages 65.68% <ø> (ø) Carriedforward from 5b02ff0
packages 41.76% <100.00%> (+0.01%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...rdweb/src/react/web/ui/prebuilt/Account/avatar.tsx 57.57% <100.00%> (+3.47%) ⬆️
...hirdweb/src/react/web/ui/prebuilt/Account/name.tsx 72.54% <100.00%> (+2.98%) ⬆️

... and 5 files with indirect coverage changes

<>
<div className="space-y-2">
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl">
NFTImage
Copy link

Choose a reason for hiding this comment

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

The component heading shows NFTImage but the examples use NFTMedia. Consider updating the heading to match the actual component name to avoid confusion in the documentation.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

<>
<div className="space-y-2">
<h2 className="font-semibold text-2xl tracking-tight sm:text-3xl">
NFTImage
Copy link

Choose a reason for hiding this comment

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

The component heading NFTImage does not match the actual component being used (NFTMedia). For consistency with the implementation, the heading should be updated to NFTMedia.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

return num.toString();
}
if (num < 1_000_000) {
return formatLargeNumber(num, 1000000, "k");
Copy link

Choose a reason for hiding this comment

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

The divisor for formatting thousands (k suffix) appears incorrect - using 1000000 instead of 1000. This means numbers between 1,000-999,999 won't be properly formatted with the 'k' suffix. Recommend changing to:

return formatLargeNumber(num, 1000, 'k');

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +167 to +171
queryKey: [
"account-avatar",
address,
{ socialType },
{ resolverAddress, resolverChain },
Copy link

Choose a reason for hiding this comment

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

Simplify query key array to use direct values instead of objects: ['account-avatar', address, socialType, resolverAddress, resolverChain]

Spotted by Graphite Reviewer (based on CI logs)

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +312 to +351
lang="tsx"
/>
</>
);
}

function formatNumber(value: number, decimalPlaces: number) {
if (value === 0) return 0;
const precision = 10 ** decimalPlaces;
const threshold = 1 / 10 ** decimalPlaces; // anything below this if rounded will result in zero - so use ceil instead
const fn: "ceil" | "round" = value < threshold ? "ceil" : "round";
return Math[fn]((value + Number.EPSILON) * precision) / precision;
}

function formatAccountBalance(props: AccountBalanceFormatParams): string {
if (props.fiatBalance && props.fiatSymbol) {
// Need to keep them short to avoid UI overflow issues
const formattedTokenBalance = formatNumber(props.tokenBalance, 1);
const formattedFiatBalance = formatFiatValue(props.fiatBalance, 0);
return `${formattedTokenBalance} ${props.tokenSymbol} (${props.fiatSymbol}${formattedFiatBalance})`;
}
const formattedTokenBalance = formatNumber(
props.tokenBalance,
props.tokenBalance < 1 ? 5 : 4,
);
return `${formattedTokenBalance} ${props.tokenSymbol}`;
}

function formatFiatValue(value: number, decimals: number): string {
const num = formatNumber(value, decimals);
if (num < 1000) {
return num.toString();
}
if (num < 1_000_000) {
return formatLargeNumber(num, 1000000, "k");
}
if (num < 1000000000) {
return formatLargeNumber(num, 1000000, "M");
}
return formatLargeNumber(num, 1000000000, "B");
Copy link

Choose a reason for hiding this comment

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

Move formatting utility functions to a shared utility file to reduce code duplication and bundle size

Spotted by Graphite Reviewer (based on CI logs)

Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages Playground Changes involving the Playground codebase. SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant