diff --git a/packages/checkout/sdk/src/widgets/definitions/events/addTokens.ts b/packages/checkout/sdk/src/widgets/definitions/events/addTokens.ts index 677738369a..190458ac2e 100644 --- a/packages/checkout/sdk/src/widgets/definitions/events/addTokens.ts +++ b/packages/checkout/sdk/src/widgets/definitions/events/addTokens.ts @@ -22,7 +22,7 @@ export type AddTokensSuccess = { }; /** - * Type representing a add tokens failure + * Type representing add tokens failure * @property {string} reason * @property {number} timestamp */ @@ -34,7 +34,7 @@ export type AddTokensFailed = { }; /** - * Type representing a successfull provider connection + * Type representing a successful provider connection * @property {Web3Provider} provider * @property {EIP6963ProviderInfo} providerInfo * @property {'from' | 'to'} providerType diff --git a/packages/checkout/sdk/src/widgets/definitions/events/commerce.ts b/packages/checkout/sdk/src/widgets/definitions/events/commerce.ts index cb98a9a37b..a6f600e9ff 100644 --- a/packages/checkout/sdk/src/widgets/definitions/events/commerce.ts +++ b/packages/checkout/sdk/src/widgets/definitions/events/commerce.ts @@ -38,6 +38,7 @@ export enum CommerceSuccessEventType { BRIDGE_SUCCESS = 'BRIDGE_SUCCESS', BRIDGE_CLAIM_WITHDRAWAL_SUCCESS = 'BRIDGE_CLAIM_WITHDRAWAL_SUCCESS', ADD_TOKENS_SUCCESS = 'ADD_TOKENS_SUCCESS', + ADD_TOKENS_CONNECT_SUCCESS = 'ADD_TOKENS_CONNECT_SUCCESS', } export enum CommerceFailureEventType { @@ -107,7 +108,7 @@ export type CommerceAddTokensSuccessEvent = { }; export type CommerceAddTokensConnectSuccessEvent = { - type: CommerceSuccessEventType.CONNECT_SUCCESS; + type: CommerceSuccessEventType.ADD_TOKENS_CONNECT_SUCCESS; data: AddTokensConnectSuccess; }; diff --git a/packages/checkout/widgets-lib/src/widgets/add-tokens/hooks/useExecute.ts b/packages/checkout/widgets-lib/src/widgets/add-tokens/hooks/useExecute.ts index ac6d94e92e..4804fb97d9 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-tokens/hooks/useExecute.ts +++ b/packages/checkout/widgets-lib/src/widgets/add-tokens/hooks/useExecute.ts @@ -1,4 +1,5 @@ import { Web3Provider } from '@ethersproject/providers'; +import { useContext } from 'react'; import { RouteResponse } from '@0xsquid/squid-types'; import { Squid } from '@0xsquid/sdk'; import { ethers } from 'ethers'; @@ -6,9 +7,14 @@ import { Environment } from '@imtbl/config'; import { isSquidNativeToken } from '../functions/isSquidNativeToken'; import { useError } from './useError'; import { AddTokensError, AddTokensErrorTypes } from '../types'; +import { EventTargetContext } from '../../../context/event-target-context/EventTargetContext'; +import { sendAddTokensFailedEvent } from '../AddTokensWidgetEvents'; export const useExecute = (environment: Environment) => { const { showErrorHandover } = useError(environment); + const { + eventTargetState: { eventTarget }, + } = useContext(EventTargetContext); const handleTransactionError = (err: unknown) => { const reason = `${ @@ -37,6 +43,7 @@ export const useExecute = (environment: Environment) => { || reason.includes('transaction failed') ) { errorType = AddTokensErrorTypes.TRANSACTION_FAILED; + sendAddTokensFailedEvent(eventTarget, errorType); } if ( diff --git a/packages/checkout/widgets-lib/src/widgets/add-tokens/views/Review.tsx b/packages/checkout/widgets-lib/src/widgets/add-tokens/views/Review.tsx index 65b0109f36..781cbca328 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-tokens/views/Review.tsx +++ b/packages/checkout/widgets-lib/src/widgets/add-tokens/views/Review.tsx @@ -68,6 +68,8 @@ import { import { convertToNetworkChangeableProvider } from '../functions/convertToNetworkChangeableProvider'; import { SquidFooter } from '../components/SquidFooter'; import { useError } from '../hooks/useError'; +import { sendAddTokensSuccessEvent } from '../AddTokensWidgetEvents'; +import { EventTargetContext } from '../../../context/event-target-context/EventTargetContext'; interface ReviewProps { data: AddTokensReviewData; @@ -104,6 +106,8 @@ export function Review({ }, } = useProvidersContext(); + const { eventTargetState: { eventTarget } } = useContext(EventTargetContext); + const [route, setRoute] = useState(); const [proceedDisabled, setProceedDisabled] = useState(true); const [showFeeBreakdown, setShowFeeBreakdown] = useState(false); @@ -328,6 +332,8 @@ export function Review({ }, }); + sendAddTokensSuccessEvent(eventTarget, executeTxnReceipt.transactionHash); + showHandover( EXECUTE_TXN_ANIMATION, RiveStateMachineInput.PROCESSING, diff --git a/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getCommerceWidgetEvent.ts b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getCommerceWidgetEvent.ts index 4ee9cfd755..b1fccae2f3 100644 --- a/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getCommerceWidgetEvent.ts +++ b/packages/checkout/widgets-lib/src/widgets/immutable-commerce/functions/getCommerceWidgetEvent.ts @@ -139,6 +139,35 @@ function mapAddTokensWidgetEvent( const { type } = event.detail; switch (type) { + case AddTokensEventType.SUCCESS: + return { + type: CommerceEventType.SUCCESS, + data: { + type: CommerceSuccessEventType.ADD_TOKENS_SUCCESS, + data: event.detail.data, + }, + }; + case AddTokensEventType.CONNECT_SUCCESS: + return { + type: CommerceEventType.SUCCESS, + data: { + type: CommerceSuccessEventType.ADD_TOKENS_CONNECT_SUCCESS, + data: event.detail.data, + }, + }; + case AddTokensEventType.FAILURE: + return { + type: CommerceEventType.FAILURE, + data: { + type: CommerceFailureEventType.ADD_TOKENS_FAILED, + data: event.detail.data, + }, + }; + case AddTokensEventType.CLOSE_WIDGET: + return { + type: CommerceEventType.CLOSE, + data: {}, + }; default: throw new Error(`Unknown add tokens event type "${event.detail.type}"`); }