diff --git a/packages/checkout/sdk/src/widgets/definitions/global.ts b/packages/checkout/sdk/src/widgets/definitions/global.ts index 8d4e733e1b..4ee3b12e56 100644 --- a/packages/checkout/sdk/src/widgets/definitions/global.ts +++ b/packages/checkout/sdk/src/widgets/definitions/global.ts @@ -8,6 +8,7 @@ import { WidgetProperties, WidgetType, WidgetEventData, + IWidgetsFactoryCreate, } from './types'; /** @@ -19,7 +20,7 @@ declare global { namespace ImmutableCheckoutWidgets { class WidgetsFactory implements IWidgetsFactory { constructor(sdk: Checkout, config: CheckoutWidgetsConfig); - create(type: T, props?: WidgetProperties): Widget; + create: IWidgetsFactoryCreate; updateProvider(provider: Web3Provider): void; } diff --git a/packages/checkout/sdk/src/widgets/definitions/types.ts b/packages/checkout/sdk/src/widgets/definitions/types.ts index 55c8c3edc9..5c98666339 100644 --- a/packages/checkout/sdk/src/widgets/definitions/types.ts +++ b/packages/checkout/sdk/src/widgets/definitions/types.ts @@ -271,7 +271,7 @@ export interface IWidgetsFactory { * @param type widget type to instantiate. * @param props widget configurations and provider. */ - create(type: T, props?: WidgetProperties): Widget; + create: IWidgetsFactoryCreate; /** * Update the widgets provider instance. * @param provider the provider instance to update all widgets. @@ -279,6 +279,16 @@ export interface IWidgetsFactory { updateProvider(provider: Web3Provider): void; } +export interface IWidgetsFactoryCreate { + (type: WidgetType.IMMUTABLE_COMMERCE, props?: WidgetProperties): + Widget; + + /** @deprecated + * Use WidgetType.IMMUTABLE_COMMERCE instead, see https://docs.immutable.com/products/zkEVM/checkout/commerce-widget + * */ + >(type: T, props?: WidgetProperties): Widget; +} + /** * Widget interface. Every widget implements this interface. */ diff --git a/packages/checkout/widgets-lib/src/factory.ts b/packages/checkout/widgets-lib/src/factory.ts index b1d25204e0..7a9b323093 100644 --- a/packages/checkout/widgets-lib/src/factory.ts +++ b/packages/checkout/widgets-lib/src/factory.ts @@ -2,6 +2,7 @@ import { Web3Provider } from '@ethersproject/providers'; import { Checkout, IWidgetsFactory, + IWidgetsFactoryCreate, Widget, WidgetConfiguration, WidgetConfigurations, @@ -17,8 +18,8 @@ import { import { WalletConnectManager } from './lib/walletConnect'; import { AddTokens } from './widgets/add-tokens/AddTokensRoot'; import { Bridge } from './widgets/bridge/BridgeWidgetRoot'; -import { CommerceWidgetRoot } from './widgets/immutable-commerce/CommerceWidgetRoot'; import { Connect } from './widgets/connect/ConnectWidgetRoot'; +import { CommerceWidgetRoot } from './widgets/immutable-commerce/CommerceWidgetRoot'; import { OnRamp } from './widgets/on-ramp/OnRampWidgetRoot'; import { Sale } from './widgets/sale/SaleWidgetRoot'; import { Swap } from './widgets/swap/SwapWidgetRoot'; @@ -53,9 +54,9 @@ export class WidgetsFactory implements IWidgetsFactory { sendProviderUpdatedEvent({ provider }); } - create(type: T, props?: WidgetProperties): Widget { + create: IWidgetsFactoryCreate = (type: T, props?: WidgetProperties) => { const { provider } = props ?? {}; - const config = props?.config as WidgetConfigurations[T] || {}; + const config = props?.config as WidgetConfigurations[WidgetType] || {}; switch (type) { case WidgetType.CONNECT: { @@ -109,5 +110,5 @@ export class WidgetsFactory implements IWidgetsFactory { default: throw new Error('widget type not supported'); } - } + }; }