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

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 (29) hide show
  1. package/dist/browser/{AddTokensWidget-ShqEH0bA.js → AddTokensWidget-Cc0KWTV_.js} +12 -20
  2. package/dist/browser/{BridgeWidget-DJLZDZAJ.js → BridgeWidget-BAdLiV9Q.js} +68 -32
  3. package/dist/browser/{CommerceWidget-nbdP_6Ip.js → CommerceWidget-DpIWO690.js} +13 -13
  4. package/dist/browser/{FeesBreakdown-DvFl9V2q.js → FeesBreakdown-duH3aiG_.js} +1 -1
  5. package/dist/browser/{OnRampWidget-cqzl_-aK.js → OnRampWidget-BRqvNBIW.js} +3 -3
  6. package/dist/browser/{SaleWidget-iKKGkvvk.js → SaleWidget-C9LWF0tq.js} +10 -10
  7. package/dist/browser/{SpendingCapHero-Daz_5xcg.js → SpendingCapHero-0cb1nVlJ.js} +1 -1
  8. package/dist/browser/{SwapWidget-Y6Xo5WSo.js → SwapWidget-D4qZlTKK.js} +6 -6
  9. package/dist/browser/{TokenImage-DW2XzMbU.js → TokenImage-CgJoDXQx.js} +1 -1
  10. package/dist/browser/{TopUpView-BORiBYNf.js → TopUpView-DPkkY3li.js} +1 -1
  11. package/dist/browser/{WalletApproveHero-4jx0GgAA.js → WalletApproveHero-KRUZaNJ3.js} +2 -2
  12. package/dist/browser/{WalletWidget-BwFVpnAI.js → WalletWidget-CQ9LuBPk.js} +3 -3
  13. package/dist/browser/{auto-track-DZymc0UC.js → auto-track-B5p62nFH.js} +1 -1
  14. package/dist/browser/{index-CZhAFfYE.js → index-Bzl9xL_I.js} +1 -1
  15. package/dist/browser/{index-Bhny47VI.js → index-CMHg67uc.js} +1 -1
  16. package/dist/browser/{index-BjxyO_sP.js → index-D0lw0K3Z.js} +1 -1
  17. package/dist/browser/{index-bhVqRauZ.js → index-D1k-7TIh.js} +1 -1
  18. package/dist/browser/{index-BQ53A9R_.js → index-D8OCBEkl.js} +2 -2
  19. package/dist/browser/{index-B6p10_zD.js → index-LTPJBFEb.js} +21 -20
  20. package/dist/browser/{index-DQSmVvsC.js → index-h09gCjtD.js} +1 -1
  21. package/dist/browser/{index-CGpeUDFk.js → index-x6hMkab9.js} +1 -1
  22. package/dist/browser/index.js +1 -1
  23. package/dist/browser/{index.umd-DQuNDZ-6.js → index.umd-DgZgeH6R.js} +1 -1
  24. package/dist/browser/{useInterval-BPf23nxq.js → useInterval-BdI5Jj46.js} +1 -1
  25. package/dist/types/functions/checkSanctionedAddresses.d.ts +6 -1
  26. package/package.json +7 -7
  27. package/src/functions/checkSanctionedAddresses.ts +15 -4
  28. package/src/widgets/add-tokens/views/AddTokens.tsx +2 -17
  29. package/src/widgets/bridge/components/BridgeForm.tsx +78 -29
@@ -1,2 +1,7 @@
1
1
  import { CheckoutConfiguration } from '@imtbl/checkout-sdk';
