@reown/appkit-core-react-native 1.2.6 → 1.3.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/BlockchainApiController.js +65 -1
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectorController.js +3 -3
- package/lib/commonjs/controllers/ConnectorController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/NetworkController.js +2 -2
- package/lib/commonjs/controllers/NetworkController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +475 -0
- package/lib/commonjs/controllers/OnRampController.js.map +1 -0
- package/lib/commonjs/controllers/OptionsController.js +3 -0
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +3 -2
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +8 -5
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +69 -5
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +28 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +20 -4
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/StorageUtil.js +185 -1
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +29 -0
- package/lib/commonjs/utils/TypeUtil.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +64 -0
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectorController.js +3 -3
- package/lib/module/controllers/ConnectorController.js.map +1 -1
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/NetworkController.js +2 -2
- package/lib/module/controllers/NetworkController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +470 -0
- package/lib/module/controllers/OnRampController.js.map +1 -0
- package/lib/module/controllers/OptionsController.js +3 -0
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +3 -2
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +8 -5
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +68 -4
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +26 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +20 -4
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/StorageUtil.js +186 -1
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +27 -1
- package/lib/module/utils/TypeUtil.js.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +16 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectorController.d.ts +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/NetworkController.d.ts +3 -2
- package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts +55 -0
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -0
- package/lib/typescript/controllers/OptionsController.d.ts +2 -0
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +4 -3
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +55 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +3 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +4 -4
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StorageUtil.d.ts +16 -2
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +172 -0
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/controllers/BlockchainApiController.ts +87 -1
- package/src/controllers/ConnectorController.ts +3 -3
- package/src/controllers/ModalController.ts +1 -2
- package/src/controllers/NetworkController.ts +4 -4
- package/src/controllers/OnRampController.ts +663 -0
- package/src/controllers/OptionsController.ts +5 -0
- package/src/controllers/RouterController.ts +16 -3
- package/src/index.ts +1 -0
- package/src/utils/AssetUtil.ts +9 -5
- package/src/utils/ConstantsUtil.ts +49 -4
- package/src/utils/CoreHelperUtil.ts +30 -0
- package/src/utils/FetchUtil.ts +21 -8
- package/src/utils/StorageUtil.ts +225 -3
- package/src/utils/TypeUtil.ts +201 -1
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { proxy } from 'valtio';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
WcWallet,
|
|
4
|
+
CaipNetwork,
|
|
5
|
+
Connector,
|
|
6
|
+
SwapInputTarget,
|
|
7
|
+
OnRampTransactionResult
|
|
8
|
+
} from '../utils/TypeUtil';
|
|
3
9
|
|
|
4
10
|
// -- Types --------------------------------------------- //
|
|
5
11
|
type TransactionAction = {
|
|
@@ -28,6 +34,11 @@ export interface RouterControllerState {
|
|
|
28
34
|
| 'EmailVerifyOtp'
|
|
29
35
|
| 'GetWallet'
|
|
30
36
|
| 'Networks'
|
|
37
|
+
| 'OnRamp'
|
|
38
|
+
| 'OnRampCheckout'
|
|
39
|
+
| 'OnRampLoading'
|
|
40
|
+
| 'OnRampSettings'
|
|
41
|
+
| 'OnRampTransaction'
|
|
31
42
|
| 'SwitchNetwork'
|
|
32
43
|
| 'Swap'
|
|
33
44
|
| 'SwapSelectToken'
|
|
@@ -54,6 +65,7 @@ export interface RouterControllerState {
|
|
|
54
65
|
email?: string;
|
|
55
66
|
newEmail?: string;
|
|
56
67
|
swapTarget?: SwapInputTarget;
|
|
68
|
+
onrampResult?: OnRampTransactionResult;
|
|
57
69
|
};
|
|
58
70
|
transactionStack: TransactionAction[];
|
|
59
71
|
}
|
|
@@ -101,13 +113,14 @@ export const RouterController = {
|
|
|
101
113
|
}
|
|
102
114
|
},
|
|
103
115
|
|
|
104
|
-
reset(view: RouterControllerState['view']) {
|
|
116
|
+
reset(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
|
|
105
117
|
state.view = view;
|
|
106
118
|
state.history = [view];
|
|
119
|
+
state.data = data;
|
|
107
120
|
},
|
|
108
121
|
|
|
109
122
|
replace(view: RouterControllerState['view'], data?: RouterControllerState['data']) {
|
|
110
|
-
if (state.history.length
|
|
123
|
+
if (state.history.length >= 1 && state.history.at(-1) !== view) {
|
|
111
124
|
state.view = view;
|
|
112
125
|
state.history[state.history.length - 1] = view;
|
|
113
126
|
state.data = data;
|
package/src/index.ts
CHANGED
|
@@ -56,6 +56,7 @@ export {
|
|
|
56
56
|
|
|
57
57
|
export { SendController, type SendControllerState } from './controllers/SendController';
|
|
58
58
|
|
|
59
|
+
export { OnRampController, type OnRampControllerState } from './controllers/OnRampController';
|
|
59
60
|
export { WebviewController, type WebviewControllerState } from './controllers/WebviewController';
|
|
60
61
|
|
|
61
62
|
// -- Utils -------------------------------------------------------------------
|
package/src/utils/AssetUtil.ts
CHANGED
|
@@ -14,13 +14,17 @@ export const AssetUtil = {
|
|
|
14
14
|
return undefined;
|
|
15
15
|
},
|
|
16
16
|
|
|
17
|
-
getNetworkImage(network?: CaipNetwork) {
|
|
18
|
-
if (network
|
|
19
|
-
return
|
|
17
|
+
getNetworkImage(network?: CaipNetwork, networkImages?: Record<string, string>) {
|
|
18
|
+
if (!network) {
|
|
19
|
+
return undefined;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if (network
|
|
23
|
-
return
|
|
22
|
+
if (network.imageUrl) {
|
|
23
|
+
return network.imageUrl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (network.imageId) {
|
|
27
|
+
return networkImages?.[network.imageId];
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
return undefined;
|
|
@@ -2,11 +2,28 @@ import type { Features } from './TypeUtil';
|
|
|
2
2
|
|
|
3
3
|
const defaultFeatures: Features = {
|
|
4
4
|
swaps: true,
|
|
5
|
+
onramp: true,
|
|
5
6
|
email: true,
|
|
6
7
|
emailShowWallets: true,
|
|
7
8
|
socials: ['x', 'discord', 'apple']
|
|
8
9
|
};
|
|
9
10
|
|
|
11
|
+
export const OnRampErrorType = {
|
|
12
|
+
AMOUNT_TOO_LOW: 'INVALID_AMOUNT_TOO_LOW',
|
|
13
|
+
AMOUNT_TOO_HIGH: 'INVALID_AMOUNT_TOO_HIGH',
|
|
14
|
+
INVALID_AMOUNT: 'INVALID_AMOUNT',
|
|
15
|
+
INCOMPATIBLE_REQUEST: 'INCOMPATIBLE_REQUEST',
|
|
16
|
+
BAD_REQUEST: 'BAD_REQUEST',
|
|
17
|
+
NO_VALID_QUOTES: 'NO_VALID_QUOTES',
|
|
18
|
+
FAILED_TO_LOAD: 'FAILED_TO_LOAD',
|
|
19
|
+
FAILED_TO_LOAD_COUNTRIES: 'FAILED_TO_LOAD_COUNTRIES',
|
|
20
|
+
FAILED_TO_LOAD_PROVIDERS: 'FAILED_TO_LOAD_PROVIDERS',
|
|
21
|
+
FAILED_TO_LOAD_METHODS: 'FAILED_TO_LOAD_METHODS',
|
|
22
|
+
FAILED_TO_LOAD_CURRENCIES: 'FAILED_TO_LOAD_CURRENCIES',
|
|
23
|
+
FAILED_TO_LOAD_LIMITS: 'FAILED_TO_LOAD_LIMITS',
|
|
24
|
+
UNKNOWN: 'UNKNOWN_ERROR'
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
10
27
|
export const ConstantsUtil = {
|
|
11
28
|
FOUR_MINUTES_MS: 240000,
|
|
12
29
|
|
|
@@ -14,12 +31,14 @@ export const ConstantsUtil = {
|
|
|
14
31
|
|
|
15
32
|
ONE_SEC_MS: 1000,
|
|
16
33
|
|
|
17
|
-
EMAIL_REGEX: /^[a-zA-Z0-9
|
|
34
|
+
EMAIL_REGEX: /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/,
|
|
18
35
|
|
|
19
36
|
LINKING_ERROR: 'LINKING_ERROR',
|
|
20
37
|
|
|
21
38
|
NATIVE_TOKEN_ADDRESS: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
|
|
22
39
|
|
|
40
|
+
ONRAMP_ERROR_TYPES: OnRampErrorType,
|
|
41
|
+
|
|
23
42
|
SWAP_SUGGESTED_TOKENS: [
|
|
24
43
|
'ETH',
|
|
25
44
|
'UNI',
|
|
@@ -46,7 +65,7 @@ export const ConstantsUtil = {
|
|
|
46
65
|
'BICO',
|
|
47
66
|
'CRV',
|
|
48
67
|
'ENS',
|
|
49
|
-
'
|
|
68
|
+
'POL',
|
|
50
69
|
'OP'
|
|
51
70
|
],
|
|
52
71
|
|
|
@@ -76,7 +95,7 @@ export const ConstantsUtil = {
|
|
|
76
95
|
'BICO',
|
|
77
96
|
'CRV',
|
|
78
97
|
'ENS',
|
|
79
|
-
'
|
|
98
|
+
'POL',
|
|
80
99
|
'OP',
|
|
81
100
|
'METAL',
|
|
82
101
|
'DAI',
|
|
@@ -139,5 +158,31 @@ export const ConstantsUtil = {
|
|
|
139
158
|
|
|
140
159
|
CONVERT_SLIPPAGE_TOLERANCE: 1,
|
|
141
160
|
|
|
142
|
-
DEFAULT_FEATURES: defaultFeatures
|
|
161
|
+
DEFAULT_FEATURES: defaultFeatures,
|
|
162
|
+
|
|
163
|
+
NETWORK_DEFAULT_CURRENCIES: {
|
|
164
|
+
'eip155:1': 'ETH', // Ethereum Mainnet
|
|
165
|
+
'eip155:56': 'BNB', // Binance Smart Chain
|
|
166
|
+
'eip155:137': 'POL', // Polygon
|
|
167
|
+
'eip155:42161': 'ETH_ARBITRUM', // Arbitrum One
|
|
168
|
+
'eip155:43114': 'AVAX', // Avalanche C-Chain
|
|
169
|
+
'eip155:10': 'ETH_OPTIMISM', // Optimism
|
|
170
|
+
'eip155:250': 'FTM', // Fantom
|
|
171
|
+
'eip155:100': 'xDAI', // Gnosis Chain (formerly xDai)
|
|
172
|
+
'eip155:8453': 'ETH_BASE', // Base
|
|
173
|
+
'eip155:1284': 'GLMR', // Moonbeam
|
|
174
|
+
'eip155:1285': 'MOVR', // Moonriver
|
|
175
|
+
'eip155:25': 'CRO', // Cronos
|
|
176
|
+
'eip155:42220': 'CELO', // Celo
|
|
177
|
+
'eip155:8217': 'KLAY', // Klaytn
|
|
178
|
+
'eip155:1313161554': 'AURORA_ETH', // Aurora
|
|
179
|
+
'eip155:40': 'TLOS', // Telos EVM
|
|
180
|
+
'eip155:1088': 'METIS', // Metis Andromeda
|
|
181
|
+
'eip155:2222': 'KAVA', // Kava EVM
|
|
182
|
+
'eip155:7777777': 'ZETA', // ZetaChain
|
|
183
|
+
'eip155:7700': 'CANTO', // Canto
|
|
184
|
+
'eip155:59144': 'ETH_LINEA', // Linea
|
|
185
|
+
'eip155:1101': 'ETH_POLYGONZKEVM', // Polygon zkEVM
|
|
186
|
+
'eip155:196': 'XIN' // Mixin
|
|
187
|
+
}
|
|
143
188
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Linking, Platform } from 'react-native';
|
|
4
4
|
import { ConstantsUtil as CommonConstants, type Balance } from '@reown/appkit-common-react-native';
|
|
5
|
+
import * as ct from 'countries-and-timezones';
|
|
5
6
|
|
|
6
7
|
import { ConstantsUtil } from './ConstantsUtil';
|
|
7
8
|
import type { CaipAddress, CaipNetwork, DataWallet, LinkingRecord } from './TypeUtil';
|
|
@@ -172,10 +173,25 @@ export const CoreHelperUtil = {
|
|
|
172
173
|
return CommonConstants.BLOCKCHAIN_API_RPC_URL;
|
|
173
174
|
},
|
|
174
175
|
|
|
176
|
+
getBlockchainStagingApiUrl() {
|
|
177
|
+
return CommonConstants.BLOCKCHAIN_API_RPC_URL_STAGING;
|
|
178
|
+
},
|
|
179
|
+
|
|
175
180
|
getAnalyticsUrl() {
|
|
176
181
|
return CommonConstants.PULSE_API_URL;
|
|
177
182
|
},
|
|
178
183
|
|
|
184
|
+
getCountryFromTimezone() {
|
|
185
|
+
try {
|
|
186
|
+
const { timeZone } = new Intl.DateTimeFormat().resolvedOptions();
|
|
187
|
+
const country = ct.getCountryForTimezone(timeZone);
|
|
188
|
+
|
|
189
|
+
return country ? country.id : 'US'; // 'id' is the ISO country code (e.g., "US" for United States)
|
|
190
|
+
} catch (error) {
|
|
191
|
+
return 'US';
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
|
|
179
195
|
getUUID() {
|
|
180
196
|
if ((global as any)?.crypto.getRandomValues) {
|
|
181
197
|
const buffer = new Uint8Array(16);
|
|
@@ -287,5 +303,19 @@ export const CoreHelperUtil = {
|
|
|
287
303
|
}
|
|
288
304
|
|
|
289
305
|
return requested;
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
debounce<F extends (...args: any[]) => any>(func: F, wait: number) {
|
|
309
|
+
let timeout: ReturnType<typeof setTimeout> | null = null;
|
|
310
|
+
|
|
311
|
+
return function (...args: Parameters<F>) {
|
|
312
|
+
if (timeout) {
|
|
313
|
+
clearTimeout(timeout);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
timeout = setTimeout(() => {
|
|
317
|
+
func(...args);
|
|
318
|
+
}, wait);
|
|
319
|
+
};
|
|
290
320
|
}
|
|
291
321
|
};
|
package/src/utils/FetchUtil.ts
CHANGED
|
@@ -28,41 +28,44 @@ export class FetchUtil {
|
|
|
28
28
|
this.clientId = clientId;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
public async get<T>({ headers, ...args }: RequestArguments) {
|
|
31
|
+
public async get<T>({ headers, signal, ...args }: RequestArguments) {
|
|
32
32
|
const url = this.createUrl(args);
|
|
33
|
-
const response = await fetch(url, { method: 'GET', headers });
|
|
33
|
+
const response = await fetch(url, { method: 'GET', headers, signal });
|
|
34
34
|
|
|
35
35
|
return this.processResponse<T>(response);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
public async post<T>({ body, headers, ...args }: PostArguments) {
|
|
38
|
+
public async post<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
39
39
|
const url = this.createUrl(args);
|
|
40
40
|
const response = await fetch(url, {
|
|
41
41
|
method: 'POST',
|
|
42
42
|
headers,
|
|
43
|
-
body: body ? JSON.stringify(body) : undefined
|
|
43
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
44
|
+
signal
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
return this.processResponse<T>(response);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
public async put<T>({ body, headers, ...args }: PostArguments) {
|
|
50
|
+
public async put<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
50
51
|
const url = this.createUrl(args);
|
|
51
52
|
const response = await fetch(url, {
|
|
52
53
|
method: 'PUT',
|
|
53
54
|
headers,
|
|
54
|
-
body: body ? JSON.stringify(body) : undefined
|
|
55
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
56
|
+
signal
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
return this.processResponse<T>(response);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
public async delete<T>({ body, headers, ...args }: PostArguments) {
|
|
62
|
+
public async delete<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
61
63
|
const url = this.createUrl(args);
|
|
62
64
|
const response = await fetch(url, {
|
|
63
65
|
method: 'DELETE',
|
|
64
66
|
headers,
|
|
65
|
-
body: body ? JSON.stringify(body) : undefined
|
|
67
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
68
|
+
signal
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
return this.processResponse<T>(response);
|
|
@@ -124,6 +127,16 @@ export class FetchUtil {
|
|
|
124
127
|
|
|
125
128
|
private async processResponse<T>(response: Response) {
|
|
126
129
|
if (!response.ok) {
|
|
130
|
+
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
131
|
+
try {
|
|
132
|
+
const errorData = await response.json();
|
|
133
|
+
|
|
134
|
+
return Promise.reject(errorData);
|
|
135
|
+
} catch (jsonError) {
|
|
136
|
+
return Promise.reject(`Code: ${response.status} - ${response.statusText}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
127
140
|
const errorText = await response.text();
|
|
128
141
|
|
|
129
142
|
return Promise.reject(`Code: ${response.status} - ${response.statusText} - ${errorText}`);
|
package/src/utils/StorageUtil.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
OnRampCountry,
|
|
5
|
+
OnRampCountryDefaults,
|
|
6
|
+
OnRampFiatCurrency,
|
|
7
|
+
OnRampFiatLimit,
|
|
8
|
+
OnRampServiceProvider,
|
|
9
|
+
WcWallet
|
|
10
|
+
} from './TypeUtil';
|
|
11
|
+
import {
|
|
12
|
+
DateUtil,
|
|
13
|
+
type SocialProvider,
|
|
14
|
+
type ConnectorType
|
|
15
|
+
} from '@reown/appkit-common-react-native';
|
|
5
16
|
|
|
6
17
|
// -- Helpers -----------------------------------------------------------------
|
|
7
18
|
const WC_DEEPLINK = 'WALLETCONNECT_DEEPLINK_CHOICE';
|
|
@@ -9,7 +20,13 @@ const RECENT_WALLET = '@w3m/recent';
|
|
|
9
20
|
const CONNECTED_WALLET_IMAGE_URL = '@w3m/connected_wallet_image_url';
|
|
10
21
|
const CONNECTED_CONNECTOR = '@w3m/connected_connector';
|
|
11
22
|
const CONNECTED_SOCIAL = '@appkit/connected_social';
|
|
12
|
-
|
|
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';
|
|
13
30
|
// -- Utility -----------------------------------------------------------------
|
|
14
31
|
export const StorageUtil = {
|
|
15
32
|
setWalletConnectDeepLink({ href, name }: { href: string; name: string }) {
|
|
@@ -164,5 +181,210 @@ export const StorageUtil = {
|
|
|
164
181
|
} catch {
|
|
165
182
|
console.info('Unable to remove Connected Social Provider');
|
|
166
183
|
}
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
async setOnRampPreferredCountry(country: OnRampCountry) {
|
|
187
|
+
try {
|
|
188
|
+
await AsyncStorage.setItem(ONRAMP_PREFERRED_COUNTRY, JSON.stringify(country));
|
|
189
|
+
} catch {
|
|
190
|
+
console.info('Unable to set OnRamp Preferred Country');
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
async getOnRampPreferredCountry() {
|
|
195
|
+
try {
|
|
196
|
+
const country = await AsyncStorage.getItem(ONRAMP_PREFERRED_COUNTRY);
|
|
197
|
+
|
|
198
|
+
return country ? (JSON.parse(country) as OnRampCountry) : undefined;
|
|
199
|
+
} catch {
|
|
200
|
+
console.info('Unable to get OnRamp Preferred Country');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return undefined;
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
async setOnRampPreferredFiatCurrency(currency: OnRampFiatCurrency) {
|
|
207
|
+
try {
|
|
208
|
+
await AsyncStorage.setItem(ONRAMP_PREFERRED_FIAT_CURRENCY, JSON.stringify(currency));
|
|
209
|
+
} catch {
|
|
210
|
+
console.info('Unable to set OnRamp Preferred Fiat Currency');
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
async getOnRampPreferredFiatCurrency() {
|
|
215
|
+
try {
|
|
216
|
+
const currency = await AsyncStorage.getItem(ONRAMP_PREFERRED_FIAT_CURRENCY);
|
|
217
|
+
|
|
218
|
+
return currency ? (JSON.parse(currency) as OnRampFiatCurrency) : undefined;
|
|
219
|
+
} catch {
|
|
220
|
+
console.info('Unable to get OnRamp Preferred Fiat Currency');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return undefined;
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
async setOnRampCountries(countries: OnRampCountry[]) {
|
|
227
|
+
try {
|
|
228
|
+
await AsyncStorage.setItem(ONRAMP_COUNTRIES, JSON.stringify(countries));
|
|
229
|
+
} catch {
|
|
230
|
+
console.info('Unable to set OnRamp Countries');
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
async getOnRampCountries() {
|
|
235
|
+
try {
|
|
236
|
+
const countries = await AsyncStorage.getItem(ONRAMP_COUNTRIES);
|
|
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 })
|
|
253
|
+
);
|
|
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
|
+
|
|
274
|
+
return data ? (data as OnRampCountryDefaults[]) : [];
|
|
275
|
+
} catch {
|
|
276
|
+
console.info('Unable to get OnRamp Countries Defaults');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return [];
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
async setOnRampServiceProviders(serviceProviders: OnRampServiceProvider[]) {
|
|
283
|
+
try {
|
|
284
|
+
const timestamp = Date.now();
|
|
285
|
+
|
|
286
|
+
await AsyncStorage.setItem(
|
|
287
|
+
ONRAMP_SERVICE_PROVIDERS,
|
|
288
|
+
JSON.stringify({ data: serviceProviders, timestamp })
|
|
289
|
+
);
|
|
290
|
+
} catch {
|
|
291
|
+
console.info('Unable to set OnRamp Service Providers');
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
async getOnRampServiceProviders() {
|
|
296
|
+
try {
|
|
297
|
+
const result = await AsyncStorage.getItem(ONRAMP_SERVICE_PROVIDERS);
|
|
298
|
+
|
|
299
|
+
if (!result) {
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const { data, timestamp } = JSON.parse(result);
|
|
304
|
+
|
|
305
|
+
// Cache for 1 week
|
|
306
|
+
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return data ? (data as OnRampServiceProvider[]) : [];
|
|
311
|
+
} catch (err) {
|
|
312
|
+
console.error(err);
|
|
313
|
+
console.info('Unable to get OnRamp Service Providers');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return [];
|
|
317
|
+
},
|
|
318
|
+
|
|
319
|
+
async setOnRampFiatLimits(fiatLimits: OnRampFiatLimit[]) {
|
|
320
|
+
try {
|
|
321
|
+
const timestamp = Date.now();
|
|
322
|
+
|
|
323
|
+
await AsyncStorage.setItem(
|
|
324
|
+
ONRAMP_FIAT_LIMITS,
|
|
325
|
+
JSON.stringify({ data: fiatLimits, timestamp })
|
|
326
|
+
);
|
|
327
|
+
} catch {
|
|
328
|
+
console.info('Unable to set OnRamp Fiat Limits');
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
async getOnRampFiatLimits() {
|
|
333
|
+
try {
|
|
334
|
+
const result = await AsyncStorage.getItem(ONRAMP_FIAT_LIMITS);
|
|
335
|
+
|
|
336
|
+
if (!result) {
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const { data, timestamp } = JSON.parse(result);
|
|
341
|
+
|
|
342
|
+
// Cache for 1 week
|
|
343
|
+
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return data ? (data as OnRampFiatLimit[]) : [];
|
|
348
|
+
} catch {
|
|
349
|
+
console.info('Unable to get OnRamp Fiat Limits');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return [];
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
async setOnRampFiatCurrencies(fiatCurrencies: OnRampFiatCurrency[]) {
|
|
356
|
+
try {
|
|
357
|
+
const timestamp = Date.now();
|
|
358
|
+
|
|
359
|
+
await AsyncStorage.setItem(
|
|
360
|
+
ONRAMP_FIAT_CURRENCIES,
|
|
361
|
+
JSON.stringify({ data: fiatCurrencies, timestamp })
|
|
362
|
+
);
|
|
363
|
+
} catch {
|
|
364
|
+
console.info('Unable to set OnRamp Fiat Currencies');
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
|
|
368
|
+
async getOnRampFiatCurrencies() {
|
|
369
|
+
try {
|
|
370
|
+
const result = await AsyncStorage.getItem(ONRAMP_FIAT_CURRENCIES);
|
|
371
|
+
|
|
372
|
+
if (!result) {
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const { data, timestamp } = JSON.parse(result);
|
|
377
|
+
|
|
378
|
+
// Cache for 1 week
|
|
379
|
+
if (timestamp && DateUtil.isMoreThanOneWeekAgo(timestamp)) {
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return data ? (data as OnRampFiatCurrency[]) : [];
|
|
384
|
+
} catch {
|
|
385
|
+
console.info('Unable to get OnRamp Fiat Currencies');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return [];
|
|
167
389
|
}
|
|
168
390
|
};
|