anza-xyz / solana-pay

A new standard for decentralized payments.
https://solanapay.com
Apache License 2.0
1.29k stars 450 forks source link

corrected amount decimalPlaces logic #155

Closed Niten619 closed 1 year ago

Niten619 commented 2 years ago

While invoking createTransfer method for transferring native SOL and SPL tokens, the logic which checks whether the amount provided has greater precision than the SOL/mint or not (line 119 & line 148 of core/src/createTransfer.ts) will always throw CreateTransferError('amount decimals invalid') error even if we provide the amount value which is less than 9 decimals (eg. 0.5 or 1.00254) because the logic "(amount.decimalPlaces() ?? 0 > SOL_DECIMALS)" will always be True for any decimal values (whether it be less than 9 decimal (eg. 0.08) or greater than 9 decimal (eg. 0.0021547854). Adding parenthesis to the logic like so would solve this.

vercel[bot] commented 2 years ago

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

Name Status Preview Updated
solana-pay ✅ Ready (Inspect) Visit Preview Sep 5, 2022 at 6:09PM (UTC)
solana-pay-docs ✅ Ready (Inspect) Visit Preview Sep 5, 2022 at 6:09PM (UTC)
jordaaash commented 2 years ago

Thanks for the description of the issue! Could you remove the core/app stuff from the PR though?

Niten619 commented 2 years ago

Copy that.. anything else sir?

jordaaash commented 2 years ago

Thanks, much easier to review now. It looks like this fix is needed in a few more places though:

https://github.com/solana-labs/solana-pay/search?q=decimalPlaces&type=

jordaaash commented 1 year ago

Released: @solana/pay v0.2.4

flodef commented 1 year ago

Thanks a lot, sir !