-
Notifications
You must be signed in to change notification settings - Fork 446
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
Read the amount from the URL if it is set #203
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
examples/point-of-sale/src/client/components/contexts/PaymentProvider.tsx
Outdated
Show resolved
Hide resolved
if (Array.isArray(queryAmount)) return new BigNumber(queryAmount[0]); | ||
return new BigNumber(queryAmount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think we might need to validate the amount in some way. If it doesn't pass a simple regex, we probably don't want to instantiate a BigNumber
from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some validation (not NaN, finite, >0) using BigNumber functions. I think that's a bit more straightforward than adding our own regex, and since the amount is displayed on screen + in the wallet it's ok to allow whatever parsing flexibility BigNumber has here. Can add a regex instead if you'd prefer though, I don't have a strong view either way really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think either is fine. My idea was simply to check it against ^\d+(\.\d+)?$
since this is (more or less) what describes a valid manual amount entry into the UI. Zero amounts are technically probably okay to allow (they are allowed in the protocol) but I don't care enough to change this.
71a2fd3
to
106d85c
Compare
106d85c
to
2caf489
Compare
Closes #202
This issue is caused by the POS app using only local state for the
amount
, while other fields (like recipient and label) use the URL values. This PR sets the initial value of theamount
state using theamount
query param if it is present.