2
- export declare const checkSanctionedAddresses: (addresses: string[], config: CheckoutConfiguration) => Promise<boolean>;
2
+ type TokenAmount = {
3
+ address: string;
4
+ amount: bigint;
5
+ };
6
+ export declare const checkSanctionedAddresses: (addresses: string[], amount: TokenAmount, config: CheckoutConfiguration) => Promise<boolean>;
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imtbl/checkout-widgets",
3
- "version": "2.4.14-alpha.1",
3
+ "version": "2.4.14-alpha.3",
4
4
  "browserslist": {
5
5
  "production": [
6
6
  ">0.2%",
@@ -18,12 +18,12 @@
18
18
  "@biom3/design-tokens": "^0.4.5",
19
19
  "@biom3/react": "^0.29.4",
20
20
  "@emotion/react": "^11.11.3",
21
- "@imtbl/bridge-sdk": "2.4.14-alpha.1",
22
- "@imtbl/checkout-sdk": "2.4.14-alpha.1",
23
- "@imtbl/config": "2.4.14-alpha.1",
24
- "@imtbl/cryptofiat": "2.4.14-alpha.1",
25
- "@imtbl/dex-sdk": "2.4.14-alpha.1",
26
- "@imtbl/passport": "2.4.14-alpha.1",
21
+ "@imtbl/bridge-sdk": "2.4.14-alpha.3",
22
+ "@imtbl/checkout-sdk": "2.4.14-alpha.3",
23
+ "@imtbl/config": "2.4.14-alpha.3",
24
+ "@imtbl/cryptofiat": "2.4.14-alpha.3",
25
+ "@imtbl/dex-sdk": "2.4.14-alpha.3",
26
+ "@imtbl/passport": "2.4.14-alpha.3",
27
27
  "@imtbl/react-analytics": "0.3.2-alpha",
28
28
  "@rive-app/react-canvas-lite": "^4.9.0",
29
29
  "@walletconnect/ethereum-provider": "^2.11.1",
@@ -1,13 +1,24 @@
1
1
  import {
2
2
  CheckoutConfiguration,
3
- fetchRiskAssessment,
4
- isAddressSanctioned,
3
+ fetchRiskAssessmentV2,
4
+ resultHasSanctionedWallets,
5
5
  } from '@imtbl/checkout-sdk';
6
6
 
7
+ type TokenAmount = {
8
+ address: string;
9
+ amount: bigint;
10
+ };
11
+
7
12
  export const checkSanctionedAddresses = async (
8
13
  addresses: string[],
14
+ amount: TokenAmount,
9
15
  config: CheckoutConfiguration,
10
16
  ): Promise<boolean> => {
11
- const result = await fetchRiskAssessment(addresses, config);
12
- return isAddressSanctioned(result, undefined);
17
+ const assessmentData = addresses.map((address) => ({
18
+ address,
19
+ amount: amount.amount,
20
+ tokenAddr: amount.address,
21
+ }));
22
+ const result = await fetchRiskAssessmentV2(assessmentData, config);
23
+ return resultHasSanctionedWallets(result);
13
24
  };
@@ -30,6 +30,7 @@ import {
30
30
  import { useTranslation } from 'react-i18next';
31
31
  import { ActionType } from '@0xsquid/squid-types';
32
32
  import { trackFlow } from '@imtbl/metrics';
33
+ import { parseUnits } from 'ethers/utils';
33
34
  import { SimpleLayout } from '../../../components/SimpleLayout/SimpleLayout';
34
35
  import { EventTargetContext } from '../../../context/event-target-context/EventTargetContext';
35
36
  import {
@@ -423,23 +424,6 @@ export function AddTokens({
423
424
  }, [checkout, id]);
424
425
 
425
426
  const sendRequestOnRampEvent = async () => {
426
- if (
427
- toAddress
428
- && (await checkSanctionedAddresses([toAddress], checkout.config))
429
- ) {
430
- viewDispatch({
431
- payload: {
432
- type: ViewActions.UPDATE_VIEW,
433
- view: {
434
- type: SharedViews.SERVICE_UNAVAILABLE_ERROR_VIEW,
435
- error: new Error('Sanctioned address'),
436
- },
437
- },
438
- });
439
-
440
- return;
441
- }
442
-
443
427
  track({
444
428
  userJourney: UserJourney.ADD_TOKENS,
445
429
  screen: 'InputScreen',
@@ -501,6 +485,7 @@ export function AddTokens({
501
485
  && toAddress
502
486
  && (await checkSanctionedAddresses(
503
487
  [fromAddress, toAddress],
488
+ { address: selectedToken.address, amount: parseUnits(selectedAmount, selectedToken.decimals) },
504
489
  checkout.config,
505
490
  ))
506
491
  ) {
@@ -5,14 +5,17 @@ import {
5
5
  OptionKey,
6
6
  } from '@biom3/react';
7
7
  import {
8
- fetchRiskAssessment,
8
+ fetchRiskAssessmentV2,
9
9
  GetBalanceResult, WidgetTheme,
10
+ resultHasSanctionedWallets,
10
11
  } from '@imtbl/checkout-sdk';
12
+ import { parseUnits } from 'ethers';
11
13
  import {
12
14
  useCallback, useContext, useEffect, useMemo, useRef, useState,
13
15
  } from 'react';
14
16
  import { useTranslation } from 'react-i18next';
15
17
  import { Environment } from '@imtbl/config';
18
+ import { trackError } from '@imtbl/metrics';
16
19
  import { UserJourney, useAnalytics } from '../../../context/analytics-provider/SegmentAnalyticsProvider';
17
20
  import { amountInputValidation } from '../../../lib/validations/amountInputValidations';
18
21
  import { BridgeActions, BridgeContext } from '../context/BridgeContext';
@@ -62,6 +65,7 @@ export function BridgeForm(props: BridgeFormProps) {
62
65
  to,
63
66
  amount,
64
67
  token,
68
+ tokenBridge,
65
69
  },
66
70
  } = useContext(BridgeContext);
67
71
 
@@ -142,9 +146,7 @@ export function BridgeForm(props: BridgeFormProps) {
142
146
  tokenBalances,
143
147
  cryptoFiatState.conversions,
144
148
  defaultTokenAddress,
145
- hasSetDefaultState.current,
146
149
  formatTokenOptionsId,
147
- formatZeroAmount,
148
150
  ]);
149
151
 
150
152
  useEffect(() => {
@@ -168,36 +170,15 @@ export function BridgeForm(props: BridgeFormProps) {
168
170
  amount: '',
169
171
  },
170
172
  });
171
- }, [amount, token, tokenBalances]);
173
+ }, [amount, token, tokenBalances, bridgeDispatch]);
172
174
 
173
175
  const selectedOption = useMemo(
174
176
  () => (formToken && formToken.token
175
177
  ? formatTokenOptionsId(formToken.token.symbol, formToken.token.address)
176
178
  : undefined),
177
- [formToken, tokenBalances, cryptoFiatState.conversions, formatTokenOptionsId],
179
+ [formToken, formatTokenOptionsId],
178
180
  );
179
181
 
180
- useEffect(() => {
181
- if (!checkout || !from || !to) {
182
- return;
183
- }
184
-
185
- (async () => {
186
- const addresses = [from.walletAddress];
187
- if (to.walletAddress.toLowerCase() !== from.walletAddress.toLowerCase()) {
188
- addresses.push(to.walletAddress);
189
- }
190
-
191
- const assessment = await fetchRiskAssessment(addresses, checkout.config);
192
- bridgeDispatch({
193
- payload: {
194
- type: BridgeActions.SET_RISK_ASSESSMENT,
195
- riskAssessment: assessment,
196
- },
197
- });
198
- })();
199
- }, [checkout, from, to]);
200
-
201
182
  const canFetchEstimates = (silently: boolean): boolean => {
202
183
  if (Number.isNaN(parseFloat(formAmount))) return false;
203
184
  if (parseFloat(formAmount) <= 0) return false;
@@ -255,7 +236,7 @@ export function BridgeForm(props: BridgeFormProps) {
255
236
  formToken.token.symbol,
256
237
  cryptoFiatState.conversions,
257
238
  ));
258
- }, [formAmount, formToken]);
239
+ }, [formAmount, formToken, cryptoFiatState.conversions]);
259
240
 
