@reown/appkit-core-react-native 1.2.4 → 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/controllers/ApiController.js +11 -11
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +187 -14
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionController.js +7 -1
- package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +205 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/ConnectorController.js +1 -0
- package/lib/commonjs/controllers/ConnectorController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +421 -0
- package/lib/commonjs/controllers/OnRampController.js.map +1 -0
- package/lib/commonjs/controllers/OptionsController.js +11 -3
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +3 -2
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +5 -5
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +51 -40
- 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 +2 -2
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/index.js +10 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +5 -6
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +599 -6
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +28 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +15 -4
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/StorageUtil.js +218 -0
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +19 -10
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/ApiController.js +11 -11
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +187 -14
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionController.js +7 -1
- package/lib/module/controllers/ConnectionController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +200 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/ConnectorController.js +1 -0
- package/lib/module/controllers/ConnectorController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +416 -0
- package/lib/module/controllers/OnRampController.js.map +1 -0
- package/lib/module/controllers/OptionsController.js +11 -3
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +3 -2
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +5 -5
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +51 -40
- 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 +2 -2
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +5 -6
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +598 -5
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +26 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +15 -4
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/StorageUtil.js +219 -0
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +19 -10
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/typescript/controllers/AccountController.d.ts +2 -2
- package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
- package/lib/typescript/controllers/ApiController.d.ts +1 -1
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +27 -2
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +2 -0
- package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +43 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/ConnectorController.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 +54 -0
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -0
- 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 +5 -3
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +1 -1
- 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/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +2 -2
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +474 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +5 -2
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +5 -5
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/NetworkUtil.d.ts +1 -1
- package/lib/typescript/utils/NetworkUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StorageUtil.d.ts +26 -2
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +164 -25
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/controllers/AccountController.ts +2 -2
- package/src/controllers/ApiController.ts +12 -7
- package/src/controllers/BlockchainApiController.ts +238 -15
- package/src/controllers/ConnectionController.ts +10 -2
- package/src/controllers/ConnectionsController.ts +291 -0
- package/src/controllers/ConnectorController.ts +1 -0
- package/src/controllers/NetworkController.ts +1 -1
- package/src/controllers/OnRampController.ts +585 -0
- package/src/controllers/OptionsController.ts +19 -13
- package/src/controllers/PublicStateController.ts +1 -1
- package/src/controllers/RouterController.ts +17 -3
- package/src/controllers/SendController.ts +5 -5
- package/src/controllers/SwapController.ts +58 -48
- package/src/controllers/ThemeController.ts +11 -2
- package/src/controllers/TransactionsController.ts +2 -2
- package/src/index.ts +6 -1
- package/src/utils/AssetUtil.ts +5 -7
- package/src/utils/ConstantsUtil.ts +584 -5
- package/src/utils/CoreHelperUtil.ts +38 -3
- package/src/utils/FetchUtil.ts +16 -9
- package/src/utils/NetworkUtil.ts +1 -1
- package/src/utils/StorageUtil.ts +267 -2
- package/src/utils/SwapApiUtil.ts +22 -10
- package/src/utils/TypeUtil.ts +185 -29
- package/lib/commonjs/utils/ConnectionUtil.js +0 -33
- package/lib/commonjs/utils/ConnectionUtil.js.map +0 -1
- package/lib/module/utils/ConnectionUtil.js +0 -27
- package/lib/module/utils/ConnectionUtil.js.map +0 -1
- package/lib/typescript/utils/ConnectionUtil.d.ts +0 -4
- package/lib/typescript/utils/ConnectionUtil.d.ts.map +0 -1
- package/src/utils/ConnectionUtil.ts +0 -27
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;
|
|
@@ -28,41 +28,44 @@ export class FetchUtil {
|
|
|
28
28
|
this.clientId = clientId;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
public async get<T>({ headers, ...args }: RequestArguments) {
|
|
31
|
+
public async get<T>({ headers, signal, ...args }: RequestArguments) {
|
|
32
32
|
const url = this.createUrl(args);
|
|
33
|
-
const response = await fetch(url, { method: 'GET', headers });
|
|
33
|
+
const response = await fetch(url, { method: 'GET', headers, signal });
|
|
34
34
|
|
|
35
35
|
return this.processResponse<T>(response);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
public async post<T>({ body, headers, ...args }: PostArguments) {
|
|
38
|
+
public async post<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
39
39
|
const url = this.createUrl(args);
|
|
40
40
|
const response = await fetch(url, {
|
|
41
41
|
method: 'POST',
|
|
42
42
|
headers,
|
|
43
|
-
body: body ? JSON.stringify(body) : undefined
|
|
43
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
44
|
+
signal
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
return this.processResponse<T>(response);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
public async put<T>({ body, headers, ...args }: PostArguments) {
|
|
50
|
+
public async put<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
50
51
|
const url = this.createUrl(args);
|
|
51
52
|
const response = await fetch(url, {
|
|
52
53
|
method: 'PUT',
|
|
53
54
|
headers,
|
|
54
|
-
body: body ? JSON.stringify(body) : undefined
|
|
55
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
56
|
+
signal
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
return this.processResponse<T>(response);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
public async delete<T>({ body, headers, ...args }: PostArguments) {
|
|
62
|
+
public async delete<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
61
63
|
const url = this.createUrl(args);
|
|
62
64
|
const response = await fetch(url, {
|
|
63
65
|
method: 'DELETE',
|
|
64
66
|
headers,
|
|
65
|
-
body: body ? JSON.stringify(body) : undefined
|
|
67
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
68
|
+
signal
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
return this.processResponse<T>(response);
|
|
@@ -103,6 +106,10 @@ export class FetchUtil {
|
|
|
103
106
|
|
|
104
107
|
private async processResponse<T>(response: Response) {
|
|
105
108
|
if (!response.ok) {
|
|
109
|
+
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
110
|
+
return Promise.reject((await response.json()) as T);
|
|
111
|
+
}
|
|
112
|
+
|
|
106
113
|
const errorText = await response.text();
|
|
107
114
|
|
|
108
115
|
return Promise.reject(`Code: ${response.status} - ${response.statusText} - ${errorText}`);
|
package/src/utils/NetworkUtil.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { NetworkController } from '../controllers/NetworkController';
|
|
|
4
4
|
import { AccountController } from '../controllers/AccountController';
|
|
5
5
|
import { ConnectorController } from '../controllers/ConnectorController';
|
|
6
6
|
import { SwapController } from '../controllers/SwapController';
|
|
7
|
-
import type
|
|
7
|
+
import { type CaipNetwork } from '@reown/appkit-common-react-native';
|
|
8
8
|
|
|
9
9
|
export const NetworkUtil = {
|
|
10
10
|
async handleNetworkSwitch(network: CaipNetwork) {
|
package/src/utils/StorageUtil.ts
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
OnRampCountry,
|
|
5
|
+
OnRampFiatCurrency,
|
|
6
|
+
OnRampFiatLimit,
|
|
7
|
+
OnRampServiceProvider,
|
|
8
|
+
WcWallet
|
|
9
|
+
} from './TypeUtil';
|
|
10
|
+
import {
|
|
11
|
+
DateUtil,
|
|
12
|
+
type SocialProvider,
|
|
13
|
+
type New_ConnectorType,
|
|
14
|
+
type ConnectorType,
|
|
15
|
+
type ChainNamespace
|
|
16
|
+
} from '@reown/appkit-common-react-native';
|
|
5
17
|
|
|
6
18
|
// -- Helpers -----------------------------------------------------------------
|
|
7
19
|
const WC_DEEPLINK = 'WALLETCONNECT_DEEPLINK_CHOICE';
|
|
8
20
|
const RECENT_WALLET = '@w3m/recent';
|
|
9
21
|
const CONNECTED_WALLET_IMAGE_URL = '@w3m/connected_wallet_image_url';
|
|
10
22
|
const CONNECTED_CONNECTOR = '@w3m/connected_connector';
|
|
23
|
+
const CONNECTED_CONNECTORS = '@appkit/connected_connectors';
|
|
11
24
|
const CONNECTED_SOCIAL = '@appkit/connected_social';
|
|
25
|
+
const ONRAMP_PREFERRED_COUNTRY = '@appkit/onramp_preferred_country';
|
|
26
|
+
const ONRAMP_COUNTRIES = '@appkit/onramp_countries';
|
|
27
|
+
const ONRAMP_SERVICE_PROVIDERS = '@appkit/onramp_service_providers';
|
|
28
|
+
const ONRAMP_FIAT_LIMITS = '@appkit/onramp_fiat_limits';
|
|
29
|
+
const ONRAMP_FIAT_CURRENCIES = '@appkit/onramp_fiat_currencies';
|
|
30
|
+
const ONRAMP_PREFERRED_FIAT_CURRENCY = '@appkit/onramp_preferred_fiat_currency';
|
|
31
|
+
const ACTIVE_NAMESPACE = '@appkit/active_namespace';
|
|
12
32
|
|
|
13
33
|
// -- Utility -----------------------------------------------------------------
|
|
14
34
|
export const StorageUtil = {
|
|
@@ -84,6 +104,7 @@ export const StorageUtil = {
|
|
|
84
104
|
return [];
|
|
85
105
|
},
|
|
86
106
|
|
|
107
|
+
//TODO: remove this
|
|
87
108
|
async setConnectedConnector(connectorType: ConnectorType) {
|
|
88
109
|
try {
|
|
89
110
|
await AsyncStorage.setItem(CONNECTED_CONNECTOR, JSON.stringify(connectorType));
|
|
@@ -112,6 +133,47 @@ export const StorageUtil = {
|
|
|
112
133
|
}
|
|
113
134
|
},
|
|
114
135
|
|
|
136
|
+
async setConnectedConnectors({
|
|
137
|
+
type,
|
|
138
|
+
namespaces
|
|
139
|
+
}: {
|
|
140
|
+
type: New_ConnectorType;
|
|
141
|
+
namespaces: string[];
|
|
142
|
+
}) {
|
|
143
|
+
try {
|
|
144
|
+
const currentConnectors = (await StorageUtil.getConnectedConnectors()) || [];
|
|
145
|
+
// Only add if it doesn't exist already
|
|
146
|
+
if (!currentConnectors.some(c => c.type === type)) {
|
|
147
|
+
const updatedConnectors = [...currentConnectors, { type, namespaces }];
|
|
148
|
+
await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
console.info('Unable to set Connected Connector');
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
async getConnectedConnectors(): Promise<{ type: New_ConnectorType; namespaces: string[] }[]> {
|
|
156
|
+
try {
|
|
157
|
+
const connectors = await AsyncStorage.getItem(CONNECTED_CONNECTORS);
|
|
158
|
+
|
|
159
|
+
return connectors ? JSON.parse(connectors) : [];
|
|
160
|
+
} catch {
|
|
161
|
+
console.info('Unable to get Connected Connector');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return [];
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
async removeConnectedConnectors(type: New_ConnectorType) {
|
|
168
|
+
try {
|
|
169
|
+
const currentConnectors = await StorageUtil.getConnectedConnectors();
|
|
170
|
+
const updatedConnectors = currentConnectors.filter(c => c.type !== type);
|
|
171
|
+
await AsyncStorage.setItem(CONNECTED_CONNECTORS, JSON.stringify(updatedConnectors));
|
|
172
|
+
} catch {
|
|
173
|
+
console.info('Unable to remove Connected Connector');
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
|
|
115
177
|
async setConnectedWalletImageUrl(url: string) {
|
|
116
178
|
try {
|
|
117
179
|
await AsyncStorage.setItem(CONNECTED_WALLET_IMAGE_URL, url);
|
|
@@ -164,5 +226,208 @@ export const StorageUtil = {
|
|
|
164
226
|
} catch {
|
|
165
227
|
console.info('Unable to remove Connected Social Provider');
|
|
166
228
|
}
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
async setOnRampPreferredCountry(country: OnRampCountry) {
|
|
232
|
+
try {
|
|
233
|
+
await AsyncStorage.setItem(ONRAMP_PREFERRED_COUNTRY, JSON.stringify(country));
|
|
234
|
+
} catch {
|
|
235
|
+
console.info('Unable to set OnRamp Preferred Country');
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
async getOnRampPreferredCountry() {
|
|
240
|
+
try {
|
|
241
|
+
const country = await AsyncStorage.getItem(ONRAMP_PREFERRED_COUNTRY);
|
|
242
|
+
|
|
243
|
+
return country ? (JSON.parse(country) as OnRampCountry) : undefined;
|
|
244
|
+
} catch {
|
|
245
|
+
console.info('Unable to get OnRamp Preferred Country');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return undefined;
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
async setOnRampPreferredFiatCurrency(currency: OnRampFiatCurrency) {
|
|
252
|
+
try {
|
|
253
|
+
await AsyncStorage.setItem(ONRAMP_PREFERRED_FIAT_CURRENCY, JSON.stringify(currency));
|
|
254
|
+
} catch {
|
|
255
|
+
console.info('Unable to set OnRamp Preferred Fiat Currency');
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
async getOnRampPreferredFiatCurrency() {
|
|
260
|
+
try {
|
|
261
|
+
const currency = await AsyncStorage.getItem(ONRAMP_PREFERRED_FIAT_CURRENCY);
|
|
262
|
+
|
|
263
|
+
return currency ? (JSON.parse(currency) as OnRampFiatCurrency) : undefined;
|
|
264
|
+
} catch {
|
|
265
|
+
console.info('Unable to get OnRamp Preferred Fiat Currency');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return undefined;
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
async setOnRampCountries(countries: OnRampCountry[]) {
|
|
272
|
+
try {
|
|
273
|
+
await AsyncStorage.setItem(ONRAMP_COUNTRIES, JSON.stringify(countries));
|
|
274
|
+
} catch {
|
|
275
|
+
console.info('Unable to set OnRamp Countries');
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
async getOnRampCountries() {
|
|
280
|
+
try {
|
|
281
|
+
const countries = await AsyncStorage.getItem(ONRAMP_COUNTRIES);
|
|
282
|
+
|
|
283
|
+
return countries ? (JSON.parse(countries) as OnRampCountry[]) : [];
|
|
284
|
+
} catch {
|
|
285
|
+
console.info('Unable to get OnRamp Countries');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return [];
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
async setOnRampServiceProviders(serviceProviders: OnRampServiceProvider[]) {
|
|
292
|
+
try {
|
|
293
|
+
const timestamp = Date.now();
|
|
294
|
+
|
|
295
|
+
await AsyncStorage.setItem(
|
|
296
|
+
ONRAMP_SERVICE_PROVIDERS,
|
|
297
|
+
JSON.stringify({ data: serviceProviders, timestamp })
|
|
298
|
+
);
|
|
299
|
+
} catch {
|
|
300
|
+
console.info('Unable to set OnRamp Service Providers');
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
async getOnRampServiceProviders() {
|
|
305
|
+
try {
|
|
306
|
+
const result = await AsyncStorage.getItem(ONRAMP_SERVICE_PROVIDERS);
|
|
307
|
+
|
|
308
|
+
if (!result) {
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const { data, timestamp } = JSON.parse(result);
|
|
313
|
+
|
|
314
|
+
// Cache for 1 week
|
|
315
|
+
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
316
|
+
return [];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return data ? (data as OnRampServiceProvider[]) : [];
|
|
320
|
+
} catch (err) {
|
|
321
|
+
console.error(err);
|
|
322
|
+
console.info('Unable to get OnRamp Service Providers');
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return [];
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
async setOnRampFiatLimits(fiatLimits: OnRampFiatLimit[]) {
|
|
329
|
+
try {
|
|
330
|
+
const timestamp = Date.now();
|
|
331
|
+
|
|
332
|
+
await AsyncStorage.setItem(
|
|
333
|
+
ONRAMP_FIAT_LIMITS,
|
|
334
|
+
JSON.stringify({ data: fiatLimits, timestamp })
|
|
335
|
+
);
|
|
336
|
+
} catch {
|
|
337
|
+
console.info('Unable to set OnRamp Fiat Limits');
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
|
|
341
|
+
async getOnRampFiatLimits() {
|
|
342
|
+
try {
|
|
343
|
+
const result = await AsyncStorage.getItem(ONRAMP_FIAT_LIMITS);
|
|
344
|
+
|
|
345
|
+
if (!result) {
|
|
346
|
+
return [];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const { data, timestamp } = JSON.parse(result);
|
|
350
|
+
|
|
351
|
+
// Cache for 1 week
|
|
352
|
+
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
353
|
+
return [];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return data ? (data as OnRampFiatLimit[]) : [];
|
|
357
|
+
} catch {
|
|
358
|
+
console.info('Unable to get OnRamp Fiat Limits');
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return [];
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
async setOnRampFiatCurrencies(fiatCurrencies: OnRampFiatCurrency[]) {
|
|
365
|
+
try {
|
|
366
|
+
const timestamp = Date.now();
|
|
367
|
+
|
|
368
|
+
await AsyncStorage.setItem(
|
|
369
|
+
ONRAMP_FIAT_CURRENCIES,
|
|
370
|
+
JSON.stringify({ data: fiatCurrencies, timestamp })
|
|
371
|
+
);
|
|
372
|
+
} catch {
|
|
373
|
+
console.info('Unable to set OnRamp Fiat Currencies');
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
async getOnRampFiatCurrencies() {
|
|
378
|
+
try {
|
|
379
|
+
const result = await AsyncStorage.getItem(ONRAMP_FIAT_CURRENCIES);
|
|
380
|
+
|
|
381
|
+
if (!result) {
|
|
382
|
+
return [];
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const { data, timestamp } = JSON.parse(result);
|
|
386
|
+
|
|
387
|
+
// Cache for 1 week
|
|
388
|
+
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
389
|
+
return [];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return data ? (data as OnRampFiatCurrency[]) : [];
|
|
393
|
+
} catch {
|
|
394
|
+
console.info('Unable to get OnRamp Fiat Currencies');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return [];
|
|
398
|
+
},
|
|
399
|
+
|
|
400
|
+
async setActiveNamespace(namespace?: ChainNamespace) {
|
|
401
|
+
try {
|
|
402
|
+
if (!namespace) {
|
|
403
|
+
await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
|
|
404
|
+
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
await AsyncStorage.setItem(ACTIVE_NAMESPACE, namespace);
|
|
409
|
+
} catch {
|
|
410
|
+
console.info('Unable to set Active Namespace');
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
async getActiveNamespace() {
|
|
415
|
+
try {
|
|
416
|
+
const namespace = (await AsyncStorage.getItem(ACTIVE_NAMESPACE)) as ChainNamespace;
|
|
417
|
+
|
|
418
|
+
return namespace ?? undefined;
|
|
419
|
+
} catch (err) {
|
|
420
|
+
console.info('Unable to get Active Namespace');
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return undefined;
|
|
424
|
+
},
|
|
425
|
+
|
|
426
|
+
async removeActiveNamespace() {
|
|
427
|
+
try {
|
|
428
|
+
await AsyncStorage.removeItem(ACTIVE_NAMESPACE);
|
|
429
|
+
} catch {
|
|
430
|
+
console.info('Unable to remove Active Namespace');
|
|
431
|
+
}
|
|
167
432
|
}
|
|
168
433
|
};
|
package/src/utils/SwapApiUtil.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
2
2
|
import { OptionsController } from '../controllers/OptionsController';
|
|
3
|
-
import { NetworkController } from '../controllers/NetworkController';
|
|
4
3
|
import type {
|
|
5
4
|
BlockchainApiBalanceResponse,
|
|
6
5
|
BlockchainApiSwapAllowanceRequest,
|
|
7
6
|
SwapTokenWithBalance
|
|
8
7
|
} from './TypeUtil';
|
|
9
8
|
import { AccountController } from '../controllers/AccountController';
|
|
10
|
-
import {
|
|
9
|
+
import { ConnectionsController } from '../controllers/ConnectionsController';
|
|
10
|
+
import type { CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
11
|
+
import { ConstantsUtil } from './ConstantsUtil';
|
|
11
12
|
|
|
12
13
|
export const SwapApiUtil = {
|
|
13
14
|
async getTokenList() {
|
|
15
|
+
const chainId: CaipNetworkId =
|
|
16
|
+
ConnectionsController.state.activeNetwork?.caipNetworkId ?? 'eip155:1';
|
|
14
17
|
const response = await BlockchainApiController.fetchSwapTokens({
|
|
15
18
|
projectId: OptionsController.state.projectId,
|
|
16
|
-
chainId
|
|
19
|
+
chainId
|
|
17
20
|
});
|
|
18
21
|
const tokens =
|
|
19
22
|
response?.tokens?.map(
|
|
@@ -52,7 +55,7 @@ export const SwapApiUtil = {
|
|
|
52
55
|
|
|
53
56
|
if (response?.allowance && sourceTokenAmount && sourceTokenDecimals) {
|
|
54
57
|
const parsedValue =
|
|
55
|
-
|
|
58
|
+
ConnectionsController.parseUnits(sourceTokenAmount, sourceTokenDecimals) || 0;
|
|
56
59
|
const hasAllowance = BigInt(response.allowance) >= parsedValue;
|
|
57
60
|
|
|
58
61
|
return hasAllowance;
|
|
@@ -62,14 +65,18 @@ export const SwapApiUtil = {
|
|
|
62
65
|
},
|
|
63
66
|
|
|
64
67
|
async getMyTokensWithBalance(forceUpdate?: string) {
|
|
65
|
-
const
|
|
66
|
-
const
|
|
68
|
+
const { activeAddress, activeNetwork: network } = ConnectionsController.state;
|
|
69
|
+
const address = activeAddress?.split(':')[2];
|
|
67
70
|
|
|
68
71
|
if (!address) {
|
|
69
72
|
return [];
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
const response = await BlockchainApiController.getBalance(
|
|
75
|
+
const response = await BlockchainApiController.getBalance(
|
|
76
|
+
address,
|
|
77
|
+
network?.caipNetworkId,
|
|
78
|
+
forceUpdate
|
|
79
|
+
);
|
|
73
80
|
const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
|
|
74
81
|
|
|
75
82
|
AccountController.setTokenBalance(balances);
|
|
@@ -78,12 +85,17 @@ export const SwapApiUtil = {
|
|
|
78
85
|
},
|
|
79
86
|
|
|
80
87
|
mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
|
|
88
|
+
const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
|
|
89
|
+
const address = activeNamespace
|
|
90
|
+
? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
|
|
91
|
+
: undefined;
|
|
92
|
+
|
|
81
93
|
return (
|
|
82
94
|
balances?.map(
|
|
83
95
|
token =>
|
|
84
96
|
({
|
|
85
97
|
...token,
|
|
86
|
-
address: token?.address
|
|
98
|
+
address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
|
|
87
99
|
decimals: parseInt(token.quantity.decimals, 10),
|
|
88
100
|
logoUri: token.iconUrl,
|
|
89
101
|
eip2612: false
|
|
@@ -94,7 +106,7 @@ export const SwapApiUtil = {
|
|
|
94
106
|
|
|
95
107
|
async fetchGasPrice() {
|
|
96
108
|
const projectId = OptionsController.state.projectId;
|
|
97
|
-
const caipNetwork =
|
|
109
|
+
const caipNetwork = ConnectionsController.state.activeNetwork;
|
|
98
110
|
|
|
99
111
|
if (!caipNetwork) {
|
|
100
112
|
return null;
|
|
@@ -102,7 +114,7 @@ export const SwapApiUtil = {
|
|
|
102
114
|
|
|
103
115
|
return await BlockchainApiController.fetchGasPrice({
|
|
104
116
|
projectId,
|
|
105
|
-
chainId: caipNetwork.
|
|
117
|
+
chainId: caipNetwork.caipNetworkId
|
|
106
118
|
});
|
|
107
119
|
}
|
|
108
120
|
};
|