-
Notifications
You must be signed in to change notification settings - Fork 12
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
Multi-Currency-Checkout: Types #346
Conversation
Instead let the browser handle parsing and rendering of currency amounts with toLocaleString. Also rename 'digits' to 'decimals' for consistency with other code.
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.
Too much use of the word undefined
for my taste :D
Again, please do not make changes by rebasing! Always add commits when resolving review suggestions. In the end, when it's approved, you can rebase, but not before. Changes are impossible to track with rebasing.
Also, make sure you don't overlook the 53 hidden comments 😉
|| ((this.request as ParsedCheckoutRequest).paymentOptions.find( | ||
(option) => option.currency === Currency.NIM, | ||
) as ParsedNimiqDirectPaymentOptions).protocolSpecific.recipient; |
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 feel this finding of the Nimiq PaymentOption is so much used, it warrants its own helper function. This helper would also be typed correctly, so no need for this repetition everywhere.
recipient = nimiqPaymentOption.protocolSpecific.recipient!; | ||
value = nimiqPaymentOption.amount; | ||
fee = nimiqPaymentOption.protocolSpecific.fee!; | ||
flags = nimiqPaymentOption.protocolSpecific.flags; |
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.
Maybe it works here, too? (I have not tried this, just feel this can work.)
{ recipient!, fee!, flags } = nimiqPaymentOption.protocolSpecific;
value = nimiqPaymentOption.amount;
"es2017", | ||
"esnext", |
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.
"esnext"
includes "es2017"
, so "es2017"
can be removed.
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.
Mostly suggestions and some small modifications.
src/lib/RequestTypes.ts
Outdated
} | ||
} | ||
|
||
protected isNonNegativeInteger(value: string | number | bigint | BigInteger) { |
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.
This seems to me like a function which could move to Helpers.ts.
} | ||
|
||
public get total(): number { | ||
return this.amount + this.fee; |
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.
constructor and update()
.
- Fix integer parsing checks for strings - Enforce integer type check and non-negativity for numbers that should be non-negative integers - Add type checking for extraData - Differentiate between undefined and falsish values - Support scientific number notation consistently - Add type checking for nimiq recipient type - Add type checking for nimiq validity duration - Add type checking for nimiq flags - type non-optional parsed NimiqPaymentOption properties as not optional - simplify nimiq address parsing - Avoid code duplication between Nimiq Checkout v1 and v2 parsing - Avoid code duplication for amount parsing
Also updating @types/node to avoid error "Duplicate identifier 'IteratorResult'" between newest typescript and previous @types/node. Also added @types/node to package.json as it was previously only installed as a sub dependency of other dependencies but is actually a direct dependency as we're using node's 'require', 'global' and 'process' at some places in the code. Made it a dev dependency as no node types are required in the output code or types.
Check that the currency and type of the unparsed input payment options object matches the ParsedPaymentOptions it should get parsed to. While for the initial request data this is already ensured by the RequestParser this is relevant for updated data that comes in via the webhook. To access the currency and type of the child classes already in the constructor of the base class, these have been changed from properties to getters. Additionally, some common properties have been moved from the base class to the interface.
818fd2c
to
33e401f
Compare
0698600
to
9391ec1
Compare
also smaller code updates
9391ec1
to
1e6f51d
Compare
First PR in a series of pull requests that add the multi-currency-checkout feature.
This first PR adds the required changes for the checkout API, type definitions and parsing.
Subsequent PRs will add the corresponding UI changes.
Note that this PR is not able to build without these UI changes.
The earliest commit that is able to build is "Update Checkout to use Carousel of CheckoutOptions" in "sebastian/checkout/checkout".
As the multi-currency-checkout PRs combined form the multi-currency-checkout feature, the single PRs target a
multi-currency-checkout
feature branch which will then be merged intomaster
once all single PRs have been merged together into the feature branch.This way, merge conflicts do not need to be resolved for every single PR but only when merging the complete change set into
master
in the end.