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