@reown/appkit-react-native 2.0.0-alpha.0 → 2.0.0
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 +87 -42
- 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 +88 -42
- 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 -5
- 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 -46
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-account-default-view/index.tsx"],"names":[],"mappings":"AAuCA,wBAAgB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-account-default-view/index.tsx"],"names":[],"mappings":"AAuCA,wBAAgB,kBAAkB,4CAySjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-connect-view/index.tsx"],"names":[],"mappings":"AAyBA,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-connect-view/index.tsx"],"names":[],"mappings":"AAyBA,wBAAgB,WAAW,4CAoH1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-connecting-view/index.tsx"],"names":[],"mappings":"AAuBA,wBAAgB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-connecting-view/index.tsx"],"names":[],"mappings":"AAuBA,wBAAgB,cAAc,4CA8I7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-swap-preview-view/index.tsx"],"names":[],"mappings":"AAmBA,wBAAgB,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-swap-preview-view/index.tsx"],"names":[],"mappings":"AAmBA,wBAAgB,eAAe,4CAgI9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-swap-view/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/w3m-swap-view/index.tsx"],"names":[],"mappings":"AAqBA,wBAAgB,QAAQ,4CA+LvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reown/appkit-react-native",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"types": "lib/typescript/index.d.ts",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@reown/appkit-common-react-native": "2.0.0
|
|
41
|
-
"@reown/appkit-core-react-native": "2.0.0
|
|
42
|
-
"@reown/appkit-siwe-react-native": "2.
|
|
43
|
-
"@reown/appkit-ui-react-native": "2.0.0
|
|
40
|
+
"@reown/appkit-common-react-native": "2.0.0",
|
|
41
|
+
"@reown/appkit-core-react-native": "2.0.0",
|
|
42
|
+
"@reown/appkit-siwe-react-native": "1.2.4",
|
|
43
|
+
"@reown/appkit-ui-react-native": "2.0.0",
|
|
44
44
|
"@walletconnect/universal-provider": "2.20.2",
|
|
45
45
|
"valtio": "^1.13.2"
|
|
46
46
|
},
|
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,13 +57,12 @@ 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
|
|
|
60
64
|
export class AppKit {
|
|
61
65
|
private projectId: string;
|
|
62
|
-
private metadata: Metadata;
|
|
63
66
|
private adapters: BlockchainAdapter[];
|
|
64
67
|
private networks: AppKitNetwork[];
|
|
65
68
|
private defaultNetwork?: AppKitNetwork;
|
|
@@ -69,7 +72,6 @@ export class AppKit {
|
|
|
69
72
|
|
|
70
73
|
constructor(config: AppKitConfig) {
|
|
71
74
|
this.projectId = config.projectId;
|
|
72
|
-
this.metadata = config.metadata;
|
|
73
75
|
this.adapters = config.adapters;
|
|
74
76
|
|
|
75
77
|
// Validate adapters to ensure no duplicate chainNamespaces
|
|
@@ -102,18 +104,17 @@ export class AppKit {
|
|
|
102
104
|
/**
|
|
103
105
|
* Handles the full connection flow for a given connector type.
|
|
104
106
|
* @param type - The type of connector to use.
|
|
105
|
-
* @param
|
|
107
|
+
* @param options - Optional connection options.
|
|
106
108
|
*/
|
|
107
|
-
async connect(type: New_ConnectorType,
|
|
109
|
+
async connect(type: New_ConnectorType, options?: ConnectOptions): Promise<void> {
|
|
108
110
|
try {
|
|
111
|
+
const { namespaces, defaultChain, universalLink } = options ?? {};
|
|
109
112
|
const connector = await this.createConnector(type);
|
|
110
|
-
const defaultChain = this.defaultNetwork
|
|
111
|
-
? NetworkUtil.getDefaultChainId(this.defaultNetwork)
|
|
112
|
-
: undefined;
|
|
113
113
|
|
|
114
114
|
const approvedNamespaces = await connector.connect({
|
|
115
|
-
namespaces:
|
|
116
|
-
defaultChain
|
|
115
|
+
namespaces: namespaces ?? this.namespaces,
|
|
116
|
+
defaultChain,
|
|
117
|
+
universalLink
|
|
117
118
|
});
|
|
118
119
|
|
|
119
120
|
const walletInfo = connector.getWalletInfo();
|
|
@@ -166,10 +167,12 @@ export class AppKit {
|
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
const connection = ConnectionsController.state.connections
|
|
170
|
+
const connection = ConnectionsController.state.connections.get(
|
|
171
|
+
activeNamespace as ChainNamespace
|
|
172
|
+
);
|
|
170
173
|
const connectorType = connection?.adapter?.connector?.type;
|
|
171
174
|
|
|
172
|
-
await ConnectionsController.disconnect(activeNamespace, isInternal);
|
|
175
|
+
await ConnectionsController.disconnect(activeNamespace as ChainNamespace, isInternal);
|
|
173
176
|
|
|
174
177
|
if (connectorType) {
|
|
175
178
|
await StorageUtil.removeConnectedConnectors(connectorType);
|
|
@@ -203,7 +206,9 @@ export class AppKit {
|
|
|
203
206
|
const activeNamespace = namespace ?? ConnectionsController.state.activeNamespace;
|
|
204
207
|
if (!activeNamespace) return null;
|
|
205
208
|
|
|
206
|
-
const connection = ConnectionsController.state.connections
|
|
209
|
+
const connection = ConnectionsController.state.connections.get(
|
|
210
|
+
activeNamespace as ChainNamespace
|
|
211
|
+
);
|
|
207
212
|
if (!connection || !connection.adapter || !connection.adapter.connector) return null;
|
|
208
213
|
|
|
209
214
|
return connection.adapter.connector.getProvider() as T;
|
|
@@ -227,7 +232,7 @@ export class AppKit {
|
|
|
227
232
|
}
|
|
228
233
|
});
|
|
229
234
|
|
|
230
|
-
ConnectionsController.
|
|
235
|
+
ConnectionsController.setActiveNetwork(
|
|
231
236
|
adapter.getSupportedNamespace(),
|
|
232
237
|
`${adapter.getSupportedNamespace()}:${network.id}` as CaipNetworkId
|
|
233
238
|
);
|
|
@@ -248,15 +253,28 @@ export class AppKit {
|
|
|
248
253
|
private async createConnector(type: New_ConnectorType): Promise<WalletConnector> {
|
|
249
254
|
// Check if an extra connector was provided by the developer
|
|
250
255
|
const CustomConnector = this.extraConnectors.find(
|
|
251
|
-
connector => connector.
|
|
256
|
+
connector => connector.type.toLowerCase() === type.toLowerCase()
|
|
252
257
|
);
|
|
253
258
|
|
|
254
259
|
if (CustomConnector) {
|
|
260
|
+
await CustomConnector.init({
|
|
261
|
+
storage: this.config.storage,
|
|
262
|
+
metadata: this.config.metadata
|
|
263
|
+
});
|
|
264
|
+
|
|
255
265
|
return CustomConnector;
|
|
256
266
|
}
|
|
257
267
|
|
|
258
268
|
// Default to WalletConnectConnector if no custom connector matches
|
|
259
|
-
|
|
269
|
+
const walletConnectConnector = new WalletConnectConnector({
|
|
270
|
+
projectId: this.projectId
|
|
271
|
+
});
|
|
272
|
+
await walletConnectConnector.init({
|
|
273
|
+
storage: this.config.storage,
|
|
274
|
+
metadata: this.config.metadata
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
return walletConnectConnector;
|
|
260
278
|
}
|
|
261
279
|
|
|
262
280
|
//TODO: reuse logic with connect method
|
|
@@ -327,28 +345,36 @@ export class AppKit {
|
|
|
327
345
|
}
|
|
328
346
|
|
|
329
347
|
private getAdapterByNamespace(namespace: ChainNamespace): BlockchainAdapter | null {
|
|
330
|
-
const namespaceConnection = ConnectionsController.state.connections
|
|
348
|
+
const namespaceConnection = ConnectionsController.state.connections.get(namespace);
|
|
349
|
+
if (namespaceConnection) {
|
|
350
|
+
return namespaceConnection.adapter;
|
|
351
|
+
}
|
|
331
352
|
|
|
332
|
-
return
|
|
353
|
+
return null;
|
|
333
354
|
}
|
|
334
355
|
|
|
335
356
|
private async syncAccounts(adapters: BlockchainAdapter[]) {
|
|
336
|
-
|
|
337
|
-
adapters.map(adapter => {
|
|
357
|
+
adapters.forEach(async adapter => {
|
|
338
358
|
const namespace = adapter.getSupportedNamespace();
|
|
339
|
-
const connection = ConnectionsController.state.connections
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
359
|
+
const connection = ConnectionsController.state.connections.get(namespace);
|
|
360
|
+
if (connection) {
|
|
361
|
+
const accounts = adapter.getAccounts();
|
|
362
|
+
if (accounts && accounts.length > 0) {
|
|
363
|
+
ConnectionsController.updateAccounts(namespace, accounts);
|
|
364
|
+
|
|
365
|
+
const network = this.networks.find(
|
|
366
|
+
n => n.id?.toString() === connection?.caipNetwork?.split(':')[1]
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
const address = accounts.find(
|
|
370
|
+
a => a.split(':')[1] === connection.caipNetwork?.split(':')[1]
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
if (address) {
|
|
374
|
+
adapter.getBalance({ address, network, tokens: this.config.tokens });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
352
378
|
});
|
|
353
379
|
}
|
|
354
380
|
|
|
@@ -364,14 +390,14 @@ export class AppKit {
|
|
|
364
390
|
|
|
365
391
|
const accounts = namespaceDetails.accounts ?? [];
|
|
366
392
|
const chains = namespaceDetails.chains ?? [];
|
|
367
|
-
const
|
|
393
|
+
const caipNetwork = adapter?.connector?.getChainId(namespace);
|
|
368
394
|
|
|
369
395
|
ConnectionsController.storeConnection({
|
|
370
396
|
namespace,
|
|
371
397
|
adapter,
|
|
372
398
|
accounts,
|
|
373
399
|
chains,
|
|
374
|
-
|
|
400
|
+
caipNetwork,
|
|
375
401
|
wallet
|
|
376
402
|
});
|
|
377
403
|
});
|
|
@@ -387,15 +413,17 @@ export class AppKit {
|
|
|
387
413
|
}
|
|
388
414
|
|
|
389
415
|
private subscribeToAdapterEvents(adapter: BlockchainAdapter): void {
|
|
390
|
-
adapter.on('accountsChanged', ({ accounts
|
|
416
|
+
adapter.on('accountsChanged', ({ accounts }) => {
|
|
417
|
+
const namespace = adapter.getSupportedNamespace();
|
|
391
418
|
//eslint-disable-next-line no-console
|
|
392
419
|
console.log('accountsChanged', accounts, namespace);
|
|
393
420
|
//TODO: check this
|
|
394
421
|
});
|
|
395
422
|
|
|
396
|
-
adapter.on('chainChanged', ({ chainId
|
|
423
|
+
adapter.on('chainChanged', ({ chainId }) => {
|
|
424
|
+
const namespace = adapter.getSupportedNamespace();
|
|
397
425
|
const chain = `${namespace}:${chainId}` as CaipNetworkId;
|
|
398
|
-
ConnectionsController.
|
|
426
|
+
ConnectionsController.setActiveNetwork(namespace, chain);
|
|
399
427
|
|
|
400
428
|
const network = this.networks.find(n => n.id?.toString() === chainId);
|
|
401
429
|
if (network) {
|
|
@@ -406,18 +434,19 @@ export class AppKit {
|
|
|
406
434
|
}
|
|
407
435
|
});
|
|
408
436
|
|
|
409
|
-
adapter.on('disconnect', (
|
|
410
|
-
|
|
437
|
+
adapter.on('disconnect', () => {
|
|
438
|
+
const namespace = adapter.getSupportedNamespace();
|
|
411
439
|
this.disconnect(namespace, false);
|
|
412
440
|
});
|
|
413
441
|
|
|
414
|
-
adapter.on('balanceChanged', ({
|
|
442
|
+
adapter.on('balanceChanged', ({ address, balance }) => {
|
|
443
|
+
const namespace = adapter.getSupportedNamespace();
|
|
415
444
|
ConnectionsController.updateBalance(namespace, address, balance);
|
|
416
445
|
});
|
|
417
446
|
}
|
|
418
447
|
|
|
419
448
|
private async initControllers(options: AppKitConfig) {
|
|
420
|
-
await this.initAsyncValues();
|
|
449
|
+
await this.initAsyncValues(options);
|
|
421
450
|
|
|
422
451
|
OptionsController.setProjectId(options.projectId);
|
|
423
452
|
OptionsController.setMetadata(options.metadata);
|
|
@@ -428,7 +457,8 @@ export class AppKit {
|
|
|
428
457
|
OptionsController.setCustomWallets(options.customWallets);
|
|
429
458
|
OptionsController.setEnableAnalytics(options.enableAnalytics);
|
|
430
459
|
OptionsController.setDebug(options.debug);
|
|
431
|
-
|
|
460
|
+
OptionsController.setFeatures(options.features);
|
|
461
|
+
OptionsController.setStorage(options.storage);
|
|
432
462
|
|
|
433
463
|
ThemeController.setThemeMode(options.themeMode);
|
|
434
464
|
ThemeController.setThemeVariables(options.themeVariables);
|
|
@@ -454,7 +484,7 @@ export class AppKit {
|
|
|
454
484
|
// }
|
|
455
485
|
}
|
|
456
486
|
|
|
457
|
-
private async
|
|
487
|
+
private async initActiveNamespace() {
|
|
458
488
|
const activeNamespace = await StorageUtil.getActiveNamespace();
|
|
459
489
|
if (activeNamespace) {
|
|
460
490
|
ConnectionsController.setActiveNamespace(activeNamespace);
|
|
@@ -462,6 +492,35 @@ export class AppKit {
|
|
|
462
492
|
ConnectionsController.setActiveNamespace(this.defaultNetwork?.chainNamespace);
|
|
463
493
|
}
|
|
464
494
|
}
|
|
495
|
+
|
|
496
|
+
private async initRecentWallets(options: AppKitConfig) {
|
|
497
|
+
const wallets = await StorageUtil.getRecentWallets();
|
|
498
|
+
const connectedWalletImage = await StorageUtil.getConnectedWalletImageUrl();
|
|
499
|
+
|
|
500
|
+
const filteredWallets = wallets.filter(wallet => {
|
|
501
|
+
const { includeWalletIds, excludeWalletIds } = options;
|
|
502
|
+
if (includeWalletIds) {
|
|
503
|
+
return includeWalletIds.includes(wallet.id);
|
|
504
|
+
}
|
|
505
|
+
if (excludeWalletIds) {
|
|
506
|
+
return !excludeWalletIds.includes(wallet.id);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return true;
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
ConnectionController.setRecentWallets(filteredWallets);
|
|
513
|
+
|
|
514
|
+
if (connectedWalletImage) {
|
|
515
|
+
ConnectionController.setConnectedWalletImageUrl(connectedWalletImage);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
private async initAsyncValues(options: AppKitConfig) {
|
|
520
|
+
await this.initActiveNamespace();
|
|
521
|
+
await this.initRecentWallets(options);
|
|
522
|
+
//disable coinbase if connector is not set
|
|
523
|
+
}
|
|
465
524
|
}
|
|
466
525
|
|
|
467
526
|
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
|
});
|