[READY] /supported-payment-methods & /supported-cryptocurrencies#696
Conversation
…) and fiat (ars,brl,eurc) params
✅ Deploy Preview for pendulum-pay canceled.
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for fetching available fiat payment methods and on-chain cryptocurrencies via new endpoints, refactors network helper functions for case-insensitive lookup, and wires up corresponding API routes and configurations.
- Refactor
shared/helpers/networks.tsto centralize and normalize network metadata lookups. - Introduce
supported-payment-methodsandsupported-cryptocurrenciesendpoints (types, controllers, routes). - Add API configs for payment methods and cryptocurrencies and mount new routes in
api.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| shared/src/tokens/utils/helpers.ts | Removed unused imports |
| shared/src/helpers/networks.ts | Refactored network lookup functions |
| shared/src/endpoints/supported-cryptocurrencies.endpoints.ts | Defined types for supported cryptocurrencies |
| shared/src/endpoints/payment-methods.endpoints.ts | Defined types for supported payment methods |
| shared/src/endpoints/index.ts | Exported new endpoint modules |
| api/src/config/payment-methods.config.ts | Configured fiat payment methods |
| api/src/config/cryptocurrencies.config.ts | Configured on-chain cryptocurrency details |
| api/src/api/services/transactions/squidrouter/offramp.ts | Removed unused gas fee variable |
| api/src/api/routes/v1/payment-methods.route.ts | Added payment methods route |
| api/src/api/routes/v1/cryptocurrencies.route.ts | Added cryptocurrencies route |
| api/src/api/routes/v1/index.ts | Mounted new v1 routes |
| api/src/api/middlewares/validators.ts | Reordered imports to include new endpoints |
| api/src/api/controllers/payment-methods.controller.ts | Implemented payment methods controller |
| api/src/api/controllers/cryptocurrencies.controller.ts | Implemented cryptocurrencies controller |
Comments suppressed due to low confidence (3)
shared/src/helpers/networks.ts:109
- Calling getNetworkMetadata and performing a find on each isNetworkEVM check adds unnecessary overhead. Consider using a direct lookup:
NETWORK_METADATA[network].isEVMfor O(1) access.
return getNetworkMetadata(network)?.isEVM ?? false;
shared/src/helpers/networks.ts:116
- Changed return type to
number | undefinedmay break callers that expect a guaranteednumber. Either restore the original behavior (always return a valid number) or explicitly handle theundefinedcase where this function is used.
export function getNetworkId(network: Networks): number | undefined {
shared/src/helpers/networks.ts:120
- This now returns
string | undefined, which could introduce runtime undefined errors for callers that assume astring. Consider preserving the original contract (always returning a string) or updating callers to handleundefined.
export function getNetworkDisplayName(network: Networks): string | undefined {
gianfra-t
left a comment
There was a problem hiding this comment.
Looks good to me! I wonder one thing, will we need an endpoint that returns all supported payments and cryptocurrencies without any sort selection param? For instance, returning results for all networks.
ebma
left a comment
There was a problem hiding this comment.
We either add handling I suggested in my comment or we go a different route.
Instead of returning nothing when the endpoint is called without a parameter (fiat and type for the payment method, or network for the cryptocurrencies) we could also return all available items.
If it's too much effort, let's stick to at least return a response that indicates the parameters that are required.
| const paymentMethodsByType = getPaymentMethodsByType(type); | ||
| const paymentMethodsByFiat = getPaymentMethodsByFiat(paymentMethodsByType, fiat); |
There was a problem hiding this comment.
If type is not provided, we should return an http status with an error that indicates that the type is missing and needs to be provided. Same goes for fiat.
There was a problem hiding this comment.
@ebma When the supported-payment-methods endpoint is called without any parameters, the default values are applied—specifically, type=sell - the endpoint returns all payment methods available for sell.
There was a problem hiding this comment.
@ebma When we call the supported-cryptocurrencies endpoint without any parameters, we apply the default value which is network=polygon and we return all the cryptocurrencies supported on polygon.
…urn all the tokens for all the networks
Add:
/supported-payment-methodswith params:type={ sell (default) | buy },fiat={ ars, brl, eur }Example response:
supported-cryptocurrencieswith params:network={ polygon(default), assethub... ...base }Example response:
For the implementation I used the tokens already defined in the
sharedso we have only one-source-of-truth for the tokens config.