-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NO CHANGELOG][Checkout Widget] Subscribe to checkout iframe events (#…
- Loading branch information
Showing
7 changed files
with
203 additions
and
67 deletions.
There are no files selected for viewing
10 changes: 9 additions & 1 deletion
10
packages/checkout/sdk/src/widgets/definitions/events/checkout.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
export enum CheckoutEventType { | ||
|
||
CHECKOUT_APP_READY = 'CHECKOUT_APP_READY', | ||
CHECKOUT_APP_EVENT = 'CHECKOUT_APP_EVENT', | ||
} | ||
/** | ||
* Represents a successful connection. | ||
* @property {Web3Provider} provider | ||
* @property {WalletProviderName | undefined} walletProviderName | ||
*/ | ||
export type CheckoutEventReady = { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/checkout/widgets-lib/src/widgets/checkout/CheckoutWidgetEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
WidgetEvent, | ||
CheckoutEventType, | ||
IMTBLWidgetEvents, | ||
WidgetType, | ||
} from '@imtbl/checkout-sdk'; | ||
|
||
export const sendCheckoutReadyEvent = (eventTarget: Window | EventTarget) => { | ||
const event = new CustomEvent< | ||
WidgetEvent<WidgetType.CHECKOUT, CheckoutEventType.CHECKOUT_APP_READY> | ||
>(IMTBLWidgetEvents.IMTBL_CHECKOUT_WIDGET_EVENT, { | ||
detail: { | ||
type: CheckoutEventType.CHECKOUT_APP_READY, | ||
data: {}, | ||
}, | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('checkout app ready ', eventTarget, event); | ||
if (eventTarget !== undefined) eventTarget.dispatchEvent(event); | ||
}; | ||
|
||
export const sendCheckoutEvent = ( | ||
eventTarget: Window | EventTarget, | ||
data: Record<string, unknown>, | ||
) => { | ||
const event = new CustomEvent< | ||
WidgetEvent<WidgetType.CHECKOUT, CheckoutEventType.CHECKOUT_APP_EVENT> | ||
>(IMTBLWidgetEvents.IMTBL_CHECKOUT_WIDGET_EVENT, { | ||
detail: { | ||
type: CheckoutEventType.CHECKOUT_APP_EVENT, | ||
data, | ||
}, | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('checkout app event ', eventTarget, event); | ||
if (eventTarget !== undefined) eventTarget.dispatchEvent(event); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.