@reown/appkit-core-react-native 2.0.0-alpha.1 → 2.0.0-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 (228) hide show
  1. package/lib/commonjs/controllers/ApiController.js +16 -21
  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 +102 -112
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionsController.js +248 -51
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
  9. package/lib/commonjs/controllers/EnsController.js +4 -4
  10. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  11. package/lib/commonjs/controllers/EventsController.js +4 -4
  12. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  13. package/lib/commonjs/controllers/ModalController.js +6 -7
  14. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  15. package/lib/commonjs/controllers/OnRampController.js +117 -53
  16. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  17. package/lib/commonjs/controllers/OptionsController.js +10 -4
  18. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  19. package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
  20. package/lib/commonjs/controllers/RouterController.js +6 -21
  21. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  22. package/lib/commonjs/controllers/SendController.js +100 -100
  23. package/lib/commonjs/controllers/SendController.js.map +1 -1
  24. package/lib/commonjs/controllers/SnackController.js +29 -5
  25. package/lib/commonjs/controllers/SnackController.js.map +1 -1
  26. package/lib/commonjs/controllers/SwapController.js +109 -117
  27. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  28. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  29. package/lib/commonjs/controllers/TransactionsController.js +23 -19
  30. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  31. package/lib/commonjs/controllers/WcController.js +73 -0
  32. package/lib/commonjs/controllers/WcController.js.map +1 -0
  33. package/lib/commonjs/index.js +3 -38
  34. package/lib/commonjs/index.js.map +1 -1
  35. package/lib/commonjs/package.json +1 -0
  36. package/lib/commonjs/utils/ApiUtil.js.map +1 -1
  37. package/lib/commonjs/utils/AssetUtil.js +6 -14
  38. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  39. package/lib/commonjs/utils/ConstantsUtil.js +13 -425
  40. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  41. package/lib/commonjs/utils/CoreHelperUtil.js +13 -8
  42. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  43. package/lib/commonjs/utils/EventUtil.js.map +1 -1
  44. package/lib/commonjs/utils/FetchUtil.js +34 -10
  45. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  46. package/lib/commonjs/utils/RouterUtil.js.map +1 -1
  47. package/lib/commonjs/utils/StorageUtil.js +77 -129
  48. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  49. package/lib/commonjs/utils/SwapApiUtil.js +2 -17
  50. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  51. package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -1
  52. package/lib/module/controllers/ApiController.js +17 -21
  53. package/lib/module/controllers/ApiController.js.map +1 -1
  54. package/lib/module/controllers/AssetController.js +2 -4
  55. package/lib/module/controllers/AssetController.js.map +1 -1
  56. package/lib/module/controllers/BlockchainApiController.js +103 -111
  57. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  58. package/lib/module/controllers/ConnectionsController.js +250 -51
  59. package/lib/module/controllers/ConnectionsController.js.map +1 -1
  60. package/lib/module/controllers/EnsController.js +4 -2
  61. package/lib/module/controllers/EnsController.js.map +1 -1
  62. package/lib/module/controllers/EventsController.js +3 -1
  63. package/lib/module/controllers/EventsController.js.map +1 -1
  64. package/lib/module/controllers/ModalController.js +8 -7
  65. package/lib/module/controllers/ModalController.js.map +1 -1
  66. package/lib/module/controllers/OnRampController.js +118 -52
  67. package/lib/module/controllers/OnRampController.js.map +1 -1
  68. package/lib/module/controllers/OptionsController.js +12 -4
  69. package/lib/module/controllers/OptionsController.js.map +1 -1
  70. package/lib/module/controllers/PublicStateController.js +2 -0
  71. package/lib/module/controllers/PublicStateController.js.map +1 -1
  72. package/lib/module/controllers/RouterController.js +8 -21
  73. package/lib/module/controllers/RouterController.js.map +1 -1
  74. package/lib/module/controllers/SendController.js +99 -97
  75. package/lib/module/controllers/SendController.js.map +1 -1
  76. package/lib/module/controllers/SnackController.js +31 -5
  77. package/lib/module/controllers/SnackController.js.map +1 -1
  78. package/lib/module/controllers/SwapController.js +111 -117
  79. package/lib/module/controllers/SwapController.js.map +1 -1
  80. package/lib/module/controllers/ThemeController.js +2 -0
  81. package/lib/module/controllers/ThemeController.js.map +1 -1
  82. package/lib/module/controllers/TransactionsController.js +23 -17
  83. package/lib/module/controllers/TransactionsController.js.map +1 -1
  84. package/lib/module/controllers/WcController.js +70 -0
  85. package/lib/module/controllers/WcController.js.map +1 -0
  86. package/lib/module/index.js +5 -6
  87. package/lib/module/index.js.map +1 -1
  88. package/lib/module/utils/ApiUtil.js +2 -0
  89. package/lib/module/utils/ApiUtil.js.map +1 -1
  90. package/lib/module/utils/AssetUtil.js +8 -14
  91. package/lib/module/utils/AssetUtil.js.map +1 -1
  92. package/lib/module/utils/ConstantsUtil.js +15 -425
  93. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  94. package/lib/module/utils/CoreHelperUtil.js +15 -6
  95. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  96. package/lib/module/utils/EventUtil.js +2 -0
  97. package/lib/module/utils/EventUtil.js.map +1 -1
  98. package/lib/module/utils/FetchUtil.js +36 -10
  99. package/lib/module/utils/FetchUtil.js.map +1 -1
  100. package/lib/module/utils/RouterUtil.js +2 -0
  101. package/lib/module/utils/RouterUtil.js.map +1 -1
  102. package/lib/module/utils/StorageUtil.js +80 -129
  103. package/lib/module/utils/StorageUtil.js.map +1 -1
  104. package/lib/module/utils/SwapApiUtil.js +4 -17
  105. package/lib/module/utils/SwapApiUtil.js.map +1 -1
  106. package/lib/module/utils/SwapCalculationUtil.js +3 -0
  107. package/lib/module/utils/SwapCalculationUtil.js.map +1 -1
  108. package/lib/typescript/controllers/ApiController.d.ts +3 -4
  109. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  110. package/lib/typescript/controllers/AssetController.d.ts +0 -2
  111. package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
  112. package/lib/typescript/controllers/BlockchainApiController.d.ts +21 -13
  113. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  114. package/lib/typescript/controllers/ConnectionsController.d.ts +19 -17
  115. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
  116. package/lib/typescript/controllers/EnsController.d.ts +1 -1
  117. package/lib/typescript/controllers/EventsController.d.ts +1 -1
  118. package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
  119. package/lib/typescript/controllers/ModalController.d.ts +1 -1
  120. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  121. package/lib/typescript/controllers/OnRampController.d.ts +4 -3
  122. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  123. package/lib/typescript/controllers/OptionsController.d.ts +4 -4
  124. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  125. package/lib/typescript/controllers/RouterController.d.ts +5 -20
  126. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  127. package/lib/typescript/controllers/SendController.d.ts +5 -7
  128. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  129. package/lib/typescript/controllers/SnackController.d.ts +3 -3
  130. package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
  131. package/lib/typescript/controllers/SwapController.d.ts +11 -11
  132. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  133. package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
  134. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  135. package/lib/typescript/controllers/WcController.d.ts +27 -0
  136. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  137. package/lib/typescript/index.d.ts +1 -7
  138. package/lib/typescript/index.d.ts.map +1 -1
  139. package/lib/typescript/utils/AssetUtil.d.ts +2 -3
  140. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  141. package/lib/typescript/utils/ConstantsUtil.d.ts +7 -415
  142. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  143. package/lib/typescript/utils/CoreHelperUtil.d.ts +4 -4
  144. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  145. package/lib/typescript/utils/EventUtil.d.ts +1 -1
  146. package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
  147. package/lib/typescript/utils/FetchUtil.d.ts +1 -1
  148. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  149. package/lib/typescript/utils/StorageUtil.d.ts +8 -19
  150. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  151. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
  152. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  153. package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
  154. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
  155. package/package.json +9 -23
  156. package/src/controllers/ApiController.ts +24 -28
  157. package/src/controllers/AssetController.ts +0 -6
  158. package/src/controllers/BlockchainApiController.ts +76 -121
  159. package/src/controllers/ConnectionsController.ts +308 -78
  160. package/src/controllers/EnsController.ts +3 -3
  161. package/src/controllers/EventsController.ts +2 -2
  162. package/src/controllers/ModalController.ts +7 -9
  163. package/src/controllers/OnRampController.ts +179 -82
  164. package/src/controllers/OptionsController.ts +24 -8
  165. package/src/controllers/RouterController.ts +12 -54
  166. package/src/controllers/SendController.ts +123 -112
  167. package/src/controllers/SnackController.ts +31 -5
  168. package/src/controllers/SwapController.ts +130 -146
  169. package/src/controllers/TransactionsController.ts +24 -18
  170. package/src/controllers/WcController.ts +93 -0
  171. package/src/index.ts +2 -21
  172. package/src/utils/AssetUtil.ts +7 -17
  173. package/src/utils/ConstantsUtil.ts +15 -429
  174. package/src/utils/CoreHelperUtil.ts +31 -8
  175. package/src/utils/EventUtil.ts +1 -1
  176. package/src/utils/FetchUtil.ts +38 -11
  177. package/src/utils/StorageUtil.ts +146 -157
  178. package/src/utils/SwapApiUtil.ts +18 -37
  179. package/src/utils/SwapCalculationUtil.ts +1 -2
  180. package/lib/commonjs/controllers/AccountController.js +0 -93
  181. package/lib/commonjs/controllers/AccountController.js.map +0 -1
  182. package/lib/commonjs/controllers/ConnectionController.js +0 -132
  183. package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
  184. package/lib/commonjs/controllers/ConnectorController.js +0 -50
  185. package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
  186. package/lib/commonjs/controllers/NetworkController.js +0 -90
  187. package/lib/commonjs/controllers/NetworkController.js.map +0 -1
  188. package/lib/commonjs/controllers/WebviewController.js +0 -52
  189. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  190. package/lib/commonjs/utils/NetworkUtil.js +0 -46
  191. package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
  192. package/lib/commonjs/utils/TypeUtil.js +0 -6
  193. package/lib/commonjs/utils/TypeUtil.js.map +0 -1
  194. package/lib/module/controllers/AccountController.js +0 -88
  195. package/lib/module/controllers/AccountController.js.map +0 -1
  196. package/lib/module/controllers/ConnectionController.js +0 -127
  197. package/lib/module/controllers/ConnectionController.js.map +0 -1
  198. package/lib/module/controllers/ConnectorController.js +0 -45
  199. package/lib/module/controllers/ConnectorController.js.map +0 -1
  200. package/lib/module/controllers/NetworkController.js +0 -85
  201. package/lib/module/controllers/NetworkController.js.map +0 -1
  202. package/lib/module/controllers/WebviewController.js +0 -47
  203. package/lib/module/controllers/WebviewController.js.map +0 -1
  204. package/lib/module/utils/NetworkUtil.js +0 -40
  205. package/lib/module/utils/NetworkUtil.js.map +0 -1
  206. package/lib/module/utils/TypeUtil.js +0 -2
  207. package/lib/module/utils/TypeUtil.js.map +0 -1
  208. package/lib/typescript/controllers/AccountController.d.ts +0 -33
  209. package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
  210. package/lib/typescript/controllers/ConnectionController.d.ts +0 -68
  211. package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
  212. package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
  213. package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
  214. package/lib/typescript/controllers/NetworkController.d.ts +0 -34
  215. package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
  216. package/lib/typescript/controllers/WebviewController.d.ts +0 -21
  217. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  218. package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
  219. package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
  220. package/lib/typescript/utils/TypeUtil.d.ts +0 -817
  221. package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
  222. package/src/controllers/AccountController.ts +0 -128
  223. package/src/controllers/ConnectionController.ts +0 -208
  224. package/src/controllers/ConnectorController.ts +0 -64
  225. package/src/controllers/NetworkController.ts +0 -120
  226. package/src/controllers/WebviewController.ts +0 -63
  227. package/src/utils/NetworkUtil.ts +0 -33
  228. package/src/utils/TypeUtil.ts +0 -995
