@reown/appkit-core-react-native 0.0.0-feat-onramp-20250307133336 → 0.0.0-feat-onramp-20250310175400

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.
@@ -180,7 +180,7 @@ export const OnRampController = {
180
180
  ConstantsUtil.NETWORK_DEFAULT_CURRENCIES[
181
181
  NetworkController.state.caipNetwork
182
182
  ?.id as keyof typeof ConstantsUtil.NETWORK_DEFAULT_CURRENCIES
183
- ] || 'ETH';
183
+ ];
184
184
  selectedCurrency = state.purchaseCurrencies?.find(c => c.currencyCode === defaultCurrency);
185
185
  }
186
186
 
@@ -218,13 +218,10 @@ export const OnRampController = {
218
218
  if (preferredCountry) {
219
219
  state.selectedCountry = preferredCountry;
220
220
  } else {
221
- const timezone = CoreHelperUtil.getTimezone()?.toLowerCase()?.split('/');
221
+ const countryCode = CoreHelperUtil.getCountryFromTimezone();
222
222
 
223
223
  state.selectedCountry =
224
- countries.find(c => timezone?.includes(c.name.toLowerCase())) ||
225
- countries.find(c => c.countryCode === 'US') ||
226
- countries[0] ||
227
- undefined;
224
+ countries.find(c => c.countryCode === countryCode) || countries[0] || undefined;
228
225
  }
229
226
  } catch (error) {
230
227
  state.error = {
@@ -416,15 +413,11 @@ export const OnRampController = {
416
413
 
417
414
  const quotes = response.sort((a, b) => b.customerScore - a.customerScore);
418
415
 
419
- if (state.paymentAmount && state.paymentAmount > 0) {
420
- state.quotes = quotes;
421
- state.selectedQuote = quotes[0];
422
- state.selectedServiceProvider = state.serviceProviders.find(
423
- sp => sp.serviceProvider === quotes[0]?.serviceProvider
424
- );
425
- } else {
426
- this.clearQuotes();
427
- }
416
+ state.quotes = quotes;
417
+ state.selectedQuote = quotes[0];
418
+ state.selectedServiceProvider = state.serviceProviders.find(
419
+ sp => sp.serviceProvider === quotes[0]?.serviceProvider
420
+ );
428
421
  } catch (error: any) {
429
422
  if (error.name === 'AbortError') {
430
423
  // Do nothing, another request was made
@@ -555,6 +548,8 @@ export const OnRampController = {
555
548
 
556
549
  async loadOnRampData() {
557
550
  state.initialLoading = true;
551
+ state.error = undefined;
552
+
558
553
  try {
559
554
  await this.fetchCountries();
560
555
  await this.fetchServiceProviders();
@@ -566,10 +561,12 @@ export const OnRampController = {
566
561
  this.fetchFiatCurrencies()
567
562
  ]);
568
563
  } catch (error) {
569
- state.error = {
570
- type: OnRampErrorType.FAILED_TO_LOAD,
571
- message: 'Failed to load data'
572
- };
564
+ if (!state.error) {
565
+ state.error = {
566
+ type: OnRampErrorType.FAILED_TO_LOAD,
567
+ message: 'Failed to load onramp data'
568
+ };
569
+ }
573
570
  } finally {
574
571
  state.initialLoading = false;
575
572
  }
@@ -415,33 +415,31 @@ export const ConstantsUtil = {
415
415
  },
416
416
 
417
417
  NETWORK_DEFAULT_CURRENCIES: {
418
- 'eip155:1': 'ETH',
419
- 'eip155:56': 'BNB',
420
- 'eip155:137': 'MATIC',
421
- 'eip155:42161': 'ETH',
422
- 'eip155:43114': 'AVAX',
423
- 'eip155:10': 'ETH',
424
- 'eip155:250': 'FTM',
425
- 'eip155:100': 'xDAI',
426
- 'eip155:8453': 'ETH',
427
- 'eip155:1284': 'GLMR',
428
- 'eip155:1285': 'MOVR',
429
- 'eip155:66': 'OKT',
430
- 'eip155:25': 'CRO',
431
- 'eip155:42220': 'CELO',
432
- 'eip155:8217': 'KLAY',
433
- 'eip155:1313161554': 'ETH',
434
- 'eip155:40': 'TLOS',
435
- 'eip155:1088': 'METIS',
436
- 'eip155:2222': 'KAVA',
437
- 'eip155:7777777': 'ZETA',
438
- 'eip155:7700': 'CANTO',
439
- 'eip155:59144': 'ETH',
440
- 'eip155:1101': 'ETH',
441
- 'eip155:196': 'XIN',
442
- 'eip155:777777': 'ETH',
443
- 'eip155:11155111': 'ETH'
418
+ 'eip155:1': 'ETH', // Ethereum Mainnet
419
+ 'eip155:56': 'BNB', // Binance Smart Chain
420
+ 'eip155:137': 'MATIC', // Polygon
421
+ 'eip155:42161': 'ETH_ARBITRUM', // Arbitrum One
422
+ 'eip155:43114': 'AVAX', // Avalanche C-Chain
423
+ 'eip155:10': 'ETH_OPTIMISM', // Optimism
424
+ 'eip155:250': 'FTM', // Fantom
425
+ 'eip155:100': 'xDAI', // Gnosis Chain (formerly xDai)
426
+ 'eip155:8453': 'ETH_BASE', // Base
427
+ 'eip155:1284': 'GLMR', // Moonbeam
428
+ 'eip155:1285': 'MOVR', // Moonriver
429
+ 'eip155:25': 'CRO', // Cronos
430
+ 'eip155:42220': 'CELO', // Celo
431
+ 'eip155:8217': 'KLAY', // Klaytn
432
+ 'eip155:1313161554': 'AURORA_ETH', // Aurora
433
+ 'eip155:40': 'TLOS', // Telos EVM
434
+ 'eip155:1088': 'METIS', // Metis Andromeda
435
+ 'eip155:2222': 'KAVA', // Kava EVM
436
+ 'eip155:7777777': 'ZETA', // ZetaChain
437
+ 'eip155:7700': 'CANTO', // Canto
438
+ 'eip155:59144': 'ETH_LINEA', // Linea
439
+ 'eip155:1101': 'ETH_POLYGONZKEVM', // Polygon zkEVM
440
+ 'eip155:196': 'XIN' // Mixin
444
441
  },
442
+
445
443
  COUNTRY_DEFAULT_PAYMENT_METHOD: {
446
444
  AE: ['CREDIT_DEBIT_CARD', 'BINANCE_P2P', 'UAE_BANK_TRANSFER'],
447
445
  AR: ['CREDIT_DEBIT_CARD', 'AR_BANK_TRANSFER', 'BINANCE_P2P'],
@@ -506,5 +504,102 @@ export const ConstantsUtil = {
506
504
  US: ['CREDIT_DEBIT_CARD', 'APPLE_PAY', 'GOOGLE_PAY'],
507
505
  VN: ['BINANCE_P2P', 'VN_BANK_TRANSFER', 'CREDIT_DEBIT_CARD'],
508
506
  ZA: ['BINANCE_P2P', 'LOCAL_BANK_TRANSFER', 'CREDIT_DEBIT_CARD']
507
+ },
508
+
509
+ CURRENCY_SUGGESTED_VALUES: {
510
+ AED: [50, 100, 500],
511
+ AMD: [5000, 10000, 50000],
512
+ ANG: [50, 100, 500],
513
+ AOA: [10000, 20000, 50000],
514
+ ARS: [20000, 35000, 50000],
515
+ AUD: [50, 100, 150],
516
+ AZN: [50, 100, 200],
517
+ BDT: [2500, 5000, 10000],
518
+ BGN: [50, 100, 200],
519
+ BHD: [10, 20, 50],
520
+ BOB: [150, 300, 500],
521
+ BRL: [100, 200, 500],
522
+ BWP: [200, 500, 1000],
523
+ CAD: [50, 100, 150],
524
+ CHF: [50, 100, 150],
525
+ CLP: [10000, 20000, 50000],
526
+ CNY: [200, 500, 1000],
527
+ COP: [50000, 100000, 200000],
528
+ CRC: [10000, 20000, 50000],
529
+ CZK: [500, 1000, 2000],
530
+ DKK: [200, 500, 1000],
531
+ DOP: [2000, 5000, 10000],
532
+ DZD: [3000, 5000, 10000],
533
+ EGP: [2000, 5000, 10000],
534
+ EUR: [50, 100, 150],
535
+ GBP: [50, 100, 150],
536
+ GEL: [100, 200, 500],
537
+ GHS: [100, 200, 500],
538
+ GTQ: [200, 500, 1000],
539
+ HKD: [200, 500, 1000],
540
+ HNL: [500, 1000, 2000],
541
+ HRK: [200, 500, 1000],
542
+ HTG: [3000, 5000, 10000],
543
+ HUF: [5000, 10000, 20000],
544
+ IDR: [100000, 200000, 500000],
545
+ ILS: [100, 200, 500],
546
+ INR: [1000, 2000, 5000],
547
+ IQD: [30000, 50000, 100000],
548
+ ISK: [5000, 10000, 20000],
549
+ JOD: [20, 50, 100],
550
+ JPY: [5000, 10000, 20000],
551
+ KES: [1000, 2000, 5000],
552
+ KGS: [1000, 2000, 5000],
553
+ KHR: [250000, 500000, 1000000],
554
+ KRW: [50000, 100000, 200000],
555
+ KWD: [10, 20, 50],
556
+ KZT: [10000, 20000, 50000],
557
+ LAK: [500000, 1000000, 2000000],
558
+ LBP: [2000000, 3000000, 5000000],
559
+ LKR: [5000, 6000, 7000],
560
+ MAD: [200, 500, 1000],
561
+ MDL: [500, 1000, 2000],
562
+ MMK: [50000, 100000, 200000],
563
+ MNT: [100000, 200000, 500000],
564
+ MWK: [5000, 10000, 20000],
565
+ MXN: [500, 1000, 2000],
566
+ MYR: [100, 200, 500],
567
+ NGN: [5000, 10000, 20000],
568
+ NIO: [1000, 2000, 5000],
569
+ NOK: [500, 1000, 2000],
570
+ NPR: [3000, 5000, 10000],
571
+ NZD: [50, 100, 150],
572
+ OMR: [10, 20, 50],
573
+ PAB: [50, 100, 200],
574
+ PEN: [100, 200, 500],
575
+ PGK: [1000, 2000, 5000],
576
+ PHP: [1000, 2000, 5000],
577
+ PKR: [5000, 10000, 20000],
578
+ PLN: [100, 200, 500],
579
+ PYG: [200000, 300000, 500000],
580
+ QAR: [100, 200, 500],
581
+ RON: [100, 200, 500],
582
+ RSD: [2000, 5000, 10000],
583
+ RWF: [5000, 10000, 20000],
584
+ SAR: [100, 200, 500],
585
+ SEK: [500, 1000, 2000],
586
+ SGD: [50, 100, 150],
587
+ THB: [1000, 2000, 5000],
588
+ TJS: [500, 1000, 2000],
589
+ TND: [100, 200, 500],
590
+ TRY: [500, 1000, 2000],
591
+ TWD: [1000, 2000, 5000],
592
+ TZS: [5000, 10000, 20000],
593
+ UAH: [1000, 2000, 5000],
594
+ UGX: [20000, 50000, 100000],
595
+ USD: [50, 100, 150],
596
+ UYU: [1000, 2000, 5000],
597
+ UZS: [300000, 500000, 1000000],
598
+ VND: [500000, 1000000, 2000000],
599
+ XAF: [5000, 10000, 20000],
600
+ XCD: [100, 200, 500],
601
+ XOF: [5000, 10000, 20000],
602
+ ZAR: [500, 1000, 2000],
603
+ ZMW: [500, 1000, 2000]
509
604
  }
510
605
  };
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { Linking, Platform } from 'react-native';
4
4
  import { ConstantsUtil as CommonConstants, type Balance } from '@reown/appkit-common-react-native';
5
+ import * as ct from 'countries-and-timezones';
5
6
 
6
7
  import { ConstantsUtil } from './ConstantsUtil';
7
8
  import type { CaipAddress, CaipNetwork, DataWallet, LinkingRecord } from './TypeUtil';
@@ -180,14 +181,14 @@ export const CoreHelperUtil = {
180
181
  return CommonConstants.PULSE_API_URL;
181
182
  },
182
183
 
183
- getTimezone() {
184
+ getCountryFromTimezone() {
184
185
  try {
185
186
  const { timeZone } = new Intl.DateTimeFormat().resolvedOptions();
186
- const capTimeZone = timeZone.toUpperCase();
187
+ const country = ct.getCountryForTimezone(timeZone);
187
188
 
188
- return capTimeZone;
189
- } catch {
190
- return undefined;
189
+ return country ? country.id : 'US'; // 'id' is the ISO country code (e.g., "GB" for United Kingdom)
190
+ } catch (error) {
191
+ return 'US';
191
192
  }
192
193
  },
193
194