Skip to content

Commit

Permalink
WT-1924 - more extendible configurations (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrearampin authored Nov 20, 2023
1 parent 9b56374 commit 8ca7317
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/checkout/sdk/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/checkout/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export type {
CheckConnectionParams,
CheckConnectionResult,
CheckoutModuleConfiguration,
CheckoutOnRampConfiguration,
CheckoutBridgeConfiguration,
CheckoutSwapConfiguration,
ConnectParams,
ConnectResult,
DexConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 31 additions & 8 deletions packages/checkout/sdk/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CheckoutOverrides> {
isOnRampEnabled?: boolean,
isSwapEnabled?: boolean,
isBridgeEnabled?: boolean,
passport?: Passport
onRamp?: CheckoutOnRampConfiguration;
swap?: CheckoutSwapConfiguration;
bridge?: CheckoutBridgeConfiguration;
passport?: Passport;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down

0 comments on commit 8ca7317

Please sign in to comment.