@@ -1,4 +1,4 @@
1
- import type { RequestCache } from './TypeUtil';
1
+ import type { RequestCache } from '@reown/appkit-common-react-native';
2
2
 
3
3
  // -- Types ----------------------------------------------------------------------
4
4
  interface Options {
@@ -88,26 +88,53 @@ export class FetchUtil {
88
88
  }
89
89
 
90
90
  private createUrl({ path, params }: RequestArguments) {
91
- const url = new URL(path, this.baseUrl);
92
- if (params) {
93
- Object.entries(params).forEach(([key, value]) => {
94
- if (value) {
95
- url.searchParams.append(key, value);
96
- }
97
- });
91
+ let fullUrl: string;
92
+
93
+ const isAbsoluteUrl = path.startsWith('http://') || path.startsWith('https://');
94
+
95
+ if (isAbsoluteUrl) {
96
+ fullUrl = path;
97
+ } else {
98
+ const baseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
99
+ const pathUrl = path.startsWith('/') ? path.substring(1) : path;
100
+ fullUrl = `${baseUrl}${pathUrl}`;
98
101
  }
99
102
 
103
+ const allParams: Record<string, string | undefined> = { ...params };
100
104
  if (this.clientId) {
101
- url.searchParams.append('clientId', this.clientId);
105
+ allParams['clientId'] = this.clientId;
106
+ }
107
+
108
+ const queryParams: string[] = [];
109
+ for (const key in allParams) {
110
+ const value = allParams[key];
111
+ if (value !== undefined && value !== null && value !== '') {
112
+ queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
113
+ }
114
+ }
115
+
116
+ if (queryParams.length > 0) {
117
+ const queryString = queryParams.join('&');
118
+ if (fullUrl.includes('?')) {
119
+ fullUrl = `${fullUrl}&${queryString}`;
120
+ } else {
121
+ fullUrl = `${fullUrl}?${queryString}`;
122
+ }
102
123
  }
103
124
 
104
- return url.toString();
125
+ return fullUrl;
105
126
  }
106
127
 
107
128
  private async processResponse<T>(response: Response) {
108
129
  if (!response.ok) {
109
130
  if (response.headers.get('content-type')?.includes('application/json')) {
110
- return Promise.reject((await response.json()) as T);
131
+ try {
132
+ const errorData = await response.json();
133
+
134
+ return Promise.reject(errorData);
135
+ } catch (jsonError) {
136
+ return Promise.reject(`Code: ${response.status} - ${response.statusText}`);
137
+ }
111
138
  }
112
139
 
113
140
  const errorText = await response.text();
@@ -1,40 +1,27 @@
1
1
  /* eslint-disable no-console */
2
- import AsyncStorage from '@react-native-async-storage/async-storage';
3
- import type {
4
- OnRampCountry,
5
- OnRampFiatCurrency,
6
- OnRampFiatLimit,
7
- OnRampServiceProvider,
8
- WcWallet
9
- } from './TypeUtil';
10
2
  import {
3
+ type OnRampCountry,
4
+ type OnRampFiatCurrency,
5
+ type OnRampFiatLimit,
6
+ type OnRampServiceProvider,
7
+ type OnRampCountryDefaults,
8
+ type WcWallet,
11
9
  DateUtil,
12
- type SocialProvider,
13
- type New_ConnectorType,
14
10
  type ConnectorType,
15
- type ChainNamespace
11
+ type ChainNamespace,
12
+ type WalletDeepLink,
13
+ ConstantsUtil
16
14
  } from '@reown/appkit-common-react-native';
17
-
18
- // -- Helpers -----------------------------------------------------------------
19
- const WC_DEEPLINK = 'WALLETCONNECT_DEEPLINK_CHOICE';
20
- const RECENT_WALLET = '@w3m/recent';
21
- const CONNECTED_WALLET_IMAGE_URL = '@w3m/connected_wallet_image_url';
22
- const CONNECTED_CONNECTOR = '@w3m/connected_connector';
23
- const CONNECTED_CONNECTORS = '@appkit/connected_connectors';
24
- const CONNECTED_SOCIAL = '@appkit/connected_social';
25
- const ONRAMP_PREFERRED_COUNTRY = '@appkit/onramp_preferred_country';
26
- const ONRAMP_COUNTRIES = '@appkit/onramp_countries';
27
- const ONRAMP_SERVICE_PROVIDERS = '@appkit/onramp_service_providers';
28
- const ONRAMP_FIAT_LIMITS = '@appkit/onramp_fiat_limits';
29
- const ONRAMP_FIAT_CURRENCIES = '@appkit/onramp_fiat_currencies';
30
- const ONRAMP_PREFERRED_FIAT_CURRENCY = '@appkit/onramp_preferred_fiat_currency';
31
- const ACTIVE_NAMESPACE = '@appkit/active_namespace';
15
+ import { OptionsController } from '../controllers/OptionsController';
32
16
 
33
17
  // -- Utility -----------------------------------------------------------------
34
18
  export const StorageUtil = {
35
- setWalletConnectDeepLink({ href, name }: { href: string; name: string }) {
19
+ setWalletConnectDeepLink({ href, name }: WalletDeepLink) {
36
20
  try {
37
- AsyncStorage.setItem(WC_DEEPLINK, JSON.stringify({ href, name }));
21
+ OptionsController.getStorage().setItem(ConstantsUtil.STORAGE_KEYS.WC_DEEPLINK, {
22
+ href,
23
+ name
24
+ });
38
25
  } catch {
39
26
  console.info('Unable to set WalletConnect deep link');
40
27
  }
@@ -42,9 +29,11 @@ export const StorageUtil = {
42
29
 
43
30
  async getWalletConnectDeepLink() {
44
31
  try {
45
- const deepLink = await AsyncStorage.getItem(WC_DEEPLINK);
32
+ const deepLink = await OptionsController.getStorage().getItem<WalletDeepLink>(
33
+ ConstantsUtil.STORAGE_KEYS.WC_DEEPLINK
34
+ );
46
35
  if (deepLink) {
47
- return JSON.parse(deepLink);
36
+ return deepLink;
48
37
  }
49
38
  } catch {
50
39
  console.info('Unable to get WalletConnect deep link');
@@ -55,9 +44,9 @@ export const StorageUtil = {
55
44
 
56
45
  async removeWalletConnectDeepLink() {
57
46
  try {
58
- await AsyncStorage.removeItem(WC_DEEPLINK);
47
+ await OptionsController.getStorage().removeItem(ConstantsUtil.STORAGE_KEYS.WC_DEEPLINK);
59
48
  } catch {
60
- console.info('Unable to delete WalletConnect deep link');
49
+ console.info('Unable to remove WalletConnect deep link');
61
50
  }
62
51
  },
63
52
 
@@ -74,7 +63,10 @@ export const StorageUtil = {
74
63
  if (recentWallets.length > 2) {
75
64
  recentWallets.pop();
76
65
  }
77
- AsyncStorage.setItem(RECENT_WALLET, JSON.stringify(recentWallets));
66
+ OptionsController.getStorage().setItem(
67
+ ConstantsUtil.STORAGE_KEYS.RECENT_WALLET,
68
+ recentWallets
69
+ );
78
70
 
79
71
  return recentWallets;
80
72
  } catch {
@@ -86,7 +78,10 @@ export const StorageUtil = {
86
78
 
87
79
  async setRecentWallets(wallets: WcWallet[]) {
88
80
  try {
89
- await AsyncStorage.setItem(RECENT_WALLET, JSON.stringify(wallets));
81
+ await OptionsController.getStorage().setItem(
82
+ ConstantsUtil.STORAGE_KEYS.RECENT_WALLET,
83
+ wallets
84
+ );
90
85
  } catch {
91
86
  console.info('Unable to set recent wallets');
92
87
  }
@@ -94,9 +89,11 @@ export const StorageUtil = {
94
89
 
95
90
  async getRecentWallets(): Promise<WcWallet[]> {
96
91
  try {
97
- const recent = await AsyncStorage.getItem(RECENT_WALLET);
92
+ const recent = await OptionsController.getStorage().getItem(
93
+ ConstantsUtil.STORAGE_KEYS.RECENT_WALLET
94
+ );
98
95
 
99
- return recent ? JSON.parse(recent) : [];
96
+ return recent ?? [];
100
97
  } catch {
101
98
  console.info('Unable to get recent wallets');
102
99
  }
@@ -104,40 +101,11 @@ export const StorageUtil = {
104
101
  return [];
105
102
  },
106
103
 
107
- //TODO: remove this
108
- async setConnectedConnector(connectorType: ConnectorType) {
109
- try {
110
- await AsyncStorage.setItem(CONNECTED_CONNECTOR, JSON.stringify(connectorType));
111
- } catch {
112
- console.info('Unable to set Connected Connector');
113
- }
114
- },
115
-
116
- async getConnectedConnector(): Promise<ConnectorType | undefined> {
117
- try {
118
- const connector = (await AsyncStorage.getItem(CONNECTED_CONNECTOR)) as ConnectorType;
119
-
120
- return connector ? JSON.parse(connector) : undefined;
121
- } catch {
122
- console.info('Unable to get Connected Connector');
123
- }
124
-
125
- return undefined;
126
- },
127
-
128
- async removeConnectedConnector() {
129
- try {
130
- await AsyncStorage.removeItem(CONNECTED_CONNECTOR);
131
- } catch {
132
- console.info('Unable to remove Connected Connector');
133
- }
134
- },
135
-
136
104
  async setConnectedConnectors({
137
105
  type,
138
106
  namespaces
139
107
  }: {
140
- type: New_ConnectorType;
108
+ type: ConnectorType;
141
109
  namespaces: string[];
142
110
  }) {
143
111
  try {
@@ -145,144 +113,151 @@ export const StorageUtil = {
145
113
  // Only add if it doesn't exist already
146
114
  if (!currentConnectors.some(c => c.type === type)) {
147
115
  const updatedConnectors = [...currentConnectors, { type, namespaces }];
148
- await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
116
+ await OptionsController.getStorage().setItem(
117
+ ConstantsUtil.STORAGE_KEYS.CONNECTED_CONNECTORS,
118
+ updatedConnectors
119
+ );
149
120
  }
150
121
  } catch {
151
122
  console.info('Unable to set Connected Connector');
152
123
  }
153
124
  },
154
125
 
155
- async getConnectedConnectors(): Promise<{ type: New_ConnectorType; namespaces: string[] }[]> {
126
+ async getConnectedConnectors(): Promise<{ type: ConnectorType; namespaces: string[] }[]> {
156
127
  try {
157
- const connectors = await AsyncStorage.getItem(CONNECTED_CONNECTORS);
128
+ const connectors = await OptionsController.getStorage().getItem<
129
+ { type: ConnectorType; namespaces: string[] }[]
130
+ >(ConstantsUtil.STORAGE_KEYS.CONNECTED_CONNECTORS);
158
131
 
159
- return connectors ? JSON.parse(connectors) : [];
160
- } catch {
132
+ return connectors ?? [];
133
+ } catch (err) {
161
134
  console.info('Unable to get Connected Connector');
162
135
  }
163
136
 
164
137
  return [];
165
138
  },
166
139
 
167
- async removeConnectedConnectors(type: New_ConnectorType) {
140
+ async removeConnectedConnectors(type: ConnectorType) {
168
141
  try {
169
142
  const currentConnectors = await StorageUtil.getConnectedConnectors();
170
143
  const updatedConnectors = currentConnectors.filter(c => c.type !== type);
171
- await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
144
+ await OptionsController.getStorage().setItem(
145
+ ConstantsUtil.STORAGE_KEYS.CONNECTED_CONNECTORS,
146
+ updatedConnectors
147
+ );
172
148
  } catch {
173
149
  console.info('Unable to remove Connected Connector');
174
150
  }
175
151
  },
176
152
 
177
- async setConnectedWalletImageUrl(url: string) {
153
+ async setOnRampPreferredCountry(country: OnRampCountry) {
178
154
  try {
179
- await AsyncStorage.setItem(CONNECTED_WALLET_IMAGE_URL, url);
155
+ await OptionsController.getStorage().setItem(
156
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_COUNTRY,
157
+ country
158
+ );
180
159
  } catch {
181
- console.info('Unable to set Connected Wallet Image URL');
160
+ console.info('Unable to set OnRamp Preferred Country');
182
161
  }
183
162
  },
184
163
 
185
- async getConnectedWalletImageUrl() {
164
+ async getOnRampPreferredCountry() {
186
165
  try {
187
- return await AsyncStorage.getItem(CONNECTED_WALLET_IMAGE_URL);
166
+ const country = await OptionsController.getStorage().getItem<OnRampCountry>(
167
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_COUNTRY
168
+ );
169
+
170
+ return country ?? undefined;
188
171
  } catch {
189
- console.info('Unable to get Connected Wallet Image URL');
172
+ console.info('Unable to get OnRamp Preferred Country');
190
173
  }
191
174
 
192
175
  return undefined;
193
176
  },
194
177
 
195
- async removeConnectedWalletImageUrl() {
196
- try {
197
- await AsyncStorage.removeItem(CONNECTED_WALLET_IMAGE_URL);
198
- } catch {
199
- console.info('Unable to remove Connected Wallet Image URL');
200
- }
201
- },
202
-
203
- async setConnectedSocialProvider(provider: SocialProvider) {
178
+ async setOnRampPreferredFiatCurrency(currency: OnRampFiatCurrency) {
204
179
  try {
205
- await AsyncStorage.setItem(CONNECTED_SOCIAL, JSON.stringify(provider));
180
+ await OptionsController.getStorage().setItem(
181
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_FIAT_CURRENCY,
182
+ currency
183
+ );
206
184
  } catch {
207
- console.info('Unable to set Connected Social Provider');
185
+ console.info('Unable to set OnRamp Preferred Fiat Currency');
208
186
  }
209
187
  },
210
188
 
211
- async getConnectedSocialProvider() {
189
+ async getOnRampPreferredFiatCurrency() {
212
190
  try {
213
- const provider = (await AsyncStorage.getItem(CONNECTED_SOCIAL)) as SocialProvider;
191
+ const currency = await OptionsController.getStorage().getItem<OnRampFiatCurrency>(
192
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_FIAT_CURRENCY
193
+ );
214
194
 
215
- return provider ? JSON.parse(provider) : undefined;
195
+ return currency ?? undefined;
216
196
  } catch {
217
- console.info('Unable to get Connected Social Provider');
197
+ console.info('Unable to get OnRamp Preferred Fiat Currency');
218
198
  }
219
199
 
220
200
  return undefined;
221
201
  },
222
202
 
223
- async removeConnectedSocialProvider() {
224
- try {
225
- await AsyncStorage.removeItem(CONNECTED_SOCIAL);
226
- } catch {
227
- console.info('Unable to remove Connected Social Provider');
228
- }
229
- },
230
-
231
- async setOnRampPreferredCountry(country: OnRampCountry) {
203
+ async setOnRampCountries(countries: OnRampCountry[]) {
232
204
  try {
233
- await AsyncStorage.setItem(ONRAMP_PREFERRED_COUNTRY, JSON.stringify(country));
205
+ await OptionsController.getStorage().setItem(
206
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_COUNTRIES,
207
+ countries
208
+ );
234
209
  } catch {
235
- console.info('Unable to set OnRamp Preferred Country');
210
+ console.info('Unable to set OnRamp Countries');
236
211
  }
237
212
  },
238
213
 
239
- async getOnRampPreferredCountry() {
214
+ async getOnRampCountries() {
240
215
  try {
241
- const country = await AsyncStorage.getItem(ONRAMP_PREFERRED_COUNTRY);
216
+ const countries = await OptionsController.getStorage().getItem<OnRampCountry[]>(
217
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_COUNTRIES
218
+ );
242
219
 
243
- return country ? (JSON.parse(country) as OnRampCountry) : undefined;
220
+ return countries ?? [];
244
221
  } catch {
245
- console.info('Unable to get OnRamp Preferred Country');
222
+ console.info('Unable to get OnRamp Countries');
246
223
  }
247
224
 
248
- return undefined;
225
+ return [];
249
226
  },
250
227
 
251
- async setOnRampPreferredFiatCurrency(currency: OnRampFiatCurrency) {
228
+ async setOnRampCountriesDefaults(countriesDefaults: OnRampCountryDefaults[]) {
252
229
  try {
253
- await AsyncStorage.setItem(ONRAMP_PREFERRED_FIAT_CURRENCY, JSON.stringify(currency));
230
+ const timestamp = Date.now();
231
+
232
+ await OptionsController.getStorage().setItem(
233
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_COUNTRIES_DEFAULTS,
234
+ { data: countriesDefaults, timestamp }
235
+ );
254
236
  } catch {
255
- console.info('Unable to set OnRamp Preferred Fiat Currency');
237
+ console.info('Unable to set OnRamp Countries Defaults');
256
238
  }
257
239
  },
258
240
 
259
- async getOnRampPreferredFiatCurrency() {
241
+ async getOnRampCountriesDefaults() {
260
242
  try {
261
- const currency = await AsyncStorage.getItem(ONRAMP_PREFERRED_FIAT_CURRENCY);
262
-
263
- return currency ? (JSON.parse(currency) as OnRampFiatCurrency) : undefined;
264
- } catch {
265
- console.info('Unable to get OnRamp Preferred Fiat Currency');
266
- }
243
+ const result = await OptionsController.getStorage().getItem(
244
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_COUNTRIES_DEFAULTS
245
+ );
267
246
 
268
- return undefined;
269
- },
247
+ if (!result) {
248
+ return [];
249
+ }
270
250
 
271
- async setOnRampCountries(countries: OnRampCountry[]) {
272
- try {
273
- await AsyncStorage.setItem(ONRAMP_COUNTRIES, JSON.stringify(countries));
274
- } catch {
275
- console.info('Unable to set OnRamp Countries');
276
- }
277
- },
251
+ const { data, timestamp } = result;
278
252
 
279
- async getOnRampCountries() {
280
- try {
281
- const countries = await AsyncStorage.getItem(ONRAMP_COUNTRIES);
253
+ // Cache for 1 week
254
+ if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
255
+ return [];
256
+ }
282
257
 
283
- return countries ? (JSON.parse(countries) as OnRampCountry[]) : [];
258
+ return (data as OnRampCountryDefaults[]) ?? [];
284
259
  } catch {
285
- console.info('Unable to get OnRamp Countries');
260
+ console.info('Unable to get OnRamp Countries Defaults');
286
261
  }
287
262
 
288
263
  return [];
@@ -292,9 +267,9 @@ export const StorageUtil = {
292
267
  try {
293
268
  const timestamp = Date.now();
294
269
 
295
- await AsyncStorage.setItem(
296
- ONRAMP_SERVICE_PROVIDERS,
297
- JSON.stringify({ data: serviceProviders, timestamp })
270
+ await OptionsController.getStorage().setItem(
271
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_SERVICE_PROVIDERS,
272
+ { data: serviceProviders, timestamp }
298
273
  );
299
274
  } catch {
300
275
  console.info('Unable to set OnRamp Service Providers');
@@ -303,20 +278,22 @@ export const StorageUtil = {
303
278
 
304
279
  async getOnRampServiceProviders() {
305
280
  try {
306
- const result = await AsyncStorage.getItem(ONRAMP_SERVICE_PROVIDERS);
281
+ const result = await OptionsController.getStorage().getItem(
282
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_SERVICE_PROVIDERS
283
+ );
307
284
 
308
285
  if (!result) {
309
286
  return [];
310
287
  }
311
288
 
312
- const { data, timestamp } = JSON.parse(result);
289
+ const { data, timestamp } = result;
313
290
 
314
291
  // Cache for 1 week
315
292
  if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
316
293
  return [];
317
294
  }
318
295
 
319
- return data ? (data as OnRampServiceProvider[]) : [];
296
+ return (data as OnRampServiceProvider[]) ?? [];
320
297
  } catch (err) {
321
298
  console.error(err);
322
299
  console.info('Unable to get OnRamp Service Providers');
@@ -329,10 +306,10 @@ export const StorageUtil = {
329
306
  try {
330
307
  const timestamp = Date.now();
331
308
 
332
- await AsyncStorage.setItem(
333
- ONRAMP_FIAT_LIMITS,
334
- JSON.stringify({ data: fiatLimits, timestamp })
335
- );
309
+ await OptionsController.getStorage().setItem(ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_LIMITS, {
310
+ data: fiatLimits,
311
+ timestamp
312
+ });
336
313
  } catch {
337
314
  console.info('Unable to set OnRamp Fiat Limits');
338
315
  }
@@ -340,20 +317,22 @@ export const StorageUtil = {
340
317
 
341
318
  async getOnRampFiatLimits() {
342
319
  try {
343
- const result = await AsyncStorage.getItem(ONRAMP_FIAT_LIMITS);
320
+ const result = await OptionsController.getStorage().getItem(
321
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_LIMITS
322
+ );
344
323
 
345
324
  if (!result) {
346
325
  return [];
347
326
  }
348
327
 
349
- const { data, timestamp } = JSON.parse(result);
328
+ const { data, timestamp } = result;
350
329
 
351
330
  // Cache for 1 week
352
331
  if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
353
332
  return [];
354
333
  }
355
334
 
356
- return data ? (data as OnRampFiatLimit[]) : [];
335
+ return (data as OnRampFiatLimit[]) ?? [];
357
336
  } catch {
358
337
  console.info('Unable to get OnRamp Fiat Limits');
359
338
  }
@@ -365,9 +344,9 @@ export const StorageUtil = {
365
344
  try {
366
345
  const timestamp = Date.now();
367
346
 
368
- await AsyncStorage.setItem(
369
- ONRAMP_FIAT_CURRENCIES,
370
- JSON.stringify({ data: fiatCurrencies, timestamp })
347
+ await OptionsController.getStorage().setItem(
348
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_CURRENCIES,
349
+ { data: fiatCurrencies, timestamp }
371
350
  );
372
351
  } catch {
373
352
  console.info('Unable to set OnRamp Fiat Currencies');
@@ -376,20 +355,22 @@ export const StorageUtil = {
376
355
 
377
356
  async getOnRampFiatCurrencies() {
378
357
  try {
379
- const result = await AsyncStorage.getItem(ONRAMP_FIAT_CURRENCIES);
358
+ const result = await OptionsController.getStorage().getItem(
359
+ ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_CURRENCIES
360
+ );
380
361
 
381
362
  if (!result) {
382
363
  return [];
383
364
  }
384
365
 
385
- const { data, timestamp } = JSON.parse(result);
366
+ const { data, timestamp } = result;
386
367
 
387
368
  // Cache for 1 week
388
369
  if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
389
370
  return [];
390
371
  }
391
372
 
392
- return data ? (data as OnRampFiatCurrency[]) : [];
373
+ return (data as OnRampFiatCurrency[]) ?? [];
393
374
  } catch {
394
375
  console.info('Unable to get OnRamp Fiat Currencies');
395
376
  }
@@ -400,12 +381,17 @@ export const StorageUtil = {
400
381
  async setActiveNamespace(namespace?: ChainNamespace) {
401
382
  try {
402
383
  if (!namespace) {
403
- await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
384
+ await OptionsController.getStorage().removeItem(
385
+ ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE
386
+ );
404
387
 
405
388
  return;
406
389
  }
407
390
 
408
- await AsyncStorage.setItem(ACTIVE_NAMESPACE, namespace);
391
+ await OptionsController.getStorage().setItem(
392
+ ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE,
393
+ namespace
394
+ );
409
395
  } catch {
410
396
  console.info('Unable to set Active Namespace');
411
397
  }
@@ -413,10 +399,13 @@ export const StorageUtil = {
413
399
 
414
400
  async getActiveNamespace() {
415
401
  try {
416
- const namespace = (await AsyncStorage.getItem(ACTIVE_NAMESPACE)) as ChainNamespace;
402
+ const namespace = (await OptionsController.getStorage().getItem(
403
+ ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE
404
+ )) as ChainNamespace;
417
405
 
418
406
  return namespace ?? undefined;
419
407
  } catch (err) {
408
+ console.error(err);
420
409
  console.info('Unable to get Active Namespace');
421
410
  }
422
411
 
@@ -425,7 +414,7 @@ export const StorageUtil = {
425
414
 
426
415
  async removeActiveNamespace() {
427
416
  try {
428
- await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
417
+ await OptionsController.getStorage().removeItem(ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE);
429
418
  } catch {
430
419
  console.info('Unable to remove Active Namespace');
431
420
  }
@@ -1,13 +1,12 @@
1
- import { BlockchainApiController } from '../controllers/BlockchainApiController';
2
- import { OptionsController } from '../controllers/OptionsController';
3
1
  import type {
4
- BlockchainApiBalanceResponse,
2
+ Balance,
3
+ CaipNetworkId,
5
4
  BlockchainApiSwapAllowanceRequest,
6
5
  SwapTokenWithBalance
7
- } from './TypeUtil';
8
- import { AccountController } from '../controllers/AccountController';
6
+ } from '@reown/appkit-common-react-native';
7
+ import { BlockchainApiController } from '../controllers/BlockchainApiController';
8
+ import { OptionsController } from '../controllers/OptionsController';
9
9
  import { ConnectionsController } from '../controllers/ConnectionsController';
10
- import type { CaipNetworkId } from '@reown/appkit-common-react-native';
11
10
  import { ConstantsUtil } from './ConstantsUtil';
12
11
 
13
12
  export const SwapApiUtil = {
@@ -64,43 +63,25 @@ export const SwapApiUtil = {
64
63
  return false;
65
64
  },
66
65
 
67
- async getMyTokensWithBalance(forceUpdate?: string) {
68
- const { activeAddress, activeNetwork: network } = ConnectionsController.state;
69
- const address = activeAddress?.split(':')[2];
70
-
71
- if (!address) {
72
- return [];
73
- }
74
-
75
- const response = await BlockchainApiController.getBalance(
76
- address,
77
- network?.caipNetworkId,
78
- forceUpdate
79
- );
80
- const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
81
-
82
- AccountController.setTokenBalance(balances);
83
-
84
- return this.mapBalancesToSwapTokens(balances);
85
- },
86
-
87
- mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
66
+ mapBalancesToSwapTokens(balances?: Balance[]) {
88
67
  const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
89
68
  const address = activeNamespace
90
69
  ? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
91
70
  : undefined;
92
71
 
93
72
  return (
94
- balances?.map(
95
- token =>
96
- ({
97
- ...token,
98
- address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
99
- decimals: parseInt(token.quantity.decimals, 10),
100
- logoUri: token.iconUrl,
101
- eip2612: false
102
- }) as SwapTokenWithBalance
103
- ) || []
73
+ balances
74
+ ?.filter(balance => balance?.quantity?.numeric)
75
+ .map(
76
+ token =>
77
+ ({
78
+ ...token,
79
+ address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
80
+ decimals: parseInt(token.quantity?.decimals ?? '0', 10),
81
+ logoUri: token.iconUrl,
82
+ eip2612: false
83
+ }) as SwapTokenWithBalance
84
+ ) || []
104
85
  );
105
86
  },
106
87