@reown/appkit-core-react-native 2.0.0-alpha.3 → 2.0.0-alpha.5
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/ApiController.js +118 -58
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +31 -18
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js +4 -1
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +4 -1
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +4 -0
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +2 -2
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +5 -0
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/index.js +7 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +2 -3
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +1 -5
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +7 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/WalletUtil.js +23 -0
- package/lib/commonjs/utils/WalletUtil.js.map +1 -0
- package/lib/module/controllers/ApiController.js +118 -57
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +1 -1
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +31 -18
- package/lib/module/controllers/ConnectionsController.js.map +1 -1
- package/lib/module/controllers/ModalController.js +4 -1
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +4 -1
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +4 -0
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +2 -2
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +5 -0
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +2 -3
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +1 -5
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +7 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/WalletUtil.js +19 -0
- package/lib/module/utils/WalletUtil.js.map +1 -0
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +3 -2
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +2 -0
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +2 -2
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts +2 -0
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +1 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/WalletUtil.d.ts +5 -0
- package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
- package/package.json +5 -4
- package/src/controllers/ApiController.ts +109 -47
- package/src/controllers/BlockchainApiController.ts +1 -1
- package/src/controllers/ConnectionsController.ts +47 -17
- package/src/controllers/ModalController.ts +5 -1
- package/src/controllers/OnRampController.ts +5 -1
- package/src/controllers/OptionsController.ts +6 -0
- package/src/controllers/RouterController.ts +8 -4
- package/src/controllers/ThemeController.ts +7 -0
- package/src/index.ts +1 -1
- package/src/utils/AssetUtil.ts +2 -3
- package/src/utils/ConstantsUtil.ts +1 -5
- package/src/utils/CoreHelperUtil.ts +10 -0
- package/src/utils/WalletUtil.ts +14 -0
- package/lib/commonjs/utils/RouterUtil.js +0 -25
- package/lib/commonjs/utils/RouterUtil.js.map +0 -1
- package/lib/module/utils/RouterUtil.js +0 -21
- package/lib/module/utils/RouterUtil.js.map +0 -1
- package/lib/typescript/utils/RouterUtil.d.ts +0 -5
- package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
- package/src/utils/RouterUtil.ts +0 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reown/appkit-core-react-native",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.5",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"types": "lib/typescript/index.d.ts",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -30,16 +30,17 @@
|
|
|
30
30
|
"repository": "https://github.com/reown-com/appkit-react-native",
|
|
31
31
|
"author": "Reown (https://discord.gg/reown)",
|
|
32
32
|
"homepage": "https://reown.com/appkit",
|
|
33
|
-
"license": "
|
|
33
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
34
34
|
"bugs": {
|
|
35
35
|
"url": "https://github.com/reown-com/appkit-react-native/issues"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"registry": "https://registry.npmjs.org/",
|
|
39
|
-
"access": "public"
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@reown/appkit-common-react-native": "2.0.0-alpha.
|
|
43
|
+
"@reown/appkit-common-react-native": "2.0.0-alpha.5",
|
|
43
44
|
"countries-and-timezones": "3.7.2",
|
|
44
45
|
"derive-valtio": "0.2.0",
|
|
45
46
|
"valtio": "2.1.5"
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
type ApiGetDataWalletsResponse,
|
|
10
10
|
type ApiGetWalletsRequest,
|
|
11
11
|
type ApiGetWalletsResponse,
|
|
12
|
+
type CustomWallet,
|
|
12
13
|
type WcWallet,
|
|
13
14
|
PresetsUtil
|
|
14
15
|
} from '@reown/appkit-common-react-native';
|
|
15
16
|
import { AssetController } from './AssetController';
|
|
16
17
|
import { OptionsController } from './OptionsController';
|
|
17
|
-
// import { ConnectorController } from './ConnectorController';
|
|
18
18
|
import { WcController } from './WcController';
|
|
19
19
|
import { ApiUtil } from '../utils/ApiUtil';
|
|
20
20
|
import { SnackController } from './SnackController';
|
|
@@ -108,59 +108,111 @@ export const ApiController = {
|
|
|
108
108
|
},
|
|
109
109
|
|
|
110
110
|
async fetchInstalledWallets() {
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
path,
|
|
115
|
-
headers: ApiController._getApiHeaders()
|
|
116
|
-
});
|
|
111
|
+
// Add timeout to prevent hanging
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
let timeoutId: NodeJS.Timeout | undefined;
|
|
117
114
|
|
|
118
|
-
|
|
115
|
+
try {
|
|
116
|
+
const { includeWalletIds, customWallets } = OptionsController.state;
|
|
117
|
+
const path = Platform.select({ default: 'getIosData', android: 'getAndroidData' });
|
|
118
|
+
const response = await api.get<ApiGetDataWalletsResponse>({
|
|
119
|
+
path,
|
|
120
|
+
headers: ApiController._getApiHeaders()
|
|
121
|
+
});
|
|
119
122
|
|
|
120
|
-
|
|
123
|
+
if (!response) return;
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
walletData = walletData.filter(({ id }) => includeWalletIds.includes(id));
|
|
124
|
-
}
|
|
125
|
+
let { data: walletData } = response;
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
isInstalled: await CoreHelperUtil.checkInstalled(item)
|
|
130
|
-
};
|
|
131
|
-
});
|
|
127
|
+
if (includeWalletIds?.length) {
|
|
128
|
+
walletData = walletData.filter(({ id }) => includeWalletIds.includes(id));
|
|
129
|
+
}
|
|
132
130
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
const promises = walletData.map(async item => {
|
|
132
|
+
return {
|
|
133
|
+
id: item.id,
|
|
134
|
+
isInstalled: await CoreHelperUtil.checkInstalled(item)
|
|
135
|
+
};
|
|
136
|
+
});
|
|
136
137
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
page: '1',
|
|
143
|
-
platform: this.platform(),
|
|
144
|
-
entries: installed?.length.toString(),
|
|
145
|
-
include: installed?.join(','),
|
|
146
|
-
exclude: excludeWalletIds?.join(',')
|
|
147
|
-
}
|
|
138
|
+
const customPromises = customWallets?.map(async item => {
|
|
139
|
+
return {
|
|
140
|
+
id: item.id,
|
|
141
|
+
isInstalled: await CoreHelperUtil.checkInstalled(item)
|
|
142
|
+
};
|
|
148
143
|
});
|
|
149
144
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
const results = await Promise.all(promises);
|
|
146
|
+
const installed = results.filter(({ isInstalled }) => isInstalled).map(({ id }) => id);
|
|
147
|
+
const { excludeWalletIds } = OptionsController.state;
|
|
148
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
149
|
+
|
|
150
|
+
// Add timeout to prevent hanging
|
|
151
|
+
timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
152
|
+
|
|
153
|
+
// Collect API-sourced installed wallets
|
|
154
|
+
let apiInstalledWallets: WcWallet[] = [];
|
|
155
|
+
if (installed.length > 0) {
|
|
156
|
+
const walletResponse = await api.get<ApiGetWalletsResponse>({
|
|
157
|
+
path: '/getWallets',
|
|
158
|
+
headers: ApiController._getApiHeaders(),
|
|
159
|
+
params: {
|
|
160
|
+
page: '1',
|
|
161
|
+
platform: this.platform(),
|
|
162
|
+
entries: installed?.length.toString(),
|
|
163
|
+
include: installed?.join(','),
|
|
164
|
+
exclude: excludeWalletIds?.join(','),
|
|
165
|
+
chains: chains.join(',')
|
|
166
|
+
},
|
|
167
|
+
signal: controller.signal
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (walletResponse?.data) {
|
|
171
|
+
const walletImages = walletResponse.data.map(d => d.image_id).filter(Boolean);
|
|
172
|
+
await CoreHelperUtil.allSettled(
|
|
173
|
+
(walletImages as string[]).map(id => ApiController._fetchWalletImage(id))
|
|
174
|
+
);
|
|
175
|
+
apiInstalledWallets = walletResponse.data;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
clearTimeout(timeoutId);
|
|
180
|
+
|
|
181
|
+
// Collect custom installed wallets
|
|
182
|
+
let customInstalledWallets: CustomWallet[] = [];
|
|
183
|
+
if (customPromises?.length) {
|
|
184
|
+
const customResults = await Promise.all(customPromises);
|
|
185
|
+
const customInstalled = customResults
|
|
186
|
+
.filter(({ isInstalled }) => isInstalled)
|
|
187
|
+
.map(({ id }) => id);
|
|
188
|
+
customInstalledWallets =
|
|
189
|
+
customWallets?.filter(wallet => customInstalled.includes(wallet.id)) ?? [];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Merge and de-duplicate by id, preserving order (API first, then custom)
|
|
193
|
+
const byId = new Map<string, WcWallet>();
|
|
194
|
+
[...apiInstalledWallets, ...customInstalledWallets].forEach(wallet => {
|
|
195
|
+
if (!byId.has(wallet.id)) {
|
|
196
|
+
byId.set(wallet.id, wallet);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const combinedInstalled = Array.from(byId.values());
|
|
200
|
+
state.installed = combinedInstalled;
|
|
201
|
+
if (combinedInstalled.length) {
|
|
202
|
+
this.updateRecentWalletsInfo(combinedInstalled);
|
|
157
203
|
}
|
|
204
|
+
} catch (error) {
|
|
205
|
+
state.installed = [];
|
|
206
|
+
clearTimeout(timeoutId);
|
|
207
|
+
// eslint-disable-next-line no-console
|
|
208
|
+
console.log('Error fetching installed wallets', error);
|
|
158
209
|
}
|
|
159
210
|
},
|
|
160
211
|
|
|
161
212
|
async fetchFeaturedWallets() {
|
|
162
213
|
const { featuredWalletIds } = OptionsController.state;
|
|
163
214
|
const exclude = state.installed.map(({ id }) => id);
|
|
215
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
164
216
|
|
|
165
217
|
if (featuredWalletIds?.length) {
|
|
166
218
|
const response = await api.get<ApiGetWalletsResponse>({
|
|
@@ -173,7 +225,8 @@ export const ApiController = {
|
|
|
173
225
|
? String(featuredWalletIds.length)
|
|
174
226
|
: recommendedEntries,
|
|
175
227
|
include: featuredWalletIds?.join(','),
|
|
176
|
-
exclude: exclude?.join(',')
|
|
228
|
+
exclude: exclude?.join(','),
|
|
229
|
+
chains: chains.join(',')
|
|
177
230
|
}
|
|
178
231
|
});
|
|
179
232
|
if (!response) return;
|
|
@@ -205,6 +258,7 @@ export const ApiController = {
|
|
|
205
258
|
async fetchRecommendedWallets() {
|
|
206
259
|
const { installed } = ApiController.state;
|
|
207
260
|
const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
|
|
261
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
208
262
|
|
|
209
263
|
const exclude = [
|
|
210
264
|
...installed.map(({ id }) => id),
|
|
@@ -220,7 +274,8 @@ export const ApiController = {
|
|
|
220
274
|
platform: this.platform(),
|
|
221
275
|
entries: recommendedEntries,
|
|
222
276
|
include: includeWalletIds?.join(','),
|
|
223
|
-
exclude: exclude?.join(',')
|
|
277
|
+
exclude: exclude?.join(','),
|
|
278
|
+
chains: chains.join(',')
|
|
224
279
|
}
|
|
225
280
|
});
|
|
226
281
|
|
|
@@ -243,6 +298,7 @@ export const ApiController = {
|
|
|
243
298
|
|
|
244
299
|
async fetchWallets({ page }: Pick<ApiGetWalletsRequest, 'page'>) {
|
|
245
300
|
const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
|
|
301
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
246
302
|
const exclude = [
|
|
247
303
|
...state.installed.map(({ id }) => id),
|
|
248
304
|
...state.recommended.map(({ id }) => id),
|
|
@@ -257,7 +313,8 @@ export const ApiController = {
|
|
|
257
313
|
platform: this.platform(),
|
|
258
314
|
entries: String(defaultEntries),
|
|
259
315
|
include: includeWalletIds?.join(','),
|
|
260
|
-
exclude: exclude.join(',')
|
|
316
|
+
exclude: exclude.join(','),
|
|
317
|
+
chains: chains.join(',')
|
|
261
318
|
}
|
|
262
319
|
});
|
|
263
320
|
|
|
@@ -280,6 +337,7 @@ export const ApiController = {
|
|
|
280
337
|
|
|
281
338
|
async searchWallet({ search }: Pick<ApiGetWalletsRequest, 'search'>) {
|
|
282
339
|
const { includeWalletIds, excludeWalletIds } = OptionsController.state;
|
|
340
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
283
341
|
state.search = [];
|
|
284
342
|
const response = await api.get<ApiGetWalletsResponse>({
|
|
285
343
|
path: '/getWallets',
|
|
@@ -290,7 +348,8 @@ export const ApiController = {
|
|
|
290
348
|
entries: String(defaultEntries),
|
|
291
349
|
search,
|
|
292
350
|
include: includeWalletIds?.join(','),
|
|
293
|
-
exclude: excludeWalletIds?.join(',')
|
|
351
|
+
exclude: excludeWalletIds?.join(','),
|
|
352
|
+
chains: chains.join(',')
|
|
294
353
|
}
|
|
295
354
|
});
|
|
296
355
|
|
|
@@ -333,19 +392,22 @@ export const ApiController = {
|
|
|
333
392
|
try {
|
|
334
393
|
state.prefetchError = false;
|
|
335
394
|
state.prefetchLoading = true;
|
|
336
|
-
// this fetch must resolve first so we filter them in the other wallet requests
|
|
337
|
-
await ApiController.fetchInstalledWallets();
|
|
338
395
|
|
|
339
396
|
const promises = [
|
|
340
|
-
ApiController.fetchFeaturedWallets(),
|
|
341
|
-
ApiController.fetchRecommendedWallets(),
|
|
342
397
|
ApiController.fetchNetworkImages(),
|
|
343
398
|
ApiController.fetchCustomWalletImages()
|
|
344
399
|
];
|
|
400
|
+
|
|
345
401
|
if (OptionsController.state.enableAnalytics === undefined) {
|
|
346
402
|
promises.push(ApiController.fetchAnalyticsConfig());
|
|
347
403
|
}
|
|
348
404
|
|
|
405
|
+
// this fetch must resolve first so we filter them in the other wallet requests
|
|
406
|
+
await ApiController.fetchInstalledWallets();
|
|
407
|
+
|
|
408
|
+
promises.push(ApiController.fetchFeaturedWallets());
|
|
409
|
+
promises.push(ApiController.fetchRecommendedWallets());
|
|
410
|
+
|
|
349
411
|
state.prefetchPromise = Promise.race([
|
|
350
412
|
CoreHelperUtil.allSettled(promises),
|
|
351
413
|
CoreHelperUtil.wait(3000)
|
|
@@ -119,7 +119,7 @@ export const BlockchainApiController = {
|
|
|
119
119
|
|
|
120
120
|
async fetchTransactions(params: BlockchainApiTransactionsRequest) {
|
|
121
121
|
const { account, projectId, cursor, signal, cache, chainId } = params;
|
|
122
|
-
const isSupported =
|
|
122
|
+
const isSupported = ConstantsUtil.ACTIVITY_SUPPORTED_CHAINS.includes(chainId);
|
|
123
123
|
|
|
124
124
|
if (!isSupported) {
|
|
125
125
|
return { data: [], next: undefined };
|
|
@@ -80,11 +80,13 @@ const updateConnection = (
|
|
|
80
80
|
namespace: ChainNamespace,
|
|
81
81
|
connection: Connection,
|
|
82
82
|
updates: Partial<Connection>
|
|
83
|
-
) => {
|
|
84
|
-
if (!connection) return;
|
|
83
|
+
): Connection => {
|
|
85
84
|
const newConnectionsMap = new Map(baseState.connections);
|
|
86
|
-
|
|
85
|
+
const newConnection = { ...connection, ...updates };
|
|
86
|
+
newConnectionsMap.set(namespace, newConnection);
|
|
87
87
|
baseState.connections = newConnectionsMap;
|
|
88
|
+
|
|
89
|
+
return newConnection;
|
|
88
90
|
};
|
|
89
91
|
|
|
90
92
|
const getActiveIdentity = (connection: Connection): Identity | undefined => {
|
|
@@ -206,6 +208,10 @@ export const ConnectionsController = {
|
|
|
206
208
|
state: derivedState,
|
|
207
209
|
|
|
208
210
|
setActiveNamespace(namespace?: ChainNamespace) {
|
|
211
|
+
if (baseState.activeNamespace === namespace) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
209
215
|
baseState.activeNamespace = namespace;
|
|
210
216
|
StorageUtil.setActiveNamespace(namespace);
|
|
211
217
|
},
|
|
@@ -247,16 +253,19 @@ export const ConnectionsController = {
|
|
|
247
253
|
baseState.connections = newConnectionsMap;
|
|
248
254
|
},
|
|
249
255
|
|
|
250
|
-
updateAccounts(namespace: ChainNamespace, accounts: CaipAddress[]) {
|
|
256
|
+
updateAccounts(namespace: ChainNamespace, accounts: CaipAddress[]): boolean {
|
|
251
257
|
const connection = baseState.connections.get(namespace);
|
|
252
258
|
if (!connection) {
|
|
253
|
-
return;
|
|
259
|
+
return false;
|
|
254
260
|
}
|
|
255
261
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
262
|
+
if (connection.accounts.toString() === accounts.toString()) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
updateConnection(namespace, connection, { accounts });
|
|
267
|
+
|
|
268
|
+
return true;
|
|
260
269
|
},
|
|
261
270
|
|
|
262
271
|
updateBalance(namespace: ChainNamespace, address: CaipAddress, balance: Balance) {
|
|
@@ -327,10 +336,9 @@ export const ConnectionsController = {
|
|
|
327
336
|
return;
|
|
328
337
|
}
|
|
329
338
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
});
|
|
339
|
+
updateConnection(namespace, connection, { caipNetwork: networkId });
|
|
340
|
+
|
|
341
|
+
this.setActiveNamespace(namespace);
|
|
334
342
|
},
|
|
335
343
|
|
|
336
344
|
setNetworks(networks: AppKitNetwork[]) {
|
|
@@ -338,6 +346,11 @@ export const ConnectionsController = {
|
|
|
338
346
|
},
|
|
339
347
|
|
|
340
348
|
getConnectedNetworks() {
|
|
349
|
+
const connection = getActiveConnection(baseState);
|
|
350
|
+
if (!connection) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
|
|
341
354
|
return baseState.networks.filter(
|
|
342
355
|
network =>
|
|
343
356
|
baseState.connections
|
|
@@ -346,14 +359,31 @@ export const ConnectionsController = {
|
|
|
346
359
|
);
|
|
347
360
|
},
|
|
348
361
|
|
|
362
|
+
getAvailableNetworks() {
|
|
363
|
+
const connection = getActiveConnection(baseState);
|
|
364
|
+
|
|
365
|
+
if (!connection) {
|
|
366
|
+
return baseState.networks;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const canAddEvmChain = connection.properties?.canAddEvmChain;
|
|
370
|
+
|
|
371
|
+
return baseState.networks.filter(
|
|
372
|
+
network =>
|
|
373
|
+
baseState.connections
|
|
374
|
+
.get(network.chainNamespace)
|
|
375
|
+
?.accounts.some(account => account.startsWith(network.caipNetworkId)) ||
|
|
376
|
+
(canAddEvmChain && network.chainNamespace === 'eip155')
|
|
377
|
+
);
|
|
378
|
+
},
|
|
379
|
+
|
|
349
380
|
setAccountType(namespace: ChainNamespace, type: AccountType) {
|
|
350
381
|
const connection = baseState.connections.get(namespace);
|
|
351
382
|
if (!connection) return;
|
|
352
383
|
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
baseState.connections = newConnectionsMap;
|
|
384
|
+
const newConnection = updateConnection(namespace, connection, { type });
|
|
385
|
+
|
|
386
|
+
return getActiveAddress(newConnection);
|
|
357
387
|
},
|
|
358
388
|
|
|
359
389
|
async disconnect(namespace: ChainNamespace, isInternal = true) {
|
|
@@ -30,10 +30,14 @@ export const ModalController = {
|
|
|
30
30
|
async open(options?: ModalControllerArguments['open']) {
|
|
31
31
|
await ApiController.state.prefetchPromise;
|
|
32
32
|
const isConnected = ConnectionsController.state.isConnected;
|
|
33
|
+
const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
|
|
33
34
|
if (options?.view) {
|
|
35
|
+
if (options.view === 'Account' && !isUniversalWallet) {
|
|
36
|
+
options.view = 'AccountDefault';
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
RouterController.reset(options.view);
|
|
35
40
|
} else if (isConnected) {
|
|
36
|
-
const isUniversalWallet = !!ConnectionsController.state.connection?.properties?.provider;
|
|
37
41
|
RouterController.reset(isUniversalWallet ? 'Account' : 'AccountDefault');
|
|
38
42
|
} else {
|
|
39
43
|
RouterController.reset('Connect');
|
|
@@ -124,7 +124,11 @@ export const OnRampController = {
|
|
|
124
124
|
state.countriesDefaults?.find(d => d.countryCode === country.countryCode)
|
|
125
125
|
?.defaultCurrencyCode || 'USD';
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
let currency = state.paymentCurrencies?.find(c => c.currencyCode === currencyCode);
|
|
128
|
+
|
|
129
|
+
if (!currency) {
|
|
130
|
+
currency = state.paymentCurrencies?.find(c => c.currencyCode === 'USD');
|
|
131
|
+
}
|
|
128
132
|
|
|
129
133
|
if (currency) {
|
|
130
134
|
this.setPaymentCurrency(currency);
|
|
@@ -34,6 +34,7 @@ export interface OptionsControllerState {
|
|
|
34
34
|
features?: Features;
|
|
35
35
|
debug?: boolean;
|
|
36
36
|
defaultNetwork?: AppKitNetwork;
|
|
37
|
+
requestedNetworks?: AppKitNetwork[];
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
// -- State --------------------------------------------- //
|
|
@@ -42,6 +43,7 @@ const state = proxy<OptionsControllerState>({
|
|
|
42
43
|
sdkType: 'appkit',
|
|
43
44
|
sdkVersion: 'react-native-undefined-undefined',
|
|
44
45
|
features: ConstantsUtil.DEFAULT_FEATURES,
|
|
46
|
+
customWallets: [],
|
|
45
47
|
debug: false
|
|
46
48
|
});
|
|
47
49
|
|
|
@@ -111,6 +113,10 @@ export const OptionsController = {
|
|
|
111
113
|
state.defaultNetwork = defaultNetwork;
|
|
112
114
|
},
|
|
113
115
|
|
|
116
|
+
setRequestedNetworks(requestedNetworks?: OptionsControllerState['requestedNetworks']) {
|
|
117
|
+
state.requestedNetworks = requestedNetworks;
|
|
118
|
+
},
|
|
119
|
+
|
|
114
120
|
isClipboardAvailable() {
|
|
115
121
|
return !!state.clipboardClient;
|
|
116
122
|
},
|
|
@@ -17,15 +17,15 @@ export interface RouterControllerState {
|
|
|
17
17
|
| 'ConnectingExternal'
|
|
18
18
|
| 'ConnectingSiwe'
|
|
19
19
|
| 'ConnectingSocial'
|
|
20
|
-
| '
|
|
20
|
+
| 'WalletConnect'
|
|
21
21
|
| 'GetWallet'
|
|
22
22
|
| 'Networks'
|
|
23
|
+
| 'SwitchNetwork'
|
|
23
24
|
| 'OnRamp'
|
|
24
25
|
| 'OnRampCheckout'
|
|
25
26
|
| 'OnRampLoading'
|
|
26
27
|
| 'OnRampSettings'
|
|
27
28
|
| 'OnRampTransaction'
|
|
28
|
-
| 'SwitchNetwork'
|
|
29
29
|
| 'Swap'
|
|
30
30
|
| 'SwapPreview'
|
|
31
31
|
| 'Transactions'
|
|
@@ -59,9 +59,13 @@ const state = proxy<RouterControllerState>({
|
|
|
59
59
|
export const RouterController = {
|
|
60
60
|
state,
|
|
61
61
|
|
|
62
|
-
push(
|
|
62
|
+
push(
|
|
63
|
+
view: RouterControllerState['view'],
|
|
64
|
+
data?: RouterControllerState['data'],
|
|
65
|
+
direction: 'forward' | 'backward' = 'forward'
|
|
66
|
+
) {
|
|
63
67
|
if (view !== state.view) {
|
|
64
|
-
state.navigationDirection =
|
|
68
|
+
state.navigationDirection = direction;
|
|
65
69
|
state.view = view;
|
|
66
70
|
state.history = [...state.history, view];
|
|
67
71
|
state.data = data;
|
|
@@ -5,12 +5,14 @@ import type { ThemeMode, ThemeVariables } from '@reown/appkit-common-react-nativ
|
|
|
5
5
|
// -- Types --------------------------------------------- //
|
|
6
6
|
export interface ThemeControllerState {
|
|
7
7
|
themeMode?: ThemeMode;
|
|
8
|
+
defaultThemeMode?: ThemeMode;
|
|
8
9
|
themeVariables?: ThemeVariables;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
// -- State --------------------------------------------- //
|
|
12
13
|
const state = proxy<ThemeControllerState>({
|
|
13
14
|
themeMode: undefined,
|
|
15
|
+
defaultThemeMode: undefined,
|
|
14
16
|
themeVariables: {}
|
|
15
17
|
});
|
|
16
18
|
|
|
@@ -30,6 +32,11 @@ export const ThemeController = {
|
|
|
30
32
|
}
|
|
31
33
|
},
|
|
32
34
|
|
|
35
|
+
setDefaultThemeMode(themeMode: ThemeControllerState['defaultThemeMode']) {
|
|
36
|
+
state.defaultThemeMode = themeMode;
|
|
37
|
+
this.setThemeMode(themeMode);
|
|
38
|
+
},
|
|
39
|
+
|
|
33
40
|
setThemeVariables(themeVariables: ThemeControllerState['themeVariables']) {
|
|
34
41
|
if (!themeVariables) {
|
|
35
42
|
state.themeVariables = {};
|
package/src/index.ts
CHANGED
|
@@ -53,6 +53,6 @@ export { ConstantsUtil } from './utils/ConstantsUtil';
|
|
|
53
53
|
export { CoreHelperUtil } from './utils/CoreHelperUtil';
|
|
54
54
|
export { StorageUtil } from './utils/StorageUtil';
|
|
55
55
|
export { EventUtil } from './utils/EventUtil';
|
|
56
|
-
export {
|
|
56
|
+
export { WalletUtil } from './utils/WalletUtil';
|
|
57
57
|
|
|
58
58
|
// Types are now exported from @reown/appkit-common-react-native
|
package/src/utils/AssetUtil.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { AppKitNetwork, WcWallet } from '@reown/appkit-common-react-native';
|
|
2
|
-
import { AssetController } from '../controllers/AssetController';
|
|
3
2
|
|
|
4
3
|
export const AssetUtil = {
|
|
5
|
-
getWalletImage(wallet?: WcWallet) {
|
|
4
|
+
getWalletImage(wallet?: WcWallet, walletImages?: Record<string, string>) {
|
|
6
5
|
if (wallet?.image_url) {
|
|
7
6
|
return wallet?.image_url;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
if (wallet?.image_id) {
|
|
11
|
-
return
|
|
10
|
+
return walletImages?.[wallet.image_id];
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
return undefined;
|
|
@@ -219,8 +219,6 @@ export const ConstantsUtil = {
|
|
|
219
219
|
'eip155:1499',
|
|
220
220
|
// Sonic
|
|
221
221
|
'eip155:7007',
|
|
222
|
-
// Swellchain
|
|
223
|
-
'eip155:7777777',
|
|
224
222
|
// Taiko
|
|
225
223
|
'eip155:167000',
|
|
226
224
|
// Viction
|
|
@@ -238,9 +236,7 @@ export const ConstantsUtil = {
|
|
|
238
236
|
// ZkLink Nova
|
|
239
237
|
'eip155:810180',
|
|
240
238
|
// re.al
|
|
241
|
-
'eip155:666'
|
|
242
|
-
// Zora
|
|
243
|
-
'eip155:7777777'
|
|
239
|
+
'eip155:666'
|
|
244
240
|
],
|
|
245
241
|
|
|
246
242
|
SWAP_SUPPORTED_NETWORKS: [
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import * as ct from 'countries-and-timezones';
|
|
19
19
|
|
|
20
20
|
import { ConstantsUtil } from './ConstantsUtil';
|
|
21
|
+
import { OptionsController } from '../controllers/OptionsController';
|
|
21
22
|
|
|
22
23
|
// -- Helpers -----------------------------------------------------------------
|
|
23
24
|
async function isAppInstalledIos(deepLink?: string): Promise<boolean> {
|
|
@@ -345,5 +346,14 @@ export const CoreHelperUtil = {
|
|
|
345
346
|
.join(',');
|
|
346
347
|
|
|
347
348
|
return `react-native-${adapterNames}-${version}`;
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
getRequestedCaipNetworkIds() {
|
|
352
|
+
const chains = OptionsController.state.requestedNetworks;
|
|
353
|
+
if (!chains) return [];
|
|
354
|
+
|
|
355
|
+
const requestedIds = chains.map(caipNetwork => caipNetwork.caipNetworkId);
|
|
356
|
+
|
|
357
|
+
return requestedIds;
|
|
348
358
|
}
|
|
349
359
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { WcWallet } from '@reown/appkit-common-react-native';
|
|
2
|
+
import { ApiController } from '../controllers/ApiController';
|
|
3
|
+
import { OptionsController } from '../controllers/OptionsController';
|
|
4
|
+
|
|
5
|
+
export const WalletUtil = {
|
|
6
|
+
getWallet: (walletId: string): WcWallet | undefined => {
|
|
7
|
+
const { wallets, recommended, featured, installed } = ApiController.state;
|
|
8
|
+
const customWallets = OptionsController.state.customWallets ?? [];
|
|
9
|
+
const allWallets = [...wallets, ...recommended, ...featured, ...installed, ...customWallets];
|
|
10
|
+
const wallet = allWallets.find(w => w.id === walletId);
|
|
11
|
+
|
|
12
|
+
return wallet;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.RouterUtil = void 0;
|
|
7
|
-
var _RouterController = require("../controllers/RouterController");
|
|
8
|
-
var _ModalController = require("../controllers/ModalController");
|
|
9
|
-
const RouterUtil = exports.RouterUtil = {
|
|
10
|
-
navigateAfterNetworkSwitch(excludeViews = []) {
|
|
11
|
-
if (excludeViews.includes(_RouterController.RouterController.state.view)) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const {
|
|
15
|
-
history
|
|
16
|
-
} = _RouterController.RouterController.state;
|
|
17
|
-
const networkSelectIndex = history.findIndex(name => name === 'Networks' || name === 'UnsupportedChain');
|
|
18
|
-
if (networkSelectIndex >= 1) {
|
|
19
|
-
_RouterController.RouterController.goBackToIndex(networkSelectIndex - 1);
|
|
20
|
-
} else {
|
|
21
|
-
_ModalController.ModalController.close();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=RouterUtil.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_RouterController","require","_ModalController","RouterUtil","exports","navigateAfterNetworkSwitch","excludeViews","includes","RouterController","state","view","history","networkSelectIndex","findIndex","name","goBackToIndex","ModalController","close"],"sourceRoot":"../../../src","sources":["utils/RouterUtil.ts"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAEO,MAAME,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG;EACxBE,0BAA0BA,CAACC,YAA6C,GAAG,EAAE,EAAE;IAC7E,IAAIA,YAAY,CAACC,QAAQ,CAACC,kCAAgB,CAACC,KAAK,CAACC,IAAI,CAAC,EAAE;MACtD;IACF;IAEA,MAAM;MAAEC;IAAQ,CAAC,GAAGH,kCAAgB,CAACC,KAAK;IAC1C,MAAMG,kBAAkB,GAAGD,OAAO,CAACE,SAAS,CAC1CC,IAAI,IAAIA,IAAI,KAAK,UAAU,IAAIA,IAAI,KAAK,kBAC1C,CAAC;IAED,IAAIF,kBAAkB,IAAI,CAAC,EAAE;MAC3BJ,kCAAgB,CAACO,aAAa,CAACH,kBAAkB,GAAG,CAAC,CAAC;IACxD,CAAC,MAAM;MACLI,gCAAe,CAACC,KAAK,CAAC,CAAC;IACzB;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { RouterController } from '../controllers/RouterController';
|
|
4
|
-
import { ModalController } from '../controllers/ModalController';
|
|
5
|
-
export const RouterUtil = {
|
|
6
|
-
navigateAfterNetworkSwitch(excludeViews = []) {
|
|
7
|
-
if (excludeViews.includes(RouterController.state.view)) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const {
|
|
11
|
-
history
|
|
12
|
-
} = RouterController.state;
|
|
13
|
-
const networkSelectIndex = history.findIndex(name => name === 'Networks' || name === 'UnsupportedChain');
|
|
14
|
-
if (networkSelectIndex >= 1) {
|
|
15
|
-
RouterController.goBackToIndex(networkSelectIndex - 1);
|
|
16
|
-
} else {
|
|
17
|
-
ModalController.close();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=RouterUtil.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["RouterController","ModalController","RouterUtil","navigateAfterNetworkSwitch","excludeViews","includes","state","view","history","networkSelectIndex","findIndex","name","goBackToIndex","close"],"sourceRoot":"../../../src","sources":["utils/RouterUtil.ts"],"mappings":";;AAAA,SAASA,gBAAgB,QAAoC,iCAAiC;AAC9F,SAASC,eAAe,QAAQ,gCAAgC;AAEhE,OAAO,MAAMC,UAAU,GAAG;EACxBC,0BAA0BA,CAACC,YAA6C,GAAG,EAAE,EAAE;IAC7E,IAAIA,YAAY,CAACC,QAAQ,CAACL,gBAAgB,CAACM,KAAK,CAACC,IAAI,CAAC,EAAE;MACtD;IACF;IAEA,MAAM;MAAEC;IAAQ,CAAC,GAAGR,gBAAgB,CAACM,KAAK;IAC1C,MAAMG,kBAAkB,GAAGD,OAAO,CAACE,SAAS,CAC1CC,IAAI,IAAIA,IAAI,KAAK,UAAU,IAAIA,IAAI,KAAK,kBAC1C,CAAC;IAED,IAAIF,kBAAkB,IAAI,CAAC,EAAE;MAC3BT,gBAAgB,CAACY,aAAa,CAACH,kBAAkB,GAAG,CAAC,CAAC;IACxD,CAAC,MAAM;MACLR,eAAe,CAACY,KAAK,CAAC,CAAC;IACzB;EACF;AACF,CAAC","ignoreList":[]}
|