@reown/appkit-core-react-native 0.0.0-feat-multi-social-20250701185040 → 0.0.0-feat-multi-social-20250708154835
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.
- package/lib/commonjs/controllers/AccountController.js +20 -17
- package/lib/commonjs/controllers/AccountController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +8 -4
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +208 -46
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js +2 -2
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +20 -15
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +22 -54
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +19 -15
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +1 -16
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/AccountController.js +20 -17
- package/lib/module/controllers/AccountController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +8 -4
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +208 -46
- package/lib/module/controllers/ConnectionsController.js.map +1 -1
- package/lib/module/controllers/ModalController.js +2 -2
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +20 -15
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +22 -54
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +19 -15
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +1 -1
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +1 -16
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/typescript/controllers/AccountController.d.ts +3 -3
- package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +2 -2
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +16 -10
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +1 -1
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +2 -2
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/controllers/TransactionsController.d.ts +2 -2
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -3
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +15 -2
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/controllers/AccountController.ts +26 -26
- package/src/controllers/BlockchainApiController.ts +11 -5
- package/src/controllers/ConnectionController.ts +1 -1
- package/src/controllers/ConnectionsController.ts +251 -67
- package/src/controllers/ModalController.ts +2 -2
- package/src/controllers/RouterController.ts +0 -1
- package/src/controllers/SendController.ts +28 -15
- package/src/controllers/SwapController.ts +28 -66
- package/src/controllers/TransactionsController.ts +22 -16
- package/src/utils/CoreHelperUtil.ts +1 -1
- package/src/utils/SwapApiUtil.ts +4 -29
- package/src/utils/TypeUtil.ts +15 -2
|
@@ -7,23 +7,25 @@ import {
|
|
|
7
7
|
type CaipAddress,
|
|
8
8
|
type CaipNetworkId,
|
|
9
9
|
type ChainNamespace,
|
|
10
|
-
type
|
|
10
|
+
type Balance,
|
|
11
11
|
type WalletInfo,
|
|
12
|
-
type ConnectionProperties
|
|
12
|
+
type ConnectionProperties,
|
|
13
|
+
type AccountType
|
|
13
14
|
} from '@reown/appkit-common-react-native';
|
|
14
15
|
import { StorageUtil } from '../utils/StorageUtil';
|
|
16
|
+
import { BlockchainApiController } from './BlockchainApiController';
|
|
17
|
+
import { SnackController } from './SnackController';
|
|
18
|
+
import { OptionsController } from './OptionsController';
|
|
15
19
|
|
|
16
20
|
// -- Types --------------------------------------------- //
|
|
17
|
-
type Balance = GetBalanceResponse;
|
|
18
|
-
|
|
19
|
-
//TODO: balance could be elsewhere
|
|
20
21
|
interface Connection {
|
|
21
22
|
accounts: CaipAddress[];
|
|
22
|
-
balances:
|
|
23
|
+
balances: Map<CaipAddress, Balance[]>;
|
|
23
24
|
adapter: BlockchainAdapter;
|
|
24
25
|
caipNetwork: CaipNetworkId;
|
|
25
26
|
wallet?: WalletInfo;
|
|
26
27
|
properties?: ConnectionProperties;
|
|
28
|
+
type?: AccountType;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export interface ConnectionsControllerState {
|
|
@@ -39,59 +41,118 @@ const baseState = proxy<ConnectionsControllerState>({
|
|
|
39
41
|
networks: []
|
|
40
42
|
});
|
|
41
43
|
|
|
44
|
+
// -- Helper Functions --------------------------------------------- //
|
|
45
|
+
const getActiveConnection = (snap: ConnectionsControllerState): Connection | undefined => {
|
|
46
|
+
if (!snap.activeNamespace) return undefined;
|
|
47
|
+
|
|
48
|
+
return snap.connections.get(snap.activeNamespace);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const hasValidAccounts = (connection: Connection): boolean => {
|
|
52
|
+
return connection?.accounts && connection.accounts.length > 0;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const findSmartAccountForNetwork = (connection: Connection): CaipAddress | undefined => {
|
|
56
|
+
return connection.properties?.smartAccounts?.find(account =>
|
|
57
|
+
account.startsWith(connection.caipNetwork)
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const findEOAForNetwork = (connection: Connection): CaipAddress | undefined => {
|
|
62
|
+
const smartAccounts = connection.properties?.smartAccounts || [];
|
|
63
|
+
|
|
64
|
+
return connection.accounts.find(
|
|
65
|
+
account => account.startsWith(connection.caipNetwork) && !smartAccounts.includes(account)
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const getActiveAddress = (connection: Connection): CaipAddress | undefined => {
|
|
70
|
+
if (!hasValidAccounts(connection)) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// For smart accounts, prioritize smart account addresses
|
|
75
|
+
if (connection.type === 'smartAccount') {
|
|
76
|
+
const smartAccount = findSmartAccountForNetwork(connection);
|
|
77
|
+
if (smartAccount) {
|
|
78
|
+
return smartAccount;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Fall back to EOA or any account that matches the network
|
|
83
|
+
return findEOAForNetwork(connection);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const updateConnection = (
|
|
87
|
+
namespace: ChainNamespace,
|
|
88
|
+
connection: Connection,
|
|
89
|
+
updates: Partial<Connection>
|
|
90
|
+
) => {
|
|
91
|
+
if (!connection) return;
|
|
92
|
+
const newConnectionsMap = new Map(baseState.connections);
|
|
93
|
+
newConnectionsMap.set(namespace, { ...connection, ...updates });
|
|
94
|
+
baseState.connections = newConnectionsMap;
|
|
95
|
+
};
|
|
96
|
+
|
|
42
97
|
const derivedState = derive(
|
|
43
98
|
{
|
|
44
99
|
activeAddress: (get): CaipAddress | undefined => {
|
|
45
100
|
const snap = get(baseState);
|
|
101
|
+
const connection = getActiveConnection(snap);
|
|
46
102
|
|
|
47
|
-
|
|
103
|
+
return connection ? getActiveAddress(connection) : undefined;
|
|
104
|
+
},
|
|
105
|
+
activeBalance: (get): Balance | undefined => {
|
|
106
|
+
const snap = get(baseState);
|
|
107
|
+
const connection = getActiveConnection(snap);
|
|
108
|
+
|
|
109
|
+
if (!connection) {
|
|
48
110
|
return undefined;
|
|
49
111
|
}
|
|
50
112
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (!connection || !connection.accounts || connection.accounts.length === 0) {
|
|
113
|
+
const activeAddress = getActiveAddress(connection);
|
|
114
|
+
if (!activeAddress || !connection.balances || connection.balances.size === 0) {
|
|
54
115
|
return undefined;
|
|
55
116
|
}
|
|
56
117
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
account.startsWith(connection.caipNetwork)
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
return activeAccount;
|
|
63
|
-
},
|
|
64
|
-
activeBalance: (get): Balance | undefined => {
|
|
65
|
-
const snap = get(baseState);
|
|
66
|
-
|
|
67
|
-
if (!snap.activeNamespace) return undefined;
|
|
68
|
-
const connection = snap.connections.get(snap.activeNamespace);
|
|
69
|
-
|
|
70
|
-
if (!connection || !connection.accounts || connection.accounts.length === 0) {
|
|
118
|
+
const addressBalances = connection.balances.get(activeAddress);
|
|
119
|
+
if (!addressBalances || addressBalances.length === 0) {
|
|
71
120
|
return undefined;
|
|
72
121
|
}
|
|
73
122
|
|
|
74
|
-
|
|
75
|
-
|
|
123
|
+
// Check if there's a specific token configured in OptionsController
|
|
124
|
+
const configuredTokens = OptionsController.state.tokens;
|
|
125
|
+
const activeNetwork = snap.networks.find(
|
|
126
|
+
network =>
|
|
127
|
+
network.chainNamespace === snap.activeNamespace &&
|
|
128
|
+
network.id?.toString() === connection.caipNetwork?.split(':')[1]
|
|
76
129
|
);
|
|
77
130
|
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
131
|
+
if (configuredTokens && activeNetwork) {
|
|
132
|
+
const configuredToken = configuredTokens[activeNetwork.caipNetworkId];
|
|
133
|
+
if (configuredToken) {
|
|
134
|
+
// Find the configured token in the balances
|
|
135
|
+
const specificToken = addressBalances.find(
|
|
136
|
+
balance => balance.address === configuredToken.address
|
|
137
|
+
);
|
|
138
|
+
if (specificToken) {
|
|
139
|
+
return specificToken;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
85
142
|
}
|
|
86
143
|
|
|
87
|
-
|
|
144
|
+
// Return the native token (first balance without address)
|
|
145
|
+
const nativeToken = addressBalances.find(balance => !balance.address);
|
|
146
|
+
if (nativeToken) {
|
|
147
|
+
return nativeToken;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Fallback to first available balance
|
|
151
|
+
return addressBalances[0];
|
|
88
152
|
},
|
|
89
153
|
activeNetwork: (get): AppKitNetwork | undefined => {
|
|
90
154
|
const snap = get(baseState);
|
|
91
|
-
|
|
92
|
-
if (!snap.activeNamespace) return undefined;
|
|
93
|
-
|
|
94
|
-
const connection = snap.connections.get(snap.activeNamespace);
|
|
155
|
+
const connection = getActiveConnection(snap);
|
|
95
156
|
|
|
96
157
|
if (!connection) return undefined;
|
|
97
158
|
|
|
@@ -103,21 +164,41 @@ const derivedState = derive(
|
|
|
103
164
|
},
|
|
104
165
|
activeCaipNetworkId: (get): CaipNetworkId | undefined => {
|
|
105
166
|
const snap = get(baseState);
|
|
167
|
+
const connection = getActiveConnection(snap);
|
|
106
168
|
|
|
107
|
-
|
|
169
|
+
return connection?.caipNetwork;
|
|
170
|
+
},
|
|
171
|
+
accountType: (get): AccountType | undefined => {
|
|
172
|
+
const snap = get(baseState);
|
|
173
|
+
const connection = getActiveConnection(snap);
|
|
108
174
|
|
|
109
|
-
|
|
175
|
+
return connection?.type;
|
|
176
|
+
},
|
|
177
|
+
connection: (get): Connection | undefined => {
|
|
178
|
+
const snap = get(baseState);
|
|
110
179
|
|
|
111
|
-
|
|
180
|
+
return getActiveConnection(snap);
|
|
181
|
+
},
|
|
182
|
+
balances: (get): Balance[] | undefined => {
|
|
183
|
+
const snap = get(baseState);
|
|
184
|
+
|
|
185
|
+
const _connection = getActiveConnection(snap);
|
|
186
|
+
|
|
187
|
+
if (!_connection) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const _activeAddress = getActiveAddress(_connection);
|
|
192
|
+
|
|
193
|
+
if (!_activeAddress) return [];
|
|
112
194
|
|
|
113
|
-
return
|
|
195
|
+
return _connection?.balances.get(_activeAddress);
|
|
114
196
|
},
|
|
115
197
|
walletInfo: (get): WalletInfo | undefined => {
|
|
116
198
|
const snap = get(baseState);
|
|
199
|
+
const connection = getActiveConnection(snap);
|
|
117
200
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return snap.connections.get(snap.activeNamespace)?.wallet;
|
|
201
|
+
return connection?.wallet;
|
|
121
202
|
}
|
|
122
203
|
},
|
|
123
204
|
{
|
|
@@ -135,30 +216,34 @@ export const ConnectionsController = {
|
|
|
135
216
|
},
|
|
136
217
|
|
|
137
218
|
setConnection({
|
|
138
|
-
namespace,
|
|
139
|
-
adapter,
|
|
140
219
|
accounts,
|
|
141
|
-
|
|
142
|
-
wallet,
|
|
220
|
+
adapter,
|
|
143
221
|
caipNetwork,
|
|
144
|
-
|
|
222
|
+
namespace,
|
|
223
|
+
properties,
|
|
224
|
+
wallet
|
|
145
225
|
}: {
|
|
146
|
-
namespace: ChainNamespace;
|
|
147
|
-
adapter: BlockchainAdapter;
|
|
148
226
|
accounts: CaipAddress[];
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
227
|
+
adapter: BlockchainAdapter;
|
|
228
|
+
caipNetwork: CaipNetworkId;
|
|
229
|
+
namespace: ChainNamespace;
|
|
152
230
|
properties?: ConnectionProperties;
|
|
231
|
+
wallet?: WalletInfo;
|
|
153
232
|
}) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
233
|
+
const type: AccountType =
|
|
234
|
+
properties?.smartAccounts?.length &&
|
|
235
|
+
properties.smartAccounts.find(account => account.startsWith(caipNetwork))
|
|
236
|
+
? 'smartAccount'
|
|
237
|
+
: 'eoa';
|
|
238
|
+
|
|
239
|
+
const newConnectionEntry: Connection = {
|
|
240
|
+
balances: new Map<CaipAddress, Balance[]>(),
|
|
241
|
+
caipNetwork,
|
|
157
242
|
adapter: ref(adapter),
|
|
158
243
|
accounts,
|
|
159
|
-
chains,
|
|
160
244
|
wallet,
|
|
161
|
-
properties
|
|
245
|
+
properties,
|
|
246
|
+
type
|
|
162
247
|
};
|
|
163
248
|
|
|
164
249
|
// Create a new Map to ensure Valtio detects the change
|
|
@@ -182,14 +267,34 @@ export const ConnectionsController = {
|
|
|
182
267
|
updateBalance(namespace: ChainNamespace, address: CaipAddress, balance: Balance) {
|
|
183
268
|
const connection = baseState.connections.get(namespace);
|
|
184
269
|
if (!connection) {
|
|
270
|
+
console.warn(`No connection found for namespace: ${namespace}`);
|
|
271
|
+
|
|
185
272
|
return;
|
|
186
273
|
}
|
|
274
|
+
const newBalances = new Map(connection.balances);
|
|
275
|
+
const existingBalances = connection.balances.get(address) || [];
|
|
276
|
+
// Check if this token already exists by contract address or symbol
|
|
277
|
+
const existingIndex = existingBalances.findIndex(existingBalance => {
|
|
278
|
+
if (balance.address) {
|
|
279
|
+
return existingBalance.address === balance.address;
|
|
280
|
+
}
|
|
187
281
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
282
|
+
return existingBalance.symbol === balance.symbol;
|
|
283
|
+
});
|
|
284
|
+
let updatedBalances: Balance[];
|
|
285
|
+
if (existingIndex >= 0) {
|
|
286
|
+
// Update existing token
|
|
287
|
+
updatedBalances = [...existingBalances];
|
|
288
|
+
updatedBalances[existingIndex] = {
|
|
289
|
+
...updatedBalances[existingIndex],
|
|
290
|
+
...balance
|
|
291
|
+
};
|
|
292
|
+
} else {
|
|
293
|
+
// Add new token
|
|
294
|
+
updatedBalances = [...existingBalances, balance];
|
|
295
|
+
}
|
|
296
|
+
newBalances.set(address, updatedBalances);
|
|
297
|
+
updateConnection(namespace, connection, { balances: newBalances });
|
|
193
298
|
},
|
|
194
299
|
|
|
195
300
|
setActiveNetwork(namespace: ChainNamespace, networkId: CaipNetworkId) {
|
|
@@ -218,6 +323,16 @@ export const ConnectionsController = {
|
|
|
218
323
|
);
|
|
219
324
|
},
|
|
220
325
|
|
|
326
|
+
setAccountType(namespace: ChainNamespace, type: AccountType) {
|
|
327
|
+
const connection = baseState.connections.get(namespace);
|
|
328
|
+
if (!connection) return;
|
|
329
|
+
|
|
330
|
+
const newConnectionsMap = new Map(baseState.connections);
|
|
331
|
+
const newConnection = { ...connection, type };
|
|
332
|
+
newConnectionsMap.set(namespace, newConnection);
|
|
333
|
+
baseState.connections = newConnectionsMap;
|
|
334
|
+
},
|
|
335
|
+
|
|
221
336
|
async disconnect(namespace: ChainNamespace, isInternal = true) {
|
|
222
337
|
const connection = baseState.connections.get(namespace);
|
|
223
338
|
if (!connection) return;
|
|
@@ -292,7 +407,6 @@ export const ConnectionsController = {
|
|
|
292
407
|
if (!baseState.activeNamespace) return undefined;
|
|
293
408
|
|
|
294
409
|
const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
|
|
295
|
-
|
|
296
410
|
if (adapter instanceof EVMAdapter) {
|
|
297
411
|
return adapter.sendTransaction(args);
|
|
298
412
|
}
|
|
@@ -304,11 +418,81 @@ export const ConnectionsController = {
|
|
|
304
418
|
if (!baseState.activeNamespace || baseState.activeNamespace !== 'eip155') return undefined;
|
|
305
419
|
|
|
306
420
|
const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
|
|
307
|
-
|
|
308
421
|
if (adapter instanceof EVMAdapter) {
|
|
309
422
|
return adapter.estimateGas(args);
|
|
310
423
|
}
|
|
311
424
|
|
|
312
425
|
return undefined;
|
|
426
|
+
},
|
|
427
|
+
|
|
428
|
+
async writeContract(args: any) {
|
|
429
|
+
if (!baseState.activeNamespace) return undefined;
|
|
430
|
+
|
|
431
|
+
const adapter = baseState.connections.get(baseState.activeNamespace)?.adapter;
|
|
432
|
+
if (adapter instanceof EVMAdapter) {
|
|
433
|
+
return adapter.writeContract(args);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return undefined;
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
async fetchBalance(forceUpdateAddresses?: CaipAddress[]) {
|
|
440
|
+
const connection = getActiveConnection(baseState);
|
|
441
|
+
if (!connection) {
|
|
442
|
+
throw new Error('No active connection found for balance fetch');
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const chainId = connection.caipNetwork;
|
|
446
|
+
const address = getActiveAddress(connection);
|
|
447
|
+
const namespace = baseState.activeNamespace;
|
|
448
|
+
if (!namespace || !address || !chainId) {
|
|
449
|
+
throw new Error('Missing required data for balance fetch');
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
try {
|
|
453
|
+
const response = await BlockchainApiController.getBalance(address, forceUpdateAddresses);
|
|
454
|
+
if (!response) {
|
|
455
|
+
throw new Error('Failed to fetch token balance');
|
|
456
|
+
}
|
|
457
|
+
// Update balances for each token in the response
|
|
458
|
+
response.balances.forEach(balance => {
|
|
459
|
+
this.updateBalance(namespace, address, {
|
|
460
|
+
name: balance.name,
|
|
461
|
+
symbol: balance.symbol,
|
|
462
|
+
amount: balance.quantity.numeric,
|
|
463
|
+
address: balance.address,
|
|
464
|
+
quantity: balance.quantity,
|
|
465
|
+
price: balance.price,
|
|
466
|
+
value: balance.value,
|
|
467
|
+
iconUrl: balance.iconUrl
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
} catch (error) {
|
|
471
|
+
SnackController.showError('Failed to get account balance');
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
|
|
475
|
+
getSmartAccountEnabledNetworks(): AppKitNetwork[] {
|
|
476
|
+
const activeConnection = getActiveConnection(baseState);
|
|
477
|
+
if (!activeConnection) {
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
if (!activeConnection.properties?.smartAccounts?.length) {
|
|
481
|
+
return [];
|
|
482
|
+
}
|
|
483
|
+
const smartAccountNetworks = new Set<CaipNetworkId>();
|
|
484
|
+
activeConnection.properties.smartAccounts.forEach(smartAccount => {
|
|
485
|
+
const parts = smartAccount.split(':');
|
|
486
|
+
if (parts.length >= 2) {
|
|
487
|
+
const networkId: CaipNetworkId = `${parts[0]}:${parts[1]}`;
|
|
488
|
+
smartAccountNetworks.add(networkId);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
return baseState.networks.filter(network => {
|
|
493
|
+
const networkId: CaipNetworkId = `${network.chainNamespace}:${network.id}`;
|
|
494
|
+
|
|
495
|
+
return smartAccountNetworks.has(networkId);
|
|
496
|
+
});
|
|
313
497
|
}
|
|
314
498
|
};
|
|
@@ -5,7 +5,7 @@ import { RouterController } from './RouterController';
|
|
|
5
5
|
import { PublicStateController } from './PublicStateController';
|
|
6
6
|
import { EventsController } from './EventsController';
|
|
7
7
|
import { ApiController } from './ApiController';
|
|
8
|
-
import {
|
|
8
|
+
import { ConnectionsController } from './ConnectionsController';
|
|
9
9
|
|
|
10
10
|
// -- Types --------------------------------------------- //
|
|
11
11
|
export interface ModalControllerState {
|
|
@@ -35,7 +35,7 @@ export const ModalController = {
|
|
|
35
35
|
if (options?.view) {
|
|
36
36
|
RouterController.reset(options.view);
|
|
37
37
|
} else if (AccountController.state.isConnected) {
|
|
38
|
-
const isUniversalWallet =
|
|
38
|
+
const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
|
|
39
39
|
RouterController.reset(isUniversalWallet ? 'Account' : 'AccountDefault');
|
|
40
40
|
} else {
|
|
41
41
|
RouterController.reset('Connect');
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { subscribeKey as subKey } from 'valtio/vanilla/utils';
|
|
2
2
|
import { proxy, ref, subscribe as sub } from 'valtio/vanilla';
|
|
3
3
|
import { ContractUtil, type Balance } from '@reown/appkit-common-react-native';
|
|
4
|
-
|
|
5
|
-
import { ConnectionController } from './ConnectionController';
|
|
4
|
+
|
|
6
5
|
import { SnackController } from './SnackController';
|
|
7
6
|
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
8
7
|
import { EventsController } from './EventsController';
|
|
@@ -97,7 +96,7 @@ export const SendController = {
|
|
|
97
96
|
type: 'track',
|
|
98
97
|
event: 'SEND_INITIATED',
|
|
99
98
|
properties: {
|
|
100
|
-
isSmartAccount:
|
|
99
|
+
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
|
|
101
100
|
token: this.state.token.address,
|
|
102
101
|
amount: this.state.sendTokenAmount,
|
|
103
102
|
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
@@ -107,20 +106,20 @@ export const SendController = {
|
|
|
107
106
|
receiverAddress: this.state.receiverAddress,
|
|
108
107
|
tokenAddress: this.state.token.address,
|
|
109
108
|
sendTokenAmount: this.state.sendTokenAmount,
|
|
110
|
-
decimals: this.state.token.quantity
|
|
109
|
+
decimals: this.state.token.quantity?.decimals || '0'
|
|
111
110
|
});
|
|
112
111
|
} else if (
|
|
113
112
|
this.state.receiverAddress &&
|
|
114
113
|
this.state.sendTokenAmount &&
|
|
115
114
|
this.state.gasPrice &&
|
|
116
|
-
this.state.token?.quantity
|
|
115
|
+
this.state.token?.quantity?.decimals
|
|
117
116
|
) {
|
|
118
117
|
state.loading = true;
|
|
119
118
|
EventsController.sendEvent({
|
|
120
119
|
type: 'track',
|
|
121
120
|
event: 'SEND_INITIATED',
|
|
122
121
|
properties: {
|
|
123
|
-
isSmartAccount:
|
|
122
|
+
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
|
|
124
123
|
token: this.state.token?.symbol,
|
|
125
124
|
amount: this.state.sendTokenAmount,
|
|
126
125
|
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
@@ -142,15 +141,21 @@ export const SendController = {
|
|
|
142
141
|
});
|
|
143
142
|
|
|
144
143
|
const to = params.receiverAddress as `0x${string}`;
|
|
145
|
-
const address =
|
|
146
|
-
|
|
144
|
+
const address = CoreHelperUtil.getPlainAddress(
|
|
145
|
+
ConnectionsController.state.activeAddress
|
|
146
|
+
) as `0x${string}`;
|
|
147
|
+
if (!address) {
|
|
148
|
+
throw new Error('Invalid address');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const value = ConnectionsController.parseUnits(
|
|
147
152
|
params.sendTokenAmount.toString(),
|
|
148
153
|
Number(params.decimals)
|
|
149
154
|
);
|
|
150
155
|
const data = '0x';
|
|
151
156
|
|
|
152
157
|
try {
|
|
153
|
-
await
|
|
158
|
+
await ConnectionsController.sendTransaction({
|
|
154
159
|
to,
|
|
155
160
|
address,
|
|
156
161
|
data,
|
|
@@ -162,7 +167,7 @@ export const SendController = {
|
|
|
162
167
|
type: 'track',
|
|
163
168
|
event: 'SEND_SUCCESS',
|
|
164
169
|
properties: {
|
|
165
|
-
isSmartAccount:
|
|
170
|
+
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
|
|
166
171
|
token: this.state.token?.symbol || '',
|
|
167
172
|
amount: params.sendTokenAmount,
|
|
168
173
|
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
@@ -175,7 +180,7 @@ export const SendController = {
|
|
|
175
180
|
type: 'track',
|
|
176
181
|
event: 'SEND_ERROR',
|
|
177
182
|
properties: {
|
|
178
|
-
isSmartAccount:
|
|
183
|
+
isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
|
|
179
184
|
token: this.state.token?.symbol || '',
|
|
180
185
|
amount: params.sendTokenAmount,
|
|
181
186
|
network: ConnectionsController.state.activeNetwork?.caipNetworkId || ''
|
|
@@ -191,14 +196,14 @@ export const SendController = {
|
|
|
191
196
|
goBack: false
|
|
192
197
|
});
|
|
193
198
|
|
|
194
|
-
const amount =
|
|
199
|
+
const amount = ConnectionsController.parseUnits(
|
|
195
200
|
params.sendTokenAmount.toString(),
|
|
196
201
|
Number(params.decimals)
|
|
197
202
|
);
|
|
198
203
|
|
|
199
204
|
try {
|
|
200
205
|
if (
|
|
201
|
-
|
|
206
|
+
ConnectionsController.state.activeAddress &&
|
|
202
207
|
params.sendTokenAmount &&
|
|
203
208
|
params.receiverAddress &&
|
|
204
209
|
params.tokenAddress
|
|
@@ -206,8 +211,16 @@ export const SendController = {
|
|
|
206
211
|
const tokenAddress = CoreHelperUtil.getPlainAddress(
|
|
207
212
|
params.tokenAddress as `${string}:${string}:${string}`
|
|
208
213
|
) as `0x${string}`;
|
|
209
|
-
|
|
210
|
-
|
|
214
|
+
|
|
215
|
+
const fromAddress = CoreHelperUtil.getPlainAddress(
|
|
216
|
+
ConnectionsController.state.activeAddress
|
|
217
|
+
) as `0x${string}`;
|
|
218
|
+
if (!fromAddress) {
|
|
219
|
+
throw new Error('Invalid address');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
await ConnectionsController.writeContract({
|
|
223
|
+
fromAddress,
|
|
211
224
|
tokenAddress,
|
|
212
225
|
receiverAddress: params.receiverAddress as `0x${string}`,
|
|
213
226
|
tokenAmount: amount,
|