Skip to content

Commit

Permalink
Merge branch 'fix/sale-widget-transaction-id' into test/merge-branch-…
Browse files Browse the repository at this point in the history
…sale-widget
  • Loading branch information
jhesgodi committed Mar 15, 2024
2 parents 23a4310 + db663bd commit 2d6805e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/checkout/sdk/src/widgets/definitions/events/sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type SaleSuccess = {
method: string;
hash: string | undefined;
}[];
/** The order reference id, use it to trace order throughout flow */
transactionId: string;
[key: string]: unknown;
};

Expand All @@ -51,6 +53,8 @@ export type SaleFailed = {
method: string;
hash: string | undefined;
}[];
/** The order reference id, use it to trace order throughout flow */
transactionId: string;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const sendSaleSuccessEvent = (
paymentMethod: SalePaymentTypes | undefined,
transactions: ExecutedTransaction[] = [],
tokenIds: string[] = [],
transactionId: string = '',
) => {
const event = new CustomEvent<
WidgetEvent<WidgetType.SALE, SaleEventType.SUCCESS>
Expand All @@ -37,6 +38,7 @@ export const sendSaleSuccessEvent = (
paymentMethod,
transactions,
tokenIds,
transactionId,
},
},
});
Expand All @@ -51,6 +53,7 @@ export const sendSaleFailedEvent = (
error: Record<string, unknown>,
paymentMethod: SalePaymentTypes | undefined,
transactions: ExecutedTransaction[] = [],
transactionId: string = '',
) => {
const event = new CustomEvent<
WidgetEvent<WidgetType.SALE, SaleEventType.FAILURE>
Expand All @@ -62,6 +65,7 @@ export const sendSaleFailedEvent = (
error,
paymentMethod,
transactions,
transactionId,
timestamp: new Date().getTime(),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const useSaleEvent = () => {
screen: string = defaultView,
transactions: ExecutedTransaction[] = [],
tokenIds: string[] = [],
details?: Record<string, unknown>,
details: Record<string, any> = {},
) => {
track({
...commonProps,
Expand All @@ -84,22 +84,24 @@ export const useSaleEvent = () => {
tokenIds,
},
});
sendSaleSuccessEvent(eventTarget, paymentMethod, transactions, tokenIds);
sendSaleSuccessEvent(eventTarget, paymentMethod, transactions, tokenIds, details.transactionId);
};

const sendFailedEvent = (
reason: string,
error: Record<string, unknown>,
transactions: ExecutedTransaction[] = [],
screen: string = defaultView,
details: Record<string, any> = {},
) => {
track({
...commonProps,
screen: toPascalCase(screen),
screen: toPascalCase(screen || defaultView),
control: 'Fail',
controlType: 'Event',
action: 'Failed',
extras: {
...details,
transactions: toStringifyTransactions(transactions),
...error,
...orderProps,
Expand All @@ -108,7 +110,7 @@ export const useSaleEvent = () => {
reason,
},
});
sendSaleFailedEvent(eventTarget, reason, error, paymentMethod, transactions);
sendSaleFailedEvent(eventTarget, reason, error, paymentMethod, transactions, details.transactionId);
};

const sendTransactionSuccessEvent = (transaction: ExecutedTransaction) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const toSignResponse = (
},
rawData: transaction.raw_data,
})),
transactionId: transactions.find((txn) => txn.method_call.startsWith('execute'))?.params.reference || '',
};
};

Expand Down
1 change: 1 addition & 0 deletions packages/checkout/widgets-lib/src/widgets/sale/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type SignedTransaction = {
export type SignResponse = {
order: SignedOrder;
transactions: SignedTransaction[];
transactionId: string;
};

export type SignOrderInput = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export function PayWithCard() {
const { sendPageView } = useSaleEvent();
const [initialised, setInitialised] = useState(false);
const {
goBackToPaymentMethods, goToErrorView, signResponse: signData, signTokenIds,
goBackToPaymentMethods,
goToErrorView,
signResponse: signData,
signTokenIds,
} = useSaleContext();
const { sendOrderCreated, sendCloseEvent, sendSuccessEvent } = useSaleEvent();
const { t } = useTranslation();
Expand Down Expand Up @@ -58,6 +61,7 @@ export function PayWithCard() {
nftDataBase64,
quantity,
signData,
transactionId: signData?.transactionId,
};

sendSuccessEvent(SaleWidgetViews.SALE_SUCCESS, [], signTokenIds, details);
Expand Down Expand Up @@ -97,6 +101,7 @@ export function PayWithCard() {
nftDataBase64,
quantity,
signData,
transactionId: signData?.transactionId,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export function PayWithCoins() {
sendTransactionSuccessEvent(txn);
},
(error, txns) => {
sendFailedEvent(error.toString(), error, txns);
const details = { transactionId: signResponse?.transactionId };
sendFailedEvent(error.toString(), error, txns, undefined, details);
},
);
};
Expand All @@ -57,7 +58,8 @@ export function PayWithCoins() {

useEffect(() => {
if (executeResponse?.done === true) {
sendSuccessEvent(SaleWidgetViews.SALE_SUCCESS, executeResponse?.transactions, signTokenIds);
const details = { transactionId: signResponse?.transactionId };
sendSuccessEvent(SaleWidgetViews.SALE_SUCCESS, executeResponse?.transactions, signTokenIds, details);
sendCloseEvent(SaleWidgetViews.SALE_SUCCESS);
}
}, [executeResponse]);
Expand Down

0 comments on commit 2d6805e

Please sign in to comment.