260
241
  const bridgeFormValidator = useCallback((): boolean => {
261
242
  const validateTokenError = validateToken(formToken);
@@ -266,10 +247,73 @@ export function BridgeForm(props: BridgeFormProps) {
266
247
  return true;
267
248
  }, [formToken, formAmount, setTokenError, setAmountError]);
268
249
 
250
+ const getRiskAssessment = useCallback(async () => {
251
+ if (!from || !to || !formToken || !formAmount || !tokenBridge || !formToken.token.address) return false;
252
+
253
+ const addresses = [from.walletAddress];
254
+ if (to.walletAddress.toLowerCase() !== from.walletAddress.toLowerCase()) {
255
+ addresses.push(to.walletAddress);
256
+ }
257
+
258
+ // Determine if we're bridging from L1 to L2 (deposit)
259
+ const isDeposit = checkout.config.l2ChainId === to.network && from.network === checkout.config.l1ChainId;
260
+
261
+ let tokenAddress = formToken.token.address;
262
+
263
+ // If we are bridging IN from L1 to L2, we need to find the token address on our chain
264
+ if (isDeposit) {
265
+ try {
266
+ const tokenMapping = await tokenBridge.getTokenMapping({
267
+ rootToken: formToken.token.address,
268
+ rootChainId: from.network.toString(),
269
+ childChainId: to.network.toString(),
270
+ });
271
+
272
+ if (!tokenMapping.childToken) {
273
+ throw new Error(`Token mapping not found for deposit token ${formToken.token.address}`);
274
+ }
275
+
276
+ // Use child token address if mapping exists, otherwise use original token address
277
+ tokenAddress = tokenMapping.childToken;
278
+ } catch (error) {
279
+ trackError('commerce', 'bridgeForm', error instanceof Error ? error : new Error(String(error)));
280
+ }
281
+ }
282
+
283
+ // Create risk assessment data array
284
+ const riskAssessmentData = [{
285
+ address: from.walletAddress,
286
+ tokenAddr: tokenAddress,
287
+ amount: parseUnits(formAmount, formToken.token.decimals),
288
+ }];
289
+
290
+ // Add second wallet if different
291
+ if (to.walletAddress.toLowerCase() !== from.walletAddress.toLowerCase()) {
292
+ riskAssessmentData.push({
293
+ address: to.walletAddress,
294
+ tokenAddr: tokenAddress,
295
+ amount: parseUnits(formAmount, formToken.token.decimals),
296
+ });
297
+ }
298
+
299
+ return fetchRiskAssessmentV2(riskAssessmentData, checkout.config);
300
+ }, [from, to, formToken, formAmount, tokenBridge, checkout]);
301
+
269
302
  const submitBridgeValues = useCallback(async () => {
270
303
  if (!bridgeFormValidator()) return;
271
304
  if (!checkout || !from?.browserProvider || !formToken) return;
272
305
 
306
+ // perform sanctions check
307
+ const riskAssessment = await getRiskAssessment();
308
+ if (riskAssessment && resultHasSanctionedWallets(riskAssessment)) {
309
+ bridgeDispatch({
310
+ payload: {
311
+ type: BridgeActions.SET_RISK_ASSESSMENT,
312
+ riskAssessment,
313
+ },
314
+ });
315
+ }
316
+
273
317
  track({
274
318
  userJourney: UserJourney.BRIDGE,
275
319
  screen: 'TokenAmount',
@@ -298,10 +342,15 @@ export function BridgeForm(props: BridgeFormProps) {
298
342
  },
299
343
  });
300
344
  }, [
301
- checkout,
302
- from?.browserProvider,
345
+ bridgeDispatch,
303
346
  bridgeFormValidator,
347
+ checkout,
348
+ formAmount,
304
349
  formToken,
350
+ from,
351
+ getRiskAssessment,
352
+ track,
353
+ viewDispatch,
305
354
  ]);
306
355
 
307
356
  const retrySubmitBridgeValues = async () => {