Skip to content

Commit

Permalink
feat: add routing params to widget config
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasackermn committed Nov 5, 2024
1 parent 770ff85 commit 86a887d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
6 changes: 3 additions & 3 deletions widget/embedded/src/hooks/useSwapInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -127,7 +127,7 @@ export function useSwapInput({
affiliateWallets,
enableCentralizedSwappers,
});
if (isFeatureEnabled('experimentalRoute', features)) {
if (isRoutingEnabled('experimental', routing)) {
requestBody.experimental = true;
}
fetchQuote(requestBody)
Expand Down
37 changes: 28 additions & 9 deletions widget/embedded/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -143,8 +140,26 @@ export type Features = Partial<
| 'customTokens',
'visible' | 'hidden'
>
> &
Partial<Record<'experimentalRoute', 'disabled' | 'enabled'>>;
>;

/**
* `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;
Expand Down Expand Up @@ -192,16 +207,19 @@ 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.
* - 'liquiditySource': Visibility state for liquidity source.
* - '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;
Expand Down Expand Up @@ -238,4 +256,5 @@ export type WidgetConfig = {
walletConnectListedDesktopWalletLink?: string;
autoUpdateSettings?: boolean; // If true, settings will be updated automatically based on the configuration.
};
routing?: Routing;
};
6 changes: 3 additions & 3 deletions widget/embedded/src/utils/settings.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 = (
Expand Down

0 comments on commit 86a887d

Please sign in to comment.