From 8ca73179e29cf0eed7559453ef24240da8de4ee0 Mon Sep 17 00:00:00 2001 From: Andrea Rampin Date: Mon, 20 Nov 2023 14:55:50 +1100 Subject: [PATCH] WT-1924 - more extendible configurations (#1178) --- packages/checkout/sdk/src/config/config.ts | 6 +-- packages/checkout/sdk/src/index.ts | 3 ++ .../routing/routingOptions.test.ts | 6 +-- packages/checkout/sdk/src/types/config.ts | 39 +++++++++++++++---- .../ui/marketplace-orchestrator/MainPage.tsx | 3 -- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/packages/checkout/sdk/src/config/config.ts b/packages/checkout/sdk/src/config/config.ts index 725c6a83a2..1a88827368 100644 --- a/packages/checkout/sdk/src/config/config.ts +++ b/packages/checkout/sdk/src/config/config.ts @@ -79,9 +79,9 @@ export class CheckoutConfiguration { // Developer mode will super set any environment configuration this.isProduction = !this.isDevelopment && this.environment === Environment.PRODUCTION; - this.isOnRampEnabled = config.isOnRampEnabled ?? DEFAULT_ON_RAMP_ENABLED; - this.isSwapEnabled = config.isSwapEnabled ?? DEFAULT_SWAP_ENABLED; - this.isBridgeEnabled = config.isBridgeEnabled ?? DEFAULT_BRIDGE_ENABLED; + this.isOnRampEnabled = config.onRamp?.enable ?? DEFAULT_ON_RAMP_ENABLED; + this.isSwapEnabled = config.swap?.enable ?? DEFAULT_SWAP_ENABLED; + this.isBridgeEnabled = config.bridge?.enable ?? DEFAULT_BRIDGE_ENABLED; this.networkMap = networkMap( this.isProduction, diff --git a/packages/checkout/sdk/src/index.ts b/packages/checkout/sdk/src/index.ts index 632e07b297..35c8e8a165 100644 --- a/packages/checkout/sdk/src/index.ts +++ b/packages/checkout/sdk/src/index.ts @@ -45,6 +45,9 @@ export type { CheckConnectionParams, CheckConnectionResult, CheckoutModuleConfiguration, + CheckoutOnRampConfiguration, + CheckoutBridgeConfiguration, + CheckoutSwapConfiguration, ConnectParams, ConnectResult, DexConfig, diff --git a/packages/checkout/sdk/src/smartCheckout/routing/routingOptions.test.ts b/packages/checkout/sdk/src/smartCheckout/routing/routingOptions.test.ts index 2aa58b0b54..0fdffcf85d 100644 --- a/packages/checkout/sdk/src/smartCheckout/routing/routingOptions.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/routing/routingOptions.test.ts @@ -42,9 +42,9 @@ describe('getAvailableRoutingOptions', () => { it('should return configured routing availability overrides if provided', async () => { const configWithOptions = new CheckoutConfiguration({ baseConfig: { environment: Environment.SANDBOX }, - isBridgeEnabled: false, - isOnRampEnabled: false, - isSwapEnabled: false, + bridge: { enable: false }, + onRamp: { enable: false }, + swap: { enable: false }, }); const routingOptions = await getAvailableRoutingOptions(configWithOptions, mockProvider); diff --git a/packages/checkout/sdk/src/types/config.ts b/packages/checkout/sdk/src/types/config.ts index 223849140b..51ead7eb8f 100644 --- a/packages/checkout/sdk/src/types/config.ts +++ b/packages/checkout/sdk/src/types/config.ts @@ -5,18 +5,41 @@ import { TokenInfo } from './tokenInfo'; import { ChainId } from './chains'; export interface CheckoutOverrides {} + +interface CheckoutFeatureConfiguration { + enable: boolean; +} + +/** + * A type representing the on-ramp configurations for the checkout SDK. + * @property {boolean} enable - To enable on-ramp feature in Checkout sdk. +*/ +export interface CheckoutOnRampConfiguration extends CheckoutFeatureConfiguration {} + +/** + * A type representing the swap configurations for the checkout SDK. + * @property {boolean} enable - To enable swap feature in Checkout sdk. +*/ +export interface CheckoutSwapConfiguration extends CheckoutFeatureConfiguration {} + +/** + * A type representing the bridge configurations for the checkout SDK. + * @property {boolean} enable - To enable bridge feature in Checkout sdk. +*/ +export interface CheckoutBridgeConfiguration extends CheckoutFeatureConfiguration {} + /** * A type representing checkout SDK configurations. - * @property {boolean} isOnRampEnabled - To enable on-ramp feature in Checkout sdk. - * @property {boolean} isSwapEnabled - To enable swap feature in Checkout sdk. - * @property {boolean} isBridgeEnabled - To enable bridge feature in Checkout sdk. - * @property {Passport} passport - To enable passport wallet with Checkout sdk. + * @property {CheckoutOnRampConfiguration} onRamp - To configure the on-ramp feature. + * @property {CheckoutSwapConfiguration} swap - To configure the swap feature. + * @property {CheckoutBridgeConfiguration} bridge - To configure the bridge feature. + * @property {Passport} passport - To enable passport wallet integration. */ export interface CheckoutModuleConfiguration extends ModuleConfiguration { - isOnRampEnabled?: boolean, - isSwapEnabled?: boolean, - isBridgeEnabled?: boolean, - passport?: Passport + onRamp?: CheckoutOnRampConfiguration; + swap?: CheckoutSwapConfiguration; + bridge?: CheckoutBridgeConfiguration; + passport?: Passport; } /** diff --git a/packages/checkout/widgets-sample-app/src/components/ui/marketplace-orchestrator/MainPage.tsx b/packages/checkout/widgets-sample-app/src/components/ui/marketplace-orchestrator/MainPage.tsx index 0fb542e992..e4221e036b 100644 --- a/packages/checkout/widgets-sample-app/src/components/ui/marketplace-orchestrator/MainPage.tsx +++ b/packages/checkout/widgets-sample-app/src/components/ui/marketplace-orchestrator/MainPage.tsx @@ -21,9 +21,6 @@ import {passport} from './passport'; // Create one instance of Checkout and inject Passport const checkout = new Checkout({ baseConfig: {environment: Environment.SANDBOX}, - isBridgeEnabled: true, - isSwapEnabled: true, - isOnRampEnabled: true, passport, })