Skip to content

feat: improve payment network types#1355

Merged
benjlevesque merged 3 commits intomasterfrom
feat/improve-payment-network-types
Feb 19, 2024
Merged

feat: improve payment network types#1355
benjlevesque merged 3 commits intomasterfrom
feat/improve-payment-network-types

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

*/
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
Contributor

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

@benjlevesque benjlevesque marked this pull request as ready for review February 15, 2024 15:37
Copy link
Contributor

@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
Contributor

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
@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