Skip to content

Commit

Permalink
chore: Remove risk assessment check from Connect widget (#2395)
Browse files Browse the repository at this point in the history
  • Loading branch information
luads authored Nov 14, 2024
1 parent b8a511e commit ea68cca
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export function ConnectWalletDrawer({
} catch (error: ConnectEIP6963ProviderError | any) {
let errorType = error.message;
switch (error.message) {
case ConnectEIP6963ProviderError.SANCTIONED_ADDRESS:
case ConnectEIP6963ProviderError.CONNECT_ERROR:
setShowUnableToConnectDrawer(true);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@ import {
EIP6963ProviderInfo,
} from '@imtbl/checkout-sdk';
import { Web3Provider } from '@ethersproject/providers';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { ConnectWalletDrawer } from './ConnectWalletDrawer';
import { ConnectEIP6963ProviderError } from '../../lib/connectEIP6963Provider';
import {
SharedViews,
ViewActions,
ViewContext,
} from '../../context/view-context/ViewContext';
import { useProvidersContext } from '../../context/providers-context/ProvidersContext';

type DeliverToWalletDrawerProps = {
Expand All @@ -35,30 +28,13 @@ export function DeliverToWalletDrawer({
providersState: { fromProviderInfo },
} = useProvidersContext();

const { viewDispatch } = useContext(ViewContext);

const handleOnConnect = (
provider: Web3Provider,
providerInfo: EIP6963ProviderInfo,
) => {
onConnect?.('to', provider, providerInfo);
};

const handleOnError = (errorType: ConnectEIP6963ProviderError) => {
if (errorType === ConnectEIP6963ProviderError.SANCTIONED_ADDRESS) {
onClose();
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
view: {
type: SharedViews.SERVICE_UNAVAILABLE_ERROR_VIEW,
error: new Error(errorType),
},
},
});
}
};

// Because wallets extensions don't support multiple wallet connections
// UX decides to have the user use the same wallet type they selected to pay with
// ie: Metamask to Metamsk, will send to same wallet address
Expand All @@ -74,7 +50,6 @@ export function DeliverToWalletDrawer({
providerType="to"
walletOptions={walletOptions}
onConnect={handleOnConnect}
onError={handleOnError}
getShouldRequestWalletPermissions={
selectedSameFromWalletType
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { EIP6963ProviderDetail, EIP6963ProviderInfo } from '@imtbl/checkout-sdk';
import { useContext, useMemo } from 'react';
import { useMemo } from 'react';
import { MenuItem } from '@biom3/react';
import { Web3Provider } from '@ethersproject/providers';
import { useTranslation } from 'react-i18next';
import { ConnectWalletDrawer } from './ConnectWalletDrawer';
import { useProvidersContext } from '../../context/providers-context/ProvidersContext';
import { ConnectEIP6963ProviderError } from '../../lib/connectEIP6963Provider';
import { SharedViews, ViewActions, ViewContext } from '../../context/view-context/ViewContext';

type PayWithWalletDrawerProps = {
visible: boolean;
Expand All @@ -29,7 +27,6 @@ export function PayWithWalletDrawer({
}: PayWithWalletDrawerProps) {
const { t } = useTranslation();
const { providersState: { fromProviderInfo } } = useProvidersContext();
const { viewDispatch } = useContext(ViewContext);

const disabledOptions = useMemo(() => {
if (insufficientBalance && fromProviderInfo) {
Expand All @@ -46,21 +43,6 @@ export function PayWithWalletDrawer({
onConnect('from', provider, providerInfo);
};

const handleOnError = (errorType: ConnectEIP6963ProviderError) => {
if (errorType === ConnectEIP6963ProviderError.SANCTIONED_ADDRESS) {
onClose();
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
view: {
type: SharedViews.SERVICE_UNAVAILABLE_ERROR_VIEW,
error: new Error(errorType),
},
},
});
}
};

const payWithCardItem = useMemo(() => {
if (!showOnRampOption) return null;

Expand Down Expand Up @@ -97,7 +79,6 @@ export function PayWithWalletDrawer({
disabledOptions={disabledOptions}
bottomSlot={payWithCardItem}
onConnect={handleOnConnect}
onError={handleOnError}
/>
);
}
14 changes: 0 additions & 14 deletions packages/checkout/widgets-lib/src/lib/connectEIP6963Provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Web3Provider } from '@ethersproject/providers';
import {
Checkout,
CheckoutError,
CheckoutErrorType,
EIP6963ProviderDetail,
WalletProviderRdns,
Expand All @@ -11,7 +10,6 @@ import { getProviderSlugFromRdns } from './provider';

export enum ConnectEIP6963ProviderError {
CONNECT_ERROR = 'CONNECT_ERROR',
SANCTIONED_ADDRESS = 'SANCTIONED_ADDRESS',
USER_REJECTED_REQUEST_ERROR = 'USER_REJECTED_REQUEST_ERROR',
}

Expand All @@ -35,16 +33,6 @@ export const connectEIP6963Provider = async (
requestWalletPermissions,
});

const address = await connectResult.provider.getSigner().getAddress();
const riskAssessment = await checkout.getRiskAssessment([address]);

if (checkout.checkIsAddressSanctioned(riskAssessment, address)) {
throw new CheckoutError(
'Sanctioned address',
ConnectEIP6963ProviderError.SANCTIONED_ADDRESS,
);
}

addProviderListenersForWidgetRoot(connectResult.provider);
return {
provider: connectResult.provider,
Expand All @@ -56,8 +44,6 @@ export const connectEIP6963Provider = async (
throw new Error(
ConnectEIP6963ProviderError.USER_REJECTED_REQUEST_ERROR,
);
case ConnectEIP6963ProviderError.SANCTIONED_ADDRESS:
throw new Error(ConnectEIP6963ProviderError.SANCTIONED_ADDRESS);
default:
throw new Error(ConnectEIP6963ProviderError.CONNECT_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
ChainId,
CheckoutErrorType,
EIP6963ProviderDetail,
fetchRiskAssessment,
isAddressSanctioned,
WalletProviderName,
WalletProviderRdns,
} from '@imtbl/checkout-sdk';
Expand All @@ -26,7 +24,6 @@ import { ConnectWidgetViews } from '../../../context/view-context/ConnectViewCon
import { ConnectActions, ConnectContext } from '../context/ConnectContext';
import { WalletItem } from './WalletItem';
import {
SharedViews,
ViewActions,
ViewContext,
} from '../../../context/view-context/ViewContext';
Expand Down Expand Up @@ -180,22 +177,6 @@ export function WalletList(props: WalletListProps) {
requestWalletPermissions: changeAccount,
});

// CM-793 Check for sanctioned address
const address = await connectResult.provider.getSigner().getAddress();
const sanctions = await fetchRiskAssessment([address], checkout.config);
if (isAddressSanctioned(sanctions, address)) {
viewDispatch({
payload: {
type: ViewActions.UPDATE_VIEW,
view: {
type: SharedViews.SERVICE_UNAVAILABLE_ERROR_VIEW,
error: new Error('Sanctioned address'),
},
},
});
return;
}

// Set up EIP-1193 provider event listeners for widget root instances
addProviderListenersForWidgetRoot(connectResult.provider);
await identifyUser(identify, connectResult.provider);
Expand Down

0 comments on commit ea68cca

Please sign in to comment.