@reown/appkit-core-react-native 0.0.0-feat-multi-social-20250715153550 → 0.0.0-feat-onramp-20250718191948

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 (194) hide show
  1. package/lib/commonjs/controllers/AccountController.js +17 -20
  2. package/lib/commonjs/controllers/AccountController.js.map +1 -1
  3. package/lib/commonjs/controllers/ApiController.js +15 -17
  4. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  5. package/lib/commonjs/controllers/BlockchainApiController.js +28 -110
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionController.js +11 -8
  8. package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
  9. package/lib/commonjs/controllers/ConnectorController.js +49 -0
  10. package/lib/commonjs/controllers/ConnectorController.js.map +1 -0
  11. package/lib/commonjs/controllers/EnsController.js +4 -4
  12. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  13. package/lib/commonjs/controllers/EventsController.js +4 -4
  14. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  15. package/lib/commonjs/controllers/ModalController.js +2 -2
  16. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  17. package/lib/commonjs/controllers/OnRampController.js +62 -21
  18. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  19. package/lib/commonjs/controllers/OptionsController.js +3 -8
  20. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  21. package/lib/commonjs/controllers/RouterController.js +22 -1
  22. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  23. package/lib/commonjs/controllers/SendController.js +33 -34
  24. package/lib/commonjs/controllers/SendController.js.map +1 -1
  25. package/lib/commonjs/controllers/SnackController.js +5 -29
  26. package/lib/commonjs/controllers/SnackController.js.map +1 -1
  27. package/lib/commonjs/controllers/SwapController.js +148 -136
  28. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  29. package/lib/commonjs/controllers/ThemeController.js +1 -9
  30. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  31. package/lib/commonjs/controllers/TransactionsController.js +21 -25
  32. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  33. package/lib/commonjs/controllers/WebviewController.js +52 -0
  34. package/lib/commonjs/controllers/WebviewController.js.map +1 -0
  35. package/lib/commonjs/index.js +24 -3
  36. package/lib/commonjs/index.js.map +1 -1
  37. package/lib/commonjs/utils/AssetUtil.js +12 -8
  38. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  39. package/lib/commonjs/utils/ConnectionUtil.js +33 -0
  40. package/lib/commonjs/utils/ConnectionUtil.js.map +1 -0
  41. package/lib/commonjs/utils/ConstantsUtil.js +8 -537
  42. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  43. package/lib/commonjs/utils/CoreHelperUtil.js +4 -4
  44. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  45. package/lib/commonjs/utils/FetchUtil.js +28 -9
  46. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  47. package/lib/commonjs/utils/NetworkUtil.js +46 -0
  48. package/lib/commonjs/utils/NetworkUtil.js.map +1 -0
  49. package/lib/commonjs/utils/StorageUtil.js +42 -51
  50. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  51. package/lib/commonjs/utils/SwapApiUtil.js +21 -15
  52. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  53. package/lib/module/controllers/AccountController.js +17 -20
  54. package/lib/module/controllers/AccountController.js.map +1 -1
  55. package/lib/module/controllers/ApiController.js +15 -16
  56. package/lib/module/controllers/ApiController.js.map +1 -1
  57. package/lib/module/controllers/BlockchainApiController.js +28 -110
  58. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  59. package/lib/module/controllers/ConnectionController.js +11 -8
  60. package/lib/module/controllers/ConnectionController.js.map +1 -1
  61. package/lib/module/controllers/ConnectorController.js +44 -0
  62. package/lib/module/controllers/ConnectorController.js.map +1 -0
  63. package/lib/module/controllers/EnsController.js +2 -2
  64. package/lib/module/controllers/EnsController.js.map +1 -1
  65. package/lib/module/controllers/EventsController.js +1 -1
  66. package/lib/module/controllers/EventsController.js.map +1 -1
  67. package/lib/module/controllers/ModalController.js +2 -2
  68. package/lib/module/controllers/ModalController.js.map +1 -1
  69. package/lib/module/controllers/OnRampController.js +62 -21
  70. package/lib/module/controllers/OnRampController.js.map +1 -1
  71. package/lib/module/controllers/OptionsController.js +3 -8
  72. package/lib/module/controllers/OptionsController.js.map +1 -1
  73. package/lib/module/controllers/RouterController.js +22 -1
  74. package/lib/module/controllers/RouterController.js.map +1 -1
  75. package/lib/module/controllers/SendController.js +30 -31
  76. package/lib/module/controllers/SendController.js.map +1 -1
  77. package/lib/module/controllers/SnackController.js +5 -29
  78. package/lib/module/controllers/SnackController.js.map +1 -1
  79. package/lib/module/controllers/SwapController.js +148 -136
  80. package/lib/module/controllers/SwapController.js.map +1 -1
  81. package/lib/module/controllers/ThemeController.js +1 -9
  82. package/lib/module/controllers/ThemeController.js.map +1 -1
  83. package/lib/module/controllers/TransactionsController.js +19 -23
  84. package/lib/module/controllers/TransactionsController.js.map +1 -1
  85. package/lib/module/controllers/WebviewController.js +47 -0
  86. package/lib/module/controllers/WebviewController.js.map +1 -0
  87. package/lib/module/index.js +4 -1
  88. package/lib/module/index.js.map +1 -1
  89. package/lib/module/utils/AssetUtil.js +12 -8
  90. package/lib/module/utils/AssetUtil.js.map +1 -1
  91. package/lib/module/utils/ConnectionUtil.js +27 -0
  92. package/lib/module/utils/ConnectionUtil.js.map +1 -0
  93. package/lib/module/utils/ConstantsUtil.js +8 -537
  94. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  95. package/lib/module/utils/CoreHelperUtil.js +4 -4
  96. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  97. package/lib/module/utils/FetchUtil.js +28 -9
  98. package/lib/module/utils/FetchUtil.js.map +1 -1
  99. package/lib/module/utils/NetworkUtil.js +40 -0
  100. package/lib/module/utils/NetworkUtil.js.map +1 -0
  101. package/lib/module/utils/StorageUtil.js +42 -51
  102. package/lib/module/utils/StorageUtil.js.map +1 -1
  103. package/lib/module/utils/SwapApiUtil.js +21 -15
  104. package/lib/module/utils/SwapApiUtil.js.map +1 -1
  105. package/lib/typescript/controllers/AccountController.d.ts +4 -4
  106. package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
  107. package/lib/typescript/controllers/ApiController.d.ts +1 -1
  108. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  109. package/lib/typescript/controllers/BlockchainApiController.d.ts +4 -16
  110. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  111. package/lib/typescript/controllers/ConnectionController.d.ts +11 -3
  112. package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
  113. package/lib/typescript/controllers/ConnectorController.d.ts +18 -0
  114. package/lib/typescript/controllers/ConnectorController.d.ts.map +1 -0
  115. package/lib/typescript/controllers/ModalController.d.ts +1 -1
  116. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  117. package/lib/typescript/controllers/NetworkController.d.ts +1 -1
  118. package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
  119. package/lib/typescript/controllers/OnRampController.d.ts +3 -1
  120. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  121. package/lib/typescript/controllers/OptionsController.d.ts +2 -5
  122. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  123. package/lib/typescript/controllers/PublicStateController.d.ts +1 -1
  124. package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -1
  125. package/lib/typescript/controllers/RouterController.d.ts +16 -4
  126. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  127. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  128. package/lib/typescript/controllers/SnackController.d.ts +3 -3
  129. package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
  130. package/lib/typescript/controllers/SwapController.d.ts +9 -9
  131. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  132. package/lib/typescript/controllers/ThemeController.d.ts +1 -1
  133. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
  134. package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
  135. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  136. package/lib/typescript/controllers/WebviewController.d.ts +21 -0
  137. package/lib/typescript/controllers/WebviewController.d.ts.map +1 -0
  138. package/lib/typescript/index.d.ts +4 -1
  139. package/lib/typescript/index.d.ts.map +1 -1
  140. package/lib/typescript/utils/AssetUtil.d.ts +3 -3
  141. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  142. package/lib/typescript/utils/ConnectionUtil.d.ts +4 -0
  143. package/lib/typescript/utils/ConnectionUtil.d.ts.map +1 -0
  144. package/lib/typescript/utils/ConstantsUtil.d.ts +1 -421
  145. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  146. package/lib/typescript/utils/CoreHelperUtil.d.ts +3 -3
  147. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  148. package/lib/typescript/utils/FetchUtil.d.ts +1 -1
  149. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  150. package/lib/typescript/utils/NetworkUtil.d.ts +8 -0
  151. package/lib/typescript/utils/NetworkUtil.d.ts.map +1 -0
  152. package/lib/typescript/utils/StorageUtil.d.ts +7 -14
  153. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  154. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -3
  155. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  156. package/lib/typescript/utils/TypeUtil.d.ts +173 -24
  157. package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
  158. package/package.json +4 -4
  159. package/src/controllers/AccountController.ts +27 -23
  160. package/src/controllers/ApiController.ts +9 -15
  161. package/src/controllers/BlockchainApiController.ts +31 -145
  162. package/src/controllers/ConnectionController.ts +24 -12
  163. package/src/controllers/ConnectorController.ts +63 -0
  164. package/src/controllers/EnsController.ts +2 -2
  165. package/src/controllers/EventsController.ts +1 -1
  166. package/src/controllers/ModalController.ts +3 -4
  167. package/src/controllers/NetworkController.ts +1 -1
  168. package/src/controllers/OnRampController.ts +93 -33
  169. package/src/controllers/OptionsController.ts +13 -14
  170. package/src/controllers/PublicStateController.ts +1 -1
  171. package/src/controllers/RouterController.ts +54 -5
  172. package/src/controllers/SendController.ts +30 -39
  173. package/src/controllers/SnackController.ts +5 -31
  174. package/src/controllers/SwapController.ts +178 -155
  175. package/src/controllers/ThemeController.ts +2 -11
  176. package/src/controllers/TransactionsController.ts +20 -26
  177. package/src/controllers/WebviewController.ts +63 -0
  178. package/src/index.ts +6 -3
  179. package/src/utils/AssetUtil.ts +14 -8
  180. package/src/utils/ConnectionUtil.ts +27 -0
  181. package/src/utils/ConstantsUtil.ts +8 -542
  182. package/src/utils/CoreHelperUtil.ts +7 -15
  183. package/src/utils/FetchUtil.ts +31 -10
  184. package/src/utils/NetworkUtil.ts +33 -0
  185. package/src/utils/StorageUtil.ts +48 -60
  186. package/src/utils/SwapApiUtil.ts +38 -27
  187. package/src/utils/TypeUtil.ts +173 -26
  188. package/lib/commonjs/controllers/ConnectionsController.js +0 -383
  189. package/lib/commonjs/controllers/ConnectionsController.js.map +0 -1
  190. package/lib/module/controllers/ConnectionsController.js +0 -378
  191. package/lib/module/controllers/ConnectionsController.js.map +0 -1
  192. package/lib/typescript/controllers/ConnectionsController.d.ts +0 -52
  193. package/lib/typescript/controllers/ConnectionsController.d.ts.map +0 -1
  194. package/src/controllers/ConnectionsController.ts +0 -503
@@ -8,7 +8,7 @@ interface Options {
8
8
 
9
9
  interface RequestArguments {
10
10
  path: string;
11
- headers?: HeadersInit;
11
+ headers?: HeadersInit_;
12
12
  params?: Record<string, string | undefined>;
13
13
  cache?: RequestCache;
14
14
  signal?: AbortSignal;
@@ -88,20 +88,41 @@ 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) {
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) {
@@ -0,0 +1,33 @@
1
+ import { RouterUtil } from './RouterUtil';
2
+ import { RouterController } from '../controllers/RouterController';
3
+ import { NetworkController } from '../controllers/NetworkController';
4
+ import { AccountController } from '../controllers/AccountController';
5
+ import { ConnectorController } from '../controllers/ConnectorController';
6
+ import { SwapController } from '../controllers/SwapController';
7
+ import type { CaipNetwork } from '../utils/TypeUtil';
8
+
9
+ export const NetworkUtil = {
10
+ async handleNetworkSwitch(network: CaipNetwork) {
11
+ const { isConnected } = AccountController.state;
12
+ const { caipNetwork, approvedCaipNetworkIds, supportsAllNetworks } = NetworkController.state;
13
+ const isAuthConnected = ConnectorController.state.connectedConnector === 'AUTH';
14
+ let eventData = null;
15
+
16
+ if (isConnected && caipNetwork?.id !== network.id) {
17
+ if (approvedCaipNetworkIds?.includes(network.id) && !isAuthConnected) {
18
+ await NetworkController.switchActiveNetwork(network);
19
+ RouterUtil.navigateAfterNetworkSwitch(['ConnectingSiwe']);
20
+ eventData = { type: 'SWITCH_NETWORK', networkId: network.id };
21
+ } else if (supportsAllNetworks || isAuthConnected) {
22
+ RouterController.push('SwitchNetwork', { network });
23
+ }
24
+ } else if (!isConnected) {
25
+ NetworkController.setCaipNetwork(network);
26
+ RouterController.push('Connect');
27
+ }
28
+
29
+ SwapController.resetState();
30
+
31
+ return eventData;
32
+ }
33
+ };
@@ -2,6 +2,7 @@
2
2
  import AsyncStorage from '@react-native-async-storage/async-storage';
3
3
  import type {
4
4
  OnRampCountry,
5
+ OnRampCountryDefaults,
5
6
  OnRampFiatCurrency,
6
7
  OnRampFiatLimit,
7
8
  OnRampServiceProvider,
@@ -10,24 +11,22 @@ import type {
10
11
  import {
11
12
  DateUtil,
12
13
  type SocialProvider,
13
- type ConnectorType,
14
- type ChainNamespace
14
+ type ConnectorType
15
15
  } from '@reown/appkit-common-react-native';
16
16
 
17
17
  // -- Helpers -----------------------------------------------------------------
18
18
  const WC_DEEPLINK = 'WALLETCONNECT_DEEPLINK_CHOICE';
19
19
  const RECENT_WALLET = '@w3m/recent';
20
20
  const CONNECTED_WALLET_IMAGE_URL = '@w3m/connected_wallet_image_url';
21
- const CONNECTED_CONNECTORS = '@appkit/connected_connectors';
21
+ const CONNECTED_CONNECTOR = '@w3m/connected_connector';
22
22
  const CONNECTED_SOCIAL = '@appkit/connected_social';
23
23
  const ONRAMP_PREFERRED_COUNTRY = '@appkit/onramp_preferred_country';
24
24
  const ONRAMP_COUNTRIES = '@appkit/onramp_countries';
25
+ const ONRAMP_COUNTRIES_DEFAULTS = '@appkit/onramp_countries_defaults';
25
26
  const ONRAMP_SERVICE_PROVIDERS = '@appkit/onramp_service_providers';
26
27
  const ONRAMP_FIAT_LIMITS = '@appkit/onramp_fiat_limits';
27
28
  const ONRAMP_FIAT_CURRENCIES = '@appkit/onramp_fiat_currencies';
28
29
  const ONRAMP_PREFERRED_FIAT_CURRENCY = '@appkit/onramp_preferred_fiat_currency';
29
- const ACTIVE_NAMESPACE = '@appkit/active_namespace';
30
-
31
30
  // -- Utility -----------------------------------------------------------------
32
31
  export const StorageUtil = {
33
32
  setWalletConnectDeepLink({ href, name }: { href: string; name: string }) {
@@ -102,42 +101,29 @@ export const StorageUtil = {
102
101
  return [];
103
102
  },
104
103
 
105
- async setConnectedConnectors({
106
- type,
107
- namespaces
108
- }: {
109
- type: ConnectorType;
110
- namespaces: string[];
111
- }) {
104
+ async setConnectedConnector(connectorType: ConnectorType) {
112
105
  try {
113
- const currentConnectors = (await StorageUtil.getConnectedConnectors()) || [];
114
- // Only add if it doesn't exist already
115
- if (!currentConnectors.some(c => c.type === type)) {
116
- const updatedConnectors = [...currentConnectors, { type, namespaces }];
117
- await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
118
- }
106
+ await AsyncStorage.setItem(CONNECTED_CONNECTOR, JSON.stringify(connectorType));
119
107
  } catch {
120
108
  console.info('Unable to set Connected Connector');
121
109
  }
122
110
  },
123
111
 
124
- async getConnectedConnectors(): Promise<{ type: ConnectorType; namespaces: string[] }[]> {
112
+ async getConnectedConnector(): Promise<ConnectorType | undefined> {
125
113
  try {
126
- const connectors = await AsyncStorage.getItem(CONNECTED_CONNECTORS);
114
+ const connector = (await AsyncStorage.getItem(CONNECTED_CONNECTOR)) as ConnectorType;
127
115
 
128
- return connectors ? JSON.parse(connectors) : [];
116
+ return connector ? JSON.parse(connector) : undefined;
129
117
  } catch {
130
118
  console.info('Unable to get Connected Connector');
131
119
  }
132
120
 
133
- return [];
121
+ return undefined;
134
122
  },
135
123
 
136
- async removeConnectedConnectors(type: ConnectorType) {
124
+ async removeConnectedConnector() {
137
125
  try {
138
- const currentConnectors = await StorageUtil.getConnectedConnectors();
139
- const updatedConnectors = currentConnectors.filter(c => c.type !== type);
140
- await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
126
+ await AsyncStorage.removeItem(CONNECTED_CONNECTOR);
141
127
  } catch {
142
128
  console.info('Unable to remove Connected Connector');
143
129
  }
@@ -257,6 +243,42 @@ export const StorageUtil = {
257
243
  return [];
258
244
  },
259
245
 
246
+ async setOnRampCountriesDefaults(countriesDefaults: OnRampCountryDefaults[]) {
247
+ try {
248
+ const timestamp = Date.now();
249
+
250
+ await AsyncStorage.setItem(
251
+ ONRAMP_COUNTRIES_DEFAULTS,
252
+ JSON.stringify({ data: countriesDefaults, timestamp })
253
+ );
254
+ } catch {
255
+ console.info('Unable to set OnRamp Countries Defaults');
256
+ }
257
+ },
258
+
259
+ async getOnRampCountriesDefaults() {
260
+ try {
261
+ const result = await AsyncStorage.getItem(ONRAMP_COUNTRIES_DEFAULTS);
262
+
263
+ if (!result) {
264
+ return [];
265
+ }
266
+
267
+ const { data, timestamp } = JSON.parse(result);
268
+
269
+ // Cache for 1 week
270
+ if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
271
+ return [];
272
+ }
273
+
274
+ return data ? (data as OnRampCountryDefaults[]) : [];
275
+ } catch {
276
+ console.info('Unable to get OnRamp Countries Defaults');
277
+ }
278
+
279
+ return [];
280
+ },
281
+
260
282
  async setOnRampServiceProviders(serviceProviders: OnRampServiceProvider[]) {
261
283
  try {
262
284
  const timestamp = Date.now();
@@ -364,39 +386,5 @@ export const StorageUtil = {
364
386
  }
365
387
 
366
388
  return [];
367
- },
368
-
369
- async setActiveNamespace(namespace?: ChainNamespace) {
370
- try {
371
- if (!namespace) {
372
- await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
373
-
374
- return;
375
- }
376
-
377
- await AsyncStorage.setItem(ACTIVE_NAMESPACE, namespace);
378
- } catch {
379
- console.info('Unable to set Active Namespace');
380
- }
381
- },
382
-
383
- async getActiveNamespace() {
384
- try {
385
- const namespace = (await AsyncStorage.getItem(ACTIVE_NAMESPACE)) as ChainNamespace;
386
-
387
- return namespace ?? undefined;
388
- } catch (err) {
389
- console.info('Unable to get Active Namespace');
390
- }
391
-
392
- return undefined;
393
- },
394
-
395
- async removeActiveNamespace() {
396
- try {
397
- await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
398
- } catch {
399
- console.info('Unable to remove Active Namespace');
400
- }
401
389
  }
402
390
  };
@@ -1,17 +1,19 @@
1
- import type { Balance, CaipNetworkId } from '@reown/appkit-common-react-native';
2
1
  import { BlockchainApiController } from '../controllers/BlockchainApiController';
3
2
  import { OptionsController } from '../controllers/OptionsController';
4
- import type { BlockchainApiSwapAllowanceRequest, SwapTokenWithBalance } from './TypeUtil';
5
- import { ConnectionsController } from '../controllers/ConnectionsController';
6
- import { ConstantsUtil } from './ConstantsUtil';
3
+ import { NetworkController } from '../controllers/NetworkController';
4
+ import type {
5
+ BlockchainApiBalanceResponse,
6
+ BlockchainApiSwapAllowanceRequest,
7
+ SwapTokenWithBalance
8
+ } from './TypeUtil';
9
+ import { AccountController } from '../controllers/AccountController';
10
+ import { ConnectionController } from '../controllers/ConnectionController';
7
11
 
8
12
  export const SwapApiUtil = {
9
13
  async getTokenList() {
10
- const chainId: CaipNetworkId =
11
- ConnectionsController.state.activeNetwork?.caipNetworkId ?? 'eip155:1';
12
14
  const response = await BlockchainApiController.fetchSwapTokens({
13
15
  projectId: OptionsController.state.projectId,
14
- chainId
16
+ chainId: NetworkController.state.caipNetwork?.id
15
17
  });
16
18
  const tokens =
17
19
  response?.tokens?.map(
@@ -50,7 +52,7 @@ export const SwapApiUtil = {
50
52
 
51
53
  if (response?.allowance && sourceTokenAmount && sourceTokenDecimals) {
52
54
  const parsedValue =
53
- ConnectionsController.parseUnits(sourceTokenAmount, sourceTokenDecimals) || 0;
55
+ ConnectionController.parseUnits(sourceTokenAmount, sourceTokenDecimals) || 0;
54
56
  const hasAllowance = BigInt(response.allowance) >= parsedValue;
55
57
 
56
58
  return hasAllowance;
@@ -59,31 +61,40 @@ export const SwapApiUtil = {
59
61
  return false;
60
62
  },
61
63
 
62
- mapBalancesToSwapTokens(balances?: Balance[]) {
63
- const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
64
- const address = activeNamespace
65
- ? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
66
- : undefined;
64
+ async getMyTokensWithBalance(forceUpdate?: string) {
65
+ const address = AccountController.state.address;
66
+ const chainId = NetworkController.state.caipNetwork?.id;
67
67
 
68
+ if (!address) {
69
+ return [];
70
+ }
71
+
72
+ const response = await BlockchainApiController.getBalance(address, chainId, forceUpdate);
73
+ const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
74
+
75
+ AccountController.setTokenBalance(balances);
76
+
77
+ return this.mapBalancesToSwapTokens(balances);
78
+ },
79
+
80
+ mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
68
81
  return (
69
- balances
70
- ?.filter(balance => balance?.quantity?.numeric)
71
- .map(
72
- token =>
73
- ({
74
- ...token,
75
- address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
76
- decimals: parseInt(token.quantity?.decimals ?? '0', 10),
77
- logoUri: token.iconUrl,
78
- eip2612: false
79
- }) as SwapTokenWithBalance
80
- ) || []
82
+ balances?.map(
83
+ token =>
84
+ ({
85
+ ...token,
86
+ address: token?.address || NetworkController.getActiveNetworkTokenAddress(),
87
+ decimals: parseInt(token.quantity.decimals, 10),
88
+ logoUri: token.iconUrl,
89
+ eip2612: false
90
+ }) as SwapTokenWithBalance
91
+ ) || []
81
92
  );
82
93
  },
83
94
 
84
95
  async fetchGasPrice() {
85
96
  const projectId = OptionsController.state.projectId;
86
- const caipNetwork = ConnectionsController.state.activeNetwork;
97
+ const caipNetwork = NetworkController.state.caipNetwork;
87
98
 
88
99
  if (!caipNetwork) {
89
100
  return null;
@@ -91,7 +102,7 @@ export const SwapApiUtil = {
91
102
 
92
103
  return await BlockchainApiController.fetchGasPrice({
93
104
  projectId,
94
- chainId: caipNetwork.caipNetworkId
105
+ chainId: caipNetwork.id
95
106
  });
96
107
  }
97
108
  };
@@ -1,12 +1,28 @@
1
- import type { AccountType, CaipAddress, CaipNetworkId } from '@reown/appkit-common-react-native';
2
- import type { SocialProvider, Transaction } from '@reown/appkit-common-react-native';
3
-
1
+ import { type EventEmitter } from 'events';
2
+ import type {
3
+ Balance,
4
+ SocialProvider,
5
+ ThemeMode,
6
+ Transaction,
7
+ ConnectorType
8
+ } from '@reown/appkit-common-react-native';
4
9
  import { OnRampErrorType } from './ConstantsUtil';
5
10
 
6
11
  export interface BaseError {
7
12
  message?: string;
8
13
  }
9
14
 
15
+ export type CaipAddress = `${string}:${string}:${string}`;
16
+
17
+ export type CaipNetworkId = `${string}:${string}`;
18
+
19
+ export interface CaipNetwork {
20
+ id: CaipNetworkId;
21
+ name?: string;
22
+ imageId?: string;
23
+ imageUrl?: string;
24
+ }
25
+
10
26
  export type ConnectedWalletInfo =
11
27
  | {
12
28
  name?: string;
@@ -32,6 +48,18 @@ export type ProjectId = string;
32
48
 
33
49
  export type Platform = 'mobile' | 'web' | 'qrcode' | 'email' | 'unsupported';
34
50
 
51
+ export type Connector = {
52
+ id: string;
53
+ type: ConnectorType;
54
+ name?: string;
55
+ imageId?: string;
56
+ explorerId?: string;
57
+ imageUrl?: string;
58
+ info?: { rdns?: string };
59
+ provider?: unknown;
60
+ installed?: boolean;
61
+ };
62
+
35
63
  export type CaipNamespaces = Record<
36
64
  string,
37
65
  {
@@ -43,13 +71,12 @@ export type CaipNamespaces = Record<
43
71
 
44
72
  export type SdkType = 'appkit';
45
73
 
46
- //TODO: check this
47
74
  export type SdkVersion =
48
75
  | `react-native-wagmi-${string}`
49
76
  | `react-native-ethers5-${string}`
50
77
  | `react-native-ethers-${string}`;
51
78
 
52
- type EnabledSocials = SocialProvider;
79
+ type EnabledSocials = Exclude<SocialProvider, 'farcaster'>;
53
80
 
54
81
  export type Features = {
55
82
  /**
@@ -63,10 +90,15 @@ export type Features = {
63
90
  */
64
91
  onramp?: boolean;
65
92
  /**
66
- * @description Show or hide the regular wallet options when socials are enabled. Enabled by default.
93
+ * @description Enable or disable the email feature. Enabled by default.
94
+ * @type {boolean}
95
+ */
96
+ email?: boolean;
97
+ /**
98
+ * @description Show or hide the regular wallet options when email is enabled. Enabled by default.
67
99
  * @type {boolean}
68
100
  */
69
- showWallets?: boolean;
101
+ emailShowWallets?: boolean;
70
102
  /**
71
103
  * @description Enable or disable the socials feature. Enabled by default.
72
104
  * @type {EnabledSocials[]}
@@ -136,22 +168,8 @@ export interface BlockchainApiIdentityResponse {
136
168
  name: string;
137
169
  }
138
170
 
139
- export interface BlockchainApiBalance {
140
- name: string;
141
- symbol: string;
142
- chainId: string;
143
- address?: CaipAddress;
144
- value?: number;
145
- price: number;
146
- quantity: {
147
- decimals: string;
148
- numeric: string;
149
- };
150
- iconUrl: string;
151
- }
152
-
153
171
  export interface BlockchainApiBalanceResponse {
154
- balances: BlockchainApiBalance[];
172
+ balances: Balance[];
155
173
  }
156
174
 
157
175
  export interface BlockchainApiTransactionsRequest {
@@ -161,7 +179,6 @@ export interface BlockchainApiTransactionsRequest {
161
179
  onramp?: 'coinbase';
162
180
  signal?: AbortSignal;
163
181
  cache?: RequestCache;
164
- chainId?: CaipNetworkId;
165
182
  }
166
183
 
167
184
  export interface BlockchainApiTransactionsResponse {
@@ -302,11 +319,12 @@ export interface BlockchainApiSwapTokensRequest {
302
319
 
303
320
  export interface BlockchainApiOnRampQuotesRequest {
304
321
  countryCode: string;
305
- paymentMethodType: string;
322
+ paymentMethodType?: string;
306
323
  destinationCurrencyCode: string;
307
324
  sourceAmount: number;
308
325
  sourceCurrencyCode: string;
309
326
  walletAddress: string;
327
+ excludeProviders?: string[];
310
328
  }
311
329
 
312
330
  export interface BlockchainApiSwapTokensResponse {
@@ -329,6 +347,25 @@ export type BlockchainApiOnRampWidgetResponse = {
329
347
  };
330
348
 
331
349
  // -- OptionsController Types ---------------------------------------------------
350
+ export interface Token {
351
+ address: string;
352
+ image?: string;
353
+ }
354
+
355
+ export type Tokens = Record<CaipNetworkId, Token>;
356
+
357
+ export type Metadata = {
358
+ name: string;
359
+ description: string;
360
+ url: string;
361
+ icons: string[];
362
+ redirect?: {
363
+ native?: string;
364
+ universal?: string;
365
+ linkMode?: boolean;
366
+ };
367
+ };
368
+
332
369
  export type CustomWallet = Pick<
333
370
  WcWallet,
334
371
  | 'id'
@@ -360,6 +397,9 @@ export type EventName =
360
397
  | 'CLICK_NETWORK_HELP'
361
398
  | 'CLICK_GET_WALLET'
362
399
  | 'EMAIL_LOGIN_SELECTED'
400
+ | 'EMAIL_SUBMITTED'
401
+ | 'DEVICE_REGISTERED_FOR_EMAIL'
402
+ | 'EMAIL_VERIFICATION_CODE_SENT'
363
403
  | 'EMAIL_VERIFICATION_CODE_PASS'
364
404
  | 'EMAIL_VERIFICATION_CODE_FAIL'
365
405
  | 'EMAIL_EDIT'
@@ -422,7 +462,7 @@ export type Event =
422
462
  type: 'track';
423
463
  event: 'SWITCH_NETWORK';
424
464
  properties: {
425
- network: number | string;
465
+ network: string;
426
466
  };
427
467
  }
428
468
  | {
@@ -474,6 +514,18 @@ export type Event =
474
514
  type: 'track';
475
515
  event: 'EMAIL_LOGIN_SELECTED';
476
516
  }
517
+ | {
518
+ type: 'track';
519
+ event: 'EMAIL_SUBMITTED';
520
+ }
521
+ | {
522
+ type: 'track';
523
+ event: 'DEVICE_REGISTERED_FOR_EMAIL';
524
+ }
525
+ | {
526
+ type: 'track';
527
+ event: 'EMAIL_VERIFICATION_CODE_SENT';
528
+ }
477
529
  | {
478
530
  type: 'track';
479
531
  event: 'EMAIL_VERIFICATION_CODE_PASS';
@@ -675,7 +727,7 @@ export type Event =
675
727
  type: 'track';
676
728
  event: 'SET_PREFERRED_ACCOUNT_TYPE';
677
729
  properties: {
678
- accountType: AccountType;
730
+ accountType: AppKitFrameAccountType;
679
731
  network: string;
680
732
  };
681
733
  }
@@ -809,6 +861,12 @@ export type OnRampCountry = {
809
861
  name: string;
810
862
  };
811
863
 
864
+ export type OnRampCountryDefaults = {
865
+ countryCode: string;
866
+ defaultCurrencyCode: string;
867
+ defaultPaymentMethods: string[];
868
+ };
869
+
812
870
  export type OnRampFiatCurrency = {
813
871
  currencyCode: string;
814
872
  name: string;
@@ -878,3 +936,92 @@ export type OnRampTransactionResult = {
878
936
  status: string | null;
879
937
  network: string | null;
880
938
  };
939
+
940
+ // -- Email Types ------------------------------------------------
941
+ /**
942
+ * Matches type defined for packages/wallet/src/AppKitFrameProvider.ts
943
+ * It's duplicated in order to decouple scaffold from email package
944
+ */
945
+
946
+ export type AppKitFrameAccountType = 'eoa' | 'smartAccount';
947
+
948
+ export interface AppKitFrameProvider {
949
+ readonly id: string;
950
+ readonly name: string;
951
+ getEventEmitter(): EventEmitter;
952
+ getSecureSiteURL(): string;
953
+ getSecureSiteDashboardURL(): string;
954
+ getSecureSiteIconURL(): string;
955
+ getEmail(): string | undefined;
956
+ getUsername(): string | undefined;
957
+ getLastUsedChainId(): Promise<number | undefined>;
958
+ rejectRpcRequest(): void;
959
+ connectEmail(payload: { email: string }): Promise<{
960
+ action: 'VERIFY_DEVICE' | 'VERIFY_OTP';
961
+ }>;
962
+ connectDevice(): Promise<unknown>;
963
+ connectSocial(uri: string): Promise<{
964
+ chainId: string | number;
965
+ email: string;
966
+ address: string;
967
+ accounts?: {
968
+ type: AppKitFrameAccountType;
969
+ address: string;
970
+ }[];
971
+ userName?: string;
972
+ }>;
973
+ getSocialRedirectUri(payload: { provider: SocialProvider }): Promise<{
974
+ uri: string;
975
+ }>;
976
+ connectOtp(payload: { otp: string }): Promise<unknown>;
977
+ connectFarcaster: () => Promise<{ userName: string }>;
978
+ getFarcasterUri(): Promise<{ url: string }>;
979
+ isConnected(): Promise<{
980
+ isConnected: boolean;
981
+ }>;
982
+ getChainId(): Promise<{
983
+ chainId: number;
984
+ }>;
985
+ updateEmail(payload: { email: string }): Promise<{
986
+ action: 'VERIFY_PRIMARY_OTP' | 'VERIFY_SECONDARY_OTP';
987
+ }>;
988
+ updateEmailPrimaryOtp(payload: { otp: string }): Promise<unknown>;
989
+ updateEmailSecondaryOtp(payload: { otp: string }): Promise<{
990
+ newEmail: string;
991
+ }>;
992
+ syncTheme(payload: {
993
+ themeMode: ThemeMode | undefined;
994
+ themeVariables: Record<string, string | number> | undefined;
995
+ }): Promise<unknown>;
996
+ syncDappData(payload: {
997
+ projectId: string;
998
+ sdkVersion: SdkVersion;
999
+ sdkType: SdkType;
1000
+ metadata?: Metadata;
1001
+ }): Promise<unknown>;
1002
+ connect(payload?: { chainId: number | undefined }): Promise<{
1003
+ chainId: number;
1004
+ email?: string | null;
1005
+ address: string;
1006
+ smartAccountDeployed: boolean;
1007
+ preferredAccountType: AppKitFrameAccountType;
1008
+ }>;
1009
+ switchNetwork(chainId: number): Promise<{
1010
+ chainId: number;
1011
+ }>;
1012
+ setPreferredAccount(type: AppKitFrameAccountType): Promise<{
1013
+ type: AppKitFrameAccountType;
1014
+ address: string;
1015
+ }>;
1016
+ setOnTimeout(callback: () => void): void;
1017
+ getSmartAccountEnabledNetworks(): Promise<{
1018
+ smartAccountEnabledNetworks: number[];
1019
+ }>;
1020
+ disconnect(): Promise<unknown>;
1021
+ request(req: any): Promise<any>;
1022
+ AuthView: () => React.JSX.Element | null;
1023
+ Webview: () => React.JSX.Element | null;
1024
+ onSetPreferredAccount: (
1025
+ callback: (values: { type: AppKitFrameAccountType; address: string }) => void
1026
+ ) => void;
1027
+ }