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

feat: improve payment network types #1355

Merged
merged 3 commits into from
Feb 19, 2024

Conversation

benjlevesque
Copy link
Contributor

@benjlevesque benjlevesque commented Feb 15, 2024

Make payment network parameters strongly typed, and more precise:

Example

 await pnFactory
      .createPaymentNetwork(
        ExtensionTypes.PAYMENT_NETWORK_ID.ANY_TO_ERC20_PROXY,
        RequestLogicTypes.CURRENCY.ERC20,
        'mainnet',
      )
      //  strongly typed to ANY_TO_ERC20_PROXY Payment Network.
      .createExtensionsDataForCreation({
         // TS error because misses `acceptedTokens`

         // TS error because `network` is not valid
         network: "not a valid name"
      }),

Comment on lines +31 to +36
if (!creationParameters.acceptedTokens) {
throw Error('acceptedTokens is required');
}
if (creationParameters.acceptedTokens.length === 0) {
throw Error('acceptedTokens cannot be empty');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just a change in error message to make it clearer

@@ -7,7 +7,7 @@ import { generate8randomBytes } from '@requestnetwork/utils';
* Abstract class to extend to get the payment balance of conversion requests
*/
export abstract class AnyToAnyDetector<
TExtension extends ExtensionTypes.PnFeeReferenceBased.IFeeReferenceBased,
TExtension extends ExtensionTypes.PnFeeReferenceBased.IFeeReferenceBased<any>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are a few any introduced in the type constraints. I think they are fine, as they are only on abstract classes, and concrete implementations enforce a type.

Comment on lines +9 to +10
network: EvmChainName;
acceptedTokens: string[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

match what's expected by the PN! 🎉

@@ -51,17 +46,27 @@ export interface IPaymentNetworkCreateParameters<T = any> {

export type PaymentNetworkCreateParameters =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the "complexity" of the type prevented usage of Extract

Copy link
Member

Choose a reason for hiding this comment

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

Arg, I remembered struggling with this.

Comment on lines +14 to +15
paymentNetworkCreationParameters: TCreationParameters,
) => Promise<ExtensionTypes.IAction<any>>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

slightly more precise...


/** Parameters for the creation action */
export type ICreationParameters = PnAnyToAnyConversion.ICreationParameters;
export type ICreationParameters = Omit<PnAnyToAnyConversion.ICreationParameters, 'network'> & {
network: ChainName;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

network is mandatory for AnyToEth

Copy link
Member

@yomarion yomarion left a comment

Choose a reason for hiding this comment

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

Long-time expected

@@ -51,17 +46,27 @@ export interface IPaymentNetworkCreateParameters<T = any> {

export type PaymentNetworkCreateParameters =
Copy link
Member

Choose a reason for hiding this comment

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

Arg, I remembered struggling with this.

@benjlevesque benjlevesque enabled auto-merge (squash) February 19, 2024 09:10
@benjlevesque benjlevesque force-pushed the feat/improve-payment-network-types branch from 2c5f8fb to 1381b85 Compare February 19, 2024 09:10
@benjlevesque benjlevesque force-pushed the feat/improve-payment-network-types branch from 1381b85 to 0bdf46f Compare February 19, 2024 09:10
@benjlevesque benjlevesque merged commit 716b498 into master Feb 19, 2024
25 checks passed
@benjlevesque benjlevesque deleted the feat/improve-payment-network-types branch February 19, 2024 09:17
@MantisClone
Copy link
Member

Nice 👍

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.

6 participants