@reown/appkit-react-native 0.0.0-feat-multichain-20250520183003 → 0.0.0-feat-multichain-phantom-20250606183519
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/AppKit.js +86 -40
- package/lib/commonjs/AppKit.js.map +1 -1
- package/lib/commonjs/client.js +0 -4
- package/lib/commonjs/client.js.map +1 -1
- package/lib/commonjs/connectors/WalletConnectConnector.js +34 -22
- package/lib/commonjs/connectors/WalletConnectConnector.js.map +1 -1
- package/lib/commonjs/hooks/useAccount.js +2 -2
- package/lib/commonjs/hooks/useAccount.js.map +1 -1
- package/lib/commonjs/hooks/useProvider.js +3 -2
- package/lib/commonjs/hooks/useProvider.js.map +1 -1
- package/lib/commonjs/index.js +37 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-account-activity/index.js +2 -3
- package/lib/commonjs/partials/w3m-account-activity/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-account-wallet-features/index.js +15 -16
- package/lib/commonjs/partials/w3m-account-wallet-features/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-send-input-token/index.js +1 -1
- package/lib/commonjs/partials/w3m-send-input-token/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-swap-details/index.js +1 -1
- package/lib/commonjs/partials/w3m-swap-details/index.js.map +1 -1
- package/lib/commonjs/partials/w3m-swap-input/index.js +1 -1
- package/lib/commonjs/utils/HelpersUtil.js +5 -9
- package/lib/commonjs/utils/HelpersUtil.js.map +1 -1
- package/lib/commonjs/utils/UiUtil.js +5 -4
- package/lib/commonjs/utils/UiUtil.js.map +1 -1
- package/lib/commonjs/views/w3m-account-default-view/index.js +14 -17
- package/lib/commonjs/views/w3m-account-default-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-connect-view/index.js +1 -0
- package/lib/commonjs/views/w3m-connect-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-connecting-view/index.js +10 -4
- package/lib/commonjs/views/w3m-connecting-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-swap-preview-view/index.js +3 -3
- package/lib/commonjs/views/w3m-swap-preview-view/index.js.map +1 -1
- package/lib/commonjs/views/w3m-swap-view/index.js +7 -2
- package/lib/commonjs/views/w3m-swap-view/index.js.map +1 -1
- package/lib/module/AppKit.js +87 -40
- package/lib/module/AppKit.js.map +1 -1
- package/lib/module/client.js +0 -4
- package/lib/module/client.js.map +1 -1
- package/lib/module/connectors/WalletConnectConnector.js +34 -22
- package/lib/module/connectors/WalletConnectConnector.js.map +1 -1
- package/lib/module/hooks/useAccount.js +2 -2
- package/lib/module/hooks/useAccount.js.map +1 -1
- package/lib/module/hooks/useProvider.js +3 -2
- package/lib/module/hooks/useProvider.js.map +1 -1
- package/lib/module/index.js +4 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/partials/w3m-account-activity/index.js +3 -4
- package/lib/module/partials/w3m-account-activity/index.js.map +1 -1
- package/lib/module/partials/w3m-account-wallet-features/index.js +16 -17
- package/lib/module/partials/w3m-account-wallet-features/index.js.map +1 -1
- package/lib/module/partials/w3m-send-input-token/index.js +1 -1
- package/lib/module/partials/w3m-send-input-token/index.js.map +1 -1
- package/lib/module/partials/w3m-swap-details/index.js +2 -2
- package/lib/module/partials/w3m-swap-details/index.js.map +1 -1
- package/lib/module/partials/w3m-swap-input/index.js +1 -1
- package/lib/module/utils/HelpersUtil.js +1 -5
- package/lib/module/utils/HelpersUtil.js.map +1 -1
- package/lib/module/utils/UiUtil.js +5 -4
- package/lib/module/utils/UiUtil.js.map +1 -1
- package/lib/module/views/w3m-account-default-view/index.js +14 -17
- package/lib/module/views/w3m-account-default-view/index.js.map +1 -1
- package/lib/module/views/w3m-connect-view/index.js +1 -0
- package/lib/module/views/w3m-connect-view/index.js.map +1 -1
- package/lib/module/views/w3m-connecting-view/index.js +10 -4
- package/lib/module/views/w3m-connecting-view/index.js.map +1 -1
- package/lib/module/views/w3m-swap-preview-view/index.js +3 -3
- package/lib/module/views/w3m-swap-preview-view/index.js.map +1 -1
- package/lib/module/views/w3m-swap-view/index.js +8 -3
- package/lib/module/views/w3m-swap-view/index.js.map +1 -1
- package/lib/typescript/AppKit.d.ts +8 -4
- package/lib/typescript/AppKit.d.ts.map +1 -1
- package/lib/typescript/AppKitContext.d.ts +1 -1
- package/lib/typescript/client.d.ts.map +1 -1
- package/lib/typescript/connectors/WalletConnectConnector.d.ts +11 -13
- package/lib/typescript/connectors/WalletConnectConnector.d.ts.map +1 -1
- package/lib/typescript/hooks/useProvider.d.ts +1 -1
- package/lib/typescript/hooks/useProvider.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/partials/w3m-account-activity/index.d.ts.map +1 -1
- package/lib/typescript/partials/w3m-account-wallet-features/index.d.ts.map +1 -1
- package/lib/typescript/partials/w3m-swap-details/index.d.ts.map +1 -1
- package/lib/typescript/utils/HelpersUtil.d.ts.map +1 -1
- package/lib/typescript/utils/UiUtil.d.ts +1 -2
- package/lib/typescript/utils/UiUtil.d.ts.map +1 -1
- package/lib/typescript/views/w3m-account-default-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-connect-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-connecting-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-swap-preview-view/index.d.ts.map +1 -1
- package/lib/typescript/views/w3m-swap-view/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/AppKit.ts +105 -44
- package/src/client.ts +0 -5
- package/src/connectors/WalletConnectConnector.ts +53 -31
- package/src/hooks/useAccount.ts +2 -2
- package/src/hooks/useProvider.ts +5 -3
- package/src/index.ts +7 -1
- package/src/partials/w3m-account-activity/index.tsx +5 -2
- package/src/partials/w3m-account-wallet-features/index.tsx +17 -20
- package/src/partials/w3m-send-input-token/index.tsx +1 -1
- package/src/partials/w3m-swap-details/index.tsx +6 -2
- package/src/partials/w3m-swap-input/index.tsx +1 -1
- package/src/utils/HelpersUtil.ts +1 -5
- package/src/utils/UiUtil.ts +5 -11
- package/src/views/w3m-account-default-view/index.tsx +22 -20
- package/src/views/w3m-connect-view/index.tsx +1 -0
- package/src/views/w3m-connecting-view/index.tsx +10 -4
- package/src/views/w3m-swap-preview-view/index.tsx +6 -3
- package/src/views/w3m-swap-view/index.tsx +9 -5
- package/lib/commonjs/networks/bitcoin.js +0 -40
- package/lib/commonjs/networks/bitcoin.js.map +0 -1
- package/lib/commonjs/networks/index.js +0 -28
- package/lib/commonjs/networks/index.js.map +0 -1
- package/lib/commonjs/networks/solana.js +0 -78
- package/lib/commonjs/networks/solana.js.map +0 -1
- package/lib/module/networks/bitcoin.js +0 -34
- package/lib/module/networks/bitcoin.js.map +0 -1
- package/lib/module/networks/index.js +0 -6
- package/lib/module/networks/index.js.map +0 -1
- package/lib/module/networks/solana.js +0 -72
- package/lib/module/networks/solana.js.map +0 -1
- package/lib/typescript/networks/bitcoin.d.ts +0 -4
- package/lib/typescript/networks/bitcoin.d.ts.map +0 -1
- package/lib/typescript/networks/index.d.ts +0 -4
- package/lib/typescript/networks/index.d.ts.map +0 -1
- package/lib/typescript/networks/solana.d.ts +0 -5
- package/lib/typescript/networks/solana.d.ts.map +0 -1
- package/src/networks/bitcoin.ts +0 -32
- package/src/networks/index.ts +0 -6
- package/src/networks/solana.ts +0 -44
package/src/AppKit.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type Features,
|
|
2
3
|
AccountController,
|
|
3
4
|
EventsController,
|
|
4
5
|
ModalController,
|
|
@@ -6,7 +7,6 @@ import {
|
|
|
6
7
|
OptionsController,
|
|
7
8
|
RouterController,
|
|
8
9
|
TransactionsController,
|
|
9
|
-
type Metadata,
|
|
10
10
|
StorageUtil,
|
|
11
11
|
type OptionsControllerState,
|
|
12
12
|
ThemeController,
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
ProposalNamespaces,
|
|
20
20
|
New_ConnectorType,
|
|
21
21
|
Namespaces,
|
|
22
|
+
Metadata,
|
|
22
23
|
CaipNetworkId,
|
|
23
24
|
AppKitNetwork,
|
|
24
25
|
Provider,
|
|
@@ -26,7 +27,9 @@ import type {
|
|
|
26
27
|
ThemeMode,
|
|
27
28
|
WalletInfo,
|
|
28
29
|
Network,
|
|
29
|
-
ChainNamespace
|
|
30
|
+
ChainNamespace,
|
|
31
|
+
ConnectOptions,
|
|
32
|
+
Storage
|
|
30
33
|
} from '@reown/appkit-common-react-native';
|
|
31
34
|
|
|
32
35
|
import { WalletConnectConnector } from './connectors/WalletConnectConnector';
|
|
@@ -40,6 +43,7 @@ interface AppKitConfig {
|
|
|
40
43
|
metadata: Metadata;
|
|
41
44
|
adapters: BlockchainAdapter[];
|
|
42
45
|
networks: Network[];
|
|
46
|
+
storage: Storage;
|
|
43
47
|
extraConnectors?: WalletConnector[];
|
|
44
48
|
clipboardClient?: OptionsControllerState['clipboardClient'];
|
|
45
49
|
includeWalletIds?: OptionsControllerState['includeWalletIds'];
|
|
@@ -53,7 +57,7 @@ interface AppKitConfig {
|
|
|
53
57
|
themeVariables?: ThemeVariables;
|
|
54
58
|
siweConfig?: AppKitSIWEClient;
|
|
55
59
|
defaultNetwork?: Network;
|
|
56
|
-
|
|
60
|
+
features?: Features;
|
|
57
61
|
// chainImages?: Record<number, string>; //TODO: rename to networkImages
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -102,18 +106,17 @@ export class AppKit {
|
|
|
102
106
|
/**
|
|
103
107
|
* Handles the full connection flow for a given connector type.
|
|
104
108
|
* @param type - The type of connector to use.
|
|
105
|
-
* @param
|
|
109
|
+
* @param options - Optional connection options.
|
|
106
110
|
*/
|
|
107
|
-
async connect(type: New_ConnectorType,
|
|
111
|
+
async connect(type: New_ConnectorType, options?: ConnectOptions): Promise<void> {
|
|
108
112
|
try {
|
|
113
|
+
const { namespaces, defaultChain, universalLink } = options ?? {};
|
|
109
114
|
const connector = await this.createConnector(type);
|
|
110
|
-
const defaultChain = this.defaultNetwork
|
|
111
|
-
? NetworkUtil.getDefaultChainId(this.defaultNetwork)
|
|
112
|
-
: undefined;
|
|
113
115
|
|
|
114
116
|
const approvedNamespaces = await connector.connect({
|
|
115
|
-
namespaces:
|
|
116
|
-
defaultChain
|
|
117
|
+
namespaces: namespaces ?? this.namespaces,
|
|
118
|
+
defaultChain,
|
|
119
|
+
universalLink
|
|
117
120
|
});
|
|
118
121
|
|
|
119
122
|
const walletInfo = connector.getWalletInfo();
|
|
@@ -166,10 +169,12 @@ export class AppKit {
|
|
|
166
169
|
return;
|
|
167
170
|
}
|
|
168
171
|
|
|
169
|
-
const connection = ConnectionsController.state.connections
|
|
172
|
+
const connection = ConnectionsController.state.connections.get(
|
|
173
|
+
activeNamespace as ChainNamespace
|
|
174
|
+
);
|
|
170
175
|
const connectorType = connection?.adapter?.connector?.type;
|
|
171
176
|
|
|
172
|
-
await ConnectionsController.disconnect(activeNamespace, isInternal);
|
|
177
|
+
await ConnectionsController.disconnect(activeNamespace as ChainNamespace, isInternal);
|
|
173
178
|
|
|
174
179
|
if (connectorType) {
|
|
175
180
|
await StorageUtil.removeConnectedConnectors(connectorType);
|
|
@@ -203,7 +208,9 @@ export class AppKit {
|
|
|
203
208
|
const activeNamespace = namespace ?? ConnectionsController.state.activeNamespace;
|
|
204
209
|
if (!activeNamespace) return null;
|
|
205
210
|
|
|
206
|
-
const connection = ConnectionsController.state.connections
|
|
211
|
+
const connection = ConnectionsController.state.connections.get(
|
|
212
|
+
activeNamespace as ChainNamespace
|
|
213
|
+
);
|
|
207
214
|
if (!connection || !connection.adapter || !connection.adapter.connector) return null;
|
|
208
215
|
|
|
209
216
|
return connection.adapter.connector.getProvider() as T;
|
|
@@ -227,7 +234,7 @@ export class AppKit {
|
|
|
227
234
|
}
|
|
228
235
|
});
|
|
229
236
|
|
|
230
|
-
ConnectionsController.
|
|
237
|
+
ConnectionsController.setActiveNetwork(
|
|
231
238
|
adapter.getSupportedNamespace(),
|
|
232
239
|
`${adapter.getSupportedNamespace()}:${network.id}` as CaipNetworkId
|
|
233
240
|
);
|
|
@@ -248,15 +255,28 @@ export class AppKit {
|
|
|
248
255
|
private async createConnector(type: New_ConnectorType): Promise<WalletConnector> {
|
|
249
256
|
// Check if an extra connector was provided by the developer
|
|
250
257
|
const CustomConnector = this.extraConnectors.find(
|
|
251
|
-
connector => connector.
|
|
258
|
+
connector => connector.type.toLowerCase() === type.toLowerCase()
|
|
252
259
|
);
|
|
253
260
|
|
|
254
261
|
if (CustomConnector) {
|
|
262
|
+
await CustomConnector.init({
|
|
263
|
+
storage: OptionsController.state.storage!,
|
|
264
|
+
metadata: this.metadata
|
|
265
|
+
});
|
|
266
|
+
|
|
255
267
|
return CustomConnector;
|
|
256
268
|
}
|
|
257
269
|
|
|
258
270
|
// Default to WalletConnectConnector if no custom connector matches
|
|
259
|
-
|
|
271
|
+
const walletConnectConnector = new WalletConnectConnector({
|
|
272
|
+
projectId: this.projectId
|
|
273
|
+
});
|
|
274
|
+
await walletConnectConnector.init({
|
|
275
|
+
storage: OptionsController.state.storage!,
|
|
276
|
+
metadata: this.metadata
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
return walletConnectConnector;
|
|
260
280
|
}
|
|
261
281
|
|
|
262
282
|
//TODO: reuse logic with connect method
|
|
@@ -327,28 +347,36 @@ export class AppKit {
|
|
|
327
347
|
}
|
|
328
348
|
|
|
329
349
|
private getAdapterByNamespace(namespace: ChainNamespace): BlockchainAdapter | null {
|
|
330
|
-
const namespaceConnection = ConnectionsController.state.connections
|
|
350
|
+
const namespaceConnection = ConnectionsController.state.connections.get(namespace);
|
|
351
|
+
if (namespaceConnection) {
|
|
352
|
+
return namespaceConnection.adapter;
|
|
353
|
+
}
|
|
331
354
|
|
|
332
|
-
return
|
|
355
|
+
return null;
|
|
333
356
|
}
|
|
334
357
|
|
|
335
358
|
private async syncAccounts(adapters: BlockchainAdapter[]) {
|
|
336
|
-
|
|
337
|
-
adapters.map(adapter => {
|
|
359
|
+
adapters.forEach(async adapter => {
|
|
338
360
|
const namespace = adapter.getSupportedNamespace();
|
|
339
|
-
const connection = ConnectionsController.state.connections
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
361
|
+
const connection = ConnectionsController.state.connections.get(namespace);
|
|
362
|
+
if (connection) {
|
|
363
|
+
const accounts = adapter.getAccounts();
|
|
364
|
+
if (accounts && accounts.length > 0) {
|
|
365
|
+
ConnectionsController.updateAccounts(namespace, accounts);
|
|
366
|
+
|
|
367
|
+
const network = this.networks.find(
|
|
368
|
+
n => n.id?.toString() === connection?.caipNetwork?.split(':')[1]
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
const address = accounts.find(
|
|
372
|
+
a => a.split(':')[1] === connection.caipNetwork?.split(':')[1]
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
if (address) {
|
|
376
|
+
adapter.getBalance({ address, network, tokens: this.config.tokens });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
352
380
|
});
|
|
353
381
|
}
|
|
354
382
|
|
|
@@ -364,14 +392,14 @@ export class AppKit {
|
|
|
364
392
|
|
|
365
393
|
const accounts = namespaceDetails.accounts ?? [];
|
|
366
394
|
const chains = namespaceDetails.chains ?? [];
|
|
367
|
-
const
|
|
395
|
+
const caipNetwork = adapter?.connector?.getChainId(namespace);
|
|
368
396
|
|
|
369
397
|
ConnectionsController.storeConnection({
|
|
370
398
|
namespace,
|
|
371
399
|
adapter,
|
|
372
400
|
accounts,
|
|
373
401
|
chains,
|
|
374
|
-
|
|
402
|
+
caipNetwork,
|
|
375
403
|
wallet
|
|
376
404
|
});
|
|
377
405
|
});
|
|
@@ -387,15 +415,17 @@ export class AppKit {
|
|
|
387
415
|
}
|
|
388
416
|
|
|
389
417
|
private subscribeToAdapterEvents(adapter: BlockchainAdapter): void {
|
|
390
|
-
adapter.on('accountsChanged', ({ accounts
|
|
418
|
+
adapter.on('accountsChanged', ({ accounts }) => {
|
|
419
|
+
const namespace = adapter.getSupportedNamespace();
|
|
391
420
|
//eslint-disable-next-line no-console
|
|
392
421
|
console.log('accountsChanged', accounts, namespace);
|
|
393
422
|
//TODO: check this
|
|
394
423
|
});
|
|
395
424
|
|
|
396
|
-
adapter.on('chainChanged', ({ chainId
|
|
425
|
+
adapter.on('chainChanged', ({ chainId }) => {
|
|
426
|
+
const namespace = adapter.getSupportedNamespace();
|
|
397
427
|
const chain = `${namespace}:${chainId}` as CaipNetworkId;
|
|
398
|
-
ConnectionsController.
|
|
428
|
+
ConnectionsController.setActiveNetwork(namespace, chain);
|
|
399
429
|
|
|
400
430
|
const network = this.networks.find(n => n.id?.toString() === chainId);
|
|
401
431
|
if (network) {
|
|
@@ -406,18 +436,19 @@ export class AppKit {
|
|
|
406
436
|
}
|
|
407
437
|
});
|
|
408
438
|
|
|
409
|
-
adapter.on('disconnect', (
|
|
410
|
-
|
|
439
|
+
adapter.on('disconnect', () => {
|
|
440
|
+
const namespace = adapter.getSupportedNamespace();
|
|
411
441
|
this.disconnect(namespace, false);
|
|
412
442
|
});
|
|
413
443
|
|
|
414
|
-
adapter.on('balanceChanged', ({
|
|
444
|
+
adapter.on('balanceChanged', ({ address, balance }) => {
|
|
445
|
+
const namespace = adapter.getSupportedNamespace();
|
|
415
446
|
ConnectionsController.updateBalance(namespace, address, balance);
|
|
416
447
|
});
|
|
417
448
|
}
|
|
418
449
|
|
|
419
450
|
private async initControllers(options: AppKitConfig) {
|
|
420
|
-
await this.initAsyncValues();
|
|
451
|
+
await this.initAsyncValues(options);
|
|
421
452
|
|
|
422
453
|
OptionsController.setProjectId(options.projectId);
|
|
423
454
|
OptionsController.setMetadata(options.metadata);
|
|
@@ -428,7 +459,8 @@ export class AppKit {
|
|
|
428
459
|
OptionsController.setCustomWallets(options.customWallets);
|
|
429
460
|
OptionsController.setEnableAnalytics(options.enableAnalytics);
|
|
430
461
|
OptionsController.setDebug(options.debug);
|
|
431
|
-
|
|
462
|
+
OptionsController.setFeatures(options.features);
|
|
463
|
+
OptionsController.setStorage(options.storage);
|
|
432
464
|
|
|
433
465
|
ThemeController.setThemeMode(options.themeMode);
|
|
434
466
|
ThemeController.setThemeVariables(options.themeVariables);
|
|
@@ -454,7 +486,7 @@ export class AppKit {
|
|
|
454
486
|
// }
|
|
455
487
|
}
|
|
456
488
|
|
|
457
|
-
private async
|
|
489
|
+
private async initActiveNamespace() {
|
|
458
490
|
const activeNamespace = await StorageUtil.getActiveNamespace();
|
|
459
491
|
if (activeNamespace) {
|
|
460
492
|
ConnectionsController.setActiveNamespace(activeNamespace);
|
|
@@ -462,6 +494,35 @@ export class AppKit {
|
|
|
462
494
|
ConnectionsController.setActiveNamespace(this.defaultNetwork?.chainNamespace);
|
|
463
495
|
}
|
|
464
496
|
}
|
|
497
|
+
|
|
498
|
+
private async initRecentWallets(options: AppKitConfig) {
|
|
499
|
+
const wallets = await StorageUtil.getRecentWallets();
|
|
500
|
+
const connectedWalletImage = await StorageUtil.getConnectedWalletImageUrl();
|
|
501
|
+
|
|
502
|
+
const filteredWallets = wallets.filter(wallet => {
|
|
503
|
+
const { includeWalletIds, excludeWalletIds } = options;
|
|
504
|
+
if (includeWalletIds) {
|
|
505
|
+
return includeWalletIds.includes(wallet.id);
|
|
506
|
+
}
|
|
507
|
+
if (excludeWalletIds) {
|
|
508
|
+
return !excludeWalletIds.includes(wallet.id);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return true;
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
ConnectionController.setRecentWallets(filteredWallets);
|
|
515
|
+
|
|
516
|
+
if (connectedWalletImage) {
|
|
517
|
+
ConnectionController.setConnectedWalletImageUrl(connectedWalletImage);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private async initAsyncValues(options: AppKitConfig) {
|
|
522
|
+
await this.initActiveNamespace();
|
|
523
|
+
await this.initRecentWallets(options);
|
|
524
|
+
//disable coinbase if connector is not set
|
|
525
|
+
}
|
|
465
526
|
}
|
|
466
527
|
|
|
467
528
|
export function createAppKit(config: AppKitConfig): AppKit {
|
package/src/client.ts
CHANGED
|
@@ -343,7 +343,6 @@ export class AppKitScaffold {
|
|
|
343
343
|
|
|
344
344
|
private async initRecentWallets(options: ScaffoldOptions) {
|
|
345
345
|
const wallets = await StorageUtil.getRecentWallets();
|
|
346
|
-
const connectedWalletImage = await StorageUtil.getConnectedWalletImageUrl();
|
|
347
346
|
|
|
348
347
|
const filteredWallets = wallets.filter(wallet => {
|
|
349
348
|
const { includeWalletIds, excludeWalletIds } = options;
|
|
@@ -358,10 +357,6 @@ export class AppKitScaffold {
|
|
|
358
357
|
});
|
|
359
358
|
|
|
360
359
|
ConnectionController.setRecentWallets(filteredWallets);
|
|
361
|
-
|
|
362
|
-
if (connectedWalletImage) {
|
|
363
|
-
ConnectionController.setConnectedWalletImageUrl(connectedWalletImage);
|
|
364
|
-
}
|
|
365
360
|
}
|
|
366
361
|
|
|
367
362
|
private async initConnectedConnector() {
|
|
@@ -1,21 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConnectionController } from '@reown/appkit-core-react-native';
|
|
2
2
|
import { UniversalProvider, type IUniversalProvider } from '@walletconnect/universal-provider';
|
|
3
3
|
import {
|
|
4
4
|
WalletConnector,
|
|
5
5
|
type AppKitNetwork,
|
|
6
6
|
type Namespaces,
|
|
7
|
-
type ProposalNamespaces,
|
|
8
7
|
type Provider,
|
|
9
8
|
type WalletInfo,
|
|
10
9
|
type ChainNamespace,
|
|
11
|
-
type CaipNetworkId
|
|
10
|
+
type CaipNetworkId,
|
|
11
|
+
type ConnectOptions,
|
|
12
|
+
type ConnectorInitOptions,
|
|
13
|
+
type Metadata
|
|
12
14
|
} from '@reown/appkit-common-react-native';
|
|
13
15
|
|
|
16
|
+
interface WalletConnectConnectorConfig {
|
|
17
|
+
projectId: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
export class WalletConnectConnector extends WalletConnector {
|
|
15
|
-
private
|
|
21
|
+
private readonly config: WalletConnectConnectorConfig;
|
|
22
|
+
|
|
23
|
+
constructor(config: WalletConnectConnectorConfig) {
|
|
24
|
+
super({ type: 'walletconnect' });
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override async init(ops: ConnectorInitOptions) {
|
|
29
|
+
super.init(ops);
|
|
30
|
+
|
|
31
|
+
const provider = await this.getUniversalProvider({
|
|
32
|
+
projectId: this.config.projectId,
|
|
33
|
+
metadata: ops.metadata
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
this.provider = provider as Provider;
|
|
37
|
+
|
|
38
|
+
await this.restoreSession();
|
|
39
|
+
}
|
|
16
40
|
|
|
17
|
-
private
|
|
18
|
-
|
|
41
|
+
private async restoreSession(): Promise<boolean> {
|
|
42
|
+
const provider = this.getProvider() as IUniversalProvider;
|
|
43
|
+
if (!provider) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
19
46
|
|
|
20
47
|
if (provider.session?.namespaces) {
|
|
21
48
|
this.namespaces = provider.session.namespaces as Namespaces;
|
|
@@ -31,50 +58,41 @@ export class WalletConnectConnector extends WalletConnector {
|
|
|
31
58
|
};
|
|
32
59
|
}
|
|
33
60
|
}
|
|
61
|
+
|
|
62
|
+
return true;
|
|
34
63
|
}
|
|
35
64
|
|
|
36
|
-
private
|
|
65
|
+
private async getUniversalProvider({
|
|
37
66
|
projectId,
|
|
38
67
|
metadata
|
|
39
68
|
}: {
|
|
40
69
|
projectId: string;
|
|
41
70
|
metadata: Metadata;
|
|
42
71
|
}): Promise<IUniversalProvider> {
|
|
43
|
-
if (!
|
|
44
|
-
|
|
72
|
+
if (!this.provider) {
|
|
73
|
+
this.provider = (await UniversalProvider.init({
|
|
45
74
|
projectId,
|
|
46
|
-
metadata
|
|
47
|
-
|
|
75
|
+
metadata,
|
|
76
|
+
storage: this.storage
|
|
77
|
+
})) as Provider;
|
|
48
78
|
}
|
|
49
79
|
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public static async create({
|
|
54
|
-
projectId,
|
|
55
|
-
metadata
|
|
56
|
-
}: {
|
|
57
|
-
projectId: string;
|
|
58
|
-
metadata: Metadata;
|
|
59
|
-
}): Promise<WalletConnectConnector> {
|
|
60
|
-
const provider = await WalletConnectConnector.getUniversalProvider({
|
|
61
|
-
projectId,
|
|
62
|
-
metadata
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return new WalletConnectConnector(provider);
|
|
80
|
+
return this.provider as IUniversalProvider;
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
override disconnect(): Promise<void> {
|
|
69
|
-
return this.
|
|
84
|
+
return this.getProvider().disconnect();
|
|
70
85
|
}
|
|
71
86
|
|
|
72
|
-
override async connect(opts:
|
|
87
|
+
override async connect(opts: ConnectOptions) {
|
|
73
88
|
function onUri(uri: string) {
|
|
74
89
|
ConnectionController.setWcUri(uri);
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
this.
|
|
92
|
+
const provider = this.getProvider() as IUniversalProvider;
|
|
93
|
+
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
provider.on('display_uri', onUri);
|
|
78
96
|
|
|
79
97
|
const session = await (this.provider as IUniversalProvider).connect({
|
|
80
98
|
namespaces: {},
|
|
@@ -87,12 +105,16 @@ export class WalletConnectConnector extends WalletConnector {
|
|
|
87
105
|
|
|
88
106
|
this.namespaces = session?.namespaces as Namespaces;
|
|
89
107
|
|
|
90
|
-
|
|
108
|
+
provider.off('display_uri', onUri);
|
|
91
109
|
|
|
92
110
|
return this.namespaces;
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
override getProvider(): Provider {
|
|
114
|
+
if (!this.provider) {
|
|
115
|
+
throw new Error('WalletConnectConnector: Provider not initialized. Call init() first.');
|
|
116
|
+
}
|
|
117
|
+
|
|
96
118
|
return this.provider;
|
|
97
119
|
}
|
|
98
120
|
|
package/src/hooks/useAccount.ts
CHANGED
|
@@ -11,11 +11,11 @@ export function useAccount() {
|
|
|
11
11
|
connections
|
|
12
12
|
} = useSnapshot(ConnectionsController.state);
|
|
13
13
|
|
|
14
|
-
const connection = activeNamespace ? connections
|
|
14
|
+
const connection = activeNamespace ? connections.get(activeNamespace) : undefined;
|
|
15
15
|
|
|
16
16
|
return {
|
|
17
17
|
address: address?.split(':')[2],
|
|
18
18
|
isConnected: !!address,
|
|
19
|
-
chainId: connection?.
|
|
19
|
+
chainId: connection?.caipNetwork
|
|
20
20
|
};
|
|
21
21
|
}
|
package/src/hooks/useProvider.ts
CHANGED
|
@@ -7,12 +7,14 @@ interface ProviderResult {
|
|
|
7
7
|
providerType?: ChainNamespace;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function useProvider(namespace?:
|
|
10
|
+
export function useProvider(namespace?: ChainNamespace): ProviderResult {
|
|
11
11
|
const { connections, activeNamespace } = useSnapshot(ConnectionsController.state);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const targetNamespace = namespace ?? activeNamespace;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
if (!targetNamespace) return { provider: undefined, providerType: undefined };
|
|
16
|
+
|
|
17
|
+
const connection = connections.get(targetNamespace);
|
|
16
18
|
|
|
17
19
|
if (!connection) return { provider: undefined, providerType: undefined };
|
|
18
20
|
|
package/src/index.ts
CHANGED
|
@@ -21,8 +21,10 @@ export type * from '@reown/appkit-core-react-native';
|
|
|
21
21
|
export { CoreHelperUtil } from '@reown/appkit-core-react-native';
|
|
22
22
|
|
|
23
23
|
export * from './AppKit';
|
|
24
|
-
export * from './networks';
|
|
25
24
|
export { AppKitProvider } from './AppKitContext';
|
|
25
|
+
|
|
26
|
+
export type { AppKitNetwork, Storage } from '@reown/appkit-common-react-native';
|
|
27
|
+
|
|
26
28
|
export { WalletConnectConnector } from './connectors/WalletConnectConnector';
|
|
27
29
|
|
|
28
30
|
/****** Hooks *******/
|
|
@@ -31,3 +33,7 @@ export { useProvider } from './hooks/useProvider';
|
|
|
31
33
|
export { useAccount } from './hooks/useAccount';
|
|
32
34
|
export { useWalletInfo } from './hooks/useWalletInfo';
|
|
33
35
|
export { useAppKitEvents, useAppKitEventSubscription } from './hooks/useAppKitEvents';
|
|
36
|
+
|
|
37
|
+
/********** Networks **********/
|
|
38
|
+
export { solana, solanaDevnet, solanaTestnet } from '@reown/appkit-common-react-native';
|
|
39
|
+
export { bitcoin, bitcoinTestnet } from '@reown/appkit-common-react-native';
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
AccountController,
|
|
16
16
|
AssetUtil,
|
|
17
17
|
ConnectionsController,
|
|
18
|
+
ConstantsUtil,
|
|
18
19
|
EventsController,
|
|
19
20
|
OptionsController,
|
|
20
21
|
TransactionsController
|
|
@@ -32,9 +33,11 @@ export function AccountActivity({ style }: Props) {
|
|
|
32
33
|
const [refreshing, setRefreshing] = useState(false);
|
|
33
34
|
const [initialLoad, setInitialLoad] = useState(true);
|
|
34
35
|
const { loading, transactions, next } = useSnapshot(TransactionsController.state);
|
|
35
|
-
const { activeNetwork
|
|
36
|
+
const { activeNetwork } = useSnapshot(ConnectionsController.state);
|
|
36
37
|
const networkImage = AssetUtil.getNetworkImage(activeNetwork?.id);
|
|
37
|
-
const isSupported =
|
|
38
|
+
const isSupported =
|
|
39
|
+
activeNetwork?.caipNetworkId &&
|
|
40
|
+
ConstantsUtil.ACTIVITY_SUPPORTED_CHAINS.includes(activeNetwork.caipNetworkId);
|
|
38
41
|
|
|
39
42
|
const handleLoadMore = () => {
|
|
40
43
|
const address = ConnectionsController.state.activeAddress?.split(':')[2];
|
|
@@ -3,10 +3,10 @@ import { useSnapshot } from 'valtio';
|
|
|
3
3
|
import { Balance, FlexView, IconLink, Tabs } from '@reown/appkit-ui-react-native';
|
|
4
4
|
import {
|
|
5
5
|
AccountController,
|
|
6
|
+
ConnectionsController,
|
|
6
7
|
ConstantsUtil,
|
|
7
8
|
CoreHelperUtil,
|
|
8
9
|
EventsController,
|
|
9
|
-
NetworkController,
|
|
10
10
|
OnRampController,
|
|
11
11
|
OptionsController,
|
|
12
12
|
RouterController,
|
|
@@ -25,8 +25,12 @@ export function AccountWalletFeatures() {
|
|
|
25
25
|
const [activeTab, setActiveTab] = useState(0);
|
|
26
26
|
const { tokenBalance } = useSnapshot(AccountController.state);
|
|
27
27
|
const { features, isOnRampEnabled } = useSnapshot(OptionsController.state);
|
|
28
|
+
const { activeNetwork } = useSnapshot(ConnectionsController.state);
|
|
28
29
|
const balance = CoreHelperUtil.calculateAndFormatBalance(tokenBalance as BalanceType[]);
|
|
29
|
-
const isSwapsEnabled =
|
|
30
|
+
const isSwapsEnabled =
|
|
31
|
+
features?.swaps &&
|
|
32
|
+
activeNetwork?.caipNetworkId &&
|
|
33
|
+
ConstantsUtil.SWAP_SUPPORTED_NETWORKS.includes(activeNetwork.caipNetworkId);
|
|
30
34
|
|
|
31
35
|
const onTabChange = (index: number) => {
|
|
32
36
|
setActiveTab(index);
|
|
@@ -46,23 +50,16 @@ export function AccountWalletFeatures() {
|
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
const onSwapPress = () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
properties: {
|
|
60
|
-
network: NetworkController.state.caipNetwork?.id || '',
|
|
61
|
-
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
RouterController.push('Swap');
|
|
65
|
-
}
|
|
53
|
+
SwapController.resetState();
|
|
54
|
+
EventsController.sendEvent({
|
|
55
|
+
type: 'track',
|
|
56
|
+
event: 'OPEN_SWAP',
|
|
57
|
+
properties: {
|
|
58
|
+
network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
|
|
59
|
+
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
RouterController.push('Swap');
|
|
66
63
|
};
|
|
67
64
|
|
|
68
65
|
const onSendPress = () => {
|
|
@@ -70,7 +67,7 @@ export function AccountWalletFeatures() {
|
|
|
70
67
|
type: 'track',
|
|
71
68
|
event: 'OPEN_SEND',
|
|
72
69
|
properties: {
|
|
73
|
-
network:
|
|
70
|
+
network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
|
|
74
71
|
isSmartAccount: AccountController.state.preferredAccountType === 'smartAccount'
|
|
75
72
|
}
|
|
76
73
|
});
|
|
@@ -43,7 +43,7 @@ export function SendInputToken({
|
|
|
43
43
|
const isNetworkToken =
|
|
44
44
|
token.address === undefined ||
|
|
45
45
|
Object.values(ConstantsUtil.NATIVE_TOKEN_ADDRESS).some(
|
|
46
|
-
nativeAddress => token?.address === nativeAddress
|
|
46
|
+
nativeAddress => token?.address?.split(':')[2] === nativeAddress
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
const numericGas = NumberUtil.bigNumber(gasPrice).shiftedBy(-token.quantity.decimals);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useSnapshot } from 'valtio';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ConnectionsController,
|
|
5
|
+
ConstantsUtil,
|
|
6
|
+
SwapController
|
|
7
|
+
} from '@reown/appkit-core-react-native';
|
|
4
8
|
import {
|
|
5
9
|
FlexView,
|
|
6
10
|
Text,
|
|
@@ -80,7 +84,7 @@ export function SwapDetails({ initialOpen, canClose }: SwapDetailsProps) {
|
|
|
80
84
|
setModalData(
|
|
81
85
|
getModalData('networkCost', {
|
|
82
86
|
networkSymbol: SwapController.state.networkTokenSymbol,
|
|
83
|
-
networkName:
|
|
87
|
+
networkName: ConnectionsController.state.activeNetwork?.name
|
|
84
88
|
})
|
|
85
89
|
);
|
|
86
90
|
};
|
|
@@ -128,7 +128,7 @@ export function SwapInput({
|
|
|
128
128
|
>
|
|
129
129
|
<Text variant="small-400" color="fg-200" numberOfLines={1}>
|
|
130
130
|
{isMarketValueGreaterThanZero
|
|
131
|
-
? `~$${UiUtil.formatNumberToLocalString(marketValue,
|
|
131
|
+
? `~$${UiUtil.formatNumberToLocalString(marketValue, 6)}`
|
|
132
132
|
: ''}
|
|
133
133
|
</Text>
|
|
134
134
|
{showMax && (
|
package/src/utils/HelpersUtil.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { Namespace, NamespaceConfig } from '@walletconnect/universal-provider';
|
|
2
|
-
|
|
3
2
|
import type {
|
|
4
3
|
AppKitNetwork,
|
|
5
4
|
CaipNetworkId,
|
|
6
5
|
ChainNamespace
|
|
7
6
|
} from '@reown/appkit-common-react-native';
|
|
8
|
-
import { solana, solanaDevnet } from '
|
|
9
|
-
// import { EnsController, type OptionsControllerState } from '@reown/appkit-controllers'
|
|
10
|
-
|
|
11
|
-
// import { solana, solanaDevnet } from '../networks/index.js'
|
|
7
|
+
import { solana, solanaDevnet } from '@reown/appkit-common-react-native';
|
|
12
8
|
|
|
13
9
|
export const DEFAULT_METHODS = {
|
|
14
10
|
solana: [
|