diff --git a/packages/rest-api/src/routes/bridgeRoute.ts b/packages/rest-api/src/routes/bridgeRoute.ts index 63e8e76300..4c6a0a610e 100644 --- a/packages/rest-api/src/routes/bridgeRoute.ts +++ b/packages/rest-api/src/routes/bridgeRoute.ts @@ -15,17 +15,17 @@ router.get( checksumAddresses(['fromToken', 'toToken']), [ check('fromChain') + .exists() + .withMessage('fromChain is required') .isNumeric() .custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) - .withMessage('Unsupported fromChain') - .exists() - .withMessage('fromChain is required'), + .withMessage('Unsupported fromChain'), check('toChain') + .exists() + .withMessage('toChain is required') .isNumeric() .custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) - .withMessage('Unsupported toChain') - .exists() - .withMessage('toChain is required'), + .withMessage('Unsupported toChain'), check('fromToken') .exists() .withMessage('fromToken is required') diff --git a/packages/rest-api/src/routes/bridgeTxInfoRoute.ts b/packages/rest-api/src/routes/bridgeTxInfoRoute.ts index f17771be1d..c4c9dc38c7 100644 --- a/packages/rest-api/src/routes/bridgeTxInfoRoute.ts +++ b/packages/rest-api/src/routes/bridgeTxInfoRoute.ts @@ -16,17 +16,17 @@ router.get( checksumAddresses(['fromToken', 'toToken']), [ check('fromChain') + .exists() + .withMessage('fromChain is required') .isNumeric() .custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) - .withMessage('Unsupported fromChain') - .exists() - .withMessage('fromChain is required'), + .withMessage('Unsupported fromChain'), check('toChain') + .exists() + .withMessage('toChain is required') .isNumeric() .custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) - .withMessage('Unsupported toChain') - .exists() - .withMessage('toChain is required'), + .withMessage('Unsupported toChain'), check('fromToken') .exists() .withMessage('fromToken is required') @@ -45,7 +45,7 @@ router.get( isTokenSupportedOnChain(value, req.query.toChain as string) ) .withMessage('Token not supported on specified chain'), - check('amount').isNumeric().exists().withMessage('amount is required'), + check('amount').exists().withMessage('amount is required').isNumeric(), check('destAddress') .exists() .withMessage('destAddress is required') diff --git a/packages/rest-api/src/routes/getBridgeTxStatusRoute.ts b/packages/rest-api/src/routes/getBridgeTxStatusRoute.ts index cc72b8ec41..d4e897422c 100644 --- a/packages/rest-api/src/routes/getBridgeTxStatusRoute.ts +++ b/packages/rest-api/src/routes/getBridgeTxStatusRoute.ts @@ -12,24 +12,24 @@ router.get( '/', [ check('destChainId') + .exists() + .withMessage('destChainId is required') .isNumeric() .custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) - .withMessage('Unsupported destChainId') - .exists() - .withMessage('destChainId is required'), + .withMessage('Unsupported destChainId'), check('bridgeModule') + .exists() + .withMessage('bridgeModule is required') .isString() .isIn(VALID_BRIDGE_MODULES) .withMessage( 'Invalid bridge module. Must be one of: ' + VALID_BRIDGE_MODULES.join(', ') - ) - .exists() - .withMessage('bridgeModule is required'), + ), check('synapseTxId') - .isString() .exists() - .withMessage('synapseTxId is required'), + .withMessage('synapseTxId is required') + .isString(), ], showFirstValidationError, getBridgeTxStatusController diff --git a/packages/rest-api/src/routes/getDestinationTxRoute.ts b/packages/rest-api/src/routes/getDestinationTxRoute.ts index 5c15f6205a..fc54d07df1 100644 --- a/packages/rest-api/src/routes/getDestinationTxRoute.ts +++ b/packages/rest-api/src/routes/getDestinationTxRoute.ts @@ -10,10 +10,10 @@ router.get( '/', [ check('originChainId') - .isNumeric() .exists() - .withMessage('originChainId is required'), - check('txHash').isString().exists().withMessage('txHash is required'), + .withMessage('originChainId is required') + .isNumeric(), + check('txHash').exists().withMessage('txHash is required').isString(), ], showFirstValidationError, getDestinationTxController diff --git a/packages/rest-api/src/routes/getSynapseTxIdRoute.ts b/packages/rest-api/src/routes/getSynapseTxIdRoute.ts index 7ea582171c..ca0a1f955b 100644 --- a/packages/rest-api/src/routes/getSynapseTxIdRoute.ts +++ b/packages/rest-api/src/routes/getSynapseTxIdRoute.ts @@ -11,19 +11,19 @@ router.get( '/', [ check('originChainId') - .isNumeric() .exists() - .withMessage('originChainId is required'), + .withMessage('originChainId is required') + .isNumeric(), check('bridgeModule') + .exists() + .withMessage('bridgeModule is required') .isString() .isIn(VALID_BRIDGE_MODULES) .withMessage( 'Invalid bridge module. Must be one of: ' + VALID_BRIDGE_MODULES.join(', ') - ) - .exists() - .withMessage('bridgeModule is required'), - check('txHash').isString().exists().withMessage('txHash is required'), + ), + check('txHash').exists().withMessage('txHash is required').isString(), ], showFirstValidationError, getSynapseTxIdController diff --git a/packages/rest-api/src/routes/swapRoute.ts b/packages/rest-api/src/routes/swapRoute.ts index 964119c199..e265305805 100644 --- a/packages/rest-api/src/routes/swapRoute.ts +++ b/packages/rest-api/src/routes/swapRoute.ts @@ -15,11 +15,11 @@ router.get( checksumAddresses(['fromToken', 'toToken']), [ check('chain') + .exists() + .withMessage('chain is required') .isNumeric() .custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) - .withMessage('Unsupported chain') - .exists() - .withMessage('chain is required'), + .withMessage('Unsupported chain'), check('fromToken') .exists() .withMessage('fromToken is required') @@ -38,7 +38,7 @@ router.get( isTokenSupportedOnChain(value, req.query.chain as string) ) .withMessage('Token not supported on specified chain'), - check('amount').isNumeric().exists().withMessage('amount is required'), + check('amount').exists().withMessage('amount is required').isNumeric(), ], showFirstValidationError, swapController diff --git a/packages/rest-api/src/routes/swapTxInfoRoute.ts b/packages/rest-api/src/routes/swapTxInfoRoute.ts index 8d85530fee..8ecba8256b 100644 --- a/packages/rest-api/src/routes/swapTxInfoRoute.ts +++ b/packages/rest-api/src/routes/swapTxInfoRoute.ts @@ -16,11 +16,11 @@ router.get( checksumAddresses(['fromToken', 'toToken']), [ check('chain') + .exists() + .withMessage('chain is required') .isNumeric() .custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) - .withMessage('Unsupported chain') - .exists() - .withMessage('chain is required'), + .withMessage('Unsupported chain'), check('fromToken') .exists() .withMessage('fromToken is required') diff --git a/packages/rest-api/src/utils/bridgeRouteMapping.ts b/packages/rest-api/src/utils/bridgeRouteMapping.ts index 1cb537c181..996652e543 100644 --- a/packages/rest-api/src/utils/bridgeRouteMapping.ts +++ b/packages/rest-api/src/utils/bridgeRouteMapping.ts @@ -73,12 +73,27 @@ const transformPair = (string: string): any => { } } -const transformBridgeRouteValues = (routes: StringifiedBridgeRoutes) => { +const transformBridgeRouteValues = ( + routes: StringifiedBridgeRoutes +): TransformedBridgeRoutes => { return Object.fromEntries( - Object.entries(routes).map(([key, values]) => [ - key, - values.map(transformPair).filter((pair) => pair !== undefined), - ]) + Object.entries(routes).map(([key, values]) => { + const uniquePairs: TokenData[] = [] + values.forEach((pairStr) => { + const transformedPair = transformPair(pairStr) + if ( + transformedPair && + !uniquePairs.some( + (pair) => + pair.symbol === transformedPair.symbol && + pair.chainId === transformedPair.chainId + ) + ) { + uniquePairs.push(transformedPair) + } + }) + return [key, uniquePairs] + }) ) }