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

[SDK] add two new utilities toEther and toWei #421

Merged
merged 16 commits into from Dec 8, 2022

Conversation

yehia67
Copy link
Contributor

@yehia67 yehia67 commented Nov 30, 2022

@changeset-bot
Copy link

changeset-bot bot commented Nov 30, 2022

🦋 Changeset detected

Latest commit: 755f018

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

This PR includes changesets to release 5 packages
Name Type
@thirdweb-dev/sdk Patch
@thirdweb-dev/auth Patch
thirdweb Patch
@thirdweb-dev/react Patch
@thirdweb-dev/unity-js-bridge 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

@nachoiacovino
Copy link
Contributor

nachoiacovino commented Nov 30, 2022

I think it might be better for it to be formatUnits and accept decimals as optional second param defaulting to 18, same for the toWei function , thoughts @joaquim-verges ? in this form we couldn't use it for USDC for example

@yehia67
Copy link
Contributor Author

yehia67 commented Nov 30, 2022

@nachoiacovino In that case we will have to change the name from toWei and toEther to formatUnit and parseUnit

@joaquim-verges
Copy link
Contributor

@yehia67 nah i actually like toWei and toEth better. How about adding a third method that would be toUnits that takes in the decimals for custom ERC20s?

@joaquim-verges
Copy link
Contributor

also make sure to add a changeset 🙏

@nachoiacovino
Copy link
Contributor

@yehia67 nah i actually like toWei and toEth better. How about adding a third method that would be toUnits that takes in the decimals for custom ERC20s?

what about the other way around? from units to wei for custom erc20?

@yehia67
Copy link
Contributor Author

yehia67 commented Dec 1, 2022

@joaquim-verges @nachoiacovino I can add two utilities toUnits and formatUnits
Sure I will add the changeset on the two PRs sorry for that

packages/sdk/src/evm/common/currency.ts Outdated Show resolved Hide resolved
packages/sdk/src/evm/common/currency.ts Outdated Show resolved Hide resolved
packages/sdk/src/evm/common/currency.ts Outdated Show resolved Hide resolved
@yehia67
Copy link
Contributor Author

yehia67 commented Dec 3, 2022

@joaquim-verges should I remove all ./changest files and leave only the latest one?

}

export function toWei(amount: BigNumberish): BigNumber {
return utils.parseEther(AmountSchema.parse(amount));
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you do y have to parse anything, just pass the BigNumberish value in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"pasreEther" params accept string only parseEther(ether: string)

Copy link
Contributor

Choose a reason for hiding this comment

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

right so it should be the opposite then:

toEther(amount: BigNumberish)
and
toWei(amount: Amount)

packages/sdk/src/evm/common/currency.ts Outdated Show resolved Hide resolved
.changeset/stale-worms-exist.md Outdated Show resolved Hide resolved
.changeset/witty-birds-hang.md Outdated Show resolved Hide resolved
.changeset/fluffy-toys-warn.md Outdated Show resolved Hide resolved
}

export function toWei(amount: BigNumberish): BigNumber {
return utils.parseEther(AmountSchema.parse(amount));
Copy link
Contributor

Choose a reason for hiding this comment

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

right so it should be the opposite then:

toEther(amount: BigNumberish)
and
toWei(amount: Amount)

@yehia67
Copy link
Contributor Author

yehia67 commented Dec 6, 2022

@joaquim-verges for toWei(amount: Amount) The parseEther(ether: string): accept string only, so Amount will not pass because it has string | number

@joaquim-verges
Copy link
Contributor

Amount.parse(amount) returns a string so you can use that internally to transform string | number to just string

@yehia67
Copy link
Contributor Author

yehia67 commented Dec 7, 2022

@joaquim-verges yes make 100% sense

@jnsdls
Copy link
Member

jnsdls commented Dec 8, 2022

thx @yehia67!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants