@reown/appkit-core-react-native 0.0.0-feat-onramp-20250722205908 → 0.0.0-feat-coinbase-20250723185200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/controllers/AccountController.js +20 -17
- package/lib/commonjs/controllers/AccountController.js.map +1 -1
- package/lib/commonjs/controllers/ApiController.js +28 -16
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +204 -74
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionController.js +8 -11
- package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +387 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +4 -4
- package/lib/commonjs/controllers/EnsController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +4 -4
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js +6 -7
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +22 -69
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +17 -3
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +1 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +101 -101
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SnackController.js +29 -5
- package/lib/commonjs/controllers/SnackController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +151 -150
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +9 -1
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +25 -21
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/index.js +3 -24
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +3 -15
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +538 -9
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +12 -6
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +9 -28
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/StorageUtil.js +90 -95
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +15 -21
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/controllers/AccountController.js +20 -17
- package/lib/module/controllers/AccountController.js.map +1 -1
- package/lib/module/controllers/ApiController.js +27 -16
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +203 -73
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionController.js +8 -11
- package/lib/module/controllers/ConnectionController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +382 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +2 -2
- package/lib/module/controllers/EnsController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +1 -1
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/ModalController.js +6 -7
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +23 -70
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +17 -3
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +1 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +98 -98
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SnackController.js +29 -5
- package/lib/module/controllers/SnackController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +151 -150
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +9 -1
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +23 -19
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/index.js +1 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +3 -15
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +538 -9
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +12 -6
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +9 -28
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/StorageUtil.js +92 -95
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +15 -21
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/typescript/controllers/AccountController.d.ts +4 -4
- package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
- package/lib/typescript/controllers/ApiController.d.ts +3 -2
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +29 -15
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +5 -16
- package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +53 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/ModalController.d.ts +1 -1
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
- package/lib/typescript/controllers/NetworkController.d.ts +1 -1
- package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts +1 -3
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +8 -2
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/PublicStateController.d.ts +1 -1
- package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +4 -16
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts +5 -7
- package/lib/typescript/controllers/SendController.d.ts.map +1 -1
- package/lib/typescript/controllers/SnackController.d.ts +3 -3
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +12 -11
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
- package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +2 -3
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +422 -3
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +5 -4
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StorageUtil.d.ts +18 -14
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -3
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +42 -195
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +4 -5
- package/src/controllers/AccountController.ts +23 -27
- package/src/controllers/ApiController.ts +29 -10
- package/src/controllers/BlockchainApiController.ts +179 -65
- package/src/controllers/ConnectionController.ts +14 -29
- package/src/controllers/ConnectionsController.ts +509 -0
- package/src/controllers/EnsController.ts +2 -2
- package/src/controllers/EventsController.ts +1 -1
- package/src/controllers/ModalController.ts +8 -8
- package/src/controllers/NetworkController.ts +1 -1
- package/src/controllers/OnRampController.ts +35 -99
- package/src/controllers/OptionsController.ts +27 -13
- package/src/controllers/PublicStateController.ts +1 -1
- package/src/controllers/RouterController.ts +5 -54
- package/src/controllers/SendController.ts +124 -113
- package/src/controllers/SnackController.ts +31 -5
- package/src/controllers/SwapController.ts +174 -181
- package/src/controllers/ThemeController.ts +11 -2
- package/src/controllers/TransactionsController.ts +26 -20
- package/src/index.ts +3 -6
- package/src/utils/AssetUtil.ts +4 -20
- package/src/utils/ConstantsUtil.ts +544 -9
- package/src/utils/CoreHelperUtil.ts +35 -8
- package/src/utils/FetchUtil.ts +10 -31
- package/src/utils/StorageUtil.ts +167 -105
- package/src/utils/SwapApiUtil.ts +27 -38
- package/src/utils/TypeUtil.ts +43 -198
- package/lib/commonjs/controllers/ConnectorController.js +0 -49
- package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
- package/lib/commonjs/controllers/WebviewController.js +0 -52
- package/lib/commonjs/controllers/WebviewController.js.map +0 -1
- package/lib/commonjs/utils/ConnectionUtil.js +0 -33
- package/lib/commonjs/utils/ConnectionUtil.js.map +0 -1
- package/lib/commonjs/utils/NetworkUtil.js +0 -46
- package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
- package/lib/module/controllers/ConnectorController.js +0 -44
- package/lib/module/controllers/ConnectorController.js.map +0 -1
- package/lib/module/controllers/WebviewController.js +0 -47
- package/lib/module/controllers/WebviewController.js.map +0 -1
- package/lib/module/utils/ConnectionUtil.js +0 -27
- package/lib/module/utils/ConnectionUtil.js.map +0 -1
- package/lib/module/utils/NetworkUtil.js +0 -40
- package/lib/module/utils/NetworkUtil.js.map +0 -1
- package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
- package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
- package/lib/typescript/controllers/WebviewController.d.ts +0 -21
- package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
- package/lib/typescript/utils/ConnectionUtil.d.ts +0 -4
- package/lib/typescript/utils/ConnectionUtil.d.ts.map +0 -1
- package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
- package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
- package/src/controllers/ConnectorController.ts +0 -63
- package/src/controllers/WebviewController.ts +0 -63
- package/src/utils/ConnectionUtil.ts +0 -27
- package/src/utils/NetworkUtil.ts +0 -33
package/src/utils/FetchUtil.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface Options {
|
|
|
8
8
|
|
|
9
9
|
interface RequestArguments {
|
|
10
10
|
path: string;
|
|
11
|
-
headers?:
|
|
11
|
+
headers?: HeadersInit;
|
|
12
12
|
params?: Record<string, string | undefined>;
|
|
13
13
|
cache?: RequestCache;
|
|
14
14
|
signal?: AbortSignal;
|
|
@@ -88,41 +88,20 @@ export class FetchUtil {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
private createUrl({ path, params }: RequestArguments) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const baseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
|
|
99
|
-
const pathUrl = path.startsWith('/') ? path.substring(1) : path;
|
|
100
|
-
fullUrl = `${baseUrl}${pathUrl}`;
|
|
91
|
+
const url = new URL(path, this.baseUrl);
|
|
92
|
+
if (params) {
|
|
93
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
94
|
+
if (value) {
|
|
95
|
+
url.searchParams.append(key, value);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
101
98
|
}
|
|
102
99
|
|
|
103
|
-
const allParams: Record<string, string | undefined> = { ...params };
|
|
104
100
|
if (this.clientId) {
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const queryParams: string[] = [];
|
|
109
|
-
for (const key in allParams) {
|
|
110
|
-
const value = allParams[key];
|
|
111
|
-
if (value !== undefined) {
|
|
112
|
-
queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (queryParams.length > 0) {
|
|
117
|
-
const queryString = queryParams.join('&');
|
|
118
|
-
if (fullUrl.includes('?')) {
|
|
119
|
-
fullUrl = `${fullUrl}&${queryString}`;
|
|
120
|
-
} else {
|
|
121
|
-
fullUrl = `${fullUrl}?${queryString}`;
|
|
122
|
-
}
|
|
101
|
+
url.searchParams.append('clientId', this.clientId);
|
|
123
102
|
}
|
|
124
103
|
|
|
125
|
-
return
|
|
104
|
+
return url.toString();
|
|
126
105
|
}
|
|
127
106
|
|
|
128
107
|
private async processResponse<T>(response: Response) {
|
package/src/utils/StorageUtil.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
2
|
import type {
|
|
4
3
|
OnRampCountry,
|
|
5
|
-
OnRampCountryDefaults,
|
|
6
4
|
OnRampFiatCurrency,
|
|
7
5
|
OnRampFiatLimit,
|
|
8
6
|
OnRampServiceProvider,
|
|
@@ -11,27 +9,21 @@ import type {
|
|
|
11
9
|
import {
|
|
12
10
|
DateUtil,
|
|
13
11
|
type SocialProvider,
|
|
14
|
-
type ConnectorType
|
|
12
|
+
type ConnectorType,
|
|
13
|
+
type ChainNamespace,
|
|
14
|
+
type WalletDeepLink,
|
|
15
|
+
ConstantsUtil
|
|
15
16
|
} from '@reown/appkit-common-react-native';
|
|
17
|
+
import { OptionsController } from '../controllers/OptionsController';
|
|
16
18
|
|
|
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
19
|
// -- Utility -----------------------------------------------------------------
|
|
31
20
|
export const StorageUtil = {
|
|
32
|
-
setWalletConnectDeepLink({ href, name }:
|
|
21
|
+
setWalletConnectDeepLink({ href, name }: WalletDeepLink) {
|
|
33
22
|
try {
|
|
34
|
-
|
|
23
|
+
OptionsController.getStorage().setItem(ConstantsUtil.STORAGE_KEYS.WC_DEEPLINK, {
|
|
24
|
+
href,
|
|
25
|
+
name
|
|
26
|
+
});
|
|
35
27
|
} catch {
|
|
36
28
|
console.info('Unable to set WalletConnect deep link');
|
|
37
29
|
}
|
|
@@ -39,9 +31,11 @@ export const StorageUtil = {
|
|
|
39
31
|
|
|
40
32
|
async getWalletConnectDeepLink() {
|
|
41
33
|
try {
|
|
42
|
-
const deepLink = await
|
|
34
|
+
const deepLink = await OptionsController.getStorage().getItem<WalletDeepLink>(
|
|
35
|
+
ConstantsUtil.STORAGE_KEYS.WC_DEEPLINK
|
|
36
|
+
);
|
|
43
37
|
if (deepLink) {
|
|
44
|
-
return
|
|
38
|
+
return deepLink;
|
|
45
39
|
}
|
|
46
40
|
} catch {
|
|
47
41
|
console.info('Unable to get WalletConnect deep link');
|
|
@@ -52,7 +46,7 @@ export const StorageUtil = {
|
|
|
52
46
|
|
|
53
47
|
async removeWalletConnectDeepLink() {
|
|
54
48
|
try {
|
|
55
|
-
await
|
|
49
|
+
await OptionsController.getStorage().removeItem(ConstantsUtil.STORAGE_KEYS.WC_DEEPLINK);
|
|
56
50
|
} catch {
|
|
57
51
|
console.info('Unable to delete WalletConnect deep link');
|
|
58
52
|
}
|
|
@@ -71,7 +65,10 @@ export const StorageUtil = {
|
|
|
71
65
|
if (recentWallets.length > 2) {
|
|
72
66
|
recentWallets.pop();
|
|
73
67
|
}
|
|
74
|
-
|
|
68
|
+
OptionsController.getStorage().setItem(
|
|
69
|
+
ConstantsUtil.STORAGE_KEYS.RECENT_WALLET,
|
|
70
|
+
JSON.stringify(recentWallets)
|
|
71
|
+
);
|
|
75
72
|
|
|
76
73
|
return recentWallets;
|
|
77
74
|
} catch {
|
|
@@ -83,7 +80,10 @@ export const StorageUtil = {
|
|
|
83
80
|
|
|
84
81
|
async setRecentWallets(wallets: WcWallet[]) {
|
|
85
82
|
try {
|
|
86
|
-
await
|
|
83
|
+
await OptionsController.getStorage().setItem(
|
|
84
|
+
ConstantsUtil.STORAGE_KEYS.RECENT_WALLET,
|
|
85
|
+
JSON.stringify(wallets)
|
|
86
|
+
);
|
|
87
87
|
} catch {
|
|
88
88
|
console.info('Unable to set recent wallets');
|
|
89
89
|
}
|
|
@@ -91,7 +91,9 @@ export const StorageUtil = {
|
|
|
91
91
|
|
|
92
92
|
async getRecentWallets(): Promise<WcWallet[]> {
|
|
93
93
|
try {
|
|
94
|
-
const recent = await
|
|
94
|
+
const recent = await OptionsController.getStorage().getItem(
|
|
95
|
+
ConstantsUtil.STORAGE_KEYS.RECENT_WALLET
|
|
96
|
+
);
|
|
95
97
|
|
|
96
98
|
return recent ? JSON.parse(recent) : [];
|
|
97
99
|
} catch {
|
|
@@ -101,29 +103,50 @@ export const StorageUtil = {
|
|
|
101
103
|
return [];
|
|
102
104
|
},
|
|
103
105
|
|
|
104
|
-
async
|
|
106
|
+
async setConnectedConnectors({
|
|
107
|
+
type,
|
|
108
|
+
namespaces
|
|
109
|
+
}: {
|
|
110
|
+
type: ConnectorType;
|
|
111
|
+
namespaces: string[];
|
|
112
|
+
}) {
|
|
105
113
|
try {
|
|
106
|
-
|
|
114
|
+
const currentConnectors = (await StorageUtil.getConnectedConnectors()) || [];
|
|
115
|
+
// Only add if it doesn't exist already
|
|
116
|
+
if (!currentConnectors.some(c => c.type === type)) {
|
|
117
|
+
const updatedConnectors = [...currentConnectors, { type, namespaces }];
|
|
118
|
+
await OptionsController.getStorage().setItem(
|
|
119
|
+
ConstantsUtil.STORAGE_KEYS.CONNECTED_CONNECTORS,
|
|
120
|
+
updatedConnectors
|
|
121
|
+
);
|
|
122
|
+
}
|
|
107
123
|
} catch {
|
|
108
124
|
console.info('Unable to set Connected Connector');
|
|
109
125
|
}
|
|
110
126
|
},
|
|
111
127
|
|
|
112
|
-
async
|
|
128
|
+
async getConnectedConnectors(): Promise<{ type: ConnectorType; namespaces: string[] }[]> {
|
|
113
129
|
try {
|
|
114
|
-
const
|
|
130
|
+
const connectors = await OptionsController.getStorage().getItem<
|
|
131
|
+
{ type: ConnectorType; namespaces: string[] }[]
|
|
132
|
+
>(ConstantsUtil.STORAGE_KEYS.CONNECTED_CONNECTORS);
|
|
115
133
|
|
|
116
|
-
return
|
|
117
|
-
} catch {
|
|
134
|
+
return connectors ?? [];
|
|
135
|
+
} catch (err) {
|
|
118
136
|
console.info('Unable to get Connected Connector');
|
|
119
137
|
}
|
|
120
138
|
|
|
121
|
-
return
|
|
139
|
+
return [];
|
|
122
140
|
},
|
|
123
141
|
|
|
124
|
-
async
|
|
142
|
+
async removeConnectedConnectors(type: ConnectorType) {
|
|
125
143
|
try {
|
|
126
|
-
await
|
|
144
|
+
const currentConnectors = await StorageUtil.getConnectedConnectors();
|
|
145
|
+
const updatedConnectors = currentConnectors.filter(c => c.type !== type);
|
|
146
|
+
await OptionsController.getStorage().setItem(
|
|
147
|
+
ConstantsUtil.STORAGE_KEYS.CONNECTED_CONNECTORS,
|
|
148
|
+
updatedConnectors
|
|
149
|
+
);
|
|
127
150
|
} catch {
|
|
128
151
|
console.info('Unable to remove Connected Connector');
|
|
129
152
|
}
|
|
@@ -131,7 +154,10 @@ export const StorageUtil = {
|
|
|
131
154
|
|
|
132
155
|
async setConnectedWalletImageUrl(url: string) {
|
|
133
156
|
try {
|
|
134
|
-
await
|
|
157
|
+
await OptionsController.getStorage().setItem(
|
|
158
|
+
ConstantsUtil.STORAGE_KEYS.CONNECTED_WALLET_IMAGE_URL,
|
|
159
|
+
url
|
|
160
|
+
);
|
|
135
161
|
} catch {
|
|
136
162
|
console.info('Unable to set Connected Wallet Image URL');
|
|
137
163
|
}
|
|
@@ -139,7 +165,9 @@ export const StorageUtil = {
|
|
|
139
165
|
|
|
140
166
|
async getConnectedWalletImageUrl() {
|
|
141
167
|
try {
|
|
142
|
-
return await
|
|
168
|
+
return await OptionsController.getStorage().getItem(
|
|
169
|
+
ConstantsUtil.STORAGE_KEYS.CONNECTED_WALLET_IMAGE_URL
|
|
170
|
+
);
|
|
143
171
|
} catch {
|
|
144
172
|
console.info('Unable to get Connected Wallet Image URL');
|
|
145
173
|
}
|
|
@@ -149,7 +177,9 @@ export const StorageUtil = {
|
|
|
149
177
|
|
|
150
178
|
async removeConnectedWalletImageUrl() {
|
|
151
179
|
try {
|
|
152
|
-
await
|
|
180
|
+
await OptionsController.getStorage().removeItem(
|
|
181
|
+
ConstantsUtil.STORAGE_KEYS.CONNECTED_WALLET_IMAGE_URL
|
|
182
|
+
);
|
|
153
183
|
} catch {
|
|
154
184
|
console.info('Unable to remove Connected Wallet Image URL');
|
|
155
185
|
}
|
|
@@ -157,17 +187,22 @@ export const StorageUtil = {
|
|
|
157
187
|
|
|
158
188
|
async setConnectedSocialProvider(provider: SocialProvider) {
|
|
159
189
|
try {
|
|
160
|
-
await
|
|
190
|
+
await OptionsController.getStorage().setItem(
|
|
191
|
+
ConstantsUtil.STORAGE_KEYS.CONNECTED_SOCIAL,
|
|
192
|
+
provider
|
|
193
|
+
);
|
|
161
194
|
} catch {
|
|
162
195
|
console.info('Unable to set Connected Social Provider');
|
|
163
196
|
}
|
|
164
197
|
},
|
|
165
198
|
|
|
166
|
-
async getConnectedSocialProvider() {
|
|
199
|
+
async getConnectedSocialProvider(): Promise<SocialProvider | undefined> {
|
|
167
200
|
try {
|
|
168
|
-
const provider =
|
|
201
|
+
const provider = await OptionsController.getStorage().getItem<SocialProvider>(
|
|
202
|
+
ConstantsUtil.STORAGE_KEYS.CONNECTED_SOCIAL
|
|
203
|
+
);
|
|
169
204
|
|
|
170
|
-
return provider
|
|
205
|
+
return provider ?? undefined;
|
|
171
206
|
} catch {
|
|
172
207
|
console.info('Unable to get Connected Social Provider');
|
|
173
208
|
}
|
|
@@ -177,7 +212,7 @@ export const StorageUtil = {
|
|
|
177
212
|
|
|
178
213
|
async removeConnectedSocialProvider() {
|
|
179
214
|
try {
|
|
180
|
-
await
|
|
215
|
+
await OptionsController.getStorage().removeItem(ConstantsUtil.STORAGE_KEYS.CONNECTED_SOCIAL);
|
|
181
216
|
} catch {
|
|
182
217
|
console.info('Unable to remove Connected Social Provider');
|
|
183
218
|
}
|
|
@@ -185,7 +220,10 @@ export const StorageUtil = {
|
|
|
185
220
|
|
|
186
221
|
async setOnRampPreferredCountry(country: OnRampCountry) {
|
|
187
222
|
try {
|
|
188
|
-
await
|
|
223
|
+
await OptionsController.getStorage().setItem(
|
|
224
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_COUNTRY,
|
|
225
|
+
country
|
|
226
|
+
);
|
|
189
227
|
} catch {
|
|
190
228
|
console.info('Unable to set OnRamp Preferred Country');
|
|
191
229
|
}
|
|
@@ -193,9 +231,11 @@ export const StorageUtil = {
|
|
|
193
231
|
|
|
194
232
|
async getOnRampPreferredCountry() {
|
|
195
233
|
try {
|
|
196
|
-
const country = await
|
|
234
|
+
const country = await OptionsController.getStorage().getItem<OnRampCountry>(
|
|
235
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_COUNTRY
|
|
236
|
+
);
|
|
197
237
|
|
|
198
|
-
return country
|
|
238
|
+
return country ?? undefined;
|
|
199
239
|
} catch {
|
|
200
240
|
console.info('Unable to get OnRamp Preferred Country');
|
|
201
241
|
}
|
|
@@ -205,7 +245,10 @@ export const StorageUtil = {
|
|
|
205
245
|
|
|
206
246
|
async setOnRampPreferredFiatCurrency(currency: OnRampFiatCurrency) {
|
|
207
247
|
try {
|
|
208
|
-
await
|
|
248
|
+
await OptionsController.getStorage().setItem(
|
|
249
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_FIAT_CURRENCY,
|
|
250
|
+
currency
|
|
251
|
+
);
|
|
209
252
|
} catch {
|
|
210
253
|
console.info('Unable to set OnRamp Preferred Fiat Currency');
|
|
211
254
|
}
|
|
@@ -213,9 +256,11 @@ export const StorageUtil = {
|
|
|
213
256
|
|
|
214
257
|
async getOnRampPreferredFiatCurrency() {
|
|
215
258
|
try {
|
|
216
|
-
const currency = await
|
|
259
|
+
const currency = await OptionsController.getStorage().getItem<OnRampFiatCurrency>(
|
|
260
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_PREFERRED_FIAT_CURRENCY
|
|
261
|
+
);
|
|
217
262
|
|
|
218
|
-
return currency
|
|
263
|
+
return currency ?? undefined;
|
|
219
264
|
} catch {
|
|
220
265
|
console.info('Unable to get OnRamp Preferred Fiat Currency');
|
|
221
266
|
}
|
|
@@ -225,7 +270,10 @@ export const StorageUtil = {
|
|
|
225
270
|
|
|
226
271
|
async setOnRampCountries(countries: OnRampCountry[]) {
|
|
227
272
|
try {
|
|
228
|
-
await
|
|
273
|
+
await OptionsController.getStorage().setItem(
|
|
274
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_COUNTRIES,
|
|
275
|
+
countries
|
|
276
|
+
);
|
|
229
277
|
} catch {
|
|
230
278
|
console.info('Unable to set OnRamp Countries');
|
|
231
279
|
}
|
|
@@ -233,47 +281,13 @@ export const StorageUtil = {
|
|
|
233
281
|
|
|
234
282
|
async getOnRampCountries() {
|
|
235
283
|
try {
|
|
236
|
-
const countries = await
|
|
237
|
-
|
|
238
|
-
return countries ? (JSON.parse(countries) as OnRampCountry[]) : [];
|
|
239
|
-
} catch {
|
|
240
|
-
console.info('Unable to get OnRamp Countries');
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return [];
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
async setOnRampCountriesDefaults(countriesDefaults: OnRampCountryDefaults[]) {
|
|
247
|
-
try {
|
|
248
|
-
const timestamp = Date.now();
|
|
249
|
-
|
|
250
|
-
await AsyncStorage.setItem(
|
|
251
|
-
ONRAMP_COUNTRIES_DEFAULTS,
|
|
252
|
-
JSON.stringify({ data: countriesDefaults, timestamp })
|
|
284
|
+
const countries = await OptionsController.getStorage().getItem<OnRampCountry[]>(
|
|
285
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_COUNTRIES
|
|
253
286
|
);
|
|
254
|
-
} catch {
|
|
255
|
-
console.info('Unable to set OnRamp Countries Defaults');
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
async getOnRampCountriesDefaults() {
|
|
260
|
-
try {
|
|
261
|
-
const result = await AsyncStorage.getItem(ONRAMP_COUNTRIES_DEFAULTS);
|
|
262
|
-
|
|
263
|
-
if (!result) {
|
|
264
|
-
return [];
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const { data, timestamp } = JSON.parse(result);
|
|
268
|
-
|
|
269
|
-
// Cache for 1 week
|
|
270
|
-
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
287
|
|
|
274
|
-
return
|
|
288
|
+
return countries ?? [];
|
|
275
289
|
} catch {
|
|
276
|
-
console.info('Unable to get OnRamp Countries
|
|
290
|
+
console.info('Unable to get OnRamp Countries');
|
|
277
291
|
}
|
|
278
292
|
|
|
279
293
|
return [];
|
|
@@ -283,9 +297,9 @@ export const StorageUtil = {
|
|
|
283
297
|
try {
|
|
284
298
|
const timestamp = Date.now();
|
|
285
299
|
|
|
286
|
-
await
|
|
287
|
-
ONRAMP_SERVICE_PROVIDERS,
|
|
288
|
-
|
|
300
|
+
await OptionsController.getStorage().setItem(
|
|
301
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_SERVICE_PROVIDERS,
|
|
302
|
+
{ data: serviceProviders, timestamp }
|
|
289
303
|
);
|
|
290
304
|
} catch {
|
|
291
305
|
console.info('Unable to set OnRamp Service Providers');
|
|
@@ -294,20 +308,22 @@ export const StorageUtil = {
|
|
|
294
308
|
|
|
295
309
|
async getOnRampServiceProviders() {
|
|
296
310
|
try {
|
|
297
|
-
const result = await
|
|
311
|
+
const result = await OptionsController.getStorage().getItem(
|
|
312
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_SERVICE_PROVIDERS
|
|
313
|
+
);
|
|
298
314
|
|
|
299
315
|
if (!result) {
|
|
300
316
|
return [];
|
|
301
317
|
}
|
|
302
318
|
|
|
303
|
-
const { data, timestamp } =
|
|
319
|
+
const { data, timestamp } = result;
|
|
304
320
|
|
|
305
321
|
// Cache for 1 week
|
|
306
322
|
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
307
323
|
return [];
|
|
308
324
|
}
|
|
309
325
|
|
|
310
|
-
return
|
|
326
|
+
return (data as OnRampServiceProvider[]) ?? [];
|
|
311
327
|
} catch (err) {
|
|
312
328
|
console.error(err);
|
|
313
329
|
console.info('Unable to get OnRamp Service Providers');
|
|
@@ -320,10 +336,10 @@ export const StorageUtil = {
|
|
|
320
336
|
try {
|
|
321
337
|
const timestamp = Date.now();
|
|
322
338
|
|
|
323
|
-
await
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
);
|
|
339
|
+
await OptionsController.getStorage().setItem(ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_LIMITS, {
|
|
340
|
+
data: fiatLimits,
|
|
341
|
+
timestamp
|
|
342
|
+
});
|
|
327
343
|
} catch {
|
|
328
344
|
console.info('Unable to set OnRamp Fiat Limits');
|
|
329
345
|
}
|
|
@@ -331,20 +347,22 @@ export const StorageUtil = {
|
|
|
331
347
|
|
|
332
348
|
async getOnRampFiatLimits() {
|
|
333
349
|
try {
|
|
334
|
-
const result = await
|
|
350
|
+
const result = await OptionsController.getStorage().getItem(
|
|
351
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_LIMITS
|
|
352
|
+
);
|
|
335
353
|
|
|
336
354
|
if (!result) {
|
|
337
355
|
return [];
|
|
338
356
|
}
|
|
339
357
|
|
|
340
|
-
const { data, timestamp } =
|
|
358
|
+
const { data, timestamp } = result;
|
|
341
359
|
|
|
342
360
|
// Cache for 1 week
|
|
343
361
|
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
344
362
|
return [];
|
|
345
363
|
}
|
|
346
364
|
|
|
347
|
-
return
|
|
365
|
+
return (data as OnRampFiatLimit[]) ?? [];
|
|
348
366
|
} catch {
|
|
349
367
|
console.info('Unable to get OnRamp Fiat Limits');
|
|
350
368
|
}
|
|
@@ -356,9 +374,9 @@ export const StorageUtil = {
|
|
|
356
374
|
try {
|
|
357
375
|
const timestamp = Date.now();
|
|
358
376
|
|
|
359
|
-
await
|
|
360
|
-
ONRAMP_FIAT_CURRENCIES,
|
|
361
|
-
|
|
377
|
+
await OptionsController.getStorage().setItem(
|
|
378
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_CURRENCIES,
|
|
379
|
+
{ data: fiatCurrencies, timestamp }
|
|
362
380
|
);
|
|
363
381
|
} catch {
|
|
364
382
|
console.info('Unable to set OnRamp Fiat Currencies');
|
|
@@ -367,24 +385,68 @@ export const StorageUtil = {
|
|
|
367
385
|
|
|
368
386
|
async getOnRampFiatCurrencies() {
|
|
369
387
|
try {
|
|
370
|
-
const result = await
|
|
388
|
+
const result = await OptionsController.getStorage().getItem(
|
|
389
|
+
ConstantsUtil.STORAGE_KEYS.ONRAMP_FIAT_CURRENCIES
|
|
390
|
+
);
|
|
371
391
|
|
|
372
392
|
if (!result) {
|
|
373
393
|
return [];
|
|
374
394
|
}
|
|
375
395
|
|
|
376
|
-
const { data, timestamp } =
|
|
396
|
+
const { data, timestamp } = result;
|
|
377
397
|
|
|
378
398
|
// Cache for 1 week
|
|
379
399
|
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
380
400
|
return [];
|
|
381
401
|
}
|
|
382
402
|
|
|
383
|
-
return
|
|
403
|
+
return (data as OnRampFiatCurrency[]) ?? [];
|
|
384
404
|
} catch {
|
|
385
405
|
console.info('Unable to get OnRamp Fiat Currencies');
|
|
386
406
|
}
|
|
387
407
|
|
|
388
408
|
return [];
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
async setActiveNamespace(namespace?: ChainNamespace) {
|
|
412
|
+
try {
|
|
413
|
+
if (!namespace) {
|
|
414
|
+
await OptionsController.getStorage().removeItem(
|
|
415
|
+
ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
await OptionsController.getStorage().setItem(
|
|
422
|
+
ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE,
|
|
423
|
+
namespace
|
|
424
|
+
);
|
|
425
|
+
} catch {
|
|
426
|
+
console.info('Unable to set Active Namespace');
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
async getActiveNamespace() {
|
|
431
|
+
try {
|
|
432
|
+
const namespace = (await OptionsController.getStorage().getItem(
|
|
433
|
+
ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE
|
|
434
|
+
)) as ChainNamespace;
|
|
435
|
+
|
|
436
|
+
return namespace ?? undefined;
|
|
437
|
+
} catch (err) {
|
|
438
|
+
console.error(err);
|
|
439
|
+
console.info('Unable to get Active Namespace');
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return undefined;
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
async removeActiveNamespace() {
|
|
446
|
+
try {
|
|
447
|
+
await OptionsController.getStorage().removeItem(ConstantsUtil.STORAGE_KEYS.ACTIVE_NAMESPACE);
|
|
448
|
+
} catch {
|
|
449
|
+
console.info('Unable to remove Active Namespace');
|
|
450
|
+
}
|
|
389
451
|
}
|
|
390
452
|
};
|
package/src/utils/SwapApiUtil.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
+
import type { Balance, CaipNetworkId } from '@reown/appkit-common-react-native';
|
|
1
2
|
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
2
3
|
import { OptionsController } from '../controllers/OptionsController';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
BlockchainApiSwapAllowanceRequest,
|
|
7
|
-
SwapTokenWithBalance
|
|
8
|
-
} from './TypeUtil';
|
|
9
|
-
import { AccountController } from '../controllers/AccountController';
|
|
10
|
-
import { ConnectionController } from '../controllers/ConnectionController';
|
|
4
|
+
import type { BlockchainApiSwapAllowanceRequest, SwapTokenWithBalance } from './TypeUtil';
|
|
5
|
+
import { ConnectionsController } from '../controllers/ConnectionsController';
|
|
6
|
+
import { ConstantsUtil } from './ConstantsUtil';
|
|
11
7
|
|
|
12
8
|
export const SwapApiUtil = {
|
|
13
9
|
async getTokenList() {
|
|
10
|
+
const chainId: CaipNetworkId =
|
|
11
|
+
ConnectionsController.state.activeNetwork?.caipNetworkId ?? 'eip155:1';
|
|
14
12
|
const response = await BlockchainApiController.fetchSwapTokens({
|
|
15
13
|
projectId: OptionsController.state.projectId,
|
|
16
|
-
chainId
|
|
14
|
+
chainId
|
|
17
15
|
});
|
|
18
16
|
const tokens =
|
|
19
17
|
response?.tokens?.map(
|
|
@@ -52,7 +50,7 @@ export const SwapApiUtil = {
|
|
|
52
50
|
|
|
53
51
|
if (response?.allowance && sourceTokenAmount && sourceTokenDecimals) {
|
|
54
52
|
const parsedValue =
|
|
55
|
-
|
|
53
|
+
ConnectionsController.parseUnits(sourceTokenAmount, sourceTokenDecimals) || 0;
|
|
56
54
|
const hasAllowance = BigInt(response.allowance) >= parsedValue;
|
|
57
55
|
|
|
58
56
|
return hasAllowance;
|
|
@@ -61,40 +59,31 @@ export const SwapApiUtil = {
|
|
|
61
59
|
return false;
|
|
62
60
|
},
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
62
|
+
mapBalancesToSwapTokens(balances?: Balance[]) {
|
|
63
|
+
const { activeNamespace, activeCaipNetworkId } = ConnectionsController.state;
|
|
64
|
+
const address = activeNamespace
|
|
65
|
+
? ConstantsUtil.NATIVE_TOKEN_ADDRESS[activeNamespace]
|
|
66
|
+
: undefined;
|
|
67
67
|
|
|
68
|
-
if (!address) {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const response = await BlockchainApiController.getBalance(address, chainId, forceUpdate);
|
|
73
|
-
const balances = response?.balances.filter(balance => balance.quantity.decimals !== '0');
|
|
74
|
-
|
|
75
|
-
AccountController.setTokenBalance(balances);
|
|
76
|
-
|
|
77
|
-
return this.mapBalancesToSwapTokens(balances);
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
mapBalancesToSwapTokens(balances?: BlockchainApiBalanceResponse['balances']) {
|
|
81
68
|
return (
|
|
82
|
-
balances
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
69
|
+
balances
|
|
70
|
+
?.filter(balance => balance?.quantity?.numeric)
|
|
71
|
+
.map(
|
|
72
|
+
token =>
|
|
73
|
+
({
|
|
74
|
+
...token,
|
|
75
|
+
address: token?.address ?? `${token?.chainId ?? activeCaipNetworkId}:${address}`,
|
|
76
|
+
decimals: parseInt(token.quantity?.decimals ?? '0', 10),
|
|
77
|
+
logoUri: token.iconUrl,
|
|
78
|
+
eip2612: false
|
|
79
|
+
}) as SwapTokenWithBalance
|
|
80
|
+
) || []
|
|
92
81
|
);
|
|
93
82
|
},
|
|
94
83
|
|
|
95
84
|
async fetchGasPrice() {
|
|
96
85
|
const projectId = OptionsController.state.projectId;
|
|
97
|
-
const caipNetwork =
|
|
86
|
+
const caipNetwork = ConnectionsController.state.activeNetwork;
|
|
98
87
|
|
|
99
88
|
if (!caipNetwork) {
|
|
100
89
|
return null;
|
|
@@ -102,7 +91,7 @@ export const SwapApiUtil = {
|
|
|
102
91
|
|
|
103
92
|
return await BlockchainApiController.fetchGasPrice({
|
|
104
93
|
projectId,
|
|
105
|
-
chainId: caipNetwork.
|
|
94
|
+
chainId: caipNetwork.caipNetworkId
|
|
106
95
|
});
|
|
107
96
|
}
|
|
108
97
|
};
|