import { WidgetEvent, BridgeEventType, IMTBLWidgetEvents, WidgetType, } from '@imtbl/checkout-sdk'; export const sendBridgeTransactionSentEvent = (eventTarget: Window | EventTarget, transactionHash: string) => { const successEvent = new CustomEvent>( IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT, { detail: { type: BridgeEventType.TRANSACTION_SENT, data: { transactionHash, }, }, }, ); // eslint-disable-next-line no-console console.log('bridge success ', eventTarget, successEvent); if (eventTarget !== undefined) eventTarget.dispatchEvent(successEvent); }; export const sendBridgeFailedEvent = (eventTarget: Window | EventTarget, reason: string) => { const failedEvent = new CustomEvent>( IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT, { detail: { type: BridgeEventType.FAILURE, data: { reason, timestamp: new Date().getTime(), }, }, }, ); // eslint-disable-next-line no-console console.log('bridge failed ', eventTarget, failedEvent); if (eventTarget !== undefined) eventTarget.dispatchEvent(failedEvent); }; export function sendBridgeWidgetCloseEvent(eventTarget: Window | EventTarget) { const closeWidgetEvent = new CustomEvent>( IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT, { detail: { type: BridgeEventType.CLOSE_WIDGET, data: {}, }, }, ); // eslint-disable-next-line no-console console.log('bridge close ', eventTarget, closeWidgetEvent); if (eventTarget !== undefined) eventTarget.dispatchEvent(closeWidgetEvent); } export const sendBridgeClaimWithdrawalSuccessEvent = (eventTarget: Window | EventTarget, transactionHash: string) => { const successEvent = new CustomEvent>( IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT, { detail: { type: BridgeEventType.CLAIM_WITHDRAWAL_SUCCESS, data: { transactionHash, }, }, }, ); // eslint-disable-next-line no-console console.log('bridge claim withdrawal success event:', eventTarget, successEvent); if (eventTarget !== undefined) eventTarget.dispatchEvent(successEvent); }; export const sendBridgeClaimWithdrawalFailedEvent = ( eventTarget: Window | EventTarget, transactionHash: string, reason: string, ) => { const failedEvent = new CustomEvent>( IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT, { detail: { type: BridgeEventType.CLAIM_WITHDRAWAL_FAILURE, data: { transactionHash, reason, timestamp: new Date().getTime(), }, }, }, ); // eslint-disable-next-line no-console console.log('bridge claim withdrawal failed event:', eventTarget, failedEvent); if (eventTarget !== undefined) eventTarget.dispatchEvent(failedEvent); };