@reown/appkit-core-react-native 0.0.0-fix-approved-networks-20250822000414 → 0.0.0-fix-ui-changes-20250828183750

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 (245) hide show
  1. package/lib/commonjs/controllers/ApiController.js +75 -38
  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 +156 -57
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionsController.js +402 -0
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
  9. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  10. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  11. package/lib/commonjs/controllers/ModalController.js +6 -7
  12. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  13. package/lib/commonjs/controllers/OnRampController.js +29 -19
  14. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  15. package/lib/commonjs/controllers/OptionsController.js +22 -7
  16. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  17. package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
  18. package/lib/commonjs/controllers/RouterController.js +7 -22
  19. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  20. package/lib/commonjs/controllers/SendController.js +96 -96
  21. package/lib/commonjs/controllers/SendController.js.map +1 -1
  22. package/lib/commonjs/controllers/SnackController.js +29 -5
  23. package/lib/commonjs/controllers/SnackController.js.map +1 -1
  24. package/lib/commonjs/controllers/SwapController.js +154 -151
  25. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  26. package/lib/commonjs/controllers/ThemeController.js +9 -1
  27. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  28. package/lib/commonjs/controllers/TransactionsController.js +22 -18
  29. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  30. package/lib/commonjs/controllers/WcController.js +73 -0
  31. package/lib/commonjs/controllers/WcController.js.map +1 -0
  32. package/lib/commonjs/index.js +13 -41
  33. package/lib/commonjs/index.js.map +1 -1
  34. package/lib/commonjs/package.json +1 -0
  35. package/lib/commonjs/utils/ApiUtil.js.map +1 -1
  36. package/lib/commonjs/utils/AssetUtil.js +8 -18
  37. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  38. package/lib/commonjs/utils/ConstantsUtil.js +122 -5
  39. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  40. package/lib/commonjs/utils/CoreHelperUtil.js +19 -7
  41. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  42. package/lib/commonjs/utils/EventUtil.js.map +1 -1
  43. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  44. package/lib/commonjs/utils/RouterUtil.js.map +1 -1
  45. package/lib/commonjs/utils/StorageUtil.js +90 -108
  46. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  47. package/lib/commonjs/utils/SwapApiUtil.js +15 -21
  48. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  49. package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -1
  50. package/lib/commonjs/utils/WalletUtil.js +23 -0
  51. package/lib/commonjs/utils/WalletUtil.js.map +1 -0
  52. package/lib/module/controllers/ApiController.js +77 -38
  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 +158 -57
  57. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  58. package/lib/module/controllers/ConnectionsController.js +399 -0
  59. package/lib/module/controllers/ConnectionsController.js.map +1 -0
  60. package/lib/module/controllers/EnsController.js +2 -0
  61. package/lib/module/controllers/EnsController.js.map +1 -1
  62. package/lib/module/controllers/EventsController.js +2 -0
  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 +27 -15
  67. package/lib/module/controllers/OnRampController.js.map +1 -1
  68. package/lib/module/controllers/OptionsController.js +24 -7
  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 +9 -22
  73. package/lib/module/controllers/RouterController.js.map +1 -1
  74. package/lib/module/controllers/SendController.js +98 -96
  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 +156 -151
  79. package/lib/module/controllers/SwapController.js.map +1 -1
  80. package/lib/module/controllers/ThemeController.js +11 -1
  81. package/lib/module/controllers/ThemeController.js.map +1 -1
  82. package/lib/module/controllers/TransactionsController.js +24 -18
  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 +7 -7
  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 +10 -18
  91. package/lib/module/utils/AssetUtil.js.map +1 -1
  92. package/lib/module/utils/ConstantsUtil.js +124 -5
  93. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  94. package/lib/module/utils/CoreHelperUtil.js +21 -5
  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 +2 -0
  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 +93 -108
  103. package/lib/module/utils/StorageUtil.js.map +1 -1
  104. package/lib/module/utils/SwapApiUtil.js +17 -21
  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/module/utils/WalletUtil.js +19 -0
  109. package/lib/module/utils/WalletUtil.js.map +1 -0
  110. package/lib/typescript/controllers/ApiController.d.ts +4 -5
  111. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  112. package/lib/typescript/controllers/AssetController.d.ts +0 -2
  113. package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
  114. package/lib/typescript/controllers/BlockchainApiController.d.ts +29 -11
  115. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  116. package/lib/typescript/controllers/ConnectionsController.d.ts +45 -0
  117. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
  118. package/lib/typescript/controllers/EnsController.d.ts +1 -1
  119. package/lib/typescript/controllers/EventsController.d.ts +1 -1
  120. package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
  121. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  122. package/lib/typescript/controllers/OnRampController.d.ts +2 -2
  123. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  124. package/lib/typescript/controllers/OptionsController.d.ts +9 -4
  125. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  126. package/lib/typescript/controllers/PublicStateController.d.ts +1 -1
  127. package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -1
  128. package/lib/typescript/controllers/RouterController.d.ts +6 -20
  129. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  130. package/lib/typescript/controllers/SendController.d.ts +5 -7
  131. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  132. package/lib/typescript/controllers/SnackController.d.ts +3 -3
  133. package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
  134. package/lib/typescript/controllers/SwapController.d.ts +12 -12
  135. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  136. package/lib/typescript/controllers/ThemeController.d.ts +1 -1
  137. package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
  138. package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
  139. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  140. package/lib/typescript/controllers/WcController.d.ts +27 -0
  141. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  142. package/lib/typescript/index.d.ts +3 -8
  143. package/lib/typescript/index.d.ts.map +1 -1
  144. package/lib/typescript/utils/AssetUtil.d.ts +3 -4
  145. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  146. package/lib/typescript/utils/ConstantsUtil.d.ts +12 -2
  147. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  148. package/lib/typescript/utils/CoreHelperUtil.d.ts +5 -4
  149. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  150. package/lib/typescript/utils/EventUtil.d.ts +1 -1
  151. package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
  152. package/lib/typescript/utils/FetchUtil.d.ts +2 -2
  153. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  154. package/lib/typescript/utils/StorageUtil.d.ts +15 -16
  155. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  156. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
  157. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  158. package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
  159. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
  160. package/lib/typescript/utils/WalletUtil.d.ts +5 -0
  161. package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
  162. package/package.json +8 -22
  163. package/src/controllers/ApiController.ts +83 -40
  164. package/src/controllers/AssetController.ts +0 -6
  165. package/src/controllers/BlockchainApiController.ts +136 -44
  166. package/src/controllers/ConnectionsController.ts +521 -0
  167. package/src/controllers/EnsController.ts +1 -1
  168. package/src/controllers/EventsController.ts +1 -1
  169. package/src/controllers/ModalController.ts +6 -7
  170. package/src/controllers/OnRampController.ts +37 -18
  171. package/src/controllers/OptionsController.ts +37 -14
  172. package/src/controllers/PublicStateController.ts +1 -1
  173. package/src/controllers/RouterController.ts +17 -54
  174. package/src/controllers/SendController.ts +122 -111
  175. package/src/controllers/SnackController.ts +31 -5
  176. package/src/controllers/SwapController.ts +177 -183
  177. package/src/controllers/ThemeController.ts +11 -2
  178. package/src/controllers/TransactionsController.ts +25 -19
  179. package/src/controllers/WcController.ts +93 -0
  180. package/src/index.ts +6 -20
  181. package/src/utils/AssetUtil.ts +9 -22
  182. package/src/utils/ConstantsUtil.ts +126 -6
  183. package/src/utils/CoreHelperUtil.ts +45 -7
  184. package/src/utils/EventUtil.ts +1 -1
  185. package/src/utils/FetchUtil.ts +2 -2
  186. package/src/utils/StorageUtil.ts +163 -131
  187. package/src/utils/SwapApiUtil.ts +30 -37
  188. package/src/utils/SwapCalculationUtil.ts +1 -2
  189. package/src/utils/WalletUtil.ts +14 -0
  190. package/lib/commonjs/controllers/AccountController.js +0 -93
  191. package/lib/commonjs/controllers/AccountController.js.map +0 -1
  192. package/lib/commonjs/controllers/ConnectionController.js +0 -126
  193. package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
  194. package/lib/commonjs/controllers/ConnectorController.js +0 -49
  195. package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
  196. package/lib/commonjs/controllers/NetworkController.js +0 -90
  197. package/lib/commonjs/controllers/NetworkController.js.map +0 -1
  198. package/lib/commonjs/controllers/WebviewController.js +0 -52
  199. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  200. package/lib/commonjs/utils/ConnectionUtil.js +0 -33
  201. package/lib/commonjs/utils/ConnectionUtil.js.map +0 -1
  202. package/lib/commonjs/utils/NetworkUtil.js +0 -46
  203. package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
  204. package/lib/commonjs/utils/TypeUtil.js +0 -35
  205. package/lib/commonjs/utils/TypeUtil.js.map +0 -1
  206. package/lib/module/controllers/AccountController.js +0 -88
  207. package/lib/module/controllers/AccountController.js.map +0 -1
  208. package/lib/module/controllers/ConnectionController.js +0 -121
  209. package/lib/module/controllers/ConnectionController.js.map +0 -1
  210. package/lib/module/controllers/ConnectorController.js +0 -44
  211. package/lib/module/controllers/ConnectorController.js.map +0 -1
  212. package/lib/module/controllers/NetworkController.js +0 -85
  213. package/lib/module/controllers/NetworkController.js.map +0 -1
  214. package/lib/module/controllers/WebviewController.js +0 -47
  215. package/lib/module/controllers/WebviewController.js.map +0 -1
  216. package/lib/module/utils/ConnectionUtil.js +0 -27
  217. package/lib/module/utils/ConnectionUtil.js.map +0 -1
  218. package/lib/module/utils/NetworkUtil.js +0 -40
  219. package/lib/module/utils/NetworkUtil.js.map +0 -1
  220. package/lib/module/utils/TypeUtil.js +0 -28
  221. package/lib/module/utils/TypeUtil.js.map +0 -1
  222. package/lib/typescript/controllers/AccountController.d.ts +0 -33
  223. package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
  224. package/lib/typescript/controllers/ConnectionController.d.ts +0 -66
  225. package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
  226. package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
  227. package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
  228. package/lib/typescript/controllers/NetworkController.d.ts +0 -35
  229. package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
  230. package/lib/typescript/controllers/WebviewController.d.ts +0 -21
  231. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  232. package/lib/typescript/utils/ConnectionUtil.d.ts +0 -4
  233. package/lib/typescript/utils/ConnectionUtil.d.ts.map +0 -1
  234. package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
  235. package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
  236. package/lib/typescript/utils/TypeUtil.d.ts +0 -850
  237. package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
  238. package/src/controllers/AccountController.ts +0 -128
  239. package/src/controllers/ConnectionController.ts +0 -200
  240. package/src/controllers/ConnectorController.ts +0 -63
  241. package/src/controllers/NetworkController.ts +0 -120
  242. package/src/controllers/WebviewController.ts +0 -63
  243. package/src/utils/ConnectionUtil.ts +0 -27
  244. package/src/utils/NetworkUtil.ts +0 -33
  245. package/src/utils/TypeUtil.ts +0 -1039
@@ -0,0 +1,521 @@
1
+ import { proxy, ref } from 'valtio';
2
+ import { derive } from 'derive-valtio';
3
+ import {
4
+ EVMAdapter,
5
+ type AppKitNetwork,
6
+ type BlockchainAdapter,
7
+ type CaipAddress,
8
+ type CaipNetworkId,
9
+ type ChainNamespace,
10
+ type Balance,
11
+ type WalletInfo,
12
+ type ConnectionProperties,
13
+ type AccountType,
14
+ type Connection,
15
+ SolanaBaseAdapter,
16
+ type Identity
17
+ } from '@reown/appkit-common-react-native';
18
+ import { StorageUtil } from '../utils/StorageUtil';
19
+ import { BlockchainApiController } from './BlockchainApiController';
20
+ import { SnackController } from './SnackController';
21
+ import { CoreHelperUtil } from '../utils/CoreHelperUtil';
22
+
23
+ // -- Types --------------------------------------------- //
24
+ export interface ConnectionsControllerState {
25
+ activeNamespace?: ChainNamespace;
26
+ connections: Map<ChainNamespace, Connection>;
27
+ networks: AppKitNetwork[];
28
+ }
29
+
30
+ // -- State --------------------------------------------- //
31
+ const baseState = proxy<ConnectionsControllerState>({
32
+ activeNamespace: undefined,
33
+ connections: new Map<ChainNamespace, Connection>(),
34
+ networks: []
35
+ });
36
+
37
+ // -- Helper Functions --------------------------------------------- //
38
+ const getActiveConnection = (snap: ConnectionsControllerState): Connection | undefined => {
39
+ if (!snap.activeNamespace) return undefined;
40
+
41
+ return snap.connections.get(snap.activeNamespace);
42
+ };
43
+
44
+ const hasValidAccounts = (connection: Connection): boolean => {
45
+ return connection?.accounts && connection.accounts.length > 0;
46
+ };
47
+
48
+ const findSmartAccountForNetwork = (connection: Connection): CaipAddress | undefined => {
49
+ return connection.properties?.smartAccounts?.find(account =>
50
+ account.startsWith(connection.caipNetwork)
51
+ );
52
+ };
53
+
54
+ const findEOAForNetwork = (connection: Connection): CaipAddress | undefined => {
55
+ const smartAccounts = connection.properties?.smartAccounts || [];
56
+
57
+ return connection.accounts.find(
58
+ account => account.startsWith(connection.caipNetwork) && !smartAccounts.includes(account)
59
+ );
60
+ };
61
+
62
+ const getActiveAddress = (connection: Connection): CaipAddress | undefined => {
63
+ if (!hasValidAccounts(connection)) {
64
+ return undefined;
65
+ }
66
+
67
+ // For smart accounts, prioritize smart account addresses
68
+ if (connection.type === 'smartAccount') {
69
+ const smartAccount = findSmartAccountForNetwork(connection);
70
+ if (smartAccount) {
71
+ return smartAccount;
72
+ }
73
+ }
74
+
75
+ // Fall back to EOA or any account that matches the network
76
+ return findEOAForNetwork(connection);
77
+ };
78
+
79
+ const updateConnection = (
80
+ namespace: ChainNamespace,
81
+ connection: Connection,
82
+ updates: Partial<Connection>
83
+ ) => {
84
+ if (!connection) return;
85
+ const newConnectionsMap = new Map(baseState.connections);
86
+ newConnectionsMap.set(namespace, { ...connection, ...updates });
87
+ baseState.connections = newConnectionsMap;
88
+ };
89
+
90
+ const getActiveIdentity = (connection: Connection): Identity | undefined => {
91
+ const activeAddress = getActiveAddress(connection);
92
+ if (!activeAddress) return undefined;
93
+
94
+ return connection.identities?.get(activeAddress);
95
+ };
96
+
97
+ const derivedState = derive(
98
+ {
99
+ isConnected: (get): boolean => {
100
+ const snap = get(baseState);
101
+
102
+ return !!snap.activeNamespace && !!snap.connections.size;
103
+ },
104
+ activeAddress: (get): CaipAddress | undefined => {
105
+ const snap = get(baseState);
106
+ const connection = getActiveConnection(snap);
107
+
108
+ return connection ? getActiveAddress(connection) : undefined;
109
+ },
110
+ identity: (get): Identity | undefined => {
111
+ const snap = get(baseState);
112
+ const connection = getActiveConnection(snap);
113
+
114
+ return connection ? getActiveIdentity(connection) : undefined;
115
+ },
116
+ activeBalance: (get): Balance | undefined => {
117
+ const snap = get(baseState);
118
+ const connection = getActiveConnection(snap);
119
+
120
+ if (!connection) {
121
+ return undefined;
122
+ }
123
+
124
+ const activeAddress = getActiveAddress(connection);
125
+ if (!activeAddress || !connection.balances || connection.balances.size === 0) {
126
+ return undefined;
127
+ }
128
+
129
+ const addressBalances = connection.balances.get(activeAddress);
130
+ if (!addressBalances || addressBalances.length === 0) {
131
+ return undefined;
132
+ }
133
+
134
+ // Return the native token (first balance without address)
135
+ const nativeToken = addressBalances.find(balance => !balance.address);
136
+ if (nativeToken) {
137
+ return nativeToken;
138
+ }
139
+
140
+ // Fallback to first available balance
141
+ return addressBalances[0];
142
+ },
143
+ activeNetwork: (get): AppKitNetwork | undefined => {
144
+ const snap = get(baseState);
145
+ const connection = getActiveConnection(snap);
146
+
147
+ if (!connection) return undefined;
148
+
149
+ return snap.networks.find(
150
+ network =>
151
+ network.chainNamespace === snap.activeNamespace &&
152
+ network.id?.toString() === connection.caipNetwork?.split(':')[1]
153
+ );
154
+ },
155
+ activeCaipNetworkId: (get): CaipNetworkId | undefined => {
156
+ const snap = get(baseState);
157
+ const connection = getActiveConnection(snap);
158
+
159
+ return connection?.caipNetwork;
160
+ },
161
+ accountType: (get): AccountType | undefined => {
162
+ const snap = get(baseState);
163
+ const connection = getActiveConnection(snap);
164
+
165
+ return connection?.type;
166
+ },
167
+ connection: (get): Connection | undefined => {
168
+ const snap = get(baseState);
169
+
170
+ return getActiveConnection(snap);
171
+ },
172
+ balances: (get): Balance[] | undefined => {
173
+ const snap = get(baseState);
174
+
175
+ const _connection = getActiveConnection(snap);
176
+
177
+ if (!_connection) {
178
+ return undefined;
179
+ }
180
+
181
+ const _activeAddress = getActiveAddress(_connection);
182
+
183
+ if (!_activeAddress) return [];
184
+
185
+ return (
186
+ _connection?.balances
187
+ .get(_activeAddress)
188
+ // Filter out tokens with no quantity
189
+ ?.filter(balance => balance?.quantity?.numeric)
190
+ );
191
+ },
192
+ walletInfo: (get): WalletInfo | undefined => {
193
+ const snap = get(baseState);
194
+ const connection = getActiveConnection(snap);
195
+
196
+ return connection?.wallet;
197
+ }
198
+ },
199
+ {
200
+ proxy: baseState // Link derived proxy to the base state proxy
201
+ }
202
+ );
203
+
204
+ // -- Controller ---------------------------------------- //
205
+ export const ConnectionsController = {
206
+ state: derivedState,
207
+
208
+ setActiveNamespace(namespace?: ChainNamespace) {
209
+ baseState.activeNamespace = namespace;
210
+ StorageUtil.setActiveNamespace(namespace);
211
+ },
212
+
213
+ setConnection({
214
+ accounts,
215
+ adapter,
216
+ caipNetwork,
217
+ namespace,
218
+ properties,
219
+ wallet
220
+ }: {
221
+ accounts: CaipAddress[];
222
+ adapter: BlockchainAdapter;
223
+ caipNetwork: CaipNetworkId;
224
+ namespace: ChainNamespace;
225
+ properties?: ConnectionProperties;
226
+ wallet?: WalletInfo;
227
+ }) {
228
+ const type: AccountType =
229
+ properties?.smartAccounts?.length &&
230
+ properties.smartAccounts.find(account => account.startsWith(caipNetwork))
231
+ ? 'smartAccount'
232
+ : 'eoa';
233
+
234
+ const newConnectionEntry: Connection = {
235
+ balances: new Map<CaipAddress, Balance[]>(),
236
+ caipNetwork,
237
+ adapter: ref(adapter),
238
+ accounts,
239
+ wallet,
240
+ properties,
241
+ type
242
+ };
243
+
244
+ // Create a new Map to ensure Valtio detects the change
245
+ const newConnectionsMap = new Map(baseState.connections);
246
+ newConnectionsMap.set(namespace, newConnectionEntry);
247
+ baseState.connections = newConnectionsMap;
248
+ },
249
+
250
+ updateAccounts(namespace: ChainNamespace, accounts: CaipAddress[]) {
251
+ const connection = baseState.connections.get(namespace);
252
+ if (!connection) {
253
+ return;
254
+ }
255
+
256
+ const newConnectionsMap = new Map(baseState.connections);
257
+ const updatedConnection = { ...connection, accounts };
258
+ newConnectionsMap.set(namespace, updatedConnection);
259
+ baseState.connections = newConnectionsMap;
260
+ },
261
+
262
+ updateBalance(namespace: ChainNamespace, address: CaipAddress, balance: Balance) {
263
+ const connection = baseState.connections.get(namespace);
264
+ if (!connection) {
265
+ console.warn(`No connection found for namespace: ${namespace}`);
266
+
267
+ return;
268
+ }
269
+ const newBalances = new Map(connection.balances);
270
+ const existingBalances = connection.balances.get(address) || [];
271
+ // Check if this token already exists by contract address or symbol
272
+ const existingIndex = existingBalances.findIndex(existingBalance => {
273
+ if (balance.address) {
274
+ return existingBalance.address === balance.address;
275
+ }
276
+
277
+ return existingBalance.symbol === balance.symbol;
278
+ });
279
+ let updatedBalances: Balance[];
280
+ if (existingIndex >= 0) {
281
+ // Update existing token
282
+ updatedBalances = [...existingBalances];
283
+ updatedBalances[existingIndex] = {
284
+ ...updatedBalances[existingIndex],
285
+ ...balance
286
+ };
287
+ } else {
288
+ // Add new token
289
+ updatedBalances = [...existingBalances, balance];
290
+ }
291
+ newBalances.set(address, updatedBalances);
292
+ updateConnection(namespace, connection, { balances: newBalances });
293
+ },
294
+
295
+ updateIdentity(
296
+ namespace: ChainNamespace,
297
+ connection: Connection,
298
+ plainAddress: string,
299
+ identity: Identity
300
+ ) {
301
+ const accounts = connection.accounts.filter(
302
+ account => CoreHelperUtil.getPlainAddress(account) === plainAddress
303
+ );
304
+
305
+ if (accounts.length > 0) {
306
+ const newIdentities = new Map(connection.identities || []);
307
+ let hasChanges = false;
308
+
309
+ accounts.forEach(account => {
310
+ const existingIdentity = newIdentities.get(account);
311
+ if (!existingIdentity || existingIdentity.name !== identity.name) {
312
+ newIdentities.set(account, identity);
313
+ hasChanges = true;
314
+ }
315
+ });
316
+
317
+ if (hasChanges) {
318
+ updateConnection(namespace, connection, { identities: newIdentities });
319
+ }
320
+ }
321
+ },
322
+
323
+ setActiveNetwork(namespace: ChainNamespace, networkId: CaipNetworkId) {
324
+ const connection = baseState.connections.get(namespace);
325
+
326
+ if (!connection) {
327
+ return;
328
+ }
329
+
330
+ baseState.connections.set(namespace, {
331
+ ...connection,
332
+ caipNetwork: networkId
333
+ });
334
+ },
335
+
336
+ setNetworks(networks: AppKitNetwork[]) {
337
+ baseState.networks = networks;
338
+ },
339
+
340
+ getConnectedNetworks() {
341
+ return baseState.networks.filter(
342
+ network =>
343
+ baseState.connections
344
+ .get(network.chainNamespace)
345
+ ?.accounts.some(account => account.startsWith(network.caipNetworkId))
346
+ );
347
+ },
348
+
349
+ setAccountType(namespace: ChainNamespace, type: AccountType) {
350
+ const connection = baseState.connections.get(namespace);
351
+ if (!connection) return;
352
+
353
+ const newConnectionsMap = new Map(baseState.connections);
354
+ const newConnection = { ...connection, type };
355
+ newConnectionsMap.set(namespace, newConnection);
356
+ baseState.connections = newConnectionsMap;
357
+ },
358
+
359
+ async disconnect(namespace: ChainNamespace, isInternal = true) {
360
+ const connection = baseState.connections.get(namespace);
361
+ if (!connection) return;
362
+
363
+ // Get the current connector from the adapter
364
+ const connector = connection.adapter.connector;
365
+ if (!connector) return;
366
+
367
+ // Find all namespaces that use the same connector
368
+ const namespacesUsingConnector = Array.from(baseState.connections.keys()).filter(
369
+ ns => baseState.connections.get(ns)?.adapter.connector === connector
370
+ );
371
+
372
+ // Unsubscribe all event listeners from the adapter
373
+ namespacesUsingConnector.forEach(ns => {
374
+ const _connection = baseState.connections.get(ns);
375
+ if (_connection?.adapter) {
376
+ _connection.adapter.removeAllListeners();
377
+ }
378
+ });
379
+
380
+ // Disconnect the adapter
381
+ if (isInternal) {
382
+ await connection.adapter.disconnect();
383
+ }
384
+
385
+ // Remove all namespaces that used this connector
386
+ const newConnectionsMap = new Map(baseState.connections);
387
+ namespacesUsingConnector.forEach(ns => {
388
+ newConnectionsMap.delete(ns);
389
+ });
390
+ baseState.connections = newConnectionsMap;
391
+
392
+ // Remove activeNamespace if it is in the list of namespaces using the connector
393
+ if (
394
+ baseState.activeNamespace &&
395
+ (baseState.activeNamespace === namespace ||
396
+ namespacesUsingConnector.includes(baseState.activeNamespace))
397
+ ) {
398
+ baseState.activeNamespace = undefined;
399
+ StorageUtil.setActiveNamespace(undefined);
400
+ }
401
+ },
402
+
403
+ parseUnits(value: string, decimals: number) {
404
+ if (!baseState.activeNamespace) return undefined;
405
+
406
+ return baseState.connections
407
+ .get(baseState.activeNamespace)
408
+ ?.adapter.parseUnits(value, decimals);
409
+ },
410
+
411
+ async signMessage(address: CaipAddress, message: string) {
412
+ if (!baseState.activeNamespace) return undefined;
413
+
414
+ const [namespace, chainId, plainAddress] = address.split(':');
415
+
416
+ if (!namespace || namespace !== baseState.activeNamespace || !chainId || !plainAddress) {
417
+ return undefined;
418
+ }
419
+
420
+ const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
421
+
422
+ if (adapter instanceof EVMAdapter && plainAddress && chainId) {
423
+ return adapter.signMessage(plainAddress, message, chainId);
424
+ }
425
+
426
+ return undefined;
427
+ },
428
+
429
+ async sendTransaction(args: any) {
430
+ if (!baseState.activeNamespace) return undefined;
431
+
432
+ const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
433
+ if (adapter instanceof EVMAdapter || adapter instanceof SolanaBaseAdapter) {
434
+ return adapter.sendTransaction(args);
435
+ }
436
+
437
+ return undefined;
438
+ },
439
+
440
+ async estimateGas(args: any) {
441
+ if (!baseState.activeNamespace || baseState.activeNamespace !== 'eip155') return undefined;
442
+
443
+ const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
444
+ if (adapter instanceof EVMAdapter) {
445
+ return adapter.estimateGas(args);
446
+ }
447
+
448
+ return undefined;
449
+ },
450
+
451
+ async writeContract(args: any) {
452
+ if (!baseState.activeNamespace) return undefined;
453
+
454
+ const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
455
+ if (adapter instanceof EVMAdapter) {
456
+ return adapter.writeContract(args);
457
+ }
458
+
459
+ return undefined;
460
+ },
461
+
462
+ async fetchBalance(forceUpdateAddresses?: CaipAddress[]) {
463
+ const connection = getActiveConnection(baseState);
464
+ if (!connection) {
465
+ throw new Error('No active connection found for balance fetch');
466
+ }
467
+
468
+ const chainId = connection.caipNetwork;
469
+ const address = getActiveAddress(connection);
470
+ const namespace = baseState.activeNamespace;
471
+ if (!namespace || !address || !chainId) {
472
+ throw new Error('Missing required data for balance fetch');
473
+ }
474
+
475
+ try {
476
+ const response = await BlockchainApiController.getBalance(address, forceUpdateAddresses);
477
+ if (!response) {
478
+ throw new Error('Failed to fetch token balance');
479
+ }
480
+ // Update balances for each token in the response
481
+ response.balances.forEach(balance => {
482
+ this.updateBalance(namespace, address, {
483
+ name: balance.name,
484
+ symbol: balance.symbol,
485
+ amount: balance.quantity.numeric,
486
+ address: balance.address,
487
+ quantity: balance.quantity,
488
+ price: balance.price,
489
+ value: balance.value,
490
+ iconUrl: balance.iconUrl
491
+ });
492
+ });
493
+ } catch (error) {
494
+ SnackController.showError('Failed to get account balance');
495
+ }
496
+ },
497
+
498
+ getSmartAccountEnabledNetworks(): AppKitNetwork[] {
499
+ const activeConnection = getActiveConnection(baseState);
500
+ if (!activeConnection) {
501
+ return [];
502
+ }
503
+ if (!activeConnection.properties?.smartAccounts?.length) {
504
+ return [];
505
+ }
506
+ const smartAccountNetworks = new Set<CaipNetworkId>();
507
+ activeConnection.properties.smartAccounts.forEach(smartAccount => {
508
+ const parts = smartAccount.split(':');
509
+ if (parts.length >= 2) {
510
+ const networkId: CaipNetworkId = `${parts[0]}:${parts[1]}`;
511
+ smartAccountNetworks.add(networkId);
512
+ }
513
+ });
514
+
515
+ return baseState.networks.filter(network => {
516
+ const networkId: CaipNetworkId = `${network.chainNamespace}:${network.id}`;
517
+
518
+ return smartAccountNetworks.has(networkId);
519
+ });
520
+ }
521
+ };
@@ -1,7 +1,7 @@
1
1
  import { subscribeKey as subKey } from 'valtio/utils';
2
2
  import { proxy, subscribe as sub } from 'valtio';
3
3
  import { BlockchainApiController } from './BlockchainApiController';
4
- import type { BlockchainApiEnsError } from '../utils/TypeUtil';
4
+ import type { BlockchainApiEnsError } from '@reown/appkit-common-react-native';
5
5
 
6
6
  // -- Types --------------------------------------------- //
7
7
 
@@ -3,7 +3,7 @@ import { ApiController } from './ApiController';
3
3
  import { OptionsController } from './OptionsController';
4
4
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
5
5
  import { FetchUtil } from '../utils/FetchUtil';
6
- import type { Event, EventName } from '../utils/TypeUtil';
6
+ import type { Event, EventName } from '@reown/appkit-common-react-native';
7
7
 
8
8
  // -- Helpers ------------------------------------------- //
9
9
  const baseUrl = CoreHelperUtil.getAnalyticsUrl();
@@ -1,10 +1,9 @@
1
1
  import { proxy } from 'valtio';
2
- import { AccountController } from './AccountController';
3
2
  import { RouterController, type RouterControllerState } from './RouterController';
4
3
  import { PublicStateController } from './PublicStateController';
5
4
  import { EventsController } from './EventsController';
6
5
  import { ApiController } from './ApiController';
7
- import { ConnectorController } from './ConnectorController';
6
+ import { ConnectionsController } from './ConnectionsController';
8
7
 
9
8
  // -- Types --------------------------------------------- //
10
9
  export interface ModalControllerState {
@@ -30,11 +29,11 @@ export const ModalController = {
30
29
 
31
30
  async open(options?: ModalControllerArguments['open']) {
32
31
  await ApiController.state.prefetchPromise;
33
- const connected = AccountController.state.isConnected;
32
+ const isConnected = ConnectionsController.state.isConnected;
34
33
  if (options?.view) {
35
34
  RouterController.reset(options.view);
36
- } else if (AccountController.state.isConnected) {
37
- const isUniversalWallet = ConnectorController.state.connectedConnector === 'AUTH';
35
+ } else if (isConnected) {
36
+ const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
38
37
  RouterController.reset(isUniversalWallet ? 'Account' : 'AccountDefault');
39
38
  } else {
40
39
  RouterController.reset('Connect');
@@ -44,12 +43,12 @@ export const ModalController = {
44
43
  EventsController.sendEvent({
45
44
  type: 'track',
46
45
  event: 'MODAL_OPEN',
47
- properties: { connected }
46
+ properties: { connected: isConnected }
48
47
  });
49
48
  },
50
49
 
51
50
  close() {
52
- const connected = AccountController.state.isConnected;
51
+ const connected = ConnectionsController.state.isConnected;
53
52
  state.open = false;
54
53
  PublicStateController.set({ open: false });
55
54
  EventsController.sendEvent({