From 86a887df0f810b3243ef94d0453234913bc4217d Mon Sep 17 00:00:00 2001 From: mikasackermn Date: Tue, 5 Nov 2024 10:15:00 +0000 Subject: [PATCH] feat: add routing params to widget config --- widget/embedded/src/hooks/useSwapInput.ts | 6 ++-- widget/embedded/src/types/config.ts | 37 +++++++++++++++++------ widget/embedded/src/utils/settings.ts | 6 ++-- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/widget/embedded/src/hooks/useSwapInput.ts b/widget/embedded/src/hooks/useSwapInput.ts index 5bca482537..4ed1cfeefe 100644 --- a/widget/embedded/src/hooks/useSwapInput.ts +++ b/widget/embedded/src/hooks/useSwapInput.ts @@ -15,7 +15,7 @@ import { getQuoteToTokenUsdPrice, sortQuotesBy, } from '../utils/quote'; -import { isFeatureEnabled } from '../utils/settings'; +import { isRoutingEnabled } from '../utils/settings'; import { createQuoteRequestBody } from '../utils/swap'; import { areTokensEqual } from '../utils/wallets'; @@ -50,7 +50,7 @@ export function useSwapInput({ const { fetch: fetchQuote, cancelFetch } = useFetchAllQuotes(); const { excludeLiquiditySources: configExcludeLiquiditySources, - features, + routing, enableCentralizedSwappers, } = useAppStore().config; const connectedWallets = useWalletsStore.use.connectedWallets(); @@ -127,7 +127,7 @@ export function useSwapInput({ affiliateWallets, enableCentralizedSwappers, }); - if (isFeatureEnabled('experimentalRoute', features)) { + if (isRoutingEnabled('experimental', routing)) { requestBody.experimental = true; } fetchQuote(requestBody) diff --git a/widget/embedded/src/types/config.ts b/widget/embedded/src/types/config.ts index e6cfe9ed04..c4b0a30040 100644 --- a/widget/embedded/src/types/config.ts +++ b/widget/embedded/src/types/config.ts @@ -121,15 +121,12 @@ export type SignersConfig = { * @property {'visible' | 'hidden'} [language] * - The visibility state for the language feature. Optional property. * - * @property {'disabled' | 'enabled'} [experimentalRoute] - * - The enablement state for the experimental route feature. Optional property. - * * @property {'visible' | 'hidden'} [connectWalletButton] * - The visibility state for the connect wallet button feature. Optional property. * * @property {'visible' | 'hidden'} [notification] * - The visibility state for the notification feature. Optional property. - * + *experimental route * @property {'visible' | 'hidden'} [liquiditySource] * - The visibility state for the liquiditySource feature. Optional property. */ @@ -143,8 +140,26 @@ export type Features = Partial< | 'customTokens', 'visible' | 'hidden' > -> & - Partial>; +>; + +/** + * `Routing` + * + * @property {'disabled' | 'enabled'} [avoidNativeFee] + * - The enablement state for the avoid native fee feature. Optional property. + * + * @property {''disabled' | 'enabled'} [maxLength] + * - The enablement state for the max length feature. Optional property. + * + * @property {'disabled' | 'enabled'} [experimental] + * - The enablement state for the experimental route feature. Optional property. + */ +export type Routing = Partial< + Record< + 'experimental' | 'avoidNativeFee' | 'maxLength', + 'disabled' | 'enabled' + > +>; export type TrezorManifest = { appUrl: string; @@ -192,7 +207,7 @@ export type TrezorManifest = { * If `externalWallets` is `true`, you should add `WidgetWallets` to your app. * @property {boolean} excludeLiquiditySources - The `excludeLiquiditySources` property is a boolean value that when you * set it to true, the list of liquidity sources provided in `liquiditySources` will be excluded; otherwise, they will be included. - * @property {Features} features - An optional object for configuring the visibility or enablement of various features. + * @property {Features} features - An optional object for configuring the visibility of various features. * Keys include: * - 'notification': Visibility state for the notification icon. * - 'theme': Visibility state for the theme. @@ -200,8 +215,11 @@ export type TrezorManifest = { * - 'connectWalletButton': Visibility state for the wallet connect icon. * - 'language': Visibility state for the language. * - 'customTokens': Visibility state for the custom tokens. - * - 'experimentalRoute': Enablement state for the experimental route. - * + * @property {Routing} routing - An optional object for configuring the enablement of various features. + * Keys include: + * - 'maxLength': Enablement state for the max length. + * - 'avoidNativeFee': Enablement state for the avoid native fee. + * - 'experimental': Enablement state for the experimental route. * @property {WidgetVariant} variant * If it is expanded, multiple routes will show up on the home page; * If it is full-expanded, multiple routes will show up on the home page with full routes; @@ -238,4 +256,5 @@ export type WidgetConfig = { walletConnectListedDesktopWalletLink?: string; autoUpdateSettings?: boolean; // If true, settings will be updated automatically based on the configuration. }; + routing?: Routing; }; diff --git a/widget/embedded/src/utils/settings.ts b/widget/embedded/src/utils/settings.ts index 8cc8ab3ca8..d921a5b121 100644 --- a/widget/embedded/src/utils/settings.ts +++ b/widget/embedded/src/utils/settings.ts @@ -1,4 +1,4 @@ -import type { Features } from '../types'; +import type { Features, Routing } from '../types'; import type { SwapperMeta, SwapperType, Token } from 'rango-sdk'; import { removeDuplicateFrom } from './common'; @@ -72,8 +72,8 @@ export function isFeatureHidden(feature: keyof Features, features?: Features) { return features?.[feature] === 'hidden'; } -export function isFeatureEnabled(feature: keyof Features, features?: Features) { - return features?.[feature] === 'enabled'; +export function isRoutingEnabled(item: keyof Routing, routing?: Routing) { + return routing?.[item] === 'enabled'; } export const addCustomTokensToSupportedTokens = (