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