Skip to content

Commit

Permalink
[Checkout Widgets][CM-990]feat: Deprecate Old Widgets (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhardwick authored Nov 12, 2024
1 parent 0e349bd commit 5ccfc6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/checkout/sdk/src/widgets/definitions/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
WidgetProperties,
WidgetType,
WidgetEventData,
IWidgetsFactoryCreate,
} from './types';

/**
Expand All @@ -19,7 +20,7 @@ declare global {
namespace ImmutableCheckoutWidgets {
class WidgetsFactory implements IWidgetsFactory {
constructor(sdk: Checkout, config: CheckoutWidgetsConfig);
create<T extends WidgetType>(type: T, props?: WidgetProperties<T>): Widget<T>;
create: IWidgetsFactoryCreate;
updateProvider(provider: Web3Provider): void;
}

Expand Down
12 changes: 11 additions & 1 deletion packages/checkout/sdk/src/widgets/definitions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,24 @@ export interface IWidgetsFactory {
* @param type widget type to instantiate.
* @param props widget configurations and provider.
*/
create<T extends WidgetType>(type: T, props?: WidgetProperties<T>): Widget<T>;
create: IWidgetsFactoryCreate;
/**
* Update the widgets provider instance.
* @param provider the provider instance to update all widgets.
*/
updateProvider(provider: Web3Provider): void;
}

export interface IWidgetsFactoryCreate {
(type: WidgetType.IMMUTABLE_COMMERCE, props?: WidgetProperties<WidgetType.IMMUTABLE_COMMERCE>):
Widget<WidgetType.IMMUTABLE_COMMERCE>;

/** @deprecated
* Use WidgetType.IMMUTABLE_COMMERCE instead, see https://docs.immutable.com/products/zkEVM/checkout/commerce-widget
* */
<T extends Exclude<WidgetType, WidgetType.IMMUTABLE_COMMERCE>>(type: T, props?: WidgetProperties<T>): Widget<T>;
}

/**
* Widget interface. Every widget implements this interface.
*/
Expand Down
9 changes: 5 additions & 4 deletions packages/checkout/widgets-lib/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Web3Provider } from '@ethersproject/providers';
import {
Checkout,
IWidgetsFactory,
IWidgetsFactoryCreate,
Widget,
WidgetConfiguration,
WidgetConfigurations,
Expand All @@ -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';
Expand Down Expand Up @@ -53,9 +54,9 @@ export class WidgetsFactory implements IWidgetsFactory {
sendProviderUpdatedEvent({ provider });
}

create<T extends WidgetType>(type: T, props?: WidgetProperties<T>): Widget<T> {
create: IWidgetsFactoryCreate = <T extends WidgetType>(type: T, props?: WidgetProperties<T>) => {
const { provider } = props ?? {};
const config = props?.config as WidgetConfigurations[T] || {};
const config = props?.config as WidgetConfigurations[WidgetType] || {};

switch (type) {
case WidgetType.CONNECT: {
Expand Down Expand Up @@ -109,5 +110,5 @@ export class WidgetsFactory implements IWidgetsFactory {
default:
throw new Error('widget type not supported');
}
}
};
}

0 comments on commit 5ccfc6c

Please sign in to comment.