@reown/appkit-core-react-native 0.0.0-feat-onramp-20250626173252 → 0.0.0-feat-multi-social-20250630195637

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 (166) hide show
  1. package/lib/commonjs/controllers/ApiController.js +11 -11
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  3. package/lib/commonjs/controllers/BlockchainApiController.js +102 -24
  4. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  5. package/lib/commonjs/controllers/ConnectionController.js +7 -5
  6. package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionsController.js +217 -0
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
  9. package/lib/commonjs/controllers/ConnectorController.js +1 -0
  10. package/lib/commonjs/controllers/ConnectorController.js.map +1 -1
  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.map +1 -1
  16. package/lib/commonjs/controllers/OnRampController.js +20 -60
  17. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  18. package/lib/commonjs/controllers/OptionsController.js +8 -3
  19. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  20. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  21. package/lib/commonjs/controllers/SendController.js +10 -10
  22. package/lib/commonjs/controllers/SendController.js.map +1 -1
  23. package/lib/commonjs/controllers/SwapController.js +51 -40
  24. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  25. package/lib/commonjs/controllers/ThemeController.js +9 -1
  26. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  27. package/lib/commonjs/controllers/TransactionsController.js +5 -5
  28. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  29. package/lib/commonjs/index.js +3 -10
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/utils/AssetUtil.js +5 -6
  32. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  33. package/lib/commonjs/utils/ConstantsUtil.js +537 -8
  34. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  35. package/lib/commonjs/utils/CoreHelperUtil.js +3 -3
  36. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  37. package/lib/commonjs/utils/StorageUtil.js +67 -33
  38. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  39. package/lib/commonjs/utils/SwapApiUtil.js +19 -10
  40. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  41. package/lib/module/controllers/ApiController.js +11 -11
  42. package/lib/module/controllers/ApiController.js.map +1 -1
  43. package/lib/module/controllers/BlockchainApiController.js +102 -24
  44. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  45. package/lib/module/controllers/ConnectionController.js +7 -5
  46. package/lib/module/controllers/ConnectionController.js.map +1 -1
  47. package/lib/module/controllers/ConnectionsController.js +212 -0
  48. package/lib/module/controllers/ConnectionsController.js.map +1 -0
  49. package/lib/module/controllers/ConnectorController.js +1 -0
  50. package/lib/module/controllers/ConnectorController.js.map +1 -1
  51. package/lib/module/controllers/EnsController.js +2 -2
  52. package/lib/module/controllers/EnsController.js.map +1 -1
  53. package/lib/module/controllers/EventsController.js +1 -1
  54. package/lib/module/controllers/EventsController.js.map +1 -1
  55. package/lib/module/controllers/ModalController.js.map +1 -1
  56. package/lib/module/controllers/OnRampController.js +20 -60
  57. package/lib/module/controllers/OnRampController.js.map +1 -1
  58. package/lib/module/controllers/OptionsController.js +8 -3
  59. package/lib/module/controllers/OptionsController.js.map +1 -1
  60. package/lib/module/controllers/RouterController.js.map +1 -1
  61. package/lib/module/controllers/SendController.js +7 -7
  62. package/lib/module/controllers/SendController.js.map +1 -1
  63. package/lib/module/controllers/SwapController.js +51 -40
  64. package/lib/module/controllers/SwapController.js.map +1 -1
  65. package/lib/module/controllers/ThemeController.js +9 -1
  66. package/lib/module/controllers/ThemeController.js.map +1 -1
  67. package/lib/module/controllers/TransactionsController.js +3 -3
  68. package/lib/module/controllers/TransactionsController.js.map +1 -1
  69. package/lib/module/index.js +1 -2
  70. package/lib/module/index.js.map +1 -1
  71. package/lib/module/utils/AssetUtil.js +5 -6
  72. package/lib/module/utils/AssetUtil.js.map +1 -1
  73. package/lib/module/utils/ConstantsUtil.js +537 -8
  74. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  75. package/lib/module/utils/CoreHelperUtil.js +3 -3
  76. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  77. package/lib/module/utils/StorageUtil.js +67 -33
  78. package/lib/module/utils/StorageUtil.js.map +1 -1
  79. package/lib/module/utils/SwapApiUtil.js +19 -10
  80. package/lib/module/utils/SwapApiUtil.js.map +1 -1
  81. package/lib/typescript/controllers/AccountController.d.ts +2 -2
  82. package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
  83. package/lib/typescript/controllers/ApiController.d.ts +1 -1
  84. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  85. package/lib/typescript/controllers/BlockchainApiController.d.ts +15 -3
  86. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  87. package/lib/typescript/controllers/ConnectionController.d.ts +2 -2
  88. package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
  89. package/lib/typescript/controllers/ConnectionsController.d.ts +44 -0
  90. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
  91. package/lib/typescript/controllers/ConnectorController.d.ts.map +1 -1
  92. package/lib/typescript/controllers/ModalController.d.ts +1 -1
  93. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  94. package/lib/typescript/controllers/NetworkController.d.ts +1 -1
  95. package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
  96. package/lib/typescript/controllers/OnRampController.d.ts +1 -3
  97. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  98. package/lib/typescript/controllers/OptionsController.d.ts +5 -2
  99. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  100. package/lib/typescript/controllers/PublicStateController.d.ts +1 -1
  101. package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -1
  102. package/lib/typescript/controllers/RouterController.d.ts +4 -2
  103. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  104. package/lib/typescript/controllers/SwapController.d.ts +1 -1
  105. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  106. package/lib/typescript/controllers/ThemeController.d.ts +1 -1
  107. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
  108. package/lib/typescript/index.d.ts +1 -2
  109. package/lib/typescript/index.d.ts.map +1 -1
  110. package/lib/typescript/utils/AssetUtil.d.ts +2 -2
  111. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  112. package/lib/typescript/utils/ConstantsUtil.d.ts +421 -1
  113. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  114. package/lib/typescript/utils/CoreHelperUtil.d.ts +3 -3
  115. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  116. package/lib/typescript/utils/FetchUtil.d.ts +1 -1
  117. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  118. package/lib/typescript/utils/NetworkUtil.d.ts +1 -1
  119. package/lib/typescript/utils/NetworkUtil.d.ts.map +1 -1
  120. package/lib/typescript/utils/StorageUtil.d.ts +14 -4
  121. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  122. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  123. package/lib/typescript/utils/TypeUtil.d.ts +8 -40
  124. package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
  125. package/package.json +4 -4
  126. package/src/controllers/AccountController.ts +2 -2
  127. package/src/controllers/ApiController.ts +12 -7
  128. package/src/controllers/BlockchainApiController.ts +135 -27
  129. package/src/controllers/ConnectionController.ts +10 -8
  130. package/src/controllers/ConnectionsController.ts +309 -0
  131. package/src/controllers/ConnectorController.ts +1 -0
  132. package/src/controllers/EnsController.ts +2 -2
  133. package/src/controllers/EventsController.ts +1 -1
  134. package/src/controllers/ModalController.ts +2 -1
  135. package/src/controllers/NetworkController.ts +1 -1
  136. package/src/controllers/OnRampController.ts +32 -91
  137. package/src/controllers/OptionsController.ts +14 -13
  138. package/src/controllers/PublicStateController.ts +1 -1
  139. package/src/controllers/RouterController.ts +3 -3
  140. package/src/controllers/SendController.ts +7 -7
  141. package/src/controllers/SwapController.ts +58 -48
  142. package/src/controllers/ThemeController.ts +11 -2
  143. package/src/controllers/TransactionsController.ts +3 -3
  144. package/src/index.ts +5 -2
  145. package/src/utils/AssetUtil.ts +5 -7
  146. package/src/utils/ConstantsUtil.ts +542 -8
  147. package/src/utils/CoreHelperUtil.ts +14 -6
  148. package/src/utils/FetchUtil.ts +1 -1
  149. package/src/utils/NetworkUtil.ts +1 -1
  150. package/src/utils/StorageUtil.ts +82 -39
  151. package/src/utils/SwapApiUtil.ts +22 -10
  152. package/src/utils/TypeUtil.ts +13 -48
  153. package/lib/commonjs/controllers/WebviewController.js +0 -52
  154. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  155. package/lib/commonjs/utils/ConnectionUtil.js +0 -33
  156. package/lib/commonjs/utils/ConnectionUtil.js.map +0 -1
  157. package/lib/module/controllers/WebviewController.js +0 -47
  158. package/lib/module/controllers/WebviewController.js.map +0 -1
  159. package/lib/module/utils/ConnectionUtil.js +0 -27
  160. package/lib/module/utils/ConnectionUtil.js.map +0 -1
  161. package/lib/typescript/controllers/WebviewController.d.ts +0 -21
  162. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  163. package/lib/typescript/utils/ConnectionUtil.d.ts +0 -4
  164. package/lib/typescript/utils/ConnectionUtil.d.ts.map +0 -1
  165. package/src/controllers/WebviewController.ts +0 -63
  166. package/src/utils/ConnectionUtil.ts +0 -27
@@ -49,8 +49,7 @@ export interface ConnectionControllerState {
49
49
  wcError?: boolean;
50
50
  pressedWallet?: WcWallet;
51
51
  recentWallets?: WcWallet[];
52
- selectedSocialProvider?: SocialProvider;
53
- connectedWalletImageUrl?: string;
52
+ connectedWalletImageUrl?: string; //TODO: remove this
54
53
  connectedSocialProvider?: SocialProvider;
55
54
  }
56
55
 
@@ -120,12 +119,17 @@ export const ConnectionController = {
120
119
  state.pressedWallet = undefined;
121
120
  },
122
121
 
123
- setRecentWallets(wallets: ConnectionControllerState['recentWallets']) {
124
- state.recentWallets = wallets;
122
+ setWcPromise(wcPromise: ConnectionControllerState['wcPromise']) {
123
+ state.wcPromise = wcPromise;
124
+ },
125
+
126
+ setWcUri(wcUri: ConnectionControllerState['wcUri']) {
127
+ state.wcUri = wcUri;
128
+ state.wcPairingExpiry = CoreHelperUtil.getPairingExpiry();
125
129
  },
126
130
 
127
- setSelectedSocialProvider(provider: ConnectionControllerState['selectedSocialProvider']) {
128
- state.selectedSocialProvider = provider;
131
+ setRecentWallets(wallets: ConnectionControllerState['recentWallets']) {
132
+ state.recentWallets = wallets;
129
133
  },
130
134
 
131
135
  async setConnectedWalletImageUrl(url: ConnectionControllerState['connectedWalletImageUrl']) {
@@ -185,14 +189,12 @@ export const ConnectionController = {
185
189
  resetWcConnection() {
186
190
  this.clearUri();
187
191
  state.pressedWallet = undefined;
188
- state.selectedSocialProvider = undefined;
189
192
  ConnectionController.setConnectedWalletImageUrl(undefined);
190
193
  ConnectorController.setConnectedConnector(undefined);
191
194
  StorageUtil.removeWalletConnectDeepLink();
192
195
  },
193
196
 
194
197
  async disconnect() {
195
- await this._getClient().disconnect();
196
198
  this.resetWcConnection();
197
199
  // remove transactions
198
200
  // RouterController.reset('Connect');
@@ -0,0 +1,309 @@
1
+ import { proxy, ref } from 'valtio';
2
+ import { derive } from 'valtio/utils';
3
+ import {
4
+ EVMAdapter,
5
+ type AppKitNetwork,
6
+ type BlockchainAdapter,
7
+ type CaipAddress,
8
+ type CaipNetworkId,
9
+ type ChainNamespace,
10
+ type GetBalanceResponse,
11
+ type WalletInfo
12
+ } from '@reown/appkit-common-react-native';
13
+ import { StorageUtil } from '../utils/StorageUtil';
14
+
15
+ // -- Types --------------------------------------------- //
16
+ type Balance = GetBalanceResponse;
17
+
18
+ //TODO: balance could be elsewhere
19
+ interface Connection {
20
+ accounts: CaipAddress[];
21
+ balances: Record<CaipAddress, Balance>; //TODO: make this an array of balances
22
+ adapter: BlockchainAdapter;
23
+ caipNetwork: CaipNetworkId;
24
+ wallet?: WalletInfo;
25
+ }
26
+
27
+ export interface ConnectionsControllerState {
28
+ activeNamespace?: ChainNamespace;
29
+ connections: Map<ChainNamespace, Connection>;
30
+ networks: AppKitNetwork[];
31
+ }
32
+
33
+ // -- State --------------------------------------------- //
34
+ const baseState = proxy<ConnectionsControllerState>({
35
+ activeNamespace: undefined,
36
+ connections: new Map<ChainNamespace, Connection>(),
37
+ networks: []
38
+ });
39
+
40
+ const derivedState = derive(
41
+ {
42
+ activeAddress: (get): CaipAddress | undefined => {
43
+ const snap = get(baseState);
44
+
45
+ if (!snap.activeNamespace) {
46
+ return undefined;
47
+ }
48
+
49
+ const connection = snap.connections.get(snap.activeNamespace);
50
+
51
+ if (!connection || !connection.accounts || connection.accounts.length === 0) {
52
+ return undefined;
53
+ }
54
+
55
+ //TODO: what happens if there are several accounts on the same chain?
56
+ const activeAccount = connection.accounts.find(account =>
57
+ account.startsWith(connection.caipNetwork)
58
+ );
59
+
60
+ return activeAccount;
61
+ },
62
+ activeBalance: (get): Balance | undefined => {
63
+ const snap = get(baseState);
64
+
65
+ if (!snap.activeNamespace) return undefined;
66
+ const connection = snap.connections.get(snap.activeNamespace);
67
+
68
+ if (!connection || !connection.accounts || connection.accounts.length === 0) {
69
+ return undefined;
70
+ }
71
+
72
+ const activeAccount = connection.accounts.find(account =>
73
+ account.startsWith(connection.caipNetwork)
74
+ );
75
+
76
+ if (
77
+ !connection ||
78
+ !connection.balances ||
79
+ !activeAccount ||
80
+ Object.keys(connection.balances).length === 0
81
+ ) {
82
+ return undefined;
83
+ }
84
+
85
+ return connection.balances[activeAccount];
86
+ },
87
+ activeNetwork: (get): AppKitNetwork | undefined => {
88
+ const snap = get(baseState);
89
+
90
+ if (!snap.activeNamespace) return undefined;
91
+
92
+ const connection = snap.connections.get(snap.activeNamespace);
93
+
94
+ if (!connection) return undefined;
95
+
96
+ return snap.networks.find(
97
+ network =>
98
+ network.chainNamespace === snap.activeNamespace &&
99
+ network.id?.toString() === connection.caipNetwork?.split(':')[1]
100
+ );
101
+ },
102
+ activeCaipNetworkId: (get): CaipNetworkId | undefined => {
103
+ const snap = get(baseState);
104
+
105
+ if (!snap.activeNamespace) return undefined;
106
+
107
+ const connection = snap.connections.get(snap.activeNamespace);
108
+
109
+ if (!connection) return undefined;
110
+
111
+ return connection.caipNetwork;
112
+ },
113
+ walletInfo: (get): WalletInfo | undefined => {
114
+ const snap = get(baseState);
115
+
116
+ if (!snap.activeNamespace) return undefined;
117
+
118
+ return snap.connections.get(snap.activeNamespace)?.wallet;
119
+ }
120
+ },
121
+ {
122
+ proxy: baseState // Link derived proxy to the base state proxy
123
+ }
124
+ );
125
+
126
+ // -- Controller ---------------------------------------- //
127
+ export const ConnectionsController = {
128
+ state: derivedState,
129
+
130
+ setActiveNamespace(namespace?: ChainNamespace) {
131
+ baseState.activeNamespace = namespace;
132
+ StorageUtil.setActiveNamespace(namespace);
133
+ },
134
+
135
+ storeConnection({
136
+ namespace,
137
+ adapter,
138
+ accounts,
139
+ chains,
140
+ wallet,
141
+ caipNetwork
142
+ }: {
143
+ namespace: ChainNamespace;
144
+ adapter: BlockchainAdapter;
145
+ accounts: CaipAddress[];
146
+ chains: CaipNetworkId[];
147
+ wallet?: WalletInfo;
148
+ caipNetwork?: CaipNetworkId;
149
+ }) {
150
+ const newConnectionEntry = {
151
+ balances: {},
152
+ caipNetwork: caipNetwork ?? chains[0]!,
153
+ adapter: ref(adapter),
154
+ accounts,
155
+ chains,
156
+ wallet
157
+ };
158
+
159
+ // Create a new Map to ensure Valtio detects the change
160
+ const newConnectionsMap = new Map(baseState.connections);
161
+ newConnectionsMap.set(namespace, newConnectionEntry);
162
+ baseState.connections = newConnectionsMap;
163
+ },
164
+
165
+ updateAccounts(namespace: ChainNamespace, accounts: CaipAddress[]) {
166
+ const connection = baseState.connections.get(namespace);
167
+ if (!connection) {
168
+ return;
169
+ }
170
+
171
+ const newConnectionsMap = new Map(baseState.connections);
172
+ const updatedConnection = { ...connection, accounts };
173
+ newConnectionsMap.set(namespace, updatedConnection);
174
+ baseState.connections = newConnectionsMap;
175
+ },
176
+
177
+ updateBalance(namespace: ChainNamespace, address: CaipAddress, balance: Balance) {
178
+ const connection = baseState.connections.get(namespace);
179
+ if (!connection) {
180
+ return;
181
+ }
182
+
183
+ const newBalances = { ...connection.balances, [address]: balance };
184
+ const updatedConnection = { ...connection, balances: newBalances };
185
+ const newConnectionsMap = new Map(baseState.connections);
186
+ newConnectionsMap.set(namespace, updatedConnection);
187
+ baseState.connections = newConnectionsMap;
188
+ },
189
+
190
+ setActiveNetwork(namespace: ChainNamespace, networkId: CaipNetworkId) {
191
+ const connection = baseState.connections.get(namespace);
192
+
193
+ if (!connection) {
194
+ return;
195
+ }
196
+
197
+ baseState.connections.set(namespace, {
198
+ ...connection,
199
+ caipNetwork: networkId
200
+ });
201
+ },
202
+
203
+ setNetworks(networks: AppKitNetwork[]) {
204
+ baseState.networks = networks;
205
+ },
206
+
207
+ getConnectedNetworks() {
208
+ return baseState.networks.filter(
209
+ network =>
210
+ baseState.connections
211
+ .get(network.chainNamespace)
212
+ ?.accounts.some(account => account.startsWith(network.caipNetworkId))
213
+ );
214
+ },
215
+
216
+ async disconnect(namespace: ChainNamespace, isInternal = true) {
217
+ const connection = baseState.connections.get(namespace);
218
+ if (!connection) return;
219
+
220
+ // Get the current connector from the adapter
221
+ const connector = connection.adapter.connector;
222
+ if (!connector) return;
223
+
224
+ // Find all namespaces that use the same connector
225
+ const namespacesUsingConnector = Array.from(baseState.connections.keys()).filter(
226
+ ns => baseState.connections.get(ns)?.adapter.connector === connector
227
+ );
228
+
229
+ // Unsubscribe all event listeners from the adapter
230
+ namespacesUsingConnector.forEach(ns => {
231
+ const _connection = baseState.connections.get(ns);
232
+ if (_connection?.adapter) {
233
+ _connection.adapter.removeAllListeners();
234
+ }
235
+ });
236
+
237
+ // Disconnect the adapter
238
+ if (isInternal) {
239
+ await connection.adapter.disconnect();
240
+ }
241
+
242
+ // Remove all namespaces that used this connector
243
+ const newConnectionsMap = new Map(baseState.connections);
244
+ namespacesUsingConnector.forEach(ns => {
245
+ newConnectionsMap.delete(ns);
246
+ });
247
+ baseState.connections = newConnectionsMap;
248
+
249
+ // Remove activeNamespace if it is in the list of namespaces using the connector
250
+ if (
251
+ baseState.activeNamespace &&
252
+ (baseState.activeNamespace === namespace ||
253
+ namespacesUsingConnector.includes(baseState.activeNamespace))
254
+ ) {
255
+ baseState.activeNamespace = undefined;
256
+ StorageUtil.setActiveNamespace(undefined);
257
+ }
258
+ },
259
+
260
+ parseUnits(value: string, decimals: number) {
261
+ if (!baseState.activeNamespace) return undefined;
262
+
263
+ return baseState.connections
264
+ .get(baseState.activeNamespace)
265
+ ?.adapter.parseUnits(value, decimals);
266
+ },
267
+
268
+ async signMessage(address: CaipAddress, message: string) {
269
+ if (!baseState.activeNamespace) return undefined;
270
+
271
+ const [namespace, chainId, plainAddress] = address.split(':');
272
+
273
+ if (!namespace || namespace !== baseState.activeNamespace || !chainId || !plainAddress) {
274
+ return undefined;
275
+ }
276
+
277
+ const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
278
+
279
+ if (adapter instanceof EVMAdapter && plainAddress && chainId) {
280
+ return adapter.signMessage(plainAddress, message, chainId);
281
+ }
282
+
283
+ return undefined;
284
+ },
285
+
286
+ async sendTransaction(args: any) {
287
+ if (!baseState.activeNamespace) return undefined;
288
+
289
+ const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
290
+
291
+ if (adapter instanceof EVMAdapter) {
292
+ return adapter.sendTransaction(args);
293
+ }
294
+
295
+ return undefined;
296
+ },
297
+
298
+ async estimateGas(args: any) {
299
+ if (!baseState.activeNamespace || baseState.activeNamespace !== 'eip155') return undefined;
300
+
301
+ const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
302
+
303
+ if (adapter instanceof EVMAdapter) {
304
+ return adapter.estimateGas(args);
305
+ }
306
+
307
+ return undefined;
308
+ }
309
+ };
@@ -50,6 +50,7 @@ export const ConnectorController = {
50
50
 
51
51
  if (saveStorage) {
52
52
  if (connectorType) {
53
+ //TODO: Check this
53
54
  StorageUtil.setConnectedConnector(connectorType);
54
55
  } else {
55
56
  StorageUtil.removeConnectedConnector();
@@ -1,5 +1,5 @@
1
- import { subscribeKey as subKey } from 'valtio/utils';
2
- import { proxy, subscribe as sub } from 'valtio';
1
+ import { subscribeKey as subKey } from 'valtio/vanilla/utils';
2
+ import { proxy, subscribe as sub } from 'valtio/vanilla';
3
3
  import { BlockchainApiController } from './BlockchainApiController';
4
4
  import type { BlockchainApiEnsError } from '../utils/TypeUtil';
5
5
 
@@ -1,4 +1,4 @@
1
- import { proxy, subscribe as sub } from 'valtio';
1
+ import { proxy, subscribe as sub } from 'valtio/vanilla';
2
2
  import { ApiController } from './ApiController';
3
3
  import { OptionsController } from './OptionsController';
4
4
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
@@ -1,6 +1,7 @@
1
1
  import { proxy } from 'valtio';
2
2
  import { AccountController } from './AccountController';
3
- import { RouterController, type RouterControllerState } from './RouterController';
3
+ import type { RouterControllerState } from './RouterController';
4
+ import { RouterController } from './RouterController';
4
5
  import { PublicStateController } from './PublicStateController';
5
6
  import { EventsController } from './EventsController';
6
7
  import { ApiController } from './ApiController';
@@ -1,5 +1,5 @@
1
1
  import { proxy, ref } from 'valtio';
2
- import type { CaipNetwork, CaipNetworkId } from '../utils/TypeUtil';
2
+ import type { CaipNetwork, CaipNetworkId } from '@reown/appkit-common-react-native';
3
3
  import { PublicStateController } from './PublicStateController';
4
4
  import { NetworkUtil } from '@reown/appkit-common-react-native';
5
5
  import { ConstantsUtil } from '../utils/ConstantsUtil';
@@ -9,8 +9,7 @@ import type {
9
9
  OnRampCryptoCurrency,
10
10
  OnRampServiceProvider,
11
11
  OnRampError,
12
- OnRampErrorTypeValues,
13
- OnRampCountryDefaults
12
+ OnRampErrorTypeValues
14
13
  } from '../utils/TypeUtil';
15
14
 
16
15
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
@@ -33,23 +32,23 @@ const mapErrorMessage = (errorCode: string): OnRampError => {
33
32
  const errorMap: Record<string, { type: OnRampErrorTypeValues; message: string }> = {
34
33
  [OnRampErrorType.AMOUNT_TOO_LOW]: {
35
34
  type: OnRampErrorType.AMOUNT_TOO_LOW,
36
- message: 'The amount is too low'
35
+ message: 'Amount is too low'
37
36
  },
38
37
  [OnRampErrorType.AMOUNT_TOO_HIGH]: {
39
38
  type: OnRampErrorType.AMOUNT_TOO_HIGH,
40
- message: 'The amount is too high'
39
+ message: 'Amount is too high'
41
40
  },
42
41
  [OnRampErrorType.INVALID_AMOUNT]: {
43
42
  type: OnRampErrorType.INVALID_AMOUNT,
44
- message: 'Enter a valid amount'
43
+ message: 'Please adjust amount'
45
44
  },
46
45
  [OnRampErrorType.INCOMPATIBLE_REQUEST]: {
47
46
  type: OnRampErrorType.INCOMPATIBLE_REQUEST,
48
- message: 'Enter a valid amount'
47
+ message: 'Try different amount or payment method'
49
48
  },
50
49
  [OnRampErrorType.BAD_REQUEST]: {
51
50
  type: OnRampErrorType.BAD_REQUEST,
52
- message: 'Enter a valid amount'
51
+ message: 'Try different amount or payment method'
53
52
  }
54
53
  };
55
54
 
@@ -64,7 +63,6 @@ const mapErrorMessage = (errorCode: string): OnRampError => {
64
63
  // -- Types --------------------------------------------- //
65
64
  export interface OnRampControllerState {
66
65
  countries: OnRampCountry[];
67
- countriesDefaults?: OnRampCountryDefaults[];
68
66
  selectedCountry?: OnRampCountry;
69
67
  serviceProviders: OnRampServiceProvider[];
70
68
  selectedServiceProvider?: OnRampServiceProvider;
@@ -116,8 +114,9 @@ export const OnRampController = {
116
114
 
117
115
  if (updateCurrency) {
118
116
  const currencyCode =
119
- state.countriesDefaults?.find(d => d.countryCode === country.countryCode)
120
- ?.defaultCurrencyCode || 'USD';
117
+ ConstantsUtil.COUNTRY_CURRENCIES[
118
+ country.countryCode as keyof typeof ConstantsUtil.COUNTRY_CURRENCIES
119
+ ] || 'USD';
121
120
 
122
121
  const currency = state.paymentCurrencies?.find(c => c.currencyCode === currencyCode);
123
122
 
@@ -127,7 +126,6 @@ export const OnRampController = {
127
126
  }
128
127
 
129
128
  await Promise.all([this.fetchPaymentMethods(), this.fetchCryptoCurrencies()]);
130
- this.clearQuotes();
131
129
 
132
130
  state.loading = false;
133
131
 
@@ -136,6 +134,8 @@ export const OnRampController = {
136
134
 
137
135
  setSelectedPaymentMethod(paymentMethod: OnRampPaymentMethod) {
138
136
  state.selectedPaymentMethod = paymentMethod;
137
+
138
+ this.clearQuotes();
139
139
  },
140
140
 
141
141
  setPurchaseCurrency(currency: OnRampCryptoCurrency) {
@@ -184,7 +184,7 @@ export const OnRampController = {
184
184
  selectedCurrency = state.purchaseCurrencies?.find(c => c.currencyCode === defaultCurrency);
185
185
  }
186
186
 
187
- state.purchaseCurrency = selectedCurrency ?? state.purchaseCurrencies?.[0] ?? undefined;
187
+ state.purchaseCurrency = selectedCurrency || state.purchaseCurrencies?.[0] || undefined;
188
188
  },
189
189
 
190
190
  getServiceProviderImage(serviceProviderName?: string) {
@@ -231,27 +231,6 @@ export const OnRampController = {
231
231
  }
232
232
  },
233
233
 
234
- async fetchCountriesDefaults() {
235
- try {
236
- let countriesDefaults = await StorageUtil.getOnRampCountriesDefaults();
237
-
238
- if (!countriesDefaults.length) {
239
- countriesDefaults = (await BlockchainApiController.fetchOnRampCountriesDefaults()) ?? [];
240
-
241
- if (countriesDefaults.length) {
242
- StorageUtil.setOnRampCountriesDefaults(countriesDefaults);
243
- }
244
- }
245
-
246
- state.countriesDefaults = countriesDefaults;
247
- } catch (error) {
248
- state.error = {
249
- type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
250
- message: 'Failed to load countries defaults'
251
- };
252
- }
253
- },
254
-
255
234
  async fetchServiceProviders() {
256
235
  try {
257
236
  let serviceProviders = await StorageUtil.getOnRampServiceProviders();
@@ -280,8 +259,10 @@ export const OnRampController = {
280
259
  });
281
260
 
282
261
  const defaultCountryPaymentMethods =
283
- state.countriesDefaults?.find(d => d.countryCode === state.selectedCountry?.countryCode)
284
- ?.defaultPaymentMethods || [];
262
+ ConstantsUtil.COUNTRY_DEFAULT_PAYMENT_METHOD[
263
+ state.selectedCountry
264
+ ?.countryCode as keyof typeof ConstantsUtil.COUNTRY_DEFAULT_PAYMENT_METHOD
265
+ ];
285
266
 
286
267
  state.paymentMethods =
287
268
  paymentMethods?.sort((a, b) => {
@@ -295,7 +276,9 @@ export const OnRampController = {
295
276
  return aIndex - bIndex;
296
277
  }) || [];
297
278
 
298
- state.selectedPaymentMethod = state.paymentMethods[0];
279
+ state.selectedPaymentMethod = paymentMethods?.[0] || undefined;
280
+
281
+ this.clearQuotes();
299
282
  } catch (error) {
300
283
  state.error = {
301
284
  type: OnRampErrorType.FAILED_TO_LOAD_METHODS,
@@ -353,8 +336,9 @@ export const OnRampController = {
353
336
 
354
337
  if (countryCode) {
355
338
  currencyCode =
356
- state.countriesDefaults?.find(d => d.countryCode === countryCode)?.defaultCurrencyCode ||
357
- 'USD';
339
+ ConstantsUtil.COUNTRY_CURRENCIES[
340
+ countryCode as keyof typeof ConstantsUtil.COUNTRY_CURRENCIES
341
+ ];
358
342
  }
359
343
 
360
344
  const preferredCurrency = await StorageUtil.getOnRampPreferredFiatCurrency();
@@ -403,24 +387,25 @@ export const OnRampController = {
403
387
  }
404
388
 
405
389
  state.quotesLoading = true;
406
- state.selectedQuote = undefined;
407
- state.selectedServiceProvider = undefined;
408
390
  state.error = undefined;
409
391
 
410
392
  this.abortGetQuotes(false);
411
393
  quotesAbortController = new AbortController();
412
- const currentSignal = quotesAbortController.signal;
413
394
 
414
395
  try {
415
396
  const body = {
416
397
  countryCode: state.selectedCountry?.countryCode!,
398
+ paymentMethodType: state.selectedPaymentMethod?.paymentMethod!,
417
399
  destinationCurrencyCode: state.purchaseCurrency?.currencyCode!,
418
400
  sourceAmount: state.paymentAmount,
419
401
  sourceCurrencyCode: state.paymentCurrency?.currencyCode!,
420
402
  walletAddress: AccountController.state.address!
421
403
  };
422
404
 
423
- const response = await BlockchainApiController.getOnRampQuotes(body, currentSignal);
405
+ const response = await BlockchainApiController.getOnRampQuotes(
406
+ body,
407
+ quotesAbortController.signal
408
+ );
424
409
 
425
410
  if (!response || !response.length) {
426
411
  throw new Error('No quotes available');
@@ -429,48 +414,9 @@ export const OnRampController = {
429
414
  const quotes = response.sort((a, b) => b.customerScore - a.customerScore);
430
415
 
431
416
  state.quotes = quotes;
432
-
433
- //Replace payment method if it's not in the quotes
434
- const isValidPaymentMethod =
435
- state.selectedPaymentMethod &&
436
- quotes.some(
437
- quote => quote.paymentMethodType === state.selectedPaymentMethod?.paymentMethod
438
- );
439
-
440
- if (!isValidPaymentMethod) {
441
- const countryMethods =
442
- state.countriesDefaults?.find(d => d.countryCode === state.selectedCountry?.countryCode)
443
- ?.defaultPaymentMethods || [];
444
-
445
- const availableQuoteMethods = new Set(quotes.map(q => q.paymentMethodType));
446
-
447
- let newPaymentMethodType: string | undefined;
448
- for (const dpm of countryMethods) {
449
- if (availableQuoteMethods.has(dpm)) {
450
- newPaymentMethodType = dpm;
451
- break;
452
- }
453
- }
454
-
455
- if (newPaymentMethodType) {
456
- state.selectedPaymentMethod =
457
- state.paymentMethods.find(m => m.paymentMethod === newPaymentMethodType) ||
458
- state.paymentMethods.find(
459
- method => method.paymentMethod === quotes[0]?.paymentMethodType
460
- );
461
- } else {
462
- state.selectedPaymentMethod = state.paymentMethods.find(
463
- method => method.paymentMethod === quotes[0]?.paymentMethodType
464
- );
465
- }
466
- }
467
-
468
- state.selectedQuote = quotes.find(
469
- quote => quote.paymentMethodType === state.selectedPaymentMethod?.paymentMethod
470
- );
471
-
417
+ state.selectedQuote = quotes[0];
472
418
  state.selectedServiceProvider = state.serviceProviders.find(
473
- sp => sp.serviceProvider === state.selectedQuote?.serviceProvider
419
+ sp => sp.serviceProvider === quotes[0]?.serviceProvider
474
420
  );
475
421
  } catch (error: any) {
476
422
  if (error.name === 'AbortError') {
@@ -489,9 +435,7 @@ export const OnRampController = {
489
435
  this.clearQuotes();
490
436
  state.error = mapErrorMessage(error?.code || 'UNKNOWN_ERROR');
491
437
  } finally {
492
- if (!currentSignal.aborted) {
493
- state.quotesLoading = false;
494
- }
438
+ state.quotesLoading = false;
495
439
  }
496
440
  },
497
441
 
@@ -548,7 +492,7 @@ export const OnRampController = {
548
492
  throw new Error('Invalid quote');
549
493
  }
550
494
 
551
- const body = {
495
+ const widget = await BlockchainApiController.getOnRampWidget({
552
496
  countryCode: quote.countryCode,
553
497
  destinationCurrencyCode: quote.destinationCurrencyCode,
554
498
  paymentMethodType: quote.paymentMethodType,
@@ -557,9 +501,7 @@ export const OnRampController = {
557
501
  sourceCurrencyCode: quote.sourceCurrencyCode,
558
502
  walletAddress: AccountController.state.address!,
559
503
  redirectUrl: metadata?.redirect?.universal ?? metadata?.redirect?.native
560
- };
561
-
562
- const widget = await BlockchainApiController.getOnRampWidget(body);
504
+ });
563
505
 
564
506
  if (!widget || !widget.widgetUrl) {
565
507
  throw new Error('Invalid widget response');
@@ -613,7 +555,6 @@ export const OnRampController = {
613
555
  await this.fetchServiceProviders();
614
556
 
615
557
  await Promise.all([
616
- this.fetchCountriesDefaults(),
617
558
  this.fetchPaymentMethods(),
618
559
  this.fetchFiatLimits(),
619
560
  this.fetchCryptoCurrencies(),