@reown/appkit-core-react-native 0.0.0-develop-20250728153935 → 0.0.0-develop-20251008155354
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 +157 -91
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/AssetController.js +0 -4
- package/lib/commonjs/controllers/AssetController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +180 -78
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +425 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +2 -0
- package/lib/commonjs/controllers/EnsController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +51 -1
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/LogController.js +188 -0
- package/lib/commonjs/controllers/LogController.js.map +1 -0
- package/lib/commonjs/controllers/ModalController.js +9 -7
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +47 -20
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +28 -10
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +7 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +111 -95
- 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 +162 -151
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +14 -1
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +24 -18
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/controllers/WcController.js +73 -0
- package/lib/commonjs/controllers/WcController.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/index.js +28 -0
- package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
- package/lib/commonjs/index.js +33 -40
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ApiUtil.js +1 -1
- package/lib/commonjs/utils/ApiUtil.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +8 -18
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +117 -5
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +32 -9
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/EventUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +7 -2
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/LogUtils.js +131 -0
- package/lib/commonjs/utils/LogUtils.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +131 -150
- 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/commonjs/utils/SwapCalculationUtil.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 +159 -91
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/AssetController.js +2 -4
- package/lib/module/controllers/AssetController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +182 -78
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +422 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +4 -0
- package/lib/module/controllers/EnsController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +53 -1
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/LogController.js +185 -0
- package/lib/module/controllers/LogController.js.map +1 -0
- package/lib/module/controllers/ModalController.js +11 -7
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +45 -16
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +30 -10
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/PublicStateController.js +2 -0
- package/lib/module/controllers/PublicStateController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +9 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +113 -95
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SnackController.js +31 -5
- package/lib/module/controllers/SnackController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +164 -151
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +16 -1
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +26 -18
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/controllers/WcController.js +70 -0
- package/lib/module/controllers/WcController.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/module/features/reown-authentication/index.js +5 -0
- package/lib/module/features/reown-authentication/index.js.map +1 -0
- package/lib/module/index.js +13 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/ApiUtil.js +3 -1
- package/lib/module/utils/ApiUtil.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +10 -18
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +119 -5
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +34 -7
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/EventUtil.js +2 -0
- package/lib/module/utils/EventUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +10 -2
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/LogUtils.js +121 -0
- package/lib/module/utils/LogUtils.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +134 -150
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +17 -21
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/utils/SwapCalculationUtil.js +3 -0
- package/lib/module/utils/SwapCalculationUtil.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 +9 -8
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/AssetController.d.ts +0 -2
- package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +29 -11
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EnsController.d.ts +1 -1
- package/lib/typescript/controllers/EnsController.d.ts.map +1 -1
- package/lib/typescript/controllers/EventsController.d.ts +13 -1
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
- package/lib/typescript/controllers/LogController.d.ts +65 -0
- package/lib/typescript/controllers/LogController.d.ts.map +1 -0
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts +2 -2
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +11 -6
- 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 +6 -20
- 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 -12
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts +3 -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/controllers/WcController.d.ts +27 -0
- package/lib/typescript/controllers/WcController.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
- package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +7 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/ApiUtil.d.ts +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +3 -4
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +11 -2
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +8 -6
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/EventUtil.d.ts +1 -1
- package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +4 -4
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/LogUtils.d.ts +15 -0
- package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
- package/lib/typescript/utils/StorageUtil.d.ts +15 -16
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
- package/lib/typescript/utils/SwapCalculationUtil.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 +11 -24
- package/src/controllers/ApiController.ts +167 -84
- package/src/controllers/AssetController.ts +0 -6
- package/src/controllers/BlockchainApiController.ts +168 -66
- package/src/controllers/ConnectionsController.ts +575 -0
- package/src/controllers/EnsController.ts +3 -1
- package/src/controllers/EventsController.ts +73 -2
- package/src/controllers/LogController.ts +250 -0
- package/src/controllers/ModalController.ts +10 -7
- package/src/controllers/OnRampController.ts +54 -19
- package/src/controllers/OptionsController.ts +46 -18
- package/src/controllers/PublicStateController.ts +1 -1
- package/src/controllers/RouterController.ts +20 -57
- package/src/controllers/SendController.ts +147 -111
- package/src/controllers/SnackController.ts +31 -5
- package/src/controllers/SwapController.ts +185 -183
- package/src/controllers/ThemeController.ts +18 -2
- package/src/controllers/TransactionsController.ts +27 -19
- package/src/controllers/WcController.ts +93 -0
- package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
- package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
- package/src/features/reown-authentication/index.ts +2 -0
- package/src/index.ts +17 -20
- package/src/utils/ApiUtil.ts +1 -1
- package/src/utils/AssetUtil.ts +9 -22
- package/src/utils/ConstantsUtil.ts +121 -6
- package/src/utils/CoreHelperUtil.ts +66 -10
- package/src/utils/EventUtil.ts +1 -1
- package/src/utils/FetchUtil.ts +14 -5
- package/src/utils/LogUtils.ts +179 -0
- package/src/utils/StorageUtil.ts +191 -176
- package/src/utils/SwapApiUtil.ts +30 -37
- package/src/utils/SwapCalculationUtil.ts +1 -2
- package/src/utils/WalletUtil.ts +14 -0
- package/lib/commonjs/controllers/AccountController.js +0 -93
- package/lib/commonjs/controllers/AccountController.js.map +0 -1
- package/lib/commonjs/controllers/ConnectionController.js +0 -126
- package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
- package/lib/commonjs/controllers/ConnectorController.js +0 -49
- package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
- package/lib/commonjs/controllers/NetworkController.js +0 -90
- package/lib/commonjs/controllers/NetworkController.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/commonjs/utils/RouterUtil.js +0 -25
- package/lib/commonjs/utils/RouterUtil.js.map +0 -1
- package/lib/commonjs/utils/TypeUtil.js +0 -35
- package/lib/commonjs/utils/TypeUtil.js.map +0 -1
- package/lib/module/controllers/AccountController.js +0 -88
- package/lib/module/controllers/AccountController.js.map +0 -1
- package/lib/module/controllers/ConnectionController.js +0 -121
- package/lib/module/controllers/ConnectionController.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/NetworkController.js +0 -85
- package/lib/module/controllers/NetworkController.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/module/utils/RouterUtil.js +0 -19
- package/lib/module/utils/RouterUtil.js.map +0 -1
- package/lib/module/utils/TypeUtil.js +0 -28
- package/lib/module/utils/TypeUtil.js.map +0 -1
- package/lib/typescript/controllers/AccountController.d.ts +0 -33
- package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +0 -66
- package/lib/typescript/controllers/ConnectionController.d.ts.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/NetworkController.d.ts +0 -34
- package/lib/typescript/controllers/NetworkController.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/lib/typescript/utils/RouterUtil.d.ts +0 -5
- package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
- package/lib/typescript/utils/TypeUtil.d.ts +0 -850
- package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
- package/src/controllers/AccountController.ts +0 -128
- package/src/controllers/ConnectionController.ts +0 -200
- package/src/controllers/ConnectorController.ts +0 -63
- package/src/controllers/NetworkController.ts +0 -120
- package/src/controllers/WebviewController.ts +0 -63
- package/src/utils/ConnectionUtil.ts +0 -27
- package/src/utils/NetworkUtil.ts +0 -33
- package/src/utils/RouterUtil.ts +0 -21
- package/src/utils/TypeUtil.ts +0 -1039
package/src/utils/StorageUtil.ts
CHANGED
|
@@ -1,50 +1,43 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
-
import type {
|
|
4
|
-
OnRampCountry,
|
|
5
|
-
OnRampCountryDefaults,
|
|
6
|
-
OnRampFiatCurrency,
|
|
7
|
-
OnRampFiatLimit,
|
|
8
|
-
OnRampServiceProvider,
|
|
9
|
-
WcWallet
|
|
10
|
-
} from './TypeUtil';
|
|
11
2
|
import {
|
|
3
|
+
type OnRampCountry,
|
|
4
|
+
type OnRampFiatCurrency,
|
|
5
|
+
type OnRampFiatLimit,
|
|
6
|
+
type OnRampServiceProvider,
|
|
7
|
+
type OnRampCountryDefaults,
|
|
8
|
+
type WcWallet,
|
|
12
9
|
DateUtil,
|
|
13
|
-
type
|
|
14
|
-
type
|
|
10
|
+
type ConnectorType,
|
|
11
|
+
type ChainNamespace,
|
|
12
|
+
type WalletDeepLink,
|
|
13
|
+
SafeStorageKeys
|
|
15
14
|
} from '@reown/appkit-common-react-native';
|
|
15
|
+
import { OptionsController } from '../controllers/OptionsController';
|
|
16
|
+
import { LogController } from '../controllers/LogController';
|
|
16
17
|
|
|
17
|
-
// -- Helpers -----------------------------------------------------------------
|
|
18
|
-
const WC_DEEPLINK = 'WALLETCONNECT_DEEPLINK_CHOICE';
|
|
19
|
-
const RECENT_WALLET = '@w3m/recent';
|
|
20
|
-
const CONNECTED_WALLET_IMAGE_URL = '@w3m/connected_wallet_image_url';
|
|
21
|
-
const CONNECTED_CONNECTOR = '@w3m/connected_connector';
|
|
22
|
-
const CONNECTED_SOCIAL = '@appkit/connected_social';
|
|
23
|
-
const ONRAMP_PREFERRED_COUNTRY = '@appkit/onramp_preferred_country';
|
|
24
|
-
const ONRAMP_COUNTRIES = '@appkit/onramp_countries';
|
|
25
|
-
const ONRAMP_COUNTRIES_DEFAULTS = '@appkit/onramp_countries_defaults';
|
|
26
|
-
const ONRAMP_SERVICE_PROVIDERS = '@appkit/onramp_service_providers';
|
|
27
|
-
const ONRAMP_FIAT_LIMITS = '@appkit/onramp_fiat_limits';
|
|
28
|
-
const ONRAMP_FIAT_CURRENCIES = '@appkit/onramp_fiat_currencies';
|
|
29
|
-
const ONRAMP_PREFERRED_FIAT_CURRENCY = '@appkit/onramp_preferred_fiat_currency';
|
|
30
18
|
// -- Utility -----------------------------------------------------------------
|
|
31
19
|
export const StorageUtil = {
|
|
32
|
-
setWalletConnectDeepLink({ href, name }:
|
|
20
|
+
setWalletConnectDeepLink({ href, name }: WalletDeepLink) {
|
|
33
21
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
OptionsController.getStorage().setItem(SafeStorageKeys.WC_DEEPLINK, {
|
|
23
|
+
href,
|
|
24
|
+
name
|
|
25
|
+
});
|
|
26
|
+
} catch (error) {
|
|
27
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setWalletConnectDeepLink');
|
|
37
28
|
}
|
|
38
29
|
},
|
|
39
30
|
|
|
40
31
|
async getWalletConnectDeepLink() {
|
|
41
32
|
try {
|
|
42
|
-
const deepLink = await
|
|
33
|
+
const deepLink = await OptionsController.getStorage().getItem<WalletDeepLink>(
|
|
34
|
+
SafeStorageKeys.WC_DEEPLINK
|
|
35
|
+
);
|
|
43
36
|
if (deepLink) {
|
|
44
|
-
return
|
|
37
|
+
return deepLink;
|
|
45
38
|
}
|
|
46
|
-
} catch {
|
|
47
|
-
|
|
39
|
+
} catch (error) {
|
|
40
|
+
LogController.sendError(error, 'StorageUtil.ts', 'getWalletConnectDeepLink');
|
|
48
41
|
}
|
|
49
42
|
|
|
50
43
|
return undefined;
|
|
@@ -52,9 +45,9 @@ export const StorageUtil = {
|
|
|
52
45
|
|
|
53
46
|
async removeWalletConnectDeepLink() {
|
|
54
47
|
try {
|
|
55
|
-
await
|
|
56
|
-
} catch {
|
|
57
|
-
|
|
48
|
+
await OptionsController.getStorage().removeItem(SafeStorageKeys.WC_DEEPLINK);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
LogController.sendError(error, 'StorageUtil.ts', 'removeWalletConnectDeepLink');
|
|
58
51
|
}
|
|
59
52
|
},
|
|
60
53
|
|
|
@@ -71,11 +64,11 @@ export const StorageUtil = {
|
|
|
71
64
|
if (recentWallets.length > 2) {
|
|
72
65
|
recentWallets.pop();
|
|
73
66
|
}
|
|
74
|
-
|
|
67
|
+
OptionsController.getStorage().setItem(SafeStorageKeys.RECENT_WALLET, recentWallets);
|
|
75
68
|
|
|
76
69
|
return recentWallets;
|
|
77
|
-
} catch {
|
|
78
|
-
|
|
70
|
+
} catch (error) {
|
|
71
|
+
LogController.sendError(error, 'StorageUtil.ts', 'addRecentWallet');
|
|
79
72
|
|
|
80
73
|
return undefined;
|
|
81
74
|
}
|
|
@@ -83,119 +76,91 @@ export const StorageUtil = {
|
|
|
83
76
|
|
|
84
77
|
async setRecentWallets(wallets: WcWallet[]) {
|
|
85
78
|
try {
|
|
86
|
-
await
|
|
87
|
-
} catch {
|
|
88
|
-
|
|
79
|
+
await OptionsController.getStorage().setItem(SafeStorageKeys.RECENT_WALLET, wallets);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setRecentWallets');
|
|
89
82
|
}
|
|
90
83
|
},
|
|
91
84
|
|
|
92
85
|
async getRecentWallets(): Promise<WcWallet[]> {
|
|
93
86
|
try {
|
|
94
|
-
const recent = await
|
|
87
|
+
const recent = await OptionsController.getStorage().getItem(SafeStorageKeys.RECENT_WALLET);
|
|
95
88
|
|
|
96
|
-
return recent
|
|
97
|
-
} catch {
|
|
98
|
-
|
|
89
|
+
return recent ?? [];
|
|
90
|
+
} catch (error) {
|
|
91
|
+
LogController.sendError(error, 'StorageUtil.ts', 'getRecentWallets');
|
|
99
92
|
}
|
|
100
93
|
|
|
101
94
|
return [];
|
|
102
95
|
},
|
|
103
96
|
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async getConnectedConnector(): Promise<ConnectorType | undefined> {
|
|
97
|
+
async setConnectedConnectors({
|
|
98
|
+
type,
|
|
99
|
+
namespaces
|
|
100
|
+
}: {
|
|
101
|
+
type: ConnectorType;
|
|
102
|
+
namespaces: string[];
|
|
103
|
+
}) {
|
|
113
104
|
try {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
await AsyncStorage.removeItem(CONNECTED_CONNECTOR);
|
|
127
|
-
} catch {
|
|
128
|
-
console.info('Unable to remove Connected Connector');
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
async setConnectedWalletImageUrl(url: string) {
|
|
133
|
-
try {
|
|
134
|
-
await AsyncStorage.setItem(CONNECTED_WALLET_IMAGE_URL, url);
|
|
135
|
-
} catch {
|
|
136
|
-
console.info('Unable to set Connected Wallet Image URL');
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
async getConnectedWalletImageUrl() {
|
|
141
|
-
try {
|
|
142
|
-
return await AsyncStorage.getItem(CONNECTED_WALLET_IMAGE_URL);
|
|
143
|
-
} catch {
|
|
144
|
-
console.info('Unable to get Connected Wallet Image URL');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return undefined;
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
async removeConnectedWalletImageUrl() {
|
|
151
|
-
try {
|
|
152
|
-
await AsyncStorage.removeItem(CONNECTED_WALLET_IMAGE_URL);
|
|
153
|
-
} catch {
|
|
154
|
-
console.info('Unable to remove Connected Wallet Image URL');
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
async setConnectedSocialProvider(provider: SocialProvider) {
|
|
159
|
-
try {
|
|
160
|
-
await AsyncStorage.setItem(CONNECTED_SOCIAL, JSON.stringify(provider));
|
|
161
|
-
} catch {
|
|
162
|
-
console.info('Unable to set Connected Social Provider');
|
|
105
|
+
const currentConnectors = (await StorageUtil.getConnectedConnectors()) || [];
|
|
106
|
+
// Only add if it doesn't exist already
|
|
107
|
+
if (!currentConnectors.some(c => c.type === type)) {
|
|
108
|
+
const updatedConnectors = [...currentConnectors, { type, namespaces }];
|
|
109
|
+
await OptionsController.getStorage().setItem(
|
|
110
|
+
SafeStorageKeys.CONNECTED_CONNECTORS,
|
|
111
|
+
updatedConnectors
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setConnectedConnectors');
|
|
163
116
|
}
|
|
164
117
|
},
|
|
165
118
|
|
|
166
|
-
async
|
|
119
|
+
async getConnectedConnectors(): Promise<{ type: ConnectorType; namespaces: string[] }[]> {
|
|
167
120
|
try {
|
|
168
|
-
const
|
|
121
|
+
const connectors = await OptionsController.getStorage().getItem<
|
|
122
|
+
{ type: ConnectorType; namespaces: string[] }[]
|
|
123
|
+
>(SafeStorageKeys.CONNECTED_CONNECTORS);
|
|
169
124
|
|
|
170
|
-
return
|
|
171
|
-
} catch {
|
|
172
|
-
|
|
125
|
+
return connectors ?? [];
|
|
126
|
+
} catch (err) {
|
|
127
|
+
LogController.sendError(err, 'StorageUtil.ts', 'getConnectedConnectors');
|
|
173
128
|
}
|
|
174
129
|
|
|
175
|
-
return
|
|
130
|
+
return [];
|
|
176
131
|
},
|
|
177
132
|
|
|
178
|
-
async
|
|
133
|
+
async removeConnectedConnectors(type: ConnectorType) {
|
|
179
134
|
try {
|
|
180
|
-
await
|
|
181
|
-
|
|
182
|
-
|
|
135
|
+
const currentConnectors = await StorageUtil.getConnectedConnectors();
|
|
136
|
+
const updatedConnectors = currentConnectors.filter(c => c.type !== type);
|
|
137
|
+
await OptionsController.getStorage().setItem(
|
|
138
|
+
SafeStorageKeys.CONNECTED_CONNECTORS,
|
|
139
|
+
updatedConnectors
|
|
140
|
+
);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
LogController.sendError(error, 'StorageUtil.ts', 'removeConnectedConnectors');
|
|
183
143
|
}
|
|
184
144
|
},
|
|
185
145
|
|
|
186
146
|
async setOnRampPreferredCountry(country: OnRampCountry) {
|
|
187
147
|
try {
|
|
188
|
-
await
|
|
189
|
-
|
|
190
|
-
|
|
148
|
+
await OptionsController.getStorage().setItem(
|
|
149
|
+
SafeStorageKeys.ONRAMP_PREFERRED_COUNTRY,
|
|
150
|
+
country
|
|
151
|
+
);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setOnRampPreferredCountry');
|
|
191
154
|
}
|
|
192
155
|
},
|
|
193
156
|
|
|
194
157
|
async getOnRampPreferredCountry() {
|
|
195
158
|
try {
|
|
196
|
-
const country = await
|
|
159
|
+
const country = await OptionsController.getStorage().getItem<OnRampCountry>(
|
|
160
|
+
SafeStorageKeys.ONRAMP_PREFERRED_COUNTRY
|
|
161
|
+
);
|
|
197
162
|
|
|
198
|
-
return country
|
|
163
|
+
return country ?? undefined;
|
|
199
164
|
} catch {
|
|
200
165
|
console.info('Unable to get OnRamp Preferred Country');
|
|
201
166
|
}
|
|
@@ -205,19 +170,24 @@ export const StorageUtil = {
|
|
|
205
170
|
|
|
206
171
|
async setOnRampPreferredFiatCurrency(currency: OnRampFiatCurrency) {
|
|
207
172
|
try {
|
|
208
|
-
await
|
|
209
|
-
|
|
210
|
-
|
|
173
|
+
await OptionsController.getStorage().setItem(
|
|
174
|
+
SafeStorageKeys.ONRAMP_PREFERRED_FIAT_CURRENCY,
|
|
175
|
+
currency
|
|
176
|
+
);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setOnRampPreferredFiatCurrency');
|
|
211
179
|
}
|
|
212
180
|
},
|
|
213
181
|
|
|
214
182
|
async getOnRampPreferredFiatCurrency() {
|
|
215
183
|
try {
|
|
216
|
-
const currency = await
|
|
184
|
+
const currency = await OptionsController.getStorage().getItem<OnRampFiatCurrency>(
|
|
185
|
+
SafeStorageKeys.ONRAMP_PREFERRED_FIAT_CURRENCY
|
|
186
|
+
);
|
|
217
187
|
|
|
218
|
-
return currency
|
|
219
|
-
} catch {
|
|
220
|
-
|
|
188
|
+
return currency ?? undefined;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
LogController.sendError(error, 'StorageUtil.ts', 'getOnRampPreferredFiatCurrency');
|
|
221
191
|
}
|
|
222
192
|
|
|
223
193
|
return undefined;
|
|
@@ -225,19 +195,21 @@ export const StorageUtil = {
|
|
|
225
195
|
|
|
226
196
|
async setOnRampCountries(countries: OnRampCountry[]) {
|
|
227
197
|
try {
|
|
228
|
-
await
|
|
229
|
-
} catch {
|
|
230
|
-
|
|
198
|
+
await OptionsController.getStorage().setItem(SafeStorageKeys.ONRAMP_COUNTRIES, countries);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setOnRampCountries');
|
|
231
201
|
}
|
|
232
202
|
},
|
|
233
203
|
|
|
234
204
|
async getOnRampCountries() {
|
|
235
205
|
try {
|
|
236
|
-
const countries = await
|
|
206
|
+
const countries = await OptionsController.getStorage().getItem<OnRampCountry[]>(
|
|
207
|
+
SafeStorageKeys.ONRAMP_COUNTRIES
|
|
208
|
+
);
|
|
237
209
|
|
|
238
|
-
return countries
|
|
239
|
-
} catch {
|
|
240
|
-
|
|
210
|
+
return countries ?? [];
|
|
211
|
+
} catch (error) {
|
|
212
|
+
LogController.sendError(error, 'StorageUtil.ts', 'getOnRampCountries');
|
|
241
213
|
}
|
|
242
214
|
|
|
243
215
|
return [];
|
|
@@ -247,33 +219,35 @@ export const StorageUtil = {
|
|
|
247
219
|
try {
|
|
248
220
|
const timestamp = Date.now();
|
|
249
221
|
|
|
250
|
-
await
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
);
|
|
254
|
-
} catch {
|
|
255
|
-
|
|
222
|
+
await OptionsController.getStorage().setItem(SafeStorageKeys.ONRAMP_COUNTRIES_DEFAULTS, {
|
|
223
|
+
data: countriesDefaults,
|
|
224
|
+
timestamp
|
|
225
|
+
});
|
|
226
|
+
} catch (error) {
|
|
227
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setOnRampCountriesDefaults');
|
|
256
228
|
}
|
|
257
229
|
},
|
|
258
230
|
|
|
259
231
|
async getOnRampCountriesDefaults() {
|
|
260
232
|
try {
|
|
261
|
-
const result = await
|
|
233
|
+
const result = await OptionsController.getStorage().getItem(
|
|
234
|
+
SafeStorageKeys.ONRAMP_COUNTRIES_DEFAULTS
|
|
235
|
+
);
|
|
262
236
|
|
|
263
237
|
if (!result) {
|
|
264
238
|
return [];
|
|
265
239
|
}
|
|
266
240
|
|
|
267
|
-
const { data, timestamp } =
|
|
241
|
+
const { data, timestamp } = result;
|
|
268
242
|
|
|
269
243
|
// Cache for 1 week
|
|
270
244
|
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
271
245
|
return [];
|
|
272
246
|
}
|
|
273
247
|
|
|
274
|
-
return
|
|
275
|
-
} catch {
|
|
276
|
-
|
|
248
|
+
return (data as OnRampCountryDefaults[]) ?? [];
|
|
249
|
+
} catch (error) {
|
|
250
|
+
LogController.sendError(error, 'StorageUtil.ts', 'getOnRampCountriesDefaults');
|
|
277
251
|
}
|
|
278
252
|
|
|
279
253
|
return [];
|
|
@@ -283,34 +257,35 @@ export const StorageUtil = {
|
|
|
283
257
|
try {
|
|
284
258
|
const timestamp = Date.now();
|
|
285
259
|
|
|
286
|
-
await
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
);
|
|
290
|
-
} catch {
|
|
291
|
-
|
|
260
|
+
await OptionsController.getStorage().setItem(SafeStorageKeys.ONRAMP_SERVICE_PROVIDERS, {
|
|
261
|
+
data: serviceProviders,
|
|
262
|
+
timestamp
|
|
263
|
+
});
|
|
264
|
+
} catch (error) {
|
|
265
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setOnRampServiceProviders');
|
|
292
266
|
}
|
|
293
267
|
},
|
|
294
268
|
|
|
295
269
|
async getOnRampServiceProviders() {
|
|
296
270
|
try {
|
|
297
|
-
const result = await
|
|
271
|
+
const result = await OptionsController.getStorage().getItem(
|
|
272
|
+
SafeStorageKeys.ONRAMP_SERVICE_PROVIDERS
|
|
273
|
+
);
|
|
298
274
|
|
|
299
275
|
if (!result) {
|
|
300
276
|
return [];
|
|
301
277
|
}
|
|
302
278
|
|
|
303
|
-
const { data, timestamp } =
|
|
279
|
+
const { data, timestamp } = result;
|
|
304
280
|
|
|
305
281
|
// Cache for 1 week
|
|
306
282
|
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
307
283
|
return [];
|
|
308
284
|
}
|
|
309
285
|
|
|
310
|
-
return
|
|
286
|
+
return (data as OnRampServiceProvider[]) ?? [];
|
|
311
287
|
} catch (err) {
|
|
312
|
-
|
|
313
|
-
console.info('Unable to get OnRamp Service Providers');
|
|
288
|
+
LogController.sendError(err, 'StorageUtil.ts', 'getOnRampServiceProviders');
|
|
314
289
|
}
|
|
315
290
|
|
|
316
291
|
return [];
|
|
@@ -320,33 +295,35 @@ export const StorageUtil = {
|
|
|
320
295
|
try {
|
|
321
296
|
const timestamp = Date.now();
|
|
322
297
|
|
|
323
|
-
await
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
);
|
|
327
|
-
} catch {
|
|
328
|
-
|
|
298
|
+
await OptionsController.getStorage().setItem(SafeStorageKeys.ONRAMP_FIAT_LIMITS, {
|
|
299
|
+
data: fiatLimits,
|
|
300
|
+
timestamp
|
|
301
|
+
});
|
|
302
|
+
} catch (error) {
|
|
303
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setOnRampFiatLimits');
|
|
329
304
|
}
|
|
330
305
|
},
|
|
331
306
|
|
|
332
307
|
async getOnRampFiatLimits() {
|
|
333
308
|
try {
|
|
334
|
-
const result = await
|
|
309
|
+
const result = await OptionsController.getStorage().getItem(
|
|
310
|
+
SafeStorageKeys.ONRAMP_FIAT_LIMITS
|
|
311
|
+
);
|
|
335
312
|
|
|
336
313
|
if (!result) {
|
|
337
314
|
return [];
|
|
338
315
|
}
|
|
339
316
|
|
|
340
|
-
const { data, timestamp } =
|
|
317
|
+
const { data, timestamp } = result;
|
|
341
318
|
|
|
342
319
|
// Cache for 1 week
|
|
343
320
|
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
344
321
|
return [];
|
|
345
322
|
}
|
|
346
323
|
|
|
347
|
-
return
|
|
348
|
-
} catch {
|
|
349
|
-
|
|
324
|
+
return (data as OnRampFiatLimit[]) ?? [];
|
|
325
|
+
} catch (error) {
|
|
326
|
+
LogController.sendError(error, 'StorageUtil.ts', 'getOnRampFiatLimits');
|
|
350
327
|
}
|
|
351
328
|
|
|
352
329
|
return [];
|
|
@@ -356,35 +333,73 @@ export const StorageUtil = {
|
|
|
356
333
|
try {
|
|
357
334
|
const timestamp = Date.now();
|
|
358
335
|
|
|
359
|
-
await
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
);
|
|
363
|
-
} catch {
|
|
364
|
-
|
|
336
|
+
await OptionsController.getStorage().setItem(SafeStorageKeys.ONRAMP_FIAT_CURRENCIES, {
|
|
337
|
+
data: fiatCurrencies,
|
|
338
|
+
timestamp
|
|
339
|
+
});
|
|
340
|
+
} catch (error) {
|
|
341
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setOnRampFiatCurrencies');
|
|
365
342
|
}
|
|
366
343
|
},
|
|
367
344
|
|
|
368
345
|
async getOnRampFiatCurrencies() {
|
|
369
346
|
try {
|
|
370
|
-
const result = await
|
|
347
|
+
const result = await OptionsController.getStorage().getItem(
|
|
348
|
+
SafeStorageKeys.ONRAMP_FIAT_CURRENCIES
|
|
349
|
+
);
|
|
371
350
|
|
|
372
351
|
if (!result) {
|
|
373
352
|
return [];
|
|
374
353
|
}
|
|
375
354
|
|
|
376
|
-
const { data, timestamp } =
|
|
355
|
+
const { data, timestamp } = result;
|
|
377
356
|
|
|
378
357
|
// Cache for 1 week
|
|
379
358
|
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
380
359
|
return [];
|
|
381
360
|
}
|
|
382
361
|
|
|
383
|
-
return
|
|
384
|
-
} catch {
|
|
385
|
-
|
|
362
|
+
return (data as OnRampFiatCurrency[]) ?? [];
|
|
363
|
+
} catch (error) {
|
|
364
|
+
LogController.sendError(error, 'StorageUtil.ts', 'getOnRampFiatCurrencies');
|
|
386
365
|
}
|
|
387
366
|
|
|
388
367
|
return [];
|
|
368
|
+
},
|
|
369
|
+
|
|
370
|
+
async setActiveNamespace(namespace?: ChainNamespace) {
|
|
371
|
+
try {
|
|
372
|
+
if (!namespace) {
|
|
373
|
+
await OptionsController.getStorage().removeItem(SafeStorageKeys.ACTIVE_NAMESPACE);
|
|
374
|
+
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
await OptionsController.getStorage().setItem(SafeStorageKeys.ACTIVE_NAMESPACE, namespace);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
LogController.sendError(error, 'StorageUtil.ts', 'setActiveNamespace');
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
|
|
384
|
+
async getActiveNamespace() {
|
|
385
|
+
try {
|
|
386
|
+
const namespace = (await OptionsController.getStorage().getItem(
|
|
387
|
+
SafeStorageKeys.ACTIVE_NAMESPACE
|
|
388
|
+
)) as ChainNamespace;
|
|
389
|
+
|
|
390
|
+
return namespace ?? undefined;
|
|
391
|
+
} catch (err) {
|
|
392
|
+
LogController.sendError(err, 'StorageUtil.ts', 'getActiveNamespace');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return undefined;
|
|
396
|
+
},
|
|
397
|
+
|
|
398
|
+
async removeActiveNamespace() {
|
|
399
|
+
try {
|
|
400
|
+
await OptionsController.getStorage().removeItem(SafeStorageKeys.ACTIVE_NAMESPACE);
|
|
401
|
+
} catch (error) {
|
|
402
|
+
LogController.sendError(error, 'StorageUtil.ts', 'removeActiveNamespace');
|
|
403
|
+
}
|
|
389
404
|
}
|
|
390
405
|
};
|
package/src/utils/SwapApiUtil.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
2
|
-
import { OptionsController } from '../controllers/OptionsController';
|
|
3
|
-
import { NetworkController } from '../controllers/NetworkController';
|
|
4
1
|
import type {
|
|
5
|
-
|
|
2
|
+
Balance,
|
|
3
|
+
CaipNetworkId,
|
|
6
4
|
BlockchainApiSwapAllowanceRequest,
|
|
7
5
|
SwapTokenWithBalance
|
|
8
|
-
} from '
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
} from '@reown/appkit-common-react-native';
|
|
7
|
+
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
8
|
+
import { OptionsController } from '../controllers/OptionsController';
|
|
9
|
+
import { ConnectionsController } from '../controllers/ConnectionsController';
|
|
10
|
+
import { ConstantsUtil } from './ConstantsUtil';
|
|
11
11
|
|
|
12
12
|
export const SwapApiUtil = {
|
|
13
13
|
async getTokenList() {
|
|
14
|
+
const chainId: CaipNetworkId =
|
|
15
|
+
ConnectionsController.state.activeNetwork?.caipNetworkId ?? 'eip155:1';
|
|
14
16
|
const response = await BlockchainApiController.fetchSwapTokens({
|
|
15
17
|
projectId: OptionsController.state.projectId,
|
|
16
|
-
chainId
|
|
18
|
+
chainId
|
|
17
19
|
});
|
|
18
20
|
const tokens =
|
|
19
21
|
response?.tokens?.map(
|
|
@@ -52,7 +54,7 @@ export const SwapApiUtil = {
|
|
|
52
54
|
|
|
53
55
|
if (response?.allowance && sourceTokenAmount && sourceTokenDecimals) {
|
|
54
56
|
const parsedValue =
|
|
55
|
-
|
|
57
|
+
ConnectionsController.parseUnits(sourceTokenAmount, sourceTokenDecimals) || 0;
|
|
56
58
|
const hasAllowance = BigInt(response.allowance) >= parsedValue;
|
|
57
59
|
|
|
58
60
|
return hasAllowance;
|
|
@@ -61,40 +63,31 @@ export const SwapApiUtil = {
|
|
|
61
63
|
return false;
|
|
62
64
|
},
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const response = await BlockchainApiController.getBalance(address, chainId, forceUpdate);
|
|
73
|
-
const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
|
|
66
|
+
mapBalancesToSwapTokens(balances?: Balance[]) {
|
|
67
|
+
const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
|
|
68
|
+
const address = activeNamespace
|
|
69
|
+
? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
|
|
70
|
+
: undefined;
|
|
74
71
|
|
|
75
|
-
AccountController.setTokenBalance(balances);
|
|
76
|
-
|
|
77
|
-
return this.mapBalancesToSwapTokens(balances);
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
|
|
81
72
|
return (
|
|
82
|
-
balances
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
73
|
+
balances
|
|
74
|
+
?.filter(balance => balance?.quantity?.numeric)
|
|
75
|
+
.map(
|
|
76
|
+
token =>
|
|
77
|
+
({
|
|
78
|
+
...token,
|
|
79
|
+
address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
|
|
80
|
+
decimals: parseInt(token.quantity?.decimals ?? '0', 10),
|
|
81
|
+
logoUri: token.iconUrl,
|
|
82
|
+
eip2612: false
|
|
83
|
+
}) as SwapTokenWithBalance
|
|
84
|
+
) || []
|
|
92
85
|
);
|
|
93
86
|
},
|
|
94
87
|
|
|
95
88
|
async fetchGasPrice() {
|
|
96
89
|
const projectId = OptionsController.state.projectId;
|
|
97
|
-
const caipNetwork =
|
|
90
|
+
const caipNetwork = ConnectionsController.state.activeNetwork;
|
|
98
91
|
|
|
99
92
|
if (!caipNetwork) {
|
|
100
93
|
return null;
|
|
@@ -102,7 +95,7 @@ export const SwapApiUtil = {
|
|
|
102
95
|
|
|
103
96
|
return await BlockchainApiController.fetchGasPrice({
|
|
104
97
|
projectId,
|
|
105
|
-
chainId: caipNetwork.
|
|
98
|
+
chainId: caipNetwork.caipNetworkId
|
|
106
99
|
});
|
|
107
100
|
}
|
|
108
101
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// -- Types --------------------------------------------- //
|
|
2
2
|
|
|
3
|
-
import { NumberUtil } from '@reown/appkit-common-react-native';
|
|
4
|
-
import type { SwapTokenWithBalance } from './TypeUtil';
|
|
3
|
+
import { NumberUtil, type SwapTokenWithBalance } from '@reown/appkit-common-react-native';
|
|
5
4
|
|
|
6
5
|
// -- Util ---------------------------------------- //
|
|
7
6
|
export const SwapCalculationUtil = {
|