}>,
-): CheckoutEventDetail {
+): CommerceEventDetail {
const { type, data } = event.detail;
switch (type) {
case SaleEventType.SUCCESS:
return {
- type: CheckoutEventType.SUCCESS,
+ type: CommerceEventType.SUCCESS,
data: {
- type: CheckoutSuccessEventType.SALE_SUCCESS,
+ type: CommerceSuccessEventType.SALE_SUCCESS,
data,
},
};
case SaleEventType.FAILURE:
return {
- type: CheckoutEventType.FAILURE,
+ type: CommerceEventType.FAILURE,
data: {
- type: CheckoutFailureEventType.SALE_FAILED,
+ type: CommerceFailureEventType.SALE_FAILED,
data,
},
};
case SaleEventType.CLOSE_WIDGET:
return {
- type: CheckoutEventType.CLOSE,
+ type: CommerceEventType.CLOSE,
data: {},
};
case SaleEventType.TRANSACTION_SUCCESS:
return {
- type: CheckoutEventType.SUCCESS,
+ type: CommerceEventType.SUCCESS,
data: {
- type: CheckoutSuccessEventType.SALE_TRANSACTION_SUCCESS,
+ type: CommerceSuccessEventType.SALE_TRANSACTION_SUCCESS,
data,
},
};
case SaleEventType.PAYMENT_METHOD:
return {
- type: CheckoutEventType.USER_ACTION,
+ type: CommerceEventType.USER_ACTION,
data: {
- type: CheckoutUserActionEventType.PAYMENT_METHOD_SELECTED,
+ type: CommerceUserActionEventType.PAYMENT_METHOD_SELECTED,
data,
},
};
case SaleEventType.PAYMENT_TOKEN:
return {
- type: CheckoutEventType.USER_ACTION,
+ type: CommerceEventType.USER_ACTION,
data: {
- type: CheckoutUserActionEventType.PAYMENT_TOKEN_SELECTED,
+ type: CommerceUserActionEventType.PAYMENT_TOKEN_SELECTED,
data,
},
};
@@ -287,14 +287,14 @@ function mapSaleWidgetEvent(
}
/**
- * Map widget events to checkout widget event detail
+ * Map widget events to commerce widget event detail
*/
-export function getCheckoutWidgetEvent(
+export function getCommerceWidgetEvent(
event: CustomEvent,
-): CheckoutEventDetail {
+): CommerceEventDetail {
if (event.detail.type === ProviderEventType.PROVIDER_UPDATED) {
return {
- type: CheckoutEventType.PROVIDER_UPDATED,
+ type: CommerceEventType.PROVIDER_UPDATED,
data: event.detail.data,
};
}
diff --git a/packages/checkout/widgets-lib/src/widgets/checkout/functions/getConnectLoaderParams.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getConnectLoaderParams.ts
similarity index 86%
rename from packages/checkout/widgets-lib/src/widgets/checkout/functions/getConnectLoaderParams.ts
rename to packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getConnectLoaderParams.ts
index 8a7de70803..4ef47e7f8d 100644
--- a/packages/checkout/widgets-lib/src/widgets/checkout/functions/getConnectLoaderParams.ts
+++ b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getConnectLoaderParams.ts
@@ -1,4 +1,4 @@
-import { ChainId, Checkout, CheckoutFlowType } from '@imtbl/checkout-sdk';
+import { ChainId, Checkout, CommerceFlowType } from '@imtbl/checkout-sdk';
import { Web3Provider } from '@ethersproject/providers';
import { ConnectLoaderParams } from '../../../components/ConnectLoader/ConnectLoader';
import { getL1ChainId, getL2ChainId } from '../../../lib/networkUtils';
@@ -22,7 +22,7 @@ export function getConnectLoaderParams(
const { type, data } = view;
switch (type) {
- case CheckoutFlowType.WALLET:
+ case CommerceFlowType.WALLET:
return {
checkout,
web3Provider,
@@ -33,8 +33,8 @@ export function getConnectLoaderParams(
getL2ChainId(checkout.config),
],
};
- case CheckoutFlowType.ONRAMP:
- case CheckoutFlowType.ADD_FUNDS:
+ case CommerceFlowType.ONRAMP:
+ case CommerceFlowType.ADD_FUNDS:
return {
checkout,
web3Provider,
@@ -44,8 +44,8 @@ export function getConnectLoaderParams(
getL2ChainId(checkout.config),
],
};
- case CheckoutFlowType.SALE:
- case CheckoutFlowType.SWAP:
+ case CommerceFlowType.SALE:
+ case CommerceFlowType.SWAP:
return {
checkout,
web3Provider,
diff --git a/packages/checkout/widgets-lib/src/widgets/checkout/functions/getFlowRequiresContext.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getFlowRequiresContext.ts
similarity index 74%
rename from packages/checkout/widgets-lib/src/widgets/checkout/functions/getFlowRequiresContext.ts
rename to packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getFlowRequiresContext.ts
index ee96e96088..d56d3a78ec 100644
--- a/packages/checkout/widgets-lib/src/widgets/checkout/functions/getFlowRequiresContext.ts
+++ b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getFlowRequiresContext.ts
@@ -1,20 +1,20 @@
-import { CheckoutFlowType } from '@imtbl/checkout-sdk';
+import { CommerceFlowType } from '@imtbl/checkout-sdk';
/**
* List of views that require a connect loader wrapper
*/
const connectLoaderFlows = [
- CheckoutFlowType.SALE,
- CheckoutFlowType.SWAP,
- CheckoutFlowType.WALLET,
- CheckoutFlowType.ONRAMP,
+ CommerceFlowType.SALE,
+ CommerceFlowType.SWAP,
+ CommerceFlowType.WALLET,
+ CommerceFlowType.ONRAMP,
] as unknown[];
/**
* List of views that require a providers context wrapper
*/
const providersContextFlows = [
- CheckoutFlowType.ADD_FUNDS,
+ CommerceFlowType.ADD_FUNDS,
] as unknown[];
/**
diff --git a/packages/checkout/widgets-lib/src/widgets/checkout/functions/getViewFromOrchestrationEventType.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getViewFromOrchestrationEventType.ts
similarity index 60%
rename from packages/checkout/widgets-lib/src/widgets/checkout/functions/getViewFromOrchestrationEventType.ts
rename to packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getViewFromOrchestrationEventType.ts
index 151b608dd8..99cfebfca8 100644
--- a/packages/checkout/widgets-lib/src/widgets/checkout/functions/getViewFromOrchestrationEventType.ts
+++ b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getViewFromOrchestrationEventType.ts
@@ -1,24 +1,24 @@
-import { CheckoutFlowType, OrchestrationEventType } from '@imtbl/checkout-sdk';
+import { CommerceFlowType, OrchestrationEventType } from '@imtbl/checkout-sdk';
/**
* Get view from orchestration event type
*/
export function getViewFromOrchestrationEventType(
type: OrchestrationEventType,
-): CheckoutFlowType | null {
+): CommerceFlowType | null {
switch (type) {
case OrchestrationEventType.REQUEST_SWAP:
- return CheckoutFlowType.SWAP;
+ return CommerceFlowType.SWAP;
case OrchestrationEventType.REQUEST_CONNECT:
- return CheckoutFlowType.CONNECT;
+ return CommerceFlowType.CONNECT;
case OrchestrationEventType.REQUEST_WALLET:
- return CheckoutFlowType.WALLET;
+ return CommerceFlowType.WALLET;
case OrchestrationEventType.REQUEST_BRIDGE:
- return CheckoutFlowType.BRIDGE;
+ return CommerceFlowType.BRIDGE;
case OrchestrationEventType.REQUEST_ONRAMP:
- return CheckoutFlowType.ONRAMP;
+ return CommerceFlowType.ONRAMP;
case OrchestrationEventType.REQUEST_ADD_FUNDS:
- return CheckoutFlowType.ADD_FUNDS;
+ return CommerceFlowType.ADD_FUNDS;
default:
return null;
}
diff --git a/packages/checkout/widgets-lib/src/widgets/checkout/functions/isOrchestrationEvent.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/isOrchestrationEvent.ts
similarity index 100%
rename from packages/checkout/widgets-lib/src/widgets/checkout/functions/isOrchestrationEvent.ts
rename to packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/isOrchestrationEvent.ts
diff --git a/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/isValidCommerceFlow.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/isValidCommerceFlow.ts
new file mode 100644
index 0000000000..131eea1023
--- /dev/null
+++ b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/isValidCommerceFlow.ts
@@ -0,0 +1,19 @@
+import { CommerceFlowType } from '@imtbl/checkout-sdk';
+
+/** Orchestration Events List */
+export const commerceFlows = [
+ CommerceFlowType.CONNECT,
+ CommerceFlowType.WALLET,
+ CommerceFlowType.SALE,
+ CommerceFlowType.SWAP,
+ CommerceFlowType.BRIDGE,
+ CommerceFlowType.ONRAMP,
+ CommerceFlowType.ADD_FUNDS,
+];
+
+/**
+ * Check if event is orchestration event
+ */
+export function isValidCommerceFlow(flow: string): boolean {
+ return commerceFlows.includes(flow as CommerceFlowType);
+}
diff --git a/packages/checkout/widgets-lib/src/widgets/checkout/hooks/useMount.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/hooks/useMount.ts
similarity index 100%
rename from packages/checkout/widgets-lib/src/widgets/checkout/hooks/useMount.ts
rename to packages/checkout/widgets-lib/src/widgets/immutable-commerce/hooks/useMount.ts
diff --git a/packages/checkout/widgets-lib/src/widgets/checkout/hooks/useWidgetEvents.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/hooks/useWidgetEvents.ts
similarity index 91%
rename from packages/checkout/widgets-lib/src/widgets/checkout/hooks/useWidgetEvents.ts
rename to packages/checkout/widgets-lib/src/widgets/immutable-commerce/hooks/useWidgetEvents.ts
index 5f66e62e1d..8d0ce43f03 100644
--- a/packages/checkout/widgets-lib/src/widgets/checkout/hooks/useWidgetEvents.ts
+++ b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/hooks/useWidgetEvents.ts
@@ -4,8 +4,8 @@ import {
OrchestrationEvent,
OrchestrationEventType,
} from '@imtbl/checkout-sdk';
-import { getCheckoutWidgetEvent } from '../functions/getCheckoutWidgetEvent';
-import { sendCheckoutEvent } from '../CheckoutWidgetEvents';
+import { getCommerceWidgetEvent } from '../functions/getCommerceWidgetEvent';
+import { sendCheckoutEvent } from '../CommerceWidgetEvents';
import {
useViewState,
ViewActions,
@@ -67,7 +67,7 @@ export function useWidgetEvents(
};
/**
- * Proxy widget events to checkout widget events
+ * Proxy widget events to Commerce Widget events
*/
const handleWidgetEvent = useMemo(() => {
if (!eventTarget) return null;
@@ -80,7 +80,7 @@ export function useWidgetEvents(
return;
}
- const eventDetail = getCheckoutWidgetEvent(customEvent);
+ const eventDetail = getCommerceWidgetEvent(customEvent);
sendCheckoutEvent(eventTarget, eventDetail);
};
}, [eventTarget]);
diff --git a/packages/checkout/widgets-lib/src/widgets/checkout/utils/.gitkeep b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/utils/.gitkeep
similarity index 100%
rename from packages/checkout/widgets-lib/src/widgets/checkout/utils/.gitkeep
rename to packages/checkout/widgets-lib/src/widgets/immutable-commerce/utils/.gitkeep
diff --git a/packages/checkout/widgets-sample-app/index.html b/packages/checkout/widgets-sample-app/index.html
index eb64dd0ec1..8e0283d2cd 100644
--- a/packages/checkout/widgets-sample-app/index.html
+++ b/packages/checkout/widgets-sample-app/index.html
@@ -4,10 +4,7 @@
-
+
diff --git a/packages/checkout/widgets-sample-app/src/App.tsx b/packages/checkout/widgets-sample-app/src/App.tsx
index c210693a42..a5e81b3630 100644
--- a/packages/checkout/widgets-sample-app/src/App.tsx
+++ b/packages/checkout/widgets-sample-app/src/App.tsx
@@ -28,7 +28,7 @@ function App() {
diff --git a/packages/checkout/widgets-sample-app/src/components/ui/checkout/checkout.tsx b/packages/checkout/widgets-sample-app/src/components/ui/checkout/checkout.tsx
index 1cf6c5739b..b66e460e29 100644
--- a/packages/checkout/widgets-sample-app/src/components/ui/checkout/checkout.tsx
+++ b/packages/checkout/widgets-sample-app/src/components/ui/checkout/checkout.tsx
@@ -21,11 +21,11 @@ import {
WidgetLanguage,
WidgetTheme,
CreateProviderParams,
- CheckoutWidgetParams,
- CheckoutEventType,
- CheckoutSuccessEventType,
+ CommerceWidgetParams,
+ CommerceEventType,
+ CommerceSuccessEventType,
WidgetType,
- CheckoutFlowType,
+ CommerceFlowType,
WalletProviderName,
Widget,
SalePaymentTypes,
@@ -77,7 +77,6 @@ const getCheckoutSdk = (passportClient: Passport, environment: Environment) =>
passport: passportClient,
baseConfig: getBaseConfig(environment),
overrides: {
- // checkoutAppUrl: "http://localhost:3001",
// environment: "development" as Environment,
},
// swap: { enable: true }
@@ -132,15 +131,15 @@ const createWeb3Provider = async (
}
};
-// checkout widget flows
-const flows: Array = [
- CheckoutFlowType.CONNECT,
- CheckoutFlowType.WALLET,
- CheckoutFlowType.ONRAMP,
- CheckoutFlowType.SWAP,
- CheckoutFlowType.BRIDGE,
- CheckoutFlowType.SALE,
- CheckoutFlowType.ADD_FUNDS,
+// Commerce Widget flows
+const flows: Array = [
+ CommerceFlowType.CONNECT,
+ CommerceFlowType.WALLET,
+ CommerceFlowType.ONRAMP,
+ CommerceFlowType.SWAP,
+ CommerceFlowType.BRIDGE,
+ CommerceFlowType.SALE,
+ CommerceFlowType.ADD_FUNDS,
];
function CheckoutUI() {
@@ -152,8 +151,6 @@ function CheckoutUI() {
Environment.SANDBOX
);
- const [checkoutAppURL, setCheckoutAppURL] = useState("");
-
const configEnvironment = useMemo(() => {
const params = new URLSearchParams(window.location.search);
return (params.get("environment") as Environment) || Environment.SANDBOX;
@@ -173,22 +170,22 @@ function CheckoutUI() {
);
// set a state to keep widget params and configs
- const [params, setParams] = useState(
+ const [params, setParams] = useState(
undefined
);
const [flowParams, setFlowParams] = useState<
- Partial>
+ Partial>
>({
CONNECT: {
- flow: CheckoutFlowType.CONNECT,
+ flow: CommerceFlowType.CONNECT,
// blocklistWalletRdns: ["io.metamask"],
// targetChainId: ChainId.SEPOLIA,
// targetWalletRdns: "io.metamask",
theme: WidgetTheme.LIGHT,
},
SALE: {
- flow: CheckoutFlowType.SALE,
+ flow: CommerceFlowType.SALE,
items: itemsMock,
environmentId: "4dfc4bec-1867-49aa-ad35-d8a13b206c94",
collectionName: "Pixel Aussie Farm",
@@ -196,16 +193,16 @@ function CheckoutUI() {
// preferredCurrency: 'USDC',
},
SWAP: {
- flow: CheckoutFlowType.SWAP,
+ flow: CommerceFlowType.SWAP,
amount: "10",
fromTokenAddress: "native",
toTokenAddress: "0x3B2d8A1931736Fc321C24864BceEe981B11c3c57",
},
WALLET: {
- flow: CheckoutFlowType.WALLET,
+ flow: CommerceFlowType.WALLET,
},
ADD_FUNDS: {
- flow: CheckoutFlowType.ADD_FUNDS,
+ flow: CommerceFlowType.ADD_FUNDS,
toAmount: "1",
toTokenAddress: "native",
},
@@ -271,14 +268,14 @@ function CheckoutUI() {
// create the widget once factory is available
// ignore language or theme changes
- const prevWidget = useRef | undefined>(
+ const prevWidget = useRef | undefined>(
undefined
);
const widget = useAsyncMemo(async () => {
if (widgetsFactory === undefined) return undefined;
if (renderAfterConnect && !web3Provider) return undefined;
- return widgetsFactory.create(WidgetType.CHECKOUT, {
+ return widgetsFactory.create(WidgetType.IMMUTABLE_COMMERCE, {
provider: web3Provider,
config: {
theme,
@@ -304,21 +301,11 @@ function CheckoutUI() {
if (!widget || mounted.current) return;
// add event listeners
- widget.addListener(CheckoutEventType.INITIALISED, () => {
+ widget.addListener(CommerceEventType.INITIALISED, () => {
setEventResults((prev) => [...prev, { initialised: true }]);
-
- if (typeof window === "undefined") return;
-
- const checkoutAppIframe = document.getElementById(
- "checkout-app"
- ) as HTMLIFrameElement;
-
- if (checkoutAppIframe?.src) {
- setCheckoutAppURL(checkoutAppIframe.src);
- }
});
- widget.addListener(CheckoutEventType.DISCONNECTED, () => {
+ widget.addListener(CommerceEventType.DISCONNECTED, () => {
setEventResults((prev) => [...prev, { disconnected: true }]);
});
// widget.addListener(
@@ -332,28 +319,28 @@ function CheckoutUI() {
// ]);
// }
// );
- widget.addListener(CheckoutEventType.SUCCESS, (payload) => {
- if (payload.type === CheckoutSuccessEventType.CONNECT_SUCCESS) {
+ widget.addListener(CommerceEventType.SUCCESS, (payload) => {
+ if (payload.type === CommerceSuccessEventType.CONNECT_SUCCESS) {
const { provider, ...data } = payload.data;
console.log("SUCCESS ---->", provider);
setWeb3Provider(provider);
setEventResults((prev) => [...prev, { success: true, ...data }]);
}
});
- widget.addListener(CheckoutEventType.USER_ACTION, (data) => {
+ widget.addListener(CommerceEventType.USER_ACTION, (data) => {
setEventResults((prev) => [...prev, { userAction: true, ...data }]);
});
- widget.addListener(CheckoutEventType.FAILURE, (data) => {
+ widget.addListener(CommerceEventType.FAILURE, (data) => {
setEventResults((prev) => [...prev, { failure: true, ...data }]);
});
- widget.addListener(CheckoutEventType.CLOSE, () => {
+ widget.addListener(CommerceEventType.CLOSE, () => {
setEventResults((prev) => [...prev, { closed: true }]);
widget.unmount();
});
// // set initial flow to wallet
// setParams({
- // flow: checkout.CheckoutFlowType.CONNECT,
+ // flow: checkout.CommerceFlowType.CONNECT,
// });
}, [widget]);
@@ -420,7 +407,7 @@ function CheckoutUI() {