@reown/appkit-core-react-native 0.0.0-feat-onramp-20250722205908 → 0.0.0-feat-coinbase-20250723173858
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/controllers/AccountController.js +20 -17
- package/lib/commonjs/controllers/AccountController.js.map +1 -1
- package/lib/commonjs/controllers/ApiController.js +28 -16
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +204 -74
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionController.js +8 -11
- package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +387 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +4 -4
- package/lib/commonjs/controllers/EnsController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +4 -4
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js +6 -7
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +22 -69
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +11 -3
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +1 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +101 -101
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SnackController.js +29 -5
- package/lib/commonjs/controllers/SnackController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +151 -150
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +9 -1
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +25 -21
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/index.js +3 -24
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +3 -15
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +538 -9
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +12 -6
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +9 -28
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/StorageUtil.js +51 -42
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +15 -21
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/AccountController.js +20 -17
- package/lib/module/controllers/AccountController.js.map +1 -1
- package/lib/module/controllers/ApiController.js +27 -16
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +203 -73
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionController.js +8 -11
- package/lib/module/controllers/ConnectionController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +382 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +2 -2
- package/lib/module/controllers/EnsController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +1 -1
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/ModalController.js +6 -7
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +23 -70
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +11 -3
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +1 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +98 -98
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SnackController.js +29 -5
- package/lib/module/controllers/SnackController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +151 -150
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +9 -1
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +23 -19
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/index.js +1 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +3 -15
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +538 -9
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +12 -6
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +9 -28
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/StorageUtil.js +51 -42
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +15 -21
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/typescript/controllers/AccountController.d.ts +4 -4
- package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
- package/lib/typescript/controllers/ApiController.d.ts +3 -2
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +29 -15
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +3 -11
- package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +53 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/ModalController.d.ts +1 -1
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
- package/lib/typescript/controllers/NetworkController.d.ts +1 -1
- package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts +1 -3
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +7 -2
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/PublicStateController.d.ts +1 -1
- package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +4 -16
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts +5 -7
- package/lib/typescript/controllers/SendController.d.ts.map +1 -1
- package/lib/typescript/controllers/SnackController.d.ts +3 -3
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +12 -11
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
- package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +2 -3
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +422 -3
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +5 -4
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StorageUtil.d.ts +14 -7
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -3
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +42 -191
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/controllers/AccountController.ts +23 -27
- package/src/controllers/ApiController.ts +29 -10
- package/src/controllers/BlockchainApiController.ts +179 -65
- package/src/controllers/ConnectionController.ts +12 -24
- package/src/controllers/ConnectionsController.ts +509 -0
- package/src/controllers/EnsController.ts +2 -2
- package/src/controllers/EventsController.ts +1 -1
- package/src/controllers/ModalController.ts +8 -8
- package/src/controllers/NetworkController.ts +1 -1
- package/src/controllers/OnRampController.ts +35 -99
- package/src/controllers/OptionsController.ts +19 -13
- package/src/controllers/PublicStateController.ts +1 -1
- package/src/controllers/RouterController.ts +5 -54
- package/src/controllers/SendController.ts +124 -113
- package/src/controllers/SnackController.ts +31 -5
- package/src/controllers/SwapController.ts +174 -181
- package/src/controllers/ThemeController.ts +11 -2
- package/src/controllers/TransactionsController.ts +26 -20
- package/src/index.ts +3 -6
- package/src/utils/AssetUtil.ts +4 -20
- package/src/utils/ConstantsUtil.ts +544 -9
- package/src/utils/CoreHelperUtil.ts +34 -9
- package/src/utils/FetchUtil.ts +10 -31
- package/src/utils/StorageUtil.ts +60 -48
- package/src/utils/SwapApiUtil.ts +27 -38
- package/src/utils/TypeUtil.ts +43 -193
- package/lib/commonjs/controllers/ConnectorController.js +0 -49
- package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
- package/lib/commonjs/controllers/WebviewController.js +0 -52
- package/lib/commonjs/controllers/WebviewController.js.map +0 -1
- package/lib/commonjs/utils/ConnectionUtil.js +0 -33
- package/lib/commonjs/utils/ConnectionUtil.js.map +0 -1
- package/lib/commonjs/utils/NetworkUtil.js +0 -46
- package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
- package/lib/module/controllers/ConnectorController.js +0 -44
- package/lib/module/controllers/ConnectorController.js.map +0 -1
- package/lib/module/controllers/WebviewController.js +0 -47
- package/lib/module/controllers/WebviewController.js.map +0 -1
- package/lib/module/utils/ConnectionUtil.js +0 -27
- package/lib/module/utils/ConnectionUtil.js.map +0 -1
- package/lib/module/utils/NetworkUtil.js +0 -40
- package/lib/module/utils/NetworkUtil.js.map +0 -1
- package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
- package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
- package/lib/typescript/controllers/WebviewController.d.ts +0 -21
- package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
- package/lib/typescript/utils/ConnectionUtil.d.ts +0 -4
- package/lib/typescript/utils/ConnectionUtil.d.ts.map +0 -1
- package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
- package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
- package/src/controllers/ConnectorController.ts +0 -63
- package/src/controllers/WebviewController.ts +0 -63
- package/src/utils/ConnectionUtil.ts +0 -27
- package/src/utils/NetworkUtil.ts +0 -33
package/src/utils/FetchUtil.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface Options {
|
|
|
8
8
|
|
|
9
9
|
interface RequestArguments {
|
|
10
10
|
path: string;
|
|
11
|
-
headers?:
|
|
11
|
+
headers?: HeadersInit;
|
|
12
12
|
params?: Record<string, string | undefined>;
|
|
13
13
|
cache?: RequestCache;
|
|
14
14
|
signal?: AbortSignal;
|
|
@@ -88,41 +88,20 @@ export class FetchUtil {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
private createUrl({ path, params }: RequestArguments) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const baseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
|
|
99
|
-
const pathUrl = path.startsWith('/') ? path.substring(1) : path;
|
|
100
|
-
fullUrl = `${baseUrl}${pathUrl}`;
|
|
91
|
+
const url = new URL(path, this.baseUrl);
|
|
92
|
+
if (params) {
|
|
93
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
94
|
+
if (value) {
|
|
95
|
+
url.searchParams.append(key, value);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
101
98
|
}
|
|
102
99
|
|
|
103
|
-
const allParams: Record<string, string | undefined> = { ...params };
|
|
104
100
|
if (this.clientId) {
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const queryParams: string[] = [];
|
|
109
|
-
for (const key in allParams) {
|
|
110
|
-
const value = allParams[key];
|
|
111
|
-
if (value !== undefined) {
|
|
112
|
-
queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (queryParams.length > 0) {
|
|
117
|
-
const queryString = queryParams.join('&');
|
|
118
|
-
if (fullUrl.includes('?')) {
|
|
119
|
-
fullUrl = `${fullUrl}&${queryString}`;
|
|
120
|
-
} else {
|
|
121
|
-
fullUrl = `${fullUrl}?${queryString}`;
|
|
122
|
-
}
|
|
101
|
+
url.searchParams.append('clientId', this.clientId);
|
|
123
102
|
}
|
|
124
103
|
|
|
125
|
-
return
|
|
104
|
+
return url.toString();
|
|
126
105
|
}
|
|
127
106
|
|
|
128
107
|
private async processResponse<T>(response: Response) {
|
package/src/utils/StorageUtil.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
3
|
import type {
|
|
4
4
|
OnRampCountry,
|
|
5
|
-
OnRampCountryDefaults,
|
|
6
5
|
OnRampFiatCurrency,
|
|
7
6
|
OnRampFiatLimit,
|
|
8
7
|
OnRampServiceProvider,
|
|
@@ -11,22 +10,24 @@ import type {
|
|
|
11
10
|
import {
|
|
12
11
|
DateUtil,
|
|
13
12
|
type SocialProvider,
|
|
14
|
-
type ConnectorType
|
|
13
|
+
type ConnectorType,
|
|
14
|
+
type ChainNamespace
|
|
15
15
|
} from '@reown/appkit-common-react-native';
|
|
16
16
|
|
|
17
17
|
// -- Helpers -----------------------------------------------------------------
|
|
18
18
|
const WC_DEEPLINK = 'WALLETCONNECT_DEEPLINK_CHOICE';
|
|
19
19
|
const RECENT_WALLET = '@w3m/recent';
|
|
20
20
|
const CONNECTED_WALLET_IMAGE_URL = '@w3m/connected_wallet_image_url';
|
|
21
|
-
const
|
|
21
|
+
const CONNECTED_CONNECTORS = '@appkit/connected_connectors';
|
|
22
22
|
const CONNECTED_SOCIAL = '@appkit/connected_social';
|
|
23
23
|
const ONRAMP_PREFERRED_COUNTRY = '@appkit/onramp_preferred_country';
|
|
24
24
|
const ONRAMP_COUNTRIES = '@appkit/onramp_countries';
|
|
25
|
-
const ONRAMP_COUNTRIES_DEFAULTS = '@appkit/onramp_countries_defaults';
|
|
26
25
|
const ONRAMP_SERVICE_PROVIDERS = '@appkit/onramp_service_providers';
|
|
27
26
|
const ONRAMP_FIAT_LIMITS = '@appkit/onramp_fiat_limits';
|
|
28
27
|
const ONRAMP_FIAT_CURRENCIES = '@appkit/onramp_fiat_currencies';
|
|
29
28
|
const ONRAMP_PREFERRED_FIAT_CURRENCY = '@appkit/onramp_preferred_fiat_currency';
|
|
29
|
+
const ACTIVE_NAMESPACE = '@appkit/active_namespace';
|
|
30
|
+
|
|
30
31
|
// -- Utility -----------------------------------------------------------------
|
|
31
32
|
export const StorageUtil = {
|
|
32
33
|
setWalletConnectDeepLink({ href, name }: { href: string; name: string }) {
|
|
@@ -101,29 +102,42 @@ export const StorageUtil = {
|
|
|
101
102
|
return [];
|
|
102
103
|
},
|
|
103
104
|
|
|
104
|
-
async
|
|
105
|
+
async setConnectedConnectors({
|
|
106
|
+
type,
|
|
107
|
+
namespaces
|
|
108
|
+
}: {
|
|
109
|
+
type: ConnectorType;
|
|
110
|
+
namespaces: string[];
|
|
111
|
+
}) {
|
|
105
112
|
try {
|
|
106
|
-
|
|
113
|
+
const currentConnectors = (await StorageUtil.getConnectedConnectors()) || [];
|
|
114
|
+
// Only add if it doesn't exist already
|
|
115
|
+
if (!currentConnectors.some(c => c.type === type)) {
|
|
116
|
+
const updatedConnectors = [...currentConnectors, { type, namespaces }];
|
|
117
|
+
await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
|
|
118
|
+
}
|
|
107
119
|
} catch {
|
|
108
120
|
console.info('Unable to set Connected Connector');
|
|
109
121
|
}
|
|
110
122
|
},
|
|
111
123
|
|
|
112
|
-
async
|
|
124
|
+
async getConnectedConnectors(): Promise<{ type: ConnectorType; namespaces: string[] }[]> {
|
|
113
125
|
try {
|
|
114
|
-
const
|
|
126
|
+
const connectors = await AsyncStorage.getItem(CONNECTED_CONNECTORS);
|
|
115
127
|
|
|
116
|
-
return
|
|
128
|
+
return connectors ? JSON.parse(connectors) : [];
|
|
117
129
|
} catch {
|
|
118
130
|
console.info('Unable to get Connected Connector');
|
|
119
131
|
}
|
|
120
132
|
|
|
121
|
-
return
|
|
133
|
+
return [];
|
|
122
134
|
},
|
|
123
135
|
|
|
124
|
-
async
|
|
136
|
+
async removeConnectedConnectors(type: ConnectorType) {
|
|
125
137
|
try {
|
|
126
|
-
await
|
|
138
|
+
const currentConnectors = await StorageUtil.getConnectedConnectors();
|
|
139
|
+
const updatedConnectors = currentConnectors.filter(c => c.type !== type);
|
|
140
|
+
await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
|
|
127
141
|
} catch {
|
|
128
142
|
console.info('Unable to remove Connected Connector');
|
|
129
143
|
}
|
|
@@ -243,42 +257,6 @@ export const StorageUtil = {
|
|
|
243
257
|
return [];
|
|
244
258
|
},
|
|
245
259
|
|
|
246
|
-
async setOnRampCountriesDefaults(countriesDefaults: OnRampCountryDefaults[]) {
|
|
247
|
-
try {
|
|
248
|
-
const timestamp = Date.now();
|
|
249
|
-
|
|
250
|
-
await AsyncStorage.setItem(
|
|
251
|
-
ONRAMP_COUNTRIES_DEFAULTS,
|
|
252
|
-
JSON.stringify({ data: countriesDefaults, timestamp })
|
|
253
|
-
);
|
|
254
|
-
} catch {
|
|
255
|
-
console.info('Unable to set OnRamp Countries Defaults');
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
async getOnRampCountriesDefaults() {
|
|
260
|
-
try {
|
|
261
|
-
const result = await AsyncStorage.getItem(ONRAMP_COUNTRIES_DEFAULTS);
|
|
262
|
-
|
|
263
|
-
if (!result) {
|
|
264
|
-
return [];
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const { data, timestamp } = JSON.parse(result);
|
|
268
|
-
|
|
269
|
-
// Cache for 1 week
|
|
270
|
-
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return data ? (data as OnRampCountryDefaults[]) : [];
|
|
275
|
-
} catch {
|
|
276
|
-
console.info('Unable to get OnRamp Countries Defaults');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return [];
|
|
280
|
-
},
|
|
281
|
-
|
|
282
260
|
async setOnRampServiceProviders(serviceProviders: OnRampServiceProvider[]) {
|
|
283
261
|
try {
|
|
284
262
|
const timestamp = Date.now();
|
|
@@ -386,5 +364,39 @@ export const StorageUtil = {
|
|
|
386
364
|
}
|
|
387
365
|
|
|
388
366
|
return [];
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
async setActiveNamespace(namespace?: ChainNamespace) {
|
|
370
|
+
try {
|
|
371
|
+
if (!namespace) {
|
|
372
|
+
await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
|
|
373
|
+
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
await AsyncStorage.setItem(ACTIVE_NAMESPACE, namespace);
|
|
378
|
+
} catch {
|
|
379
|
+
console.info('Unable to set Active Namespace');
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
|
|
383
|
+
async getActiveNamespace() {
|
|
384
|
+
try {
|
|
385
|
+
const namespace = (await AsyncStorage.getItem(ACTIVE_NAMESPACE)) as ChainNamespace;
|
|
386
|
+
|
|
387
|
+
return namespace ?? undefined;
|
|
388
|
+
} catch (err) {
|
|
389
|
+
console.info('Unable to get Active Namespace');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return undefined;
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
async removeActiveNamespace() {
|
|
396
|
+
try {
|
|
397
|
+
await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
|
|
398
|
+
} catch {
|
|
399
|
+
console.info('Unable to remove Active Namespace');
|
|
400
|
+
}
|
|
389
401
|
}
|
|
390
402
|
};
|
package/src/utils/SwapApiUtil.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
+
import type { Balance, CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
1
2
|
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
2
3
|
import { OptionsController } from '../controllers/OptionsController';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
BlockchainApiSwapAllowanceRequest,
|
|
7
|
-
SwapTokenWithBalance
|
|
8
|
-
} from './TypeUtil';
|
|
9
|
-
import { AccountController } from '../controllers/AccountController';
|
|
10
|
-
import { ConnectionController } from '../controllers/ConnectionController';
|
|
4
|
+
import type { BlockchainApiSwapAllowanceRequest, SwapTokenWithBalance } from './TypeUtil';
|
|
5
|
+
import { ConnectionsController } from '../controllers/ConnectionsController';
|
|
6
|
+
import { ConstantsUtil } from './ConstantsUtil';
|
|
11
7
|
|
|
12
8
|
export const SwapApiUtil = {
|
|
13
9
|
async getTokenList() {
|
|
10
|
+
const chainId: CaipNetworkId =
|
|
11
|
+
ConnectionsController.state.activeNetwork?.caipNetworkId ?? 'eip155:1';
|
|
14
12
|
const response = await BlockchainApiController.fetchSwapTokens({
|
|
15
13
|
projectId: OptionsController.state.projectId,
|
|
16
|
-
chainId
|
|
14
|
+
chainId
|
|
17
15
|
});
|
|
18
16
|
const tokens =
|
|
19
17
|
response?.tokens?.map(
|
|
@@ -52,7 +50,7 @@ export const SwapApiUtil = {
|
|
|
52
50
|
|
|
53
51
|
if (response?.allowance && sourceTokenAmount && sourceTokenDecimals) {
|
|
54
52
|
const parsedValue =
|
|
55
|
-
|
|
53
|
+
ConnectionsController.parseUnits(sourceTokenAmount, sourceTokenDecimals) || 0;
|
|
56
54
|
const hasAllowance = BigInt(response.allowance) >= parsedValue;
|
|
57
55
|
|
|
58
56
|
return hasAllowance;
|
|
@@ -61,40 +59,31 @@ export const SwapApiUtil = {
|
|
|
61
59
|
return false;
|
|
62
60
|
},
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
62
|
+
mapBalancesToSwapTokens(balances?: Balance[]) {
|
|
63
|
+
const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
|
|
64
|
+
const address = activeNamespace
|
|
65
|
+
? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
|
|
66
|
+
: undefined;
|
|
67
67
|
|
|
68
|
-
if (!address) {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const response = await BlockchainApiController.getBalance(address, chainId, forceUpdate);
|
|
73
|
-
const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
|
|
74
|
-
|
|
75
|
-
AccountController.setTokenBalance(balances);
|
|
76
|
-
|
|
77
|
-
return this.mapBalancesToSwapTokens(balances);
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
|
|
81
68
|
return (
|
|
82
|
-
balances
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
69
|
+
balances
|
|
70
|
+
?.filter(balance => balance?.quantity?.numeric)
|
|
71
|
+
.map(
|
|
72
|
+
token =>
|
|
73
|
+
({
|
|
74
|
+
...token,
|
|
75
|
+
address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
|
|
76
|
+
decimals: parseInt(token.quantity?.decimals ?? '0', 10),
|
|
77
|
+
logoUri: token.iconUrl,
|
|
78
|
+
eip2612: false
|
|
79
|
+
}) as SwapTokenWithBalance
|
|
80
|
+
) || []
|
|
92
81
|
);
|
|
93
82
|
},
|
|
94
83
|
|
|
95
84
|
async fetchGasPrice() {
|
|
96
85
|
const projectId = OptionsController.state.projectId;
|
|
97
|
-
const caipNetwork =
|
|
86
|
+
const caipNetwork = ConnectionsController.state.activeNetwork;
|
|
98
87
|
|
|
99
88
|
if (!caipNetwork) {
|
|
100
89
|
return null;
|
|
@@ -102,7 +91,7 @@ export const SwapApiUtil = {
|
|
|
102
91
|
|
|
103
92
|
return await BlockchainApiController.fetchGasPrice({
|
|
104
93
|
projectId,
|
|
105
|
-
chainId: caipNetwork.
|
|
94
|
+
chainId: caipNetwork.caipNetworkId
|
|
106
95
|
});
|
|
107
96
|
}
|
|
108
97
|
};
|