@reown/appkit-core-react-native 2.0.0-alpha.1 → 2.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/lib/commonjs/controllers/ApiController.js +16 -21
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  3. package/lib/commonjs/controllers/AssetController.js +0 -4
  4. package/lib/commonjs/controllers/AssetController.js.map +1 -1
  5. package/lib/commonjs/controllers/BlockchainApiController.js +102 -112
  6. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  7. package/lib/commonjs/controllers/ConnectionsController.js +248 -51
  8. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
  9. package/lib/commonjs/controllers/EnsController.js +4 -4
  10. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  11. package/lib/commonjs/controllers/EventsController.js +4 -4
  12. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  13. package/lib/commonjs/controllers/ModalController.js +6 -7
  14. package/lib/commonjs/controllers/ModalController.js.map +1 -1
  15. package/lib/commonjs/controllers/OnRampController.js +117 -53
  16. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  17. package/lib/commonjs/controllers/OptionsController.js +10 -4
  18. package/lib/commonjs/controllers/OptionsController.js.map +1 -1
  19. package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
  20. package/lib/commonjs/controllers/RouterController.js +6 -21
  21. package/lib/commonjs/controllers/RouterController.js.map +1 -1
  22. package/lib/commonjs/controllers/SendController.js +100 -100
  23. package/lib/commonjs/controllers/SendController.js.map +1 -1
  24. package/lib/commonjs/controllers/SnackController.js +29 -5
  25. package/lib/commonjs/controllers/SnackController.js.map +1 -1
  26. package/lib/commonjs/controllers/SwapController.js +109 -117
  27. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  28. package/lib/commonjs/controllers/ThemeController.js.map +1 -1
  29. package/lib/commonjs/controllers/TransactionsController.js +23 -19
  30. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  31. package/lib/commonjs/controllers/WcController.js +73 -0
  32. package/lib/commonjs/controllers/WcController.js.map +1 -0
  33. package/lib/commonjs/index.js +3 -38
  34. package/lib/commonjs/index.js.map +1 -1
  35. package/lib/commonjs/package.json +1 -0
  36. package/lib/commonjs/utils/ApiUtil.js.map +1 -1
  37. package/lib/commonjs/utils/AssetUtil.js +6 -14
  38. package/lib/commonjs/utils/AssetUtil.js.map +1 -1
  39. package/lib/commonjs/utils/ConstantsUtil.js +13 -425
  40. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  41. package/lib/commonjs/utils/CoreHelperUtil.js +13 -8
  42. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  43. package/lib/commonjs/utils/EventUtil.js.map +1 -1
  44. package/lib/commonjs/utils/FetchUtil.js +34 -10
  45. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  46. package/lib/commonjs/utils/RouterUtil.js.map +1 -1
  47. package/lib/commonjs/utils/StorageUtil.js +77 -129
  48. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  49. package/lib/commonjs/utils/SwapApiUtil.js +2 -17
  50. package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
  51. package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -1
  52. package/lib/module/controllers/ApiController.js +17 -21
  53. package/lib/module/controllers/ApiController.js.map +1 -1
  54. package/lib/module/controllers/AssetController.js +2 -4
  55. package/lib/module/controllers/AssetController.js.map +1 -1
  56. package/lib/module/controllers/BlockchainApiController.js +103 -111
  57. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  58. package/lib/module/controllers/ConnectionsController.js +250 -51
  59. package/lib/module/controllers/ConnectionsController.js.map +1 -1
  60. package/lib/module/controllers/EnsController.js +4 -2
  61. package/lib/module/controllers/EnsController.js.map +1 -1
  62. package/lib/module/controllers/EventsController.js +3 -1
  63. package/lib/module/controllers/EventsController.js.map +1 -1
  64. package/lib/module/controllers/ModalController.js +8 -7
  65. package/lib/module/controllers/ModalController.js.map +1 -1
  66. package/lib/module/controllers/OnRampController.js +118 -52
  67. package/lib/module/controllers/OnRampController.js.map +1 -1
  68. package/lib/module/controllers/OptionsController.js +12 -4
  69. package/lib/module/controllers/OptionsController.js.map +1 -1
  70. package/lib/module/controllers/PublicStateController.js +2 -0
  71. package/lib/module/controllers/PublicStateController.js.map +1 -1
  72. package/lib/module/controllers/RouterController.js +8 -21
  73. package/lib/module/controllers/RouterController.js.map +1 -1
  74. package/lib/module/controllers/SendController.js +99 -97
  75. package/lib/module/controllers/SendController.js.map +1 -1
  76. package/lib/module/controllers/SnackController.js +31 -5
  77. package/lib/module/controllers/SnackController.js.map +1 -1
  78. package/lib/module/controllers/SwapController.js +111 -117
  79. package/lib/module/controllers/SwapController.js.map +1 -1
  80. package/lib/module/controllers/ThemeController.js +2 -0
  81. package/lib/module/controllers/ThemeController.js.map +1 -1
  82. package/lib/module/controllers/TransactionsController.js +23 -17
  83. package/lib/module/controllers/TransactionsController.js.map +1 -1
  84. package/lib/module/controllers/WcController.js +70 -0
  85. package/lib/module/controllers/WcController.js.map +1 -0
  86. package/lib/module/index.js +5 -6
  87. package/lib/module/index.js.map +1 -1
  88. package/lib/module/utils/ApiUtil.js +2 -0
  89. package/lib/module/utils/ApiUtil.js.map +1 -1
  90. package/lib/module/utils/AssetUtil.js +8 -14
  91. package/lib/module/utils/AssetUtil.js.map +1 -1
  92. package/lib/module/utils/ConstantsUtil.js +15 -425
  93. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  94. package/lib/module/utils/CoreHelperUtil.js +15 -6
  95. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  96. package/lib/module/utils/EventUtil.js +2 -0
  97. package/lib/module/utils/EventUtil.js.map +1 -1
  98. package/lib/module/utils/FetchUtil.js +36 -10
  99. package/lib/module/utils/FetchUtil.js.map +1 -1
  100. package/lib/module/utils/RouterUtil.js +2 -0
  101. package/lib/module/utils/RouterUtil.js.map +1 -1
  102. package/lib/module/utils/StorageUtil.js +80 -129
  103. package/lib/module/utils/StorageUtil.js.map +1 -1
  104. package/lib/module/utils/SwapApiUtil.js +4 -17
  105. package/lib/module/utils/SwapApiUtil.js.map +1 -1
  106. package/lib/module/utils/SwapCalculationUtil.js +3 -0
  107. package/lib/module/utils/SwapCalculationUtil.js.map +1 -1
  108. package/lib/typescript/controllers/ApiController.d.ts +3 -4
  109. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  110. package/lib/typescript/controllers/AssetController.d.ts +0 -2
  111. package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
  112. package/lib/typescript/controllers/BlockchainApiController.d.ts +21 -13
  113. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  114. package/lib/typescript/controllers/ConnectionsController.d.ts +19 -17
  115. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
  116. package/lib/typescript/controllers/EnsController.d.ts +1 -1
  117. package/lib/typescript/controllers/EventsController.d.ts +1 -1
  118. package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
  119. package/lib/typescript/controllers/ModalController.d.ts +1 -1
  120. package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
  121. package/lib/typescript/controllers/OnRampController.d.ts +4 -3
  122. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  123. package/lib/typescript/controllers/OptionsController.d.ts +4 -4
  124. package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
  125. package/lib/typescript/controllers/RouterController.d.ts +5 -20
  126. package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
  127. package/lib/typescript/controllers/SendController.d.ts +5 -7
  128. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  129. package/lib/typescript/controllers/SnackController.d.ts +3 -3
  130. package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
  131. package/lib/typescript/controllers/SwapController.d.ts +11 -11
  132. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  133. package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
  134. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  135. package/lib/typescript/controllers/WcController.d.ts +27 -0
  136. package/lib/typescript/controllers/WcController.d.ts.map +1 -0
  137. package/lib/typescript/index.d.ts +1 -7
  138. package/lib/typescript/index.d.ts.map +1 -1
  139. package/lib/typescript/utils/AssetUtil.d.ts +2 -3
  140. package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
  141. package/lib/typescript/utils/ConstantsUtil.d.ts +7 -415
  142. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  143. package/lib/typescript/utils/CoreHelperUtil.d.ts +4 -4
  144. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  145. package/lib/typescript/utils/EventUtil.d.ts +1 -1
  146. package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
  147. package/lib/typescript/utils/FetchUtil.d.ts +1 -1
  148. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  149. package/lib/typescript/utils/StorageUtil.d.ts +8 -19
  150. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  151. package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
  152. package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
  153. package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
  154. package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
  155. package/package.json +9 -23
  156. package/src/controllers/ApiController.ts +24 -28
  157. package/src/controllers/AssetController.ts +0 -6
  158. package/src/controllers/BlockchainApiController.ts +76 -121
  159. package/src/controllers/ConnectionsController.ts +308 -78
  160. package/src/controllers/EnsController.ts +3 -3
  161. package/src/controllers/EventsController.ts +2 -2
  162. package/src/controllers/ModalController.ts +7 -9
  163. package/src/controllers/OnRampController.ts +179 -82
  164. package/src/controllers/OptionsController.ts +24 -8
  165. package/src/controllers/RouterController.ts +12 -54
  166. package/src/controllers/SendController.ts +123 -112
  167. package/src/controllers/SnackController.ts +31 -5
  168. package/src/controllers/SwapController.ts +130 -146
  169. package/src/controllers/TransactionsController.ts +24 -18
  170. package/src/controllers/WcController.ts +93 -0
  171. package/src/index.ts +2 -21
  172. package/src/utils/AssetUtil.ts +7 -17
  173. package/src/utils/ConstantsUtil.ts +15 -429
  174. package/src/utils/CoreHelperUtil.ts +31 -8
  175. package/src/utils/EventUtil.ts +1 -1
  176. package/src/utils/FetchUtil.ts +38 -11
  177. package/src/utils/StorageUtil.ts +146 -157
  178. package/src/utils/SwapApiUtil.ts +18 -37
  179. package/src/utils/SwapCalculationUtil.ts +1 -2
  180. package/lib/commonjs/controllers/AccountController.js +0 -93
  181. package/lib/commonjs/controllers/AccountController.js.map +0 -1
  182. package/lib/commonjs/controllers/ConnectionController.js +0 -132
  183. package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
  184. package/lib/commonjs/controllers/ConnectorController.js +0 -50
  185. package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
  186. package/lib/commonjs/controllers/NetworkController.js +0 -90
  187. package/lib/commonjs/controllers/NetworkController.js.map +0 -1
  188. package/lib/commonjs/controllers/WebviewController.js +0 -52
  189. package/lib/commonjs/controllers/WebviewController.js.map +0 -1
  190. package/lib/commonjs/utils/NetworkUtil.js +0 -46
  191. package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
  192. package/lib/commonjs/utils/TypeUtil.js +0 -6
  193. package/lib/commonjs/utils/TypeUtil.js.map +0 -1
  194. package/lib/module/controllers/AccountController.js +0 -88
  195. package/lib/module/controllers/AccountController.js.map +0 -1
  196. package/lib/module/controllers/ConnectionController.js +0 -127
  197. package/lib/module/controllers/ConnectionController.js.map +0 -1
  198. package/lib/module/controllers/ConnectorController.js +0 -45
  199. package/lib/module/controllers/ConnectorController.js.map +0 -1
  200. package/lib/module/controllers/NetworkController.js +0 -85
  201. package/lib/module/controllers/NetworkController.js.map +0 -1
  202. package/lib/module/controllers/WebviewController.js +0 -47
  203. package/lib/module/controllers/WebviewController.js.map +0 -1
  204. package/lib/module/utils/NetworkUtil.js +0 -40
  205. package/lib/module/utils/NetworkUtil.js.map +0 -1
  206. package/lib/module/utils/TypeUtil.js +0 -2
  207. package/lib/module/utils/TypeUtil.js.map +0 -1
  208. package/lib/typescript/controllers/AccountController.d.ts +0 -33
  209. package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
  210. package/lib/typescript/controllers/ConnectionController.d.ts +0 -68
  211. package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
  212. package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
  213. package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
  214. package/lib/typescript/controllers/NetworkController.d.ts +0 -34
  215. package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
  216. package/lib/typescript/controllers/WebviewController.d.ts +0 -21
  217. package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
  218. package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
  219. package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
  220. package/lib/typescript/utils/TypeUtil.d.ts +0 -817
  221. package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
  222. package/src/controllers/AccountController.ts +0 -128
  223. package/src/controllers/ConnectionController.ts +0 -208
  224. package/src/controllers/ConnectorController.ts +0 -64
  225. package/src/controllers/NetworkController.ts +0 -120
  226. package/src/controllers/WebviewController.ts +0 -63
  227. package/src/utils/NetworkUtil.ts +0 -33
  228. package/src/utils/TypeUtil.ts +0 -995
@@ -1,5 +1,5 @@
1
1
  import { proxy, ref } from 'valtio';
2
- import { derive } from 'valtio/utils';
2
+ import { derive } from 'derive-valtio';
3
3
  import {
4
4
  EVMAdapter,
5
5
  type AppKitNetwork,
@@ -7,23 +7,20 @@ import {
7
7
  type CaipAddress,
8
8
  type CaipNetworkId,
9
9
  type ChainNamespace,
10
- type GetBalanceResponse,
11
- type WalletInfo
10
+ type Balance,
11
+ type WalletInfo,
12
+ type ConnectionProperties,
13
+ type AccountType,
14
+ type Connection,
15
+ SolanaBaseAdapter,
16
+ type Identity
12
17
  } from '@reown/appkit-common-react-native';
13
18
  import { StorageUtil } from '../utils/StorageUtil';
19
+ import { BlockchainApiController } from './BlockchainApiController';
20
+ import { SnackController } from './SnackController';
21
+ import { CoreHelperUtil } from '../utils/CoreHelperUtil';
14
22
 
15
23
  // -- 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
24
  export interface ConnectionsControllerState {
28
25
  activeNamespace?: ChainNamespace;
29
26
  connections: Map<ChainNamespace, Connection>;
@@ -37,59 +34,115 @@ const baseState = proxy<ConnectionsControllerState>({
37
34
  networks: []
38
35
  });
39
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
+
40
97
  const derivedState = derive(
41
98
  {
42
- activeAddress: (get): CaipAddress | undefined => {
99
+ isConnected: (get): boolean => {
43
100
  const snap = get(baseState);
44
101
 
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
- }
102
+ return !!snap.activeNamespace && !!snap.connections.size;
103
+ },
104
+ activeAddress: (get): CaipAddress | undefined => {
105
+ const snap = get(baseState);
106
+ const connection = getActiveConnection(snap);
54
107
 
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
- );
108
+ return connection ? getActiveAddress(connection) : undefined;
109
+ },
110
+ identity: (get): Identity | undefined => {
111
+ const snap = get(baseState);
112
+ const connection = getActiveConnection(snap);
59
113
 
60
- return activeAccount;
114
+ return connection ? getActiveIdentity(connection) : undefined;
61
115
  },
62
116
  activeBalance: (get): Balance | undefined => {
63
117
  const snap = get(baseState);
118
+ const connection = getActiveConnection(snap);
64
119
 
65
- if (!snap.activeNamespace) return undefined;
66
- const connection = snap.connections.get(snap.activeNamespace);
67
-
68
- if (!connection || !connection.accounts || connection.accounts.length === 0) {
120
+ if (!connection) {
69
121
  return undefined;
70
122
  }
71
123
 
72
- const activeAccount = connection.accounts.find(account =>
73
- account.startsWith(connection.caipNetwork)
74
- );
124
+ const activeAddress = getActiveAddress(connection);
125
+ if (!activeAddress || !connection.balances || connection.balances.size === 0) {
126
+ return undefined;
127
+ }
75
128
 
76
- if (
77
- !connection ||
78
- !connection.balances ||
79
- !activeAccount ||
80
- Object.keys(connection.balances).length === 0
81
- ) {
129
+ const addressBalances = connection.balances.get(activeAddress);
130
+ if (!addressBalances || addressBalances.length === 0) {
82
131
  return undefined;
83
132
  }
84
133
 
85
- return connection.balances[activeAccount];
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];
86
142
  },
87
143
  activeNetwork: (get): AppKitNetwork | undefined => {
88
144
  const snap = get(baseState);
89
-
90
- if (!snap.activeNamespace) return undefined;
91
-
92
- const connection = snap.connections.get(snap.activeNamespace);
145
+ const connection = getActiveConnection(snap);
93
146
 
94
147
  if (!connection) return undefined;
95
148
 
@@ -101,21 +154,46 @@ const derivedState = derive(
101
154
  },
102
155
  activeCaipNetworkId: (get): CaipNetworkId | undefined => {
103
156
  const snap = get(baseState);
157
+ const connection = getActiveConnection(snap);
104
158
 
105
- if (!snap.activeNamespace) return undefined;
159
+ return connection?.caipNetwork;
160
+ },
161
+ accountType: (get): AccountType | undefined => {
162
+ const snap = get(baseState);
163
+ const connection = getActiveConnection(snap);
106
164
 
107
- const connection = snap.connections.get(snap.activeNamespace);
165
+ return connection?.type;
166
+ },
167
+ connection: (get): Connection | undefined => {
168
+ const snap = get(baseState);
108
169
 
109
- if (!connection) return undefined;
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 [];
110
184
 
111
- return connection.caipNetwork;
185
+ return (
186
+ _connection?.balances
187
+ .get(_activeAddress)
188
+ // Filter out tokens with no quantity
189
+ ?.filter(balance => balance?.quantity?.numeric)
190
+ );
112
191
  },
113
192
  walletInfo: (get): WalletInfo | undefined => {
114
193
  const snap = get(baseState);
194
+ const connection = getActiveConnection(snap);
115
195
 
116
- if (!snap.activeNamespace) return undefined;
117
-
118
- return snap.connections.get(snap.activeNamespace)?.wallet;
196
+ return connection?.wallet;
119
197
  }
120
198
  },
121
199
  {
@@ -132,28 +210,35 @@ export const ConnectionsController = {
132
210
  StorageUtil.setActiveNamespace(namespace);
133
211
  },
134
212
 
135
- storeConnection({
136
- namespace,
137
- adapter,
213
+ setConnection({
138
214
  accounts,
139
- chains,
140
- wallet,
141
- caipNetwork
215
+ adapter,
216
+ caipNetwork,
217
+ namespace,
218
+ properties,
219
+ wallet
142
220
  }: {
143
- namespace: ChainNamespace;
144
- adapter: BlockchainAdapter;
145
221
  accounts: CaipAddress[];
146
- chains: CaipNetworkId[];
222
+ adapter: BlockchainAdapter;
223
+ caipNetwork: CaipNetworkId;
224
+ namespace: ChainNamespace;
225
+ properties?: ConnectionProperties;
147
226
  wallet?: WalletInfo;
148
- caipNetwork?: CaipNetworkId;
149
227
  }) {
150
- const newConnectionEntry = {
151
- balances: {},
152
- caipNetwork: caipNetwork ?? chains[0]!,
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,
153
237
  adapter: ref(adapter),
154
238
  accounts,
155
- chains,
156
- wallet
239
+ wallet,
240
+ properties,
241
+ type
157
242
  };
158
243
 
159
244
  // Create a new Map to ensure Valtio detects the change
@@ -177,14 +262,62 @@ export const ConnectionsController = {
177
262
  updateBalance(namespace: ChainNamespace, address: CaipAddress, balance: Balance) {
178
263
  const connection = baseState.connections.get(namespace);
179
264
  if (!connection) {
265
+ console.warn(`No connection found for namespace: ${namespace}`);
266
+
180
267
  return;
181
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
+ }
182
276
 
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;
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
+ }
188
321
  },
189
322
 
190
323
  setActiveNetwork(namespace: ChainNamespace, networkId: CaipNetworkId) {
@@ -213,6 +346,16 @@ export const ConnectionsController = {
213
346
  );
214
347
  },
215
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
+
216
359
  async disconnect(namespace: ChainNamespace, isInternal = true) {
217
360
  const connection = baseState.connections.get(namespace);
218
361
  if (!connection) return;
@@ -265,27 +408,114 @@ export const ConnectionsController = {
265
408
  ?.adapter.parseUnits(value, decimals);
266
409
  },
267
410
 
268
- async sendTransaction(args: any) {
411
+ async signMessage(address: CaipAddress, message: string) {
269
412
  if (!baseState.activeNamespace) return undefined;
270
413
 
414
+ const [namespace, chainId, plainAddress] = address.split(':');
415
+
416
+ if (!namespace || namespace !== baseState.activeNamespace || !chainId || !plainAddress) {
417
+ return undefined;
418
+ }
419
+
271
420
  const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
272
421
 
273
- if (adapter instanceof EVMAdapter) {
274
- return adapter.sendTransaction(args);
422
+ if (adapter instanceof EVMAdapter && plainAddress && chainId) {
423
+ return adapter.signMessage(plainAddress, message, chainId);
275
424
  }
276
425
 
277
426
  return undefined;
278
427
  },
279
428
 
280
- async estimateGas(args: any) {
429
+ async sendTransaction(args: any) {
281
430
  if (!baseState.activeNamespace) return undefined;
282
431
 
283
432
  const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
433
+ if (adapter instanceof EVMAdapter || adapter instanceof SolanaBaseAdapter) {
434
+ return adapter.sendTransaction(args);
435
+ }
284
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;
285
444
  if (adapter instanceof EVMAdapter) {
286
445
  return adapter.estimateGas(args);
287
446
  }
288
447
 
289
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
+ });
290
520
  }
291
521
  };
@@ -1,7 +1,7 @@
1
- import { subscribeKey as subKey } from 'valtio/vanilla/utils';
2
- import { proxy, subscribe as sub } from 'valtio/vanilla';
1
+ import { subscribeKey as subKey } from 'valtio/utils';
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
 
@@ -1,9 +1,9 @@
1
- import { proxy, subscribe as sub } from 'valtio/vanilla';
1
+ import { proxy, subscribe as sub } from 'valtio';
2
2
  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,11 +1,9 @@
1
1
  import { proxy } from 'valtio';
2
- import { AccountController } from './AccountController';
3
- import type { RouterControllerState } from './RouterController';
4
- import { RouterController } from './RouterController';
2
+ import { RouterController, type RouterControllerState } from './RouterController';
5
3
  import { PublicStateController } from './PublicStateController';
6
4
  import { EventsController } from './EventsController';
7
5
  import { ApiController } from './ApiController';
8
- import { ConnectorController } from './ConnectorController';
6
+ import { ConnectionsController } from './ConnectionsController';
9
7
 
10
8
  // -- Types --------------------------------------------- //
11
9
  export interface ModalControllerState {
@@ -31,11 +29,11 @@ export const ModalController = {
31
29
 
32
30
  async open(options?: ModalControllerArguments['open']) {
33
31
  await ApiController.state.prefetchPromise;
34
- const connected = AccountController.state.isConnected;
32
+ const isConnected = ConnectionsController.state.isConnected;
35
33
  if (options?.view) {
36
34
  RouterController.reset(options.view);
37
- } else if (AccountController.state.isConnected) {
38
- const isUniversalWallet = ConnectorController.state.connectedConnector === 'AUTH';
35
+ } else if (isConnected) {
36
+ const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
39
37
  RouterController.reset(isUniversalWallet ? 'Account' : 'AccountDefault');
40
38
  } else {
41
39
  RouterController.reset('Connect');
@@ -45,12 +43,12 @@ export const ModalController = {
45
43
  EventsController.sendEvent({
46
44
  type: 'track',
47
45
  event: 'MODAL_OPEN',
48
- properties: { connected }
46
+ properties: { connected: isConnected }
49
47
  });
50
48
  },
51
49
 
52
50
  close() {
53
- const connected = AccountController.state.isConnected;
51
+ const connected = ConnectionsController.state.isConnected;
54
52
  state.open = false;
55
53
  PublicStateController.set({ open: false });
56
54
  EventsController.sendEvent({