Skip to content

Commit

Permalink
[NO CHANGELOG] [Add Tokens Widget] fix : pay with card button not cal…
Browse files Browse the repository at this point in the history
…ling on ramp (#2401)
  • Loading branch information
jiyounglee authored Nov 18, 2024
1 parent 7d86e4d commit d35a793
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
CheckoutConfiguration,
fetchRiskAssessment,
isAddressSanctioned,
} from '@imtbl/checkout-sdk';

export const checkSanctionedAddresses = async (
addresses: string[],
config: CheckoutConfiguration,
): Promise<boolean> => {
const result = await fetchRiskAssessment(addresses, config);
return isAddressSanctioned(result, undefined);
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
type Checkout,
EIP6963ProviderInfo,
IMTBLWidgetEvents,
isAddressSanctioned,
TokenFilterTypes,
type TokenInfo,
WalletProviderRdns,
Expand Down Expand Up @@ -69,7 +68,7 @@ import { SquidFooter } from '../components/SquidFooter';
import { getFormattedNumberWithDecimalPlaces } from '../functions/getFormattedNumber';
import { TokenDrawerMenu } from '../components/TokenDrawerMenu';
import { PULSE_SHADOW } from '../utils/animation';
import { useRiskAssessment } from '../hooks/useRiskAssessment';
import { checkSanctionedAddresses } from '../functions/checkSanctionedAddresses';

interface AddTokensProps {
checkout: Checkout;
Expand Down Expand Up @@ -137,8 +136,6 @@ export function AddTokens({
const [fetchingRoutes, setFetchingRoutes] = useState(false);
const [insufficientBalance, setInsufficientBalance] = useState(false);

const { riskAssessment } = useRiskAssessment();

const selectedAmountUsd = useMemo(
() => convertToUsd(tokens, inputValue, selectedToken),
[tokens, inputValue, selectedToken],
Expand Down Expand Up @@ -328,8 +325,11 @@ export function AddTokens({
fetchOnRampTokens();
}, [checkout]);

const sendRequestOnRampEvent = () => {
if (!riskAssessment || isAddressSanctioned(riskAssessment)) {
const sendRequestOnRampEvent = async () => {
if (
toAddress
&& (await checkSanctionedAddresses([toAddress], checkout.config))
) {
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
Expand Down Expand Up @@ -376,10 +376,10 @@ export function AddTokens({
};

useEffect(() => {
if (toProvider && riskAssessment && payWithCardClicked) {
if (toProvider && payWithCardClicked) {
sendRequestOnRampEvent();
}
}, [toProvider, riskAssessment, payWithCardClicked]);
}, [toProvider, payWithCardClicked]);

const handleRouteClick = (route: RouteData) => {
setShowOptionsDrawer(false);
Expand All @@ -395,10 +395,17 @@ export function AddTokens({
setShowDeliverToDrawer(false);
};

const handleReviewClick = () => {
const handleReviewClick = async () => {
if (!selectedRouteData || !selectedToken?.address) return;

if (!riskAssessment || isAddressSanctioned(riskAssessment)) {
if (
fromAddress
&& toAddress
&& (await checkSanctionedAddresses(
[fromAddress, toAddress],
checkout.config,
))
) {
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
Expand Down Expand Up @@ -471,7 +478,7 @@ export function AddTokens({
const loading = (routeInputsReady || fetchingRoutes)
&& !(selectedRouteData || insufficientBalance);

const readyToReview = routeInputsReady && !!toAddress && !!selectedRouteData && !loading && !!riskAssessment;
const readyToReview = routeInputsReady && !!toAddress && !!selectedRouteData && !loading;

const handleWalletConnected = (
providerType: 'from' | 'to',
Expand Down Expand Up @@ -676,7 +683,7 @@ export function AddTokens({
onPayWithCard={handleCardClick}
onConnect={handleWalletConnected}
insufficientBalance={insufficientBalance}
showOnRampOption={shouldShowOnRampOption}
showOnRampOption={shouldShowOnRampOption || !selectedToken}
/>
<OptionsDrawer
checkout={checkout}
Expand Down

0 comments on commit d35a793

Please sign in to comment.