@reown/appkit-core-react-native 2.0.0 → 2.0.1

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 (282) hide show
  1. package/lib/commonjs/controllers/ApiController.js +148 -82
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  3. package/lib/commonjs/controllers/AssetController.js +0 -4
  4. package/lib/commonjs/controllers/AssetController.js.map +1 -1
  5. package/lib/commonjs/controllers/BlockchainApiController.js +127 -134
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionsController.js +280 -60
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
  9. package/lib/commonjs/controllers/EnsController.js +6 -4
  10. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  11. package/lib/commonjs/controllers/EventsController.js +55 -5
  12. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  13. package/lib/commonjs/controllers/LogController.js +188 -0
  14. package/lib/commonjs/controllers/LogController.js.map +1 -0
  15. package/lib/commonjs/controllers/ModalController.js +9 -7
  16. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  17. package/lib/commonjs/controllers/OnRampController.js +134 -53
  18. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  19. package/lib/commonjs/controllers/OptionsController.js +20 -7
  20. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  21. package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
  22. package/lib/commonjs/controllers/RouterController.js +7 -22
  23. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  24. package/lib/commonjs/controllers/SendController.js +115 -99
  25. package/lib/commonjs/controllers/SendController.js.map +1 -1
  26. package/lib/commonjs/controllers/SnackController.js +29 -5
  27. package/lib/commonjs/controllers/SnackController.js.map +1 -1
  28. package/lib/commonjs/controllers/SwapController.js +119 -119
  29. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  30. package/lib/commonjs/controllers/ThemeController.js +5 -0
  31. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  32. package/lib/commonjs/controllers/TransactionsController.js +25 -19
  33. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  34. package/lib/commonjs/controllers/WcController.js +73 -0
  35. package/lib/commonjs/controllers/WcController.js.map +1 -0
  36. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
  37. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
  38. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
  39. package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  40. package/lib/commonjs/features/reown-authentication/index.js +28 -0
  41. package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
  42. package/lib/commonjs/index.js +30 -37
  43. package/lib/commonjs/index.js.map +1 -1
  44. package/lib/commonjs/package.json +1 -0
  45. package/lib/commonjs/utils/ApiUtil.js +1 -1
  46. package/lib/commonjs/utils/ApiUtil.js.map +1 -1
  47. package/lib/commonjs/utils/AssetUtil.js +8 -17
  48. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  49. package/lib/commonjs/utils/ConstantsUtil.js +14 -431
  50. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  51. package/lib/commonjs/utils/CoreHelperUtil.js +33 -10
  52. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  53. package/lib/commonjs/utils/EventUtil.js.map +1 -1
  54. package/lib/commonjs/utils/FetchUtil.js +41 -12
  55. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  56. package/lib/commonjs/utils/LogUtils.js +131 -0
  57. package/lib/commonjs/utils/LogUtils.js.map +1 -0
  58. package/lib/commonjs/utils/StorageUtil.js +119 -172
  59. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  60. package/lib/commonjs/utils/SwapApiUtil.js +2 -17
  61. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  62. package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -1
  63. package/lib/commonjs/utils/WalletUtil.js +23 -0
  64. package/lib/commonjs/utils/WalletUtil.js.map +1 -0
  65. package/lib/module/controllers/ApiController.js +150 -82
  66. package/lib/module/controllers/ApiController.js.map +1 -1
  67. package/lib/module/controllers/AssetController.js +2 -4
  68. package/lib/module/controllers/AssetController.js.map +1 -1
  69. package/lib/module/controllers/BlockchainApiController.js +128 -133
  70. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  71. package/lib/module/controllers/ConnectionsController.js +282 -60
  72. package/lib/module/controllers/ConnectionsController.js.map +1 -1
  73. package/lib/module/controllers/EnsController.js +6 -2
  74. package/lib/module/controllers/EnsController.js.map +1 -1
  75. package/lib/module/controllers/EventsController.js +54 -2
  76. package/lib/module/controllers/EventsController.js.map +1 -1
  77. package/lib/module/controllers/LogController.js +185 -0
  78. package/lib/module/controllers/LogController.js.map +1 -0
  79. package/lib/module/controllers/ModalController.js +11 -7
  80. package/lib/module/controllers/ModalController.js.map +1 -1
  81. package/lib/module/controllers/OnRampController.js +135 -52
  82. package/lib/module/controllers/OnRampController.js.map +1 -1
  83. package/lib/module/controllers/OptionsController.js +22 -7
  84. package/lib/module/controllers/OptionsController.js.map +1 -1
  85. package/lib/module/controllers/PublicStateController.js +2 -0
  86. package/lib/module/controllers/PublicStateController.js.map +1 -1
  87. package/lib/module/controllers/RouterController.js +9 -22
  88. package/lib/module/controllers/RouterController.js.map +1 -1
  89. package/lib/module/controllers/SendController.js +114 -96
  90. package/lib/module/controllers/SendController.js.map +1 -1
  91. package/lib/module/controllers/SnackController.js +31 -5
  92. package/lib/module/controllers/SnackController.js.map +1 -1
  93. package/lib/module/controllers/SwapController.js +121 -119
  94. package/lib/module/controllers/SwapController.js.map +1 -1
  95. package/lib/module/controllers/ThemeController.js +7 -0
  96. package/lib/module/controllers/ThemeController.js.map +1 -1
  97. package/lib/module/controllers/TransactionsController.js +25 -17
  98. package/lib/module/controllers/TransactionsController.js.map +1 -1
  99. package/lib/module/controllers/WcController.js +70 -0
  100. package/lib/module/controllers/WcController.js.map +1 -0
  101. package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
  102. package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
  103. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
  104. package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
  105. package/lib/module/features/reown-authentication/index.js +5 -0
  106. package/lib/module/features/reown-authentication/index.js.map +1 -0
  107. package/lib/module/index.js +12 -7
  108. package/lib/module/index.js.map +1 -1
  109. package/lib/module/utils/ApiUtil.js +3 -1
  110. package/lib/module/utils/ApiUtil.js.map +1 -1
  111. package/lib/module/utils/AssetUtil.js +10 -17
  112. package/lib/module/utils/AssetUtil.js.map +1 -1
  113. package/lib/module/utils/ConstantsUtil.js +16 -431
  114. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  115. package/lib/module/utils/CoreHelperUtil.js +35 -8
  116. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  117. package/lib/module/utils/EventUtil.js +2 -0
  118. package/lib/module/utils/EventUtil.js.map +1 -1
  119. package/lib/module/utils/FetchUtil.js +44 -12
  120. package/lib/module/utils/FetchUtil.js.map +1 -1
  121. package/lib/module/utils/LogUtils.js +121 -0
  122. package/lib/module/utils/LogUtils.js.map +1 -0
  123. package/lib/module/utils/StorageUtil.js +122 -172
  124. package/lib/module/utils/StorageUtil.js.map +1 -1
  125. package/lib/module/utils/SwapApiUtil.js +4 -17
  126. package/lib/module/utils/SwapApiUtil.js.map +1 -1
  127. package/lib/module/utils/SwapCalculationUtil.js +3 -0
  128. package/lib/module/utils/SwapCalculationUtil.js.map +1 -1
  129. package/lib/module/utils/WalletUtil.js +19 -0
  130. package/lib/module/utils/WalletUtil.js.map +1 -0
  131. package/lib/typescript/controllers/ApiController.d.ts +8 -7
  132. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  133. package/lib/typescript/controllers/AssetController.d.ts +0 -2
  134. package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
  135. package/lib/typescript/controllers/BlockchainApiController.d.ts +21 -13
  136. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  137. package/lib/typescript/controllers/ConnectionsController.d.ts +22 -18
  138. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
  139. package/lib/typescript/controllers/EnsController.d.ts +1 -1
  140. package/lib/typescript/controllers/EnsController.d.ts.map +1 -1
  141. package/lib/typescript/controllers/EventsController.d.ts +13 -1
  142. package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
  143. package/lib/typescript/controllers/LogController.d.ts +65 -0
  144. package/lib/typescript/controllers/LogController.d.ts.map +1 -0
  145. package/lib/typescript/controllers/ModalController.d.ts +1 -1
  146. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  147. package/lib/typescript/controllers/OnRampController.d.ts +4 -3
  148. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  149. package/lib/typescript/controllers/OptionsController.d.ts +8 -6
  150. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  151. package/lib/typescript/controllers/RouterController.d.ts +6 -21
  152. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  153. package/lib/typescript/controllers/SendController.d.ts +5 -7
  154. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  155. package/lib/typescript/controllers/SnackController.d.ts +3 -3
  156. package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
  157. package/lib/typescript/controllers/SwapController.d.ts +11 -11
  158. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  159. package/lib/typescript/controllers/ThemeController.d.ts +2 -0
  160. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
  161. package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
  162. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  163. package/lib/typescript/controllers/WcController.d.ts +27 -0
  164. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  165. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
  166. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
  167. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
  168. package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
  169. package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
  170. package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
  171. package/lib/typescript/index.d.ts +6 -8
  172. package/lib/typescript/index.d.ts.map +1 -1
  173. package/lib/typescript/utils/ApiUtil.d.ts +1 -1
  174. package/lib/typescript/utils/AssetUtil.d.ts +3 -4
  175. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  176. package/lib/typescript/utils/ConstantsUtil.d.ts +7 -416
  177. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  178. package/lib/typescript/utils/CoreHelperUtil.d.ts +8 -6
  179. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  180. package/lib/typescript/utils/EventUtil.d.ts +1 -1
  181. package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
  182. package/lib/typescript/utils/FetchUtil.d.ts +3 -3
  183. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  184. package/lib/typescript/utils/LogUtils.d.ts +15 -0
  185. package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
  186. package/lib/typescript/utils/StorageUtil.d.ts +8 -19
  187. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  188. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
  189. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  190. package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
  191. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
  192. package/lib/typescript/utils/WalletUtil.d.ts +5 -0
  193. package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
  194. package/package.json +12 -25
  195. package/src/controllers/ApiController.ts +158 -80
  196. package/src/controllers/AssetController.ts +0 -6
  197. package/src/controllers/BlockchainApiController.ts +109 -144
  198. package/src/controllers/ConnectionsController.ts +372 -88
  199. package/src/controllers/EnsController.ts +5 -3
  200. package/src/controllers/EventsController.ts +74 -3
  201. package/src/controllers/LogController.ts +250 -0
  202. package/src/controllers/ModalController.ts +11 -9
  203. package/src/controllers/OnRampController.ts +195 -82
  204. package/src/controllers/OptionsController.ts +40 -13
  205. package/src/controllers/RouterController.ts +20 -58
  206. package/src/controllers/SendController.ts +148 -112
  207. package/src/controllers/SnackController.ts +31 -5
  208. package/src/controllers/SwapController.ts +140 -148
  209. package/src/controllers/ThemeController.ts +7 -0
  210. package/src/controllers/TransactionsController.ts +26 -18
  211. package/src/controllers/WcController.ts +93 -0
  212. package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
  213. package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
  214. package/src/features/reown-authentication/index.ts +2 -0
  215. package/src/index.ts +15 -22
  216. package/src/utils/ApiUtil.ts +1 -1
  217. package/src/utils/AssetUtil.ts +9 -20
  218. package/src/utils/ConstantsUtil.ts +16 -435
  219. package/src/utils/CoreHelperUtil.ts +62 -11
  220. package/src/utils/EventUtil.ts +1 -1
  221. package/src/utils/FetchUtil.ts +50 -14
  222. package/src/utils/LogUtils.ts +179 -0
  223. package/src/utils/StorageUtil.ts +171 -199
  224. package/src/utils/SwapApiUtil.ts +18 -37
  225. package/src/utils/SwapCalculationUtil.ts +1 -2
  226. package/src/utils/WalletUtil.ts +14 -0
  227. package/lib/commonjs/controllers/AccountController.js +0 -93
  228. package/lib/commonjs/controllers/AccountController.js.map +0 -1
  229. package/lib/commonjs/controllers/ConnectionController.js +0 -132
  230. package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
  231. package/lib/commonjs/controllers/ConnectorController.js +0 -50
  232. package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
  233. package/lib/commonjs/controllers/NetworkController.js +0 -90
  234. package/lib/commonjs/controllers/NetworkController.js.map +0 -1
  235. package/lib/commonjs/controllers/WebviewController.js +0 -52
  236. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  237. package/lib/commonjs/utils/NetworkUtil.js +0 -46
  238. package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
  239. package/lib/commonjs/utils/RouterUtil.js +0 -25
  240. package/lib/commonjs/utils/RouterUtil.js.map +0 -1
  241. package/lib/commonjs/utils/TypeUtil.js +0 -6
  242. package/lib/commonjs/utils/TypeUtil.js.map +0 -1
  243. package/lib/module/controllers/AccountController.js +0 -88
  244. package/lib/module/controllers/AccountController.js.map +0 -1
  245. package/lib/module/controllers/ConnectionController.js +0 -127
  246. package/lib/module/controllers/ConnectionController.js.map +0 -1
  247. package/lib/module/controllers/ConnectorController.js +0 -45
  248. package/lib/module/controllers/ConnectorController.js.map +0 -1
  249. package/lib/module/controllers/NetworkController.js +0 -85
  250. package/lib/module/controllers/NetworkController.js.map +0 -1
  251. package/lib/module/controllers/WebviewController.js +0 -47
  252. package/lib/module/controllers/WebviewController.js.map +0 -1
  253. package/lib/module/utils/NetworkUtil.js +0 -40
  254. package/lib/module/utils/NetworkUtil.js.map +0 -1
  255. package/lib/module/utils/RouterUtil.js +0 -19
  256. package/lib/module/utils/RouterUtil.js.map +0 -1
  257. package/lib/module/utils/TypeUtil.js +0 -2
  258. package/lib/module/utils/TypeUtil.js.map +0 -1
  259. package/lib/typescript/controllers/AccountController.d.ts +0 -33
  260. package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
  261. package/lib/typescript/controllers/ConnectionController.d.ts +0 -68
  262. package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
  263. package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
  264. package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
  265. package/lib/typescript/controllers/NetworkController.d.ts +0 -34
  266. package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
  267. package/lib/typescript/controllers/WebviewController.d.ts +0 -21
  268. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  269. package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
  270. package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
  271. package/lib/typescript/utils/RouterUtil.d.ts +0 -5
  272. package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
  273. package/lib/typescript/utils/TypeUtil.d.ts +0 -817
  274. package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
  275. package/src/controllers/AccountController.ts +0 -128
  276. package/src/controllers/ConnectionController.ts +0 -208
  277. package/src/controllers/ConnectorController.ts +0 -64
  278. package/src/controllers/NetworkController.ts +0 -120
  279. package/src/controllers/WebviewController.ts +0 -63
  280. package/src/utils/NetworkUtil.ts +0 -33
  281. package/src/utils/RouterUtil.ts +0 -21
  282. package/src/utils/TypeUtil.ts +0 -995
@@ -1,26 +1,28 @@
1
- import { subscribeKey as subKey } from 'valtio/vanilla/utils';
2
- import { proxy, subscribe as sub } from 'valtio/vanilla';
3
- import type {
4
- OnRampPaymentMethod,
5
- OnRampCountry,
6
- OnRampFiatCurrency,
7
- OnRampQuote,
8
- OnRampFiatLimit,
9
- OnRampCryptoCurrency,
10
- OnRampServiceProvider,
11
- OnRampError,
12
- OnRampErrorTypeValues
13
- } from '../utils/TypeUtil';
1
+ import { subscribeKey as subKey } from 'valtio/utils';
2
+ import { proxy, subscribe as sub } from 'valtio';
3
+ import {
4
+ type OnRampPaymentMethod,
5
+ type OnRampCountry,
6
+ type OnRampFiatCurrency,
7
+ type OnRampQuote,
8
+ type OnRampFiatLimit,
9
+ type OnRampCryptoCurrency,
10
+ type OnRampServiceProvider,
11
+ type OnRampError,
12
+ type OnRampErrorTypeValues,
13
+ type OnRampCountryDefaults,
14
+ BlockchainOnRampError
15
+ } from '@reown/appkit-common-react-native';
14
16
 
15
17
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
16
- import { NetworkController } from './NetworkController';
17
- import { AccountController } from './AccountController';
18
18
  import { OptionsController } from './OptionsController';
19
19
  import { ConstantsUtil, OnRampErrorType } from '../utils/ConstantsUtil';
20
20
  import { StorageUtil } from '../utils/StorageUtil';
21
21
  import { SnackController } from './SnackController';
22
+ import { LogController } from './LogController';
22
23
  import { EventsController } from './EventsController';
23
- import { BlockchainApiController } from './BlockchainApiController';
24
+ import { BlockchainApiController, EXCLUDED_ONRAMP_PROVIDERS } from './BlockchainApiController';
25
+ import { ConnectionsController } from './ConnectionsController';
24
26
 
25
27
  // -- Helpers ------------------------------------------- //
26
28
 
@@ -32,23 +34,27 @@ const mapErrorMessage = (errorCode: string): OnRampError => {
32
34
  const errorMap: Record<string, { type: OnRampErrorTypeValues; message: string }> = {
33
35
  [OnRampErrorType.AMOUNT_TOO_LOW]: {
34
36
  type: OnRampErrorType.AMOUNT_TOO_LOW,
35
- message: 'Amount is too low'
37
+ message: 'The amount is too low'
36
38
  },
37
39
  [OnRampErrorType.AMOUNT_TOO_HIGH]: {
38
40
  type: OnRampErrorType.AMOUNT_TOO_HIGH,
39
- message: 'Amount is too high'
41
+ message: 'The amount is too high'
40
42
  },
41
43
  [OnRampErrorType.INVALID_AMOUNT]: {
42
44
  type: OnRampErrorType.INVALID_AMOUNT,
43
- message: 'Please adjust amount'
45
+ message: 'Enter a valid amount'
44
46
  },
45
47
  [OnRampErrorType.INCOMPATIBLE_REQUEST]: {
46
48
  type: OnRampErrorType.INCOMPATIBLE_REQUEST,
47
- message: 'Try different amount or payment method'
49
+ message: 'Enter a valid amount'
48
50
  },
49
51
  [OnRampErrorType.BAD_REQUEST]: {
50
52
  type: OnRampErrorType.BAD_REQUEST,
51
- message: 'Try different amount or payment method'
53
+ message: 'Enter a valid amount'
54
+ },
55
+ [OnRampErrorType.NO_VALID_QUOTES]: {
56
+ type: OnRampErrorType.NO_VALID_QUOTES,
57
+ message: 'No quotes available'
52
58
  }
53
59
  };
54
60
 
@@ -63,6 +69,7 @@ const mapErrorMessage = (errorCode: string): OnRampError => {
63
69
  // -- Types --------------------------------------------- //
64
70
  export interface OnRampControllerState {
65
71
  countries: OnRampCountry[];
72
+ countriesDefaults?: OnRampCountryDefaults[];
66
73
  selectedCountry?: OnRampCountry;
67
74
  serviceProviders: OnRampServiceProvider[];
68
75
  selectedServiceProvider?: OnRampServiceProvider;
@@ -109,33 +116,44 @@ export const OnRampController = {
109
116
  },
110
117
 
111
118
  async setSelectedCountry(country: OnRampCountry, updateCurrency = true) {
112
- state.selectedCountry = country;
113
- state.loading = true;
119
+ try {
120
+ state.selectedCountry = country;
121
+ state.loading = true;
114
122
 
115
- if (updateCurrency) {
116
- const currencyCode =
117
- ConstantsUtil.COUNTRY_CURRENCIES[
118
- country.countryCode as keyof typeof ConstantsUtil.COUNTRY_CURRENCIES
119
- ] || 'USD';
123
+ if (updateCurrency) {
124
+ const currencyCode =
125
+ state.countriesDefaults?.find(d => d.countryCode === country.countryCode)
126
+ ?.defaultCurrencyCode || 'USD';
120
127
 
121
- const currency = state.paymentCurrencies?.find(c => c.currencyCode === currencyCode);
128
+ let currency = state.paymentCurrencies?.find(c => c.currencyCode === currencyCode);
122
129
 
123
- if (currency) {
124
- this.setPaymentCurrency(currency);
130
+ if (!currency) {
131
+ currency = state.paymentCurrencies?.find(c => c.currencyCode === 'USD');
132
+ }
133
+
134
+ if (currency) {
135
+ this.setPaymentCurrency(currency);
136
+ }
125
137
  }
126
- }
127
138
 
128
- await Promise.all([this.fetchPaymentMethods(), this.fetchCryptoCurrencies()]);
139
+ await Promise.all([this.fetchPaymentMethods(), this.fetchCryptoCurrencies()]);
140
+ this.clearQuotes();
129
141
 
130
- state.loading = false;
142
+ state.loading = false;
131
143
 
132
- StorageUtil.setOnRampPreferredCountry(country);
144
+ StorageUtil.setOnRampPreferredCountry(country);
145
+ } catch (error) {
146
+ LogController.sendError(error, 'OnRampController.ts', 'setSelectedCountry');
147
+ state.loading = false;
148
+ state.error = {
149
+ type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
150
+ message: 'Failed to load countries'
151
+ };
152
+ }
133
153
  },
134
154
 
135
155
  setSelectedPaymentMethod(paymentMethod: OnRampPaymentMethod) {
136
156
  state.selectedPaymentMethod = paymentMethod;
137
-
138
- this.clearQuotes();
139
157
  },
140
158
 
141
159
  setPurchaseCurrency(currency: OnRampCryptoCurrency) {
@@ -175,16 +193,16 @@ export const OnRampController = {
175
193
 
176
194
  updateSelectedPurchaseCurrency() {
177
195
  let selectedCurrency;
178
- if (NetworkController.state.caipNetwork?.id) {
196
+ if (ConnectionsController.state.activeNetwork?.caipNetworkId) {
179
197
  const defaultCurrency =
180
198
  ConstantsUtil.NETWORK_DEFAULT_CURRENCIES[
181
- NetworkController.state.caipNetwork
182
- ?.id as keyof typeof ConstantsUtil.NETWORK_DEFAULT_CURRENCIES
199
+ ConnectionsController.state.activeNetwork
200
+ ?.caipNetworkId as keyof typeof ConstantsUtil.NETWORK_DEFAULT_CURRENCIES
183
201
  ];
184
202
  selectedCurrency = state.purchaseCurrencies?.find(c => c.currencyCode === defaultCurrency);
185
203
  }
186
204
 
187
- state.purchaseCurrency = selectedCurrency || state.purchaseCurrencies?.[0] || undefined;
205
+ state.purchaseCurrency = selectedCurrency ?? undefined;
188
206
  },
189
207
 
190
208
  getServiceProviderImage(serviceProviderName?: string) {
@@ -224,6 +242,7 @@ export const OnRampController = {
224
242
  countries.find(c => c.countryCode === countryCode) || countries[0] || undefined;
225
243
  }
226
244
  } catch (error) {
245
+ LogController.sendError(error, 'OnRampController.ts', 'fetchCountries');
227
246
  state.error = {
228
247
  type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
229
248
  message: 'Failed to load countries'
@@ -231,6 +250,28 @@ export const OnRampController = {
231
250
  }
232
251
  },
233
252
 
253
+ async fetchCountriesDefaults() {
254
+ try {
255
+ let countriesDefaults = await StorageUtil.getOnRampCountriesDefaults();
256
+
257
+ if (!countriesDefaults.length) {
258
+ countriesDefaults = (await BlockchainApiController.fetchOnRampCountriesDefaults()) ?? [];
259
+
260
+ if (countriesDefaults.length) {
261
+ StorageUtil.setOnRampCountriesDefaults(countriesDefaults);
262
+ }
263
+ }
264
+
265
+ state.countriesDefaults = countriesDefaults;
266
+ } catch (error) {
267
+ LogController.sendError(error, 'OnRampController.ts', 'fetchCountriesDefaults');
268
+ state.error = {
269
+ type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
270
+ message: 'Failed to load countries defaults'
271
+ };
272
+ }
273
+ },
274
+
234
275
  async fetchServiceProviders() {
235
276
  try {
236
277
  let serviceProviders = await StorageUtil.getOnRampServiceProviders();
@@ -245,6 +286,7 @@ export const OnRampController = {
245
286
 
246
287
  state.serviceProviders = serviceProviders || [];
247
288
  } catch (error) {
289
+ LogController.sendError(error, 'OnRampController.ts', 'fetchServiceProviders');
248
290
  state.error = {
249
291
  type: OnRampErrorType.FAILED_TO_LOAD_PROVIDERS,
250
292
  message: 'Failed to load service providers'
@@ -259,10 +301,8 @@ export const OnRampController = {
259
301
  });
260
302
 
261
303
  const defaultCountryPaymentMethods =
262
- ConstantsUtil.COUNTRY_DEFAULT_PAYMENT_METHOD[
263
- state.selectedCountry
264
- ?.countryCode as keyof typeof ConstantsUtil.COUNTRY_DEFAULT_PAYMENT_METHOD
265
- ];
304
+ state.countriesDefaults?.find(d => d.countryCode === state.selectedCountry?.countryCode)
305
+ ?.defaultPaymentMethods || [];
266
306
 
267
307
  state.paymentMethods =
268
308
  paymentMethods?.sort((a, b) => {
@@ -276,10 +316,9 @@ export const OnRampController = {
276
316
  return aIndex - bIndex;
277
317
  }) || [];
278
318
 
279
- state.selectedPaymentMethod = paymentMethods?.[0] || undefined;
280
-
281
- this.clearQuotes();
319
+ state.selectedPaymentMethod = state.paymentMethods[0];
282
320
  } catch (error) {
321
+ LogController.sendError(error, 'OnRampController.ts', 'fetchPaymentMethods');
283
322
  state.error = {
284
323
  type: OnRampErrorType.FAILED_TO_LOAD_METHODS,
285
324
  message: 'Failed to load payment methods'
@@ -298,17 +337,18 @@ export const OnRampController = {
298
337
  state.purchaseCurrencies = cryptoCurrencies || [];
299
338
 
300
339
  let selectedCurrency;
301
- if (NetworkController.state.caipNetwork?.id) {
340
+ if (ConnectionsController.state.activeNetwork?.caipNetworkId) {
302
341
  const defaultCurrency =
303
342
  ConstantsUtil.NETWORK_DEFAULT_CURRENCIES[
304
- NetworkController.state.caipNetwork
305
- ?.id as keyof typeof ConstantsUtil.NETWORK_DEFAULT_CURRENCIES
306
- ] || 'ETH';
343
+ ConnectionsController.state.activeNetwork
344
+ ?.caipNetworkId as keyof typeof ConstantsUtil.NETWORK_DEFAULT_CURRENCIES
345
+ ];
307
346
  selectedCurrency = state.purchaseCurrencies?.find(c => c.currencyCode === defaultCurrency);
308
347
  }
309
348
 
310
- state.purchaseCurrency = selectedCurrency || cryptoCurrencies?.[0] || undefined;
349
+ state.purchaseCurrency = selectedCurrency || undefined;
311
350
  } catch (error) {
351
+ LogController.sendError(error, 'OnRampController.ts', 'fetchCryptoCurrencies');
312
352
  state.error = {
313
353
  type: OnRampErrorType.FAILED_TO_LOAD_CURRENCIES,
314
354
  message: 'Failed to load crypto currencies'
@@ -336,9 +376,8 @@ export const OnRampController = {
336
376
 
337
377
  if (countryCode) {
338
378
  currencyCode =
339
- ConstantsUtil.COUNTRY_CURRENCIES[
340
- countryCode as keyof typeof ConstantsUtil.COUNTRY_CURRENCIES
341
- ];
379
+ state.countriesDefaults?.find(d => d.countryCode === countryCode)?.defaultCurrencyCode ||
380
+ 'USD';
342
381
  }
343
382
 
344
383
  const preferredCurrency = await StorageUtil.getOnRampPreferredFiatCurrency();
@@ -353,6 +392,7 @@ export const OnRampController = {
353
392
  this.setPaymentCurrency(defaultCurrency);
354
393
  }
355
394
  } catch (error) {
395
+ LogController.sendError(error, 'OnRampController.ts', 'fetchFiatCurrencies');
356
396
  state.error = {
357
397
  type: OnRampErrorType.FAILED_TO_LOAD_CURRENCIES,
358
398
  message: 'Failed to load fiat currencies'
@@ -375,50 +415,103 @@ export const OnRampController = {
375
415
  }
376
416
  },
377
417
 
378
- getQuotesDebounced: CoreHelperUtil.debounce(function () {
379
- OnRampController.getQuotes();
380
- }, 500),
381
-
382
418
  async getQuotes() {
383
- if (!state.paymentAmount || state.paymentAmount <= 0) {
419
+ if (!this.canGenerateQuote()) {
384
420
  this.clearQuotes();
385
421
 
386
422
  return;
387
423
  }
388
424
 
389
- state.quotesLoading = true;
390
- state.error = undefined;
391
-
392
425
  this.abortGetQuotes(false);
393
426
  quotesAbortController = new AbortController();
427
+ const currentSignal = quotesAbortController.signal;
394
428
 
395
429
  try {
430
+ if (
431
+ !state.selectedCountry?.countryCode ||
432
+ !state.purchaseCurrency?.currencyCode ||
433
+ !state.paymentCurrency?.currencyCode ||
434
+ !ConnectionsController.state.activeAddress
435
+ ) {
436
+ throw new BlockchainOnRampError(OnRampErrorType.UNKNOWN, 'Invalid quote parameters');
437
+ }
438
+
439
+ state.quotesLoading = true;
440
+ state.selectedQuote = undefined;
441
+ state.selectedServiceProvider = undefined;
442
+ state.error = undefined;
443
+
444
+ const plainAddress = CoreHelperUtil.getPlainAddress(
445
+ ConnectionsController.state.activeAddress
446
+ );
447
+
448
+ if (!plainAddress) {
449
+ throw new Error('Invalid address');
450
+ }
451
+
396
452
  const body = {
397
- countryCode: state.selectedCountry?.countryCode!,
398
- paymentMethodType: state.selectedPaymentMethod?.paymentMethod!,
399
- destinationCurrencyCode: state.purchaseCurrency?.currencyCode!,
400
- sourceAmount: state.paymentAmount,
401
- sourceCurrencyCode: state.paymentCurrency?.currencyCode!,
402
- walletAddress: AccountController.state.address!
453
+ countryCode: state.selectedCountry.countryCode,
454
+ destinationCurrencyCode: state.purchaseCurrency.currencyCode,
455
+ sourceAmount: state.paymentAmount!,
456
+ sourceCurrencyCode: state.paymentCurrency.currencyCode,
457
+ walletAddress: plainAddress,
458
+ excludeProviders: EXCLUDED_ONRAMP_PROVIDERS
403
459
  };
404
460
 
405
- const response = await BlockchainApiController.getOnRampQuotes(
406
- body,
407
- quotesAbortController.signal
408
- );
461
+ const response = await BlockchainApiController.getOnRampQuotes(body, currentSignal);
409
462
 
410
463
  if (!response || !response.length) {
411
- throw new Error('No quotes available');
464
+ throw new BlockchainOnRampError(OnRampErrorType.NO_VALID_QUOTES, 'No valid quotes');
412
465
  }
413
466
 
414
467
  const quotes = response.sort((a, b) => b.customerScore - a.customerScore);
415
468
 
416
469
  state.quotes = quotes;
417
- state.selectedQuote = quotes[0];
470
+
471
+ //Replace payment method if it's not in the quotes
472
+ const isValidPaymentMethod =
473
+ state.selectedPaymentMethod &&
474
+ quotes.some(
475
+ quote => quote.paymentMethodType === state.selectedPaymentMethod?.paymentMethod
476
+ );
477
+
478
+ if (!isValidPaymentMethod) {
479
+ const countryMethods =
480
+ state.countriesDefaults?.find(d => d.countryCode === state.selectedCountry?.countryCode)
481
+ ?.defaultPaymentMethods || [];
482
+
483
+ const availableQuoteMethods = new Set(quotes.map(q => q.paymentMethodType));
484
+
485
+ let newPaymentMethodType: string | undefined;
486
+ for (const dpm of countryMethods) {
487
+ if (availableQuoteMethods.has(dpm)) {
488
+ newPaymentMethodType = dpm;
489
+ break;
490
+ }
491
+ }
492
+
493
+ if (newPaymentMethodType) {
494
+ state.selectedPaymentMethod =
495
+ state.paymentMethods.find(m => m.paymentMethod === newPaymentMethodType) ||
496
+ state.paymentMethods.find(
497
+ method => method.paymentMethod === quotes[0]?.paymentMethodType
498
+ );
499
+ } else {
500
+ state.selectedPaymentMethod = state.paymentMethods.find(
501
+ method => method.paymentMethod === quotes[0]?.paymentMethodType
502
+ );
503
+ }
504
+ }
505
+
506
+ state.selectedQuote = quotes.find(
507
+ quote => quote.paymentMethodType === state.selectedPaymentMethod?.paymentMethod
508
+ );
509
+
418
510
  state.selectedServiceProvider = state.serviceProviders.find(
419
- sp => sp.serviceProvider === quotes[0]?.serviceProvider
511
+ sp => sp.serviceProvider === state.selectedQuote?.serviceProvider
420
512
  );
421
513
  } catch (error: any) {
514
+ LogController.sendError(error, 'OnRampController.ts', 'getQuotes');
422
515
  if (error.name === 'AbortError') {
423
516
  // Do nothing, another request was made
424
517
  return;
@@ -435,7 +528,9 @@ export const OnRampController = {
435
528
  this.clearQuotes();
436
529
  state.error = mapErrorMessage(error?.code || 'UNKNOWN_ERROR');
437
530
  } finally {
438
- state.quotesLoading = false;
531
+ if (!currentSignal.aborted) {
532
+ state.quotesLoading = false;
533
+ }
439
534
  }
440
535
  },
441
536
 
@@ -449,7 +544,7 @@ export const OnRampController = {
449
544
  state.paymentCurrency?.currencyCode &&
450
545
  state.selectedCountry &&
451
546
  !state.loading &&
452
- AccountController.state.address
547
+ ConnectionsController.state.activeAddress
453
548
  );
454
549
  },
455
550
 
@@ -467,6 +562,7 @@ export const OnRampController = {
467
562
 
468
563
  state.paymentCurrenciesLimits = limits;
469
564
  } catch (error) {
565
+ LogController.sendError(error, 'OnRampController.ts', 'fetchFiatLimits');
470
566
  state.error = {
471
567
  type: OnRampErrorType.FAILED_TO_LOAD_LIMITS,
472
568
  message: 'Failed to load fiat limits'
@@ -476,6 +572,10 @@ export const OnRampController = {
476
572
  },
477
573
 
478
574
  async generateWidget({ quote }: { quote: OnRampQuote }) {
575
+ if (!ConnectionsController.state.activeAddress) {
576
+ throw new Error('No active address');
577
+ }
578
+
479
579
  const metadata = OptionsController.state.metadata;
480
580
  const eventProperties = {
481
581
  asset: quote.destinationCurrencyCode,
@@ -492,16 +592,26 @@ export const OnRampController = {
492
592
  throw new Error('Invalid quote');
493
593
  }
494
594
 
495
- const widget = await BlockchainApiController.getOnRampWidget({
595
+ const plainAddress = CoreHelperUtil.getPlainAddress(
596
+ ConnectionsController.state.activeAddress
597
+ );
598
+
599
+ if (!plainAddress) {
600
+ throw new Error('Invalid address');
601
+ }
602
+
603
+ const body = {
496
604
  countryCode: quote.countryCode,
497
605
  destinationCurrencyCode: quote.destinationCurrencyCode,
498
606
  paymentMethodType: quote.paymentMethodType,
499
607
  serviceProvider: quote.serviceProvider,
500
608
  sourceAmount: quote.sourceAmount,
501
609
  sourceCurrencyCode: quote.sourceCurrencyCode,
502
- walletAddress: AccountController.state.address!,
610
+ walletAddress: plainAddress,
503
611
  redirectUrl: metadata?.redirect?.universal ?? metadata?.redirect?.native
504
- });
612
+ };
613
+
614
+ const widget = await BlockchainApiController.getOnRampWidget(body);
505
615
 
506
616
  if (!widget || !widget.widgetUrl) {
507
617
  throw new Error('Invalid widget response');
@@ -517,6 +627,7 @@ export const OnRampController = {
517
627
 
518
628
  return widget;
519
629
  } catch (e: any) {
630
+ LogController.sendError(e, 'OnRampController.ts', 'generateWidget', { quote });
520
631
  EventsController.sendEvent({
521
632
  type: 'track',
522
633
  event: 'BUY_FAIL',
@@ -555,12 +666,14 @@ export const OnRampController = {
555
666
  await this.fetchServiceProviders();
556
667
 
557
668
  await Promise.all([
669
+ this.fetchCountriesDefaults(),
558
670
  this.fetchPaymentMethods(),
559
671
  this.fetchFiatLimits(),
560
672
  this.fetchCryptoCurrencies(),
561
673
  this.fetchFiatCurrencies()
562
674
  ]);
563
675
  } catch (error) {
676
+ LogController.sendError(error, 'OnRampController.ts', 'loadOnRampData');
564
677
  if (!state.error) {
565
678
  state.error = {
566
679
  type: OnRampErrorType.FAILED_TO_LOAD,
@@ -1,6 +1,15 @@
1
1
  import { proxy, ref } from 'valtio';
2
- import type { Tokens, Storage, Metadata } from '@reown/appkit-common-react-native';
3
- import type { CustomWallet, Features, ProjectId, SdkType, SdkVersion } from '../utils/TypeUtil';
2
+ import type {
3
+ Storage,
4
+ Metadata,
5
+ AppKitNetwork,
6
+ CustomWallet,
7
+ Features,
8
+ ProjectId,
9
+ SdkType,
10
+ SdkVersion,
11
+ SIWXConfig
12
+ } from '@reown/appkit-common-react-native';
4
13
 
5
14
  import { ConstantsUtil } from '../utils/ConstantsUtil';
6
15
 
@@ -17,23 +26,25 @@ export interface OptionsControllerState {
17
26
  excludeWalletIds?: string[];
18
27
  featuredWalletIds?: string[];
19
28
  customWallets?: CustomWallet[];
20
- tokens?: Tokens;
21
29
  enableAnalytics?: boolean;
22
30
  sdkType: SdkType;
23
31
  sdkVersion: SdkVersion;
24
32
  metadata?: Metadata;
25
- isSiweEnabled?: boolean;
33
+ siwx?: SIWXConfig;
26
34
  isOnRampEnabled?: boolean;
27
35
  features?: Features;
28
36
  debug?: boolean;
37
+ defaultNetwork?: AppKitNetwork;
38
+ requestedNetworks?: AppKitNetwork[];
29
39
  }
30
40
 
31
41
  // -- State --------------------------------------------- //
32
42
  const state = proxy<OptionsControllerState>({
33
43
  projectId: '',
34
44
  sdkType: 'appkit',
35
- sdkVersion: 'react-native-wagmi-undefined',
45
+ sdkVersion: 'react-native-undefined-undefined',
36
46
  features: ConstantsUtil.DEFAULT_FEATURES,
47
+ customWallets: [],
37
48
  debug: false
38
49
  });
39
50
 
@@ -61,10 +72,6 @@ export const OptionsController = {
61
72
  state.featuredWalletIds = featuredWalletIds;
62
73
  },
63
74
 
64
- setTokens(tokens: OptionsControllerState['tokens']) {
65
- state.tokens = tokens;
66
- },
67
-
68
75
  setCustomWallets(customWallets: OptionsControllerState['customWallets']) {
69
76
  state.customWallets = customWallets;
70
77
  },
@@ -81,10 +88,6 @@ export const OptionsController = {
81
88
  state.metadata = metadata;
82
89
  },
83
90
 
84
- setIsSiweEnabled(isSiweEnabled: OptionsControllerState['isSiweEnabled']) {
85
- state.isSiweEnabled = isSiweEnabled;
86
- },
87
-
88
91
  setFeatures(features: OptionsControllerState['features']) {
89
92
  state.features = { ...ConstantsUtil.DEFAULT_FEATURES, ...features };
90
93
  },
@@ -103,10 +106,34 @@ export const OptionsController = {
103
106
  }
104
107
  },
105
108
 
109
+ setDefaultNetwork(defaultNetwork?: OptionsControllerState['defaultNetwork']) {
110
+ state.defaultNetwork = defaultNetwork;
111
+ },
112
+
113
+ setRequestedNetworks(requestedNetworks?: OptionsControllerState['requestedNetworks']) {
114
+ state.requestedNetworks = requestedNetworks;
115
+ },
116
+
117
+ setSiwx(siwx?: OptionsControllerState['siwx']) {
118
+ if (siwx && (siwx?.signOutOnDisconnect === undefined || siwx?.signOutOnDisconnect === null)) {
119
+ siwx.signOutOnDisconnect = true;
120
+ }
121
+
122
+ state.siwx = siwx;
123
+ },
124
+
106
125
  isClipboardAvailable() {
107
126
  return !!state.clipboardClient;
108
127
  },
109
128
 
129
+ getStorage() {
130
+ if (!state.storage) {
131
+ throw new Error('AppKit: Storage is not set');
132
+ }
133
+
134
+ return state.storage;
135
+ },
136
+
110
137
  copyToClipboard(value: string) {
111
138
  const client = state.clipboardClient;
112
139
  if (client) {