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

Multi-Currency-Checkout: Types #346

Merged
merged 22 commits into from
Jan 16, 2020

Conversation

danimoh
Copy link
Member

@danimoh danimoh commented Nov 24, 2019

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 into master 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.

Copy link
Member

@sisou sisou left a 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 😉

client/HubApi.ts Outdated Show resolved Hide resolved
client/package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/lib/Constants.ts Outdated Show resolved Hide resolved
src/lib/PublicRequestTypes.ts Outdated Show resolved Hide resolved
Comment on lines +160 to +162
|| ((this.request as ParsedCheckoutRequest).paymentOptions.find(
(option) => option.currency === Currency.NIM,
) as ParsedNimiqDirectPaymentOptions).protocolSpecific.recipient;
Copy link
Member

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.

src/views/SignTransactionLedger.vue Show resolved Hide resolved
Comment on lines +213 to +216
recipient = nimiqPaymentOption.protocolSpecific.recipient!;
value = nimiqPaymentOption.amount;
fee = nimiqPaymentOption.protocolSpecific.fee!;
flags = nimiqPaymentOption.protocolSpecific.flags;
Copy link
Member

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;

src/views/SignTransactionLedger.vue Outdated Show resolved Hide resolved
Comment on lines 26 to +27
"es2017",
"esnext",
Copy link
Member

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.

Copy link
Member

@mraveux mraveux left a 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/RequestParser.ts Outdated Show resolved Hide resolved
src/lib/RequestParser.ts Show resolved Hide resolved
src/lib/RequestParser.ts Show resolved Hide resolved
src/lib/RequestParser.ts Outdated Show resolved Hide resolved
src/lib/paymentOptions/BitcoinPaymentOptions.ts Outdated Show resolved Hide resolved
src/lib/paymentOptions/BitcoinPaymentOptions.ts Outdated Show resolved Hide resolved
src/lib/paymentOptions/EtherPaymentOptions.ts Outdated Show resolved Hide resolved
src/lib/paymentOptions/NimiqPaymentOptions.ts Outdated Show resolved Hide resolved
src/lib/Constants.ts Outdated Show resolved Hide resolved
src/lib/PublicRequestTypes.ts Outdated Show resolved Hide resolved
src/lib/PublicRequestTypes.ts Show resolved Hide resolved
src/lib/PublicRequestTypes.ts Outdated Show resolved Hide resolved
src/lib/PublicRequestTypes.ts Outdated Show resolved Hide resolved
src/lib/RequestTypes.ts Outdated Show resolved Hide resolved
}
}

protected isNonNegativeInteger(value: string | number | bigint | BigInteger) {
Copy link
Member

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.

src/lib/RequestTypes.ts Show resolved Hide resolved
src/lib/RpcApi.ts Show resolved Hide resolved
}

public get total(): number {
return this.amount + this.fee;
Copy link
Member

Choose a reason for hiding this comment

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

constructor and update().

danimoh and others added 13 commits November 29, 2019 12:31
- 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.
@nibhar nibhar force-pushed the sebastian/checkout/types branch 2 times, most recently from 0698600 to 9391ec1 Compare January 15, 2020 11:14
also smaller code  updates
@danimoh danimoh merged commit af266ac into multi-currency-checkout Jan 16, 2020
@nibhar nibhar deleted the sebastian/checkout/types branch January 28, 2020 15:02
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.

4 participants