@imtbl/checkout-widgets 2.4.14-alpha.3 → 2.4.14-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/browser/{AddTokensWidget-Cc0KWTV_.js → AddTokensWidget-CKOa9HEl.js} +3 -3
  2. package/dist/browser/{BridgeWidget-BAdLiV9Q.js → BridgeWidget-CkUQxnWu.js} +6 -6
  3. package/dist/browser/{CommerceWidget-DpIWO690.js → CommerceWidget-5j2juULv.js} +13 -13
  4. package/dist/browser/{FeesBreakdown-duH3aiG_.js → FeesBreakdown-Cr8x9ABb.js} +1 -1
  5. package/dist/browser/{OnRampWidget-BRqvNBIW.js → OnRampWidget-CkTs2VQ7.js} +8 -22
  6. package/dist/browser/{SaleWidget-C9LWF0tq.js → SaleWidget-BMObqSph.js} +42 -49
  7. package/dist/browser/{SpendingCapHero-0cb1nVlJ.js → SpendingCapHero-DaxFOJ4E.js} +1 -1
  8. package/dist/browser/{SwapWidget-D4qZlTKK.js → SwapWidget-BMR-jMhg.js} +6 -6
  9. package/dist/browser/{TokenImage-CgJoDXQx.js → TokenImage-B_tQrw7O.js} +1 -1
  10. package/dist/browser/{TopUpView-DPkkY3li.js → TopUpView-KiensbgQ.js} +1 -1
  11. package/dist/browser/{WalletApproveHero-KRUZaNJ3.js → WalletApproveHero-DED-L3bu.js} +2 -2
  12. package/dist/browser/{WalletWidget-CQ9LuBPk.js → WalletWidget-B0521lRW.js} +3 -3
  13. package/dist/browser/{auto-track-B5p62nFH.js → auto-track-CSn9fd3f.js} +1 -1
  14. package/dist/browser/{index-D8OCBEkl.js → index-Bun4aWyM.js} +2 -2
  15. package/dist/browser/{index-h09gCjtD.js → index-ByYNpGIr.js} +1 -1
  16. package/dist/browser/{index-D1k-7TIh.js → index-CTP7kCFs.js} +1 -1
  17. package/dist/browser/{index-CMHg67uc.js → index-Cp9v4E1s.js} +1 -1
  18. package/dist/browser/{index-Bzl9xL_I.js → index-DP_KJAeK.js} +1 -1
  19. package/dist/browser/{index-D0lw0K3Z.js → index-DWLaAjh-.js} +1 -1
  20. package/dist/browser/{index-x6hMkab9.js → index-Dn6kFHse.js} +1 -1
  21. package/dist/browser/{index-LTPJBFEb.js → index-DwldLJFL.js} +20 -47
  22. package/dist/browser/index.js +1 -1
  23. package/dist/browser/{index.umd-DgZgeH6R.js → index.umd-BBmM5qLu.js} +1 -1
  24. package/dist/browser/{useInterval-BdI5Jj46.js → useInterval-CaIjH33m.js} +1 -1
  25. package/dist/types/widgets/sale/context/SaleContextProvider.d.ts +1 -2
  26. package/package.json +7 -7
  27. package/src/widgets/on-ramp/views/OnRampMain.tsx +7 -24
  28. package/src/widgets/sale/context/SaleContextProvider.tsx +0 -25
  29. package/src/widgets/sale/views/OrderSummary.tsx +48 -8
  30. package/src/widgets/sale/views/PaymentMethods.tsx +2 -22
@@ -1,6 +1,4 @@
1
1
  import {
2
- AssessmentResult,
3
- fetchRiskAssessment,
4
2
  FundingRoute,
5
3
  SaleItem, SalePaymentTypes,
6
4
  } from '@imtbl/checkout-sdk';
@@ -98,7 +96,6 @@ type SaleContextValues = SaleContextProps & {
98
96
  orderQuote: OrderQuote;
99
97
  signTokenIds: string[];
100
98
  selectedCurrency: OrderQuoteCurrency | undefined;
101
- riskAssessment: AssessmentResult | undefined;
102
99
  };
103
100
 
104
101
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -141,7 +138,6 @@ const SaleContext = createContext<SaleContextValues>({
141
138
  selectedCurrency: undefined,
142
139
  waitFulfillmentSettlements: true,
143
140
  hideExcludedPaymentTypes: false,
144
- riskAssessment: undefined,
145
141
  });
146
142
 
147
143
  SaleContext.displayName = 'SaleSaleContext';
@@ -206,8 +202,6 @@ export function SaleContextProvider(props: {
206
202
 
207
203
  const [invalidParameters, setInvalidParameters] = useState<boolean>(false);
208
204
 
209
- const [riskAssessment, setRiskAssessment] = useState<AssessmentResult | undefined>();
210
-
211
205
  const { selectedCurrency, orderQuote, orderQuoteError } = useQuoteOrder({
212
206
  items,
213
207
  provider,
@@ -246,23 +240,6 @@ export function SaleContextProvider(props: {
246
240
  getUserInfo();
247
241
  }, [provider]);
248
242
 
249
- useEffect(() => {
250
- if (!checkout || riskAssessment) {
251
- return;
252
- }
253
-
254
- (async () => {
255
- const address = await (await provider?.getSigner())?.getAddress();
256
-
257
- if (!address) {
258
- return;
259
- }
260
-
261
- const assessment = await fetchRiskAssessment([address], checkout.config);
262
- setRiskAssessment(assessment);
263
- })();
264
- }, [checkout, provider]);
265
-
266
243
  const {
267
244
  sign: signOrder,
268
245
  executeAll,
@@ -416,7 +393,6 @@ export function SaleContextProvider(props: {
416
393
  selectedCurrency,
417
394
  waitFulfillmentSettlements,
418
395
  hideExcludedPaymentTypes,
419
- riskAssessment,
420
396
  }),
421
397
  [
422
398
  config,
@@ -451,7 +427,6 @@ export function SaleContextProvider(props: {
451
427
  selectedCurrency,
452
428
  waitFulfillmentSettlements,
453
429
  hideExcludedPaymentTypes,
454
- riskAssessment,
455
430
  ],
456
431
  );
457
432
 
@@ -1,7 +1,8 @@
1
1
  import { Box, Heading } from '@biom3/react';
2
- import { useContext, useEffect } from 'react';
2
+ import { useCallback, useContext, useEffect } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
- import { isAddressSanctioned, SalePaymentTypes } from '@imtbl/checkout-sdk';
4
+ import { parseUnits } from 'ethers';
5
+ import { fetchRiskAssessmentV2, isSingleAddressSanctioned, SalePaymentTypes } from '@imtbl/checkout-sdk';
5
6
 
6
7
  import {
7
8
  OrderSummarySubViews,
@@ -33,6 +34,8 @@ import { HandoverTarget } from '../../../context/handover-context/HandoverContex
33
34
  import { ViewContext, ViewActions, SharedViews } from '../../../context/view-context/ViewContext';
34
35
  import { useHandover } from '../../../lib/hooks/useHandover';
35
36
  import { errorToString, getRemoteRive } from '../../../lib/utils';
37
+ import { ConnectLoaderContext } from '../../../context/connect-loader-context/ConnectLoaderContext';
38
+ import { getPricingBySymbol } from '../utils/pricing';
36
39
 
37
40
  type OrderSummaryProps = {
38
41
  subView: OrderSummarySubViews;
@@ -50,10 +53,14 @@ export function OrderSummary({ subView }: OrderSummaryProps) {
50
53
  selectedCurrency,
51
54
  setPaymentMethod,
52
55
  environment,
53
- riskAssessment,
54
56
  paymentMethod,
57
+ orderQuote,
58
+ items,
55
59
  } = useSaleContext();
56
60
 
61
+ const { connectLoaderState } = useContext(ConnectLoaderContext);
62
+ const { checkout, provider } = connectLoaderState;
63
+
57
64
  const { viewDispatch, viewState } = useContext(ViewContext);
58
65
  const { cryptoFiatDispatch, cryptoFiatState } = useContext(CryptoFiatContext);
59
66
  const { addHandover, closeHandover } = useHandover({
@@ -92,8 +99,43 @@ export function OrderSummary({ subView }: OrderSummaryProps) {
92
99
  signAndProceed(selectedCurrency?.address);
93
100
  };
94
101
 
95
- const onProceedToBuy = (fundingBalance: FundingBalance) => {
96
- if (riskAssessment && isAddressSanctioned(riskAssessment)) {
102
+ const onProceedToBuy = useCallback(async (fundingBalance: FundingBalance) => {
103
+ if (!checkout || !provider) return;
104
+
105
+ const { type, fundingItem } = fundingBalance;
106
+
107
+ // Calculate total amount from all order items for risk assessment
108
+ // Based on how item prices are calculated in OrderItems.tsx
109
+ const totalAmount = items.reduce((total, item) => {
110
+ const pricing = getPricingBySymbol(
111
+ fundingItem.token.symbol,
112
+ orderQuote?.products[item.productId]?.pricing,
113
+ cryptoFiatState.conversions,
114
+ );
115
+ const itemAmount = pricing?.amount || 0;
116
+ return total + itemAmount;
117
+ }, 0);
118
+
119
+ // Perform sanctions check once we have valid asset and amount data
120
+ const address = await (await provider?.getSigner())?.getAddress();
121
+
122
+ if (!address) {
123
+ return;
124
+ }
125
+
126
+ if (!fundingItem.token.address) {
127
+ throw new Error('Invalid data: fundingItem.token.address is missing');
128
+ }
129
+
130
+ const riskAssessmentData = [{
131
+ address,
132
+ tokenAddr: fundingItem.token.address,
133
+ amount: parseUnits(totalAmount.toString(), fundingItem.token.decimals),
134
+ }];
135
+
136
+ const riskAssessment = await fetchRiskAssessmentV2(riskAssessmentData, checkout.config);
137
+
138
+ if (riskAssessment && isSingleAddressSanctioned(riskAssessment, address)) {
97
139
  const error = new Error('Sanctioned address');
98
140
  sendFailedEvent(error.message, {}, [], undefined, { riskAssessment, paymentMethod });
99
141
 
@@ -110,8 +152,6 @@ export function OrderSummary({ subView }: OrderSummaryProps) {
110
152
  return;
111
153
  }
112
154
 
113
- const { type, fundingItem } = fundingBalance;
114
-
115
155
  sendProceedToPay(
116
156
  SaleWidgetViews.ORDER_SUMMARY,
117
157
  fundingBalance,
@@ -138,7 +178,7 @@ export function OrderSummary({ subView }: OrderSummaryProps) {
138
178
  },
139
179
  },
140
180
  });
141
- };
181
+ }, [paymentMethod, sendFailedEvent, viewDispatch, checkout, provider]);
142
182
 
143
183
  const {
144
184
  fundingBalances,
@@ -1,7 +1,7 @@
1
1
  import { Box, Heading } from '@biom3/react';
2
2
  import { useContext, useEffect } from 'react';
3
3
 
4
- import { isAddressSanctioned, SalePaymentTypes } from '@imtbl/checkout-sdk';
4
+ import { SalePaymentTypes } from '@imtbl/checkout-sdk';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { FooterLogo } from '../../../components/Footer/FooterLogo';
7
7
  import { HeaderNavigation } from '../../../components/Header/HeaderNavigation';
@@ -32,10 +32,9 @@ export function PaymentMethods() {
32
32
  invalidParameters,
33
33
  disabledPaymentTypes,
34
34
  hideExcludedPaymentTypes,
35
- riskAssessment,
36
35
  } = useSaleContext();
37
36
  const {
38
- sendFailedEvent, sendPageView, sendCloseEvent, sendSelectedPaymentMethod,
37
+ sendPageView, sendCloseEvent, sendSelectedPaymentMethod,
39
38
  } = useSaleEvent();
40
39
 
41
40
  const handleOptionClick = (type: SalePaymentTypes) => {
@@ -51,25 +50,6 @@ export function PaymentMethods() {
51
50
  paymentMethod
52
51
  && [SalePaymentTypes.DEBIT, SalePaymentTypes.CREDIT].includes(paymentMethod)
53
52
  ) {
54
- if (riskAssessment && isAddressSanctioned(riskAssessment)) {
55
- const error = new Error('Sanctioned address');
56
- sendFailedEvent(error.message, {}, [], undefined, { riskAssessment, paymentMethod });
57
-
58
- viewDispatch({
59
- payload: {
60
- type: ViewActions.UPDATE_VIEW,
61
- view: {
62
- type: SharedViews.SERVICE_UNAVAILABLE_ERROR_VIEW,
63
- error,
64
- },
65
- },
66
- });
67
-
68
- setPaymentMethod(undefined);
69
-
70
- return;
71
- }
72
-
73
53
  sign(SignPaymentTypes.FIAT, undefined, () => {
74
54
  viewDispatch({
75
55
  payload: {