Skip to content

Commit

Permalink
fix: WT-2085 - patched onramp (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrearampin authored Jan 24, 2024
1 parent d582e00 commit d08a6b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum TransakEvents {
TRANSAK_WIDGET_OPEN = 'TRANSAK_WIDGET_OPEN', // transak widget initialised and loaded
TRANSAK_ORDER_CREATED = 'TRANSAK_ORDER_CREATED', // order created and awaiting payment from payment
TRANSAK_ORDER_CREATED = 'TRANSAK_ORDER_CREATED', // order created and awaiting payment from payment <= 3DS check happens after this event
TRANSAK_ORDER_SUCCESSFUL = 'TRANSAK_ORDER_SUCCESSFUL', // order successfully submitted and completed
TRANSAK_ORDER_FAILED = 'TRANSAK_ORDER_FAILED', // order processing failed
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Passport } from '@imtbl/passport';
import { Box } from '@biom3/react';
import {
useContext, useEffect, useMemo, useState,
useContext, useEffect, useMemo, useRef, useState,
} from 'react';
import { ExchangeType } from '@imtbl/checkout-sdk';
import url from 'url';
Expand All @@ -21,7 +21,7 @@ import { EventTargetContext } from '../../../context/event-target-context/EventT
import { TRANSAK_ORIGIN } from '../../../components/Transak/useTransakEvents';

const transakIframeId = 'transak-iframe';
const IN_PROGRESS_VIEW_DELAY_MS = 1200;
const IN_PROGRESS_VIEW_DELAY_MS = 6000; // 6 second
interface OnRampProps {
showIframe: boolean;
tokenAmount?: string;
Expand All @@ -39,6 +39,8 @@ export function OnRampMain({
const { viewState, viewDispatch } = useContext(ViewContext);
const [widgetUrl, setWidgetUrl] = useState<string>('');

const eventTimer = useRef<number | undefined>();

const isPassport = !!passport && (provider?.provider as any)?.isPassport;

const showBackButton = useMemo(() => viewState.history.length > 2
Expand Down Expand Up @@ -105,6 +107,8 @@ export function OnRampMain({
}
};
const transakEventHandler = (event: TransakEventData) => {
if (eventTimer.current) clearTimeout(eventTimer.current);

if (event.event_id === TransakEvents.TRANSAK_WIDGET_OPEN) {
viewDispatch({
payload: {
Expand All @@ -121,7 +125,11 @@ export function OnRampMain({
return;
}

if (event.event_id === TransakEvents.TRANSAK_ORDER_CREATED) {
if (event.event_id === TransakEvents.TRANSAK_ORDER_SUCCESSFUL
&& event.data.status === TransakStatuses.PROCESSING) {
// this handles 3DS -- once the user has completed the verification,
// kick off teh loading screen and then fake a IN_PROGRESS_VIEW_DELAY_MS
// delay before showing the IN_PROGRESS screen
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
Expand All @@ -130,12 +138,7 @@ export function OnRampMain({
},
},
});
return;
}

if (event.event_id === TransakEvents.TRANSAK_ORDER_SUCCESSFUL
&& event.data.status === TransakStatuses.PROCESSING) {
setTimeout(() => {
eventTimer.current = window.setTimeout(() => {
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
Expand Down

0 comments on commit d08a6b0

Please sign in to comment.