From 3157b10de4ef6c38fdd45a960eb26c13bd785c5d Mon Sep 17 00:00:00 2001 From: Micaela Estabillo Date: Fri, 25 Oct 2024 14:12:36 -0700 Subject: [PATCH] chore: move quote req validator to util file --- ui/pages/bridge/types.ts | 32 -------------------------------- ui/pages/bridge/utils/quote.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 ui/pages/bridge/utils/quote.ts diff --git a/ui/pages/bridge/types.ts b/ui/pages/bridge/types.ts index 4f6d9f525763..e2b471331390 100644 --- a/ui/pages/bridge/types.ts +++ b/ui/pages/bridge/types.ts @@ -21,38 +21,6 @@ export type BridgeAsset = { icon?: string; }; -export const isValidQuoteRequest = ( - partialRequest: Partial, - requireAmount = true, -): partialRequest is QuoteRequest => { - const STRING_FIELDS = ['srcTokenAddress', 'destTokenAddress']; - if (requireAmount) { - STRING_FIELDS.push('srcTokenAmount'); - } - const NUMBER_FIELDS = ['srcChainId', 'destChainId', 'slippage']; - - return ( - STRING_FIELDS.every( - (field) => - field in partialRequest && - typeof partialRequest[field as keyof typeof partialRequest] === - 'string' && - partialRequest[field as keyof typeof partialRequest] !== undefined && - partialRequest[field as keyof typeof partialRequest] !== '' && - partialRequest[field as keyof typeof partialRequest] !== null, - ) && - NUMBER_FIELDS.every( - (field) => - field in partialRequest && - typeof partialRequest[field as keyof typeof partialRequest] === - 'number' && - partialRequest[field as keyof typeof partialRequest] !== undefined && - !isNaN(Number(partialRequest[field as keyof typeof partialRequest])) && - partialRequest[field as keyof typeof partialRequest] !== null, - ) - ); -}; - export type QuoteRequest = { walletAddress: string; destWalletAddress?: string; diff --git a/ui/pages/bridge/utils/quote.ts b/ui/pages/bridge/utils/quote.ts new file mode 100644 index 000000000000..0b83205580b4 --- /dev/null +++ b/ui/pages/bridge/utils/quote.ts @@ -0,0 +1,33 @@ +import { QuoteRequest } from '../types'; + +export const isValidQuoteRequest = ( + partialRequest: Partial, + requireAmount = true, +): partialRequest is QuoteRequest => { + const STRING_FIELDS = ['srcTokenAddress', 'destTokenAddress']; + if (requireAmount) { + STRING_FIELDS.push('srcTokenAmount'); + } + const NUMBER_FIELDS = ['srcChainId', 'destChainId', 'slippage']; + + return ( + STRING_FIELDS.every( + (field) => + field in partialRequest && + typeof partialRequest[field as keyof typeof partialRequest] === + 'string' && + partialRequest[field as keyof typeof partialRequest] !== undefined && + partialRequest[field as keyof typeof partialRequest] !== '' && + partialRequest[field as keyof typeof partialRequest] !== null, + ) && + NUMBER_FIELDS.every( + (field) => + field in partialRequest && + typeof partialRequest[field as keyof typeof partialRequest] === + 'number' && + partialRequest[field as keyof typeof partialRequest] !== undefined && + !isNaN(Number(partialRequest[field as keyof typeof partialRequest])) && + partialRequest[field as keyof typeof partialRequest] !== null, + ) + ); +};