Skip to content

Conversation

@gregfromstl
Copy link
Contributor

@gregfromstl gregfromstl commented Nov 19, 2024

Relevant Slack discussion

CNCT-2368


PR-Codex overview

This PR focuses on adjusting the toWei function to account for different decimal configurations across chains, specifically for Hedera and zkSync, enhancing token handling in various components.

Detailed summary

  • Updated toWei function to accept a chain parameter for variable decimals.
  • Modified useSendToken.ts to use toWei(amount, activeChain).
  • Changed TransferConfirmationScreen.tsx to use toWei(tokenAmount, chain).
  • Adjusted zkDeployCreate2Factory.ts to use toWei("0.01", options.chain).
  • Altered deposit.ts to handle options.amount with respect to options.contract.chain.

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

@gregfromstl gregfromstl added the Bug Something isn't working as intended in a provided reproduction. label Nov 19, 2024
@gregfromstl gregfromstl self-assigned this Nov 19, 2024
@linear
Copy link

linear bot commented Nov 19, 2024

@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2024

🦋 Changeset detected

Latest commit: 8110d8c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
thirdweb Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link

vercel bot commented Nov 19, 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 21, 2024 9:04pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 21, 2024 9:04pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 21, 2024 9:04pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 21, 2024 9:04pm

@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 44.91 KB (-0.14% 🔽) 899 ms (-0.14% 🔽) 505 ms (+53.11% 🔺) 1.5 s
thirdweb (cjs) 104.92 KB (-0.09% 🔽) 2.1 s (-0.09% 🔽) 639 ms (-10.87% 🔽) 2.8 s
thirdweb (minimal + tree-shaking) 5.6 KB (0%) 113 ms (0%) 104 ms (+158.51% 🔺) 216 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 25 ms (+156.24% 🔺) 35 ms
thirdweb/react (minimal + tree-shaking) 18.38 KB (0%) 368 ms (0%) 111 ms (+100.62% 🔺) 479 ms

@codecov
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.

Project coverage is 43.89%. Comparing base (0e5d120) to head (5f0a093).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...ges/thirdweb/src/extensions/erc20/write/deposit.ts 0.00% 3 Missing ⚠️
packages/thirdweb/src/utils/units.ts 57.14% 3 Missing ⚠️
...ntract/deployment/zksync/zkDeployCreate2Factory.ts 0.00% 1 Missing ⚠️
...rdweb/src/react/core/hooks/wallets/useSendToken.ts 0.00% 1 Missing ⚠️
...et/screens/Buy/swap/TransferConfirmationScreen.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5466      +/-   ##
==========================================
+ Coverage   43.81%   43.89%   +0.07%     
==========================================
  Files        1069     1075       +6     
  Lines       55726    55951     +225     
  Branches     3882     3911      +29     
==========================================
+ Hits        24415    24557     +142     
- Misses      30628    30711      +83     
  Partials      683      683              
Flag Coverage Δ *Carryforward flag
legacy_packages 65.68% <ø> (ø) Carriedforward from 2e7f347
packages 38.62% <30.76%> (+0.12%) ⬆️

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

Files with missing lines Coverage Δ
...ntract/deployment/zksync/zkDeployCreate2Factory.ts 2.08% <0.00%> (ø)
...rdweb/src/react/core/hooks/wallets/useSendToken.ts 3.12% <0.00%> (ø)
...et/screens/Buy/swap/TransferConfirmationScreen.tsx 0.96% <0.00%> (ø)
...ges/thirdweb/src/extensions/erc20/write/deposit.ts 12.50% <0.00%> (-1.79%) ⬇️
packages/thirdweb/src/utils/units.ts 93.65% <57.14%> (-4.63%) ⬇️

... and 18 files with indirect coverage changes

---- 🚨 Try these New Features:

*/
export function toWei(tokens: string) {
return toUnits(tokens, 18);
export function toWei(tokens: string, chain?: Chain) {
Copy link
Member

@joaquim-verges joaquim-verges Nov 21, 2024

Choose a reason for hiding this comment

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

wonder if a better call would be to get the chain metadata async in the places where we do toWei above, and use toUnits with the chain native currency decimals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a native currency decimals thing, it's the literal wei on the chain. Peep the slack thread linked in the PR description

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but I assume we put this decimals value in the chains db right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't as of right now because (based on my understanding) it's something EVM chains would normally never deviate from. We have the native currency decimals, but that's different. It's an extreme edge case as Firekeeper said

Copy link
Member

@joaquim-verges joaquim-verges Nov 21, 2024

Choose a reason for hiding this comment

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

gotcha, its just a bit weird to me to change the public API of toWei for this. as a user i would be confused why i would pass a chain there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I hate it but not sure of any other solution

@gregfromstl gregfromstl added the merge-queue Adds the pull request to Graphite's merge queue. label Nov 21, 2024
Copy link
Contributor Author

gregfromstl commented Nov 21, 2024

Merge activity

  • Nov 20, 10:06 PM EST: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Nov 21, 3:52 PM EST: A user added this pull request to the Graphite merge queue.
  • Nov 21, 3:57 PM EST: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'Unit Tests').
  • Nov 21, 3:58 PM EST: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Nov 21, 8:58 PM UTC: The merge label 'merge-queue' was removed. This PR will no longer be merged by the Graphite merge queue

[Relevant Slack discussion](https://thirdwebdev.slack.com/archives/C04P6J3K0ES/p1731616237108399?thread_ts=1730826933.868789&cid=C04P6J3K0ES)

CNCT-2368

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on adjusting the `toWei` function to accommodate different decimal values for various chains, particularly for Hedera, improving token handling in the `thirdweb` library.

### Detailed summary
- Updated `toWei` function to accept a `chain` parameter for variable decimal handling.
- Modified `useSendToken.ts` to pass `activeChain` to `toWei`.
- Changed `TransferConfirmationScreen.tsx` to use `chain` for `toWei`.
- Adjusted `zkDeployCreate2Factory.ts` to use `options.chain` in `toWei`.
- Updated `deposit.ts` to consider `options.contract.chain` in `toWei`.

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

<!-- end pr-codex -->
@gregfromstl
Copy link
Contributor Author

Closing because I don't like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working as intended in a provided reproduction. packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants