Skip to content

Commit

Permalink
feat: Add risk assessment to OnRamp widget (#2394)
Browse files Browse the repository at this point in the history
  • Loading branch information
luads authored Nov 14, 2024
1 parent 332932a commit 769bcb0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { StatusType } from '../../components/Status/StatusType';
import { StatusView } from '../../components/Status/StatusView';
import { EventTargetContext } from '../../context/event-target-context/EventTargetContext';
import { OrderInProgress } from './views/OrderInProgress';
import { ServiceUnavailableErrorView } from '../../views/error/ServiceUnavailableErrorView';

export type OnRampWidgetInputs = OnRampWidgetParams & {
config: StrongCheckoutWidgetsConfig
Expand Down Expand Up @@ -153,6 +154,12 @@ export default function OnRampWidget({
onCloseButtonClick={() => sendOnRampWidgetCloseEvent(eventTarget)}
/>
)}
{viewState.view.type
=== SharedViews.SERVICE_UNAVAILABLE_ERROR_VIEW && (
<ServiceUnavailableErrorView
onCloseClick={() => sendOnRampWidgetCloseEvent(eventTarget)}
/>
)}
</ViewContext.Provider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Box } from '@biom3/react';
import {
useContext, useEffect, useMemo, useRef, useState,
} from 'react';
import { ExchangeType, IMTBLWidgetEvents } from '@imtbl/checkout-sdk';
import {
ExchangeType, fetchRiskAssessment, IMTBLWidgetEvents, isAddressSanctioned,
} from '@imtbl/checkout-sdk';
import url from 'url';
import { useTranslation } from 'react-i18next';
import { HeaderNavigation } from '../../../components/Header/HeaderNavigation';
Expand Down Expand Up @@ -131,6 +133,7 @@ export function OnRampMain({
default:
}
};

const transakEventHandler = (event: TransakEventData) => {
if (eventTimer.current) clearTimeout(eventTimer.current);

Expand Down Expand Up @@ -219,6 +222,24 @@ export function OnRampMain({
let userWalletAddress = '';

(async () => {
const walletAddress = await provider.getSigner().getAddress();

const assessment = await fetchRiskAssessment([walletAddress], checkout.config);

if (isAddressSanctioned(assessment)) {
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
view: {
type: SharedViews.SERVICE_UNAVAILABLE_ERROR_VIEW,
error: new Error('Sanctioned address'),
},
},
});

return;
}

const params = {
exchangeType: ExchangeType.ONRAMP,
web3Provider: provider,
Expand Down

0 comments on commit 769bcb0

Please sign in to comment.