feat: improve payment network types#1355
Conversation
| if (!creationParameters.acceptedTokens) { | ||
| throw Error('acceptedTokens is required'); | ||
| } | ||
| if (creationParameters.acceptedTokens.length === 0) { | ||
| throw Error('acceptedTokens cannot be empty'); | ||
| } |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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.
| network: EvmChainName; | ||
| acceptedTokens: string[]; |
There was a problem hiding this comment.
match what's expected by the PN! 🎉
| @@ -51,17 +46,27 @@ export interface IPaymentNetworkCreateParameters<T = any> { | |||
|
|
|||
| export type PaymentNetworkCreateParameters = | |||
There was a problem hiding this comment.
the "complexity" of the type prevented usage of Extract
There was a problem hiding this comment.
Arg, I remembered struggling with this.
| paymentNetworkCreationParameters: TCreationParameters, | ||
| ) => Promise<ExtensionTypes.IAction<any>>; |
There was a problem hiding this comment.
slightly more precise...
| /** Parameters for the creation action */ | ||
| export type ICreationParameters = PnAnyToAnyConversion.ICreationParameters; | ||
| export type ICreationParameters = Omit<PnAnyToAnyConversion.ICreationParameters, 'network'> & { | ||
| network: ChainName; |
There was a problem hiding this comment.
network is mandatory for AnyToEth
| @@ -51,17 +46,27 @@ export interface IPaymentNetworkCreateParameters<T = any> { | |||
|
|
|||
| export type PaymentNetworkCreateParameters = | |||
There was a problem hiding this comment.
Arg, I remembered struggling with this.
2c5f8fb to
1381b85
Compare
1381b85 to
0bdf46f
Compare
|
Nice 👍 |
Make payment network parameters strongly typed, and more precise:
Example