@reown/appkit-core-react-native 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/controllers/ApiController.js +148 -82
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/AssetController.js +0 -4
- package/lib/commonjs/controllers/AssetController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +127 -134
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionsController.js +280 -60
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
- package/lib/commonjs/controllers/EnsController.js +6 -4
- package/lib/commonjs/controllers/EnsController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +55 -5
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/LogController.js +188 -0
- package/lib/commonjs/controllers/LogController.js.map +1 -0
- package/lib/commonjs/controllers/ModalController.js +9 -7
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/OnRampController.js +134 -53
- package/lib/commonjs/controllers/OnRampController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +20 -7
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/PublicStateController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +7 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/controllers/SendController.js +115 -99
- package/lib/commonjs/controllers/SendController.js.map +1 -1
- package/lib/commonjs/controllers/SnackController.js +29 -5
- package/lib/commonjs/controllers/SnackController.js.map +1 -1
- package/lib/commonjs/controllers/SwapController.js +119 -119
- package/lib/commonjs/controllers/SwapController.js.map +1 -1
- package/lib/commonjs/controllers/ThemeController.js +5 -0
- package/lib/commonjs/controllers/ThemeController.js.map +1 -1
- package/lib/commonjs/controllers/TransactionsController.js +25 -19
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
- package/lib/commonjs/controllers/WcController.js +73 -0
- package/lib/commonjs/controllers/WcController.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/index.js +28 -0
- package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
- package/lib/commonjs/index.js +30 -37
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ApiUtil.js +1 -1
- package/lib/commonjs/utils/ApiUtil.js.map +1 -1
- package/lib/commonjs/utils/AssetUtil.js +8 -17
- package/lib/commonjs/utils/AssetUtil.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +14 -431
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +33 -10
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/EventUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js +41 -12
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/LogUtils.js +131 -0
- package/lib/commonjs/utils/LogUtils.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +119 -172
- package/lib/commonjs/utils/StorageUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapApiUtil.js +2 -17
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -1
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -1
- package/lib/commonjs/utils/WalletUtil.js +23 -0
- package/lib/commonjs/utils/WalletUtil.js.map +1 -0
- package/lib/module/controllers/ApiController.js +150 -82
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/AssetController.js +2 -4
- package/lib/module/controllers/AssetController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +128 -133
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionsController.js +282 -60
- package/lib/module/controllers/ConnectionsController.js.map +1 -1
- package/lib/module/controllers/EnsController.js +6 -2
- package/lib/module/controllers/EnsController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +54 -2
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/LogController.js +185 -0
- package/lib/module/controllers/LogController.js.map +1 -0
- package/lib/module/controllers/ModalController.js +11 -7
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/OnRampController.js +135 -52
- package/lib/module/controllers/OnRampController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +22 -7
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/PublicStateController.js +2 -0
- package/lib/module/controllers/PublicStateController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +9 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/controllers/SendController.js +114 -96
- package/lib/module/controllers/SendController.js.map +1 -1
- package/lib/module/controllers/SnackController.js +31 -5
- package/lib/module/controllers/SnackController.js.map +1 -1
- package/lib/module/controllers/SwapController.js +121 -119
- package/lib/module/controllers/SwapController.js.map +1 -1
- package/lib/module/controllers/ThemeController.js +7 -0
- package/lib/module/controllers/ThemeController.js.map +1 -1
- package/lib/module/controllers/TransactionsController.js +25 -17
- package/lib/module/controllers/TransactionsController.js.map +1 -1
- package/lib/module/controllers/WcController.js +70 -0
- package/lib/module/controllers/WcController.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/module/features/reown-authentication/index.js +5 -0
- package/lib/module/features/reown-authentication/index.js.map +1 -0
- package/lib/module/index.js +12 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/ApiUtil.js +3 -1
- package/lib/module/utils/ApiUtil.js.map +1 -1
- package/lib/module/utils/AssetUtil.js +10 -17
- package/lib/module/utils/AssetUtil.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +16 -431
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +35 -8
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/EventUtil.js +2 -0
- package/lib/module/utils/EventUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js +44 -12
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/LogUtils.js +121 -0
- package/lib/module/utils/LogUtils.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +122 -172
- package/lib/module/utils/StorageUtil.js.map +1 -1
- package/lib/module/utils/SwapApiUtil.js +4 -17
- package/lib/module/utils/SwapApiUtil.js.map +1 -1
- package/lib/module/utils/SwapCalculationUtil.js +3 -0
- package/lib/module/utils/SwapCalculationUtil.js.map +1 -1
- package/lib/module/utils/WalletUtil.js +19 -0
- package/lib/module/utils/WalletUtil.js.map +1 -0
- package/lib/typescript/controllers/ApiController.d.ts +8 -7
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/AssetController.d.ts +0 -2
- package/lib/typescript/controllers/AssetController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +21 -13
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionsController.d.ts +22 -18
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/EnsController.d.ts +1 -1
- package/lib/typescript/controllers/EnsController.d.ts.map +1 -1
- package/lib/typescript/controllers/EventsController.d.ts +13 -1
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
- package/lib/typescript/controllers/LogController.d.ts +65 -0
- package/lib/typescript/controllers/LogController.d.ts.map +1 -0
- package/lib/typescript/controllers/ModalController.d.ts +1 -1
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -1
- package/lib/typescript/controllers/OnRampController.d.ts +4 -3
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
- package/lib/typescript/controllers/OptionsController.d.ts +8 -6
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +6 -21
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/controllers/SendController.d.ts +5 -7
- package/lib/typescript/controllers/SendController.d.ts.map +1 -1
- package/lib/typescript/controllers/SnackController.d.ts +3 -3
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -1
- package/lib/typescript/controllers/SwapController.d.ts +11 -11
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
- package/lib/typescript/controllers/ThemeController.d.ts +2 -0
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -1
- package/lib/typescript/controllers/TransactionsController.d.ts +3 -3
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
- package/lib/typescript/controllers/WcController.d.ts +27 -0
- package/lib/typescript/controllers/WcController.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
- package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/ApiUtil.d.ts +1 -1
- package/lib/typescript/utils/AssetUtil.d.ts +3 -4
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +7 -416
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +8 -6
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/EventUtil.d.ts +1 -1
- package/lib/typescript/utils/EventUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +3 -3
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/LogUtils.d.ts +15 -0
- package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
- package/lib/typescript/utils/StorageUtil.d.ts +8 -19
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +3 -4
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -1
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +1 -1
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -1
- package/lib/typescript/utils/WalletUtil.d.ts +5 -0
- package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
- package/package.json +12 -25
- package/src/controllers/ApiController.ts +158 -80
- package/src/controllers/AssetController.ts +0 -6
- package/src/controllers/BlockchainApiController.ts +109 -144
- package/src/controllers/ConnectionsController.ts +372 -88
- package/src/controllers/EnsController.ts +5 -3
- package/src/controllers/EventsController.ts +74 -3
- package/src/controllers/LogController.ts +250 -0
- package/src/controllers/ModalController.ts +11 -9
- package/src/controllers/OnRampController.ts +195 -82
- package/src/controllers/OptionsController.ts +40 -13
- package/src/controllers/RouterController.ts +20 -58
- package/src/controllers/SendController.ts +148 -112
- package/src/controllers/SnackController.ts +31 -5
- package/src/controllers/SwapController.ts +140 -148
- package/src/controllers/ThemeController.ts +7 -0
- package/src/controllers/TransactionsController.ts +26 -18
- package/src/controllers/WcController.ts +93 -0
- package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
- package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
- package/src/features/reown-authentication/index.ts +2 -0
- package/src/index.ts +15 -22
- package/src/utils/ApiUtil.ts +1 -1
- package/src/utils/AssetUtil.ts +9 -20
- package/src/utils/ConstantsUtil.ts +16 -435
- package/src/utils/CoreHelperUtil.ts +62 -11
- package/src/utils/EventUtil.ts +1 -1
- package/src/utils/FetchUtil.ts +50 -14
- package/src/utils/LogUtils.ts +179 -0
- package/src/utils/StorageUtil.ts +171 -199
- package/src/utils/SwapApiUtil.ts +18 -37
- package/src/utils/SwapCalculationUtil.ts +1 -2
- package/src/utils/WalletUtil.ts +14 -0
- package/lib/commonjs/controllers/AccountController.js +0 -93
- package/lib/commonjs/controllers/AccountController.js.map +0 -1
- package/lib/commonjs/controllers/ConnectionController.js +0 -132
- package/lib/commonjs/controllers/ConnectionController.js.map +0 -1
- package/lib/commonjs/controllers/ConnectorController.js +0 -50
- package/lib/commonjs/controllers/ConnectorController.js.map +0 -1
- package/lib/commonjs/controllers/NetworkController.js +0 -90
- package/lib/commonjs/controllers/NetworkController.js.map +0 -1
- package/lib/commonjs/controllers/WebviewController.js +0 -52
- package/lib/commonjs/controllers/WebviewController.js.map +0 -1
- package/lib/commonjs/utils/NetworkUtil.js +0 -46
- package/lib/commonjs/utils/NetworkUtil.js.map +0 -1
- package/lib/commonjs/utils/RouterUtil.js +0 -25
- package/lib/commonjs/utils/RouterUtil.js.map +0 -1
- package/lib/commonjs/utils/TypeUtil.js +0 -6
- package/lib/commonjs/utils/TypeUtil.js.map +0 -1
- package/lib/module/controllers/AccountController.js +0 -88
- package/lib/module/controllers/AccountController.js.map +0 -1
- package/lib/module/controllers/ConnectionController.js +0 -127
- package/lib/module/controllers/ConnectionController.js.map +0 -1
- package/lib/module/controllers/ConnectorController.js +0 -45
- package/lib/module/controllers/ConnectorController.js.map +0 -1
- package/lib/module/controllers/NetworkController.js +0 -85
- package/lib/module/controllers/NetworkController.js.map +0 -1
- package/lib/module/controllers/WebviewController.js +0 -47
- package/lib/module/controllers/WebviewController.js.map +0 -1
- package/lib/module/utils/NetworkUtil.js +0 -40
- package/lib/module/utils/NetworkUtil.js.map +0 -1
- package/lib/module/utils/RouterUtil.js +0 -19
- package/lib/module/utils/RouterUtil.js.map +0 -1
- package/lib/module/utils/TypeUtil.js +0 -2
- package/lib/module/utils/TypeUtil.js.map +0 -1
- package/lib/typescript/controllers/AccountController.d.ts +0 -33
- package/lib/typescript/controllers/AccountController.d.ts.map +0 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +0 -68
- package/lib/typescript/controllers/ConnectionController.d.ts.map +0 -1
- package/lib/typescript/controllers/ConnectorController.d.ts +0 -18
- package/lib/typescript/controllers/ConnectorController.d.ts.map +0 -1
- package/lib/typescript/controllers/NetworkController.d.ts +0 -34
- package/lib/typescript/controllers/NetworkController.d.ts.map +0 -1
- package/lib/typescript/controllers/WebviewController.d.ts +0 -21
- package/lib/typescript/controllers/WebviewController.d.ts.map +0 -1
- package/lib/typescript/utils/NetworkUtil.d.ts +0 -8
- package/lib/typescript/utils/NetworkUtil.d.ts.map +0 -1
- package/lib/typescript/utils/RouterUtil.d.ts +0 -5
- package/lib/typescript/utils/RouterUtil.d.ts.map +0 -1
- package/lib/typescript/utils/TypeUtil.d.ts +0 -817
- package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
- package/src/controllers/AccountController.ts +0 -128
- package/src/controllers/ConnectionController.ts +0 -208
- package/src/controllers/ConnectorController.ts +0 -64
- package/src/controllers/NetworkController.ts +0 -120
- package/src/controllers/WebviewController.ts +0 -63
- package/src/utils/NetworkUtil.ts +0 -33
- package/src/utils/RouterUtil.ts +0 -21
- package/src/utils/TypeUtil.ts +0 -995
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
import { Linking, Platform } from 'react-native';
|
|
4
4
|
import {
|
|
5
|
+
BlockchainAdapter,
|
|
5
6
|
ConstantsUtil as CommonConstants,
|
|
7
|
+
type AdapterType,
|
|
6
8
|
type Balance,
|
|
7
9
|
type CaipAddress,
|
|
8
|
-
type CaipNetwork
|
|
10
|
+
type CaipNetwork,
|
|
11
|
+
type ChainNamespace,
|
|
12
|
+
type SocialProvider,
|
|
13
|
+
type LinkingRecord,
|
|
14
|
+
type DataWallet,
|
|
15
|
+
type SdkVersion
|
|
9
16
|
} from '@reown/appkit-common-react-native';
|
|
10
17
|
|
|
11
18
|
import * as ct from 'countries-and-timezones';
|
|
12
19
|
|
|
13
20
|
import { ConstantsUtil } from './ConstantsUtil';
|
|
14
|
-
import
|
|
21
|
+
import { OptionsController } from '../controllers/OptionsController';
|
|
22
|
+
|
|
15
23
|
// -- Helpers -----------------------------------------------------------------
|
|
16
24
|
async function isAppInstalledIos(deepLink?: string): Promise<boolean> {
|
|
17
25
|
try {
|
|
@@ -45,6 +53,20 @@ export const CoreHelperUtil = {
|
|
|
45
53
|
return Date.now() - lastRetry >= ConstantsUtil.ONE_SEC_MS;
|
|
46
54
|
},
|
|
47
55
|
|
|
56
|
+
isCaipAddress(address?: unknown): address is CaipAddress {
|
|
57
|
+
if (typeof address !== 'string') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const sections = address.split(':');
|
|
62
|
+
const namespace = sections[0];
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
sections.filter(Boolean).length === 3 &&
|
|
66
|
+
(namespace as string) in CommonConstants.CHAIN_NAME_MAP
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
|
|
48
70
|
getPairingExpiry() {
|
|
49
71
|
return Date.now() + ConstantsUtil.FOUR_MINUTES_MS;
|
|
50
72
|
},
|
|
@@ -53,8 +75,12 @@ export const CoreHelperUtil = {
|
|
|
53
75
|
return caipAddress?.split(':')[1];
|
|
54
76
|
},
|
|
55
77
|
|
|
56
|
-
getPlainAddress(
|
|
57
|
-
|
|
78
|
+
getPlainAddress(address: CaipAddress | string | undefined) {
|
|
79
|
+
if (this.isCaipAddress(address)) {
|
|
80
|
+
return address?.split(':')[2];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return address;
|
|
58
84
|
},
|
|
59
85
|
|
|
60
86
|
async wait(milliseconds: number) {
|
|
@@ -102,7 +128,7 @@ export const CoreHelperUtil = {
|
|
|
102
128
|
};
|
|
103
129
|
},
|
|
104
130
|
|
|
105
|
-
formatUniversalUrl(appUrl: string, wcUri: string): LinkingRecord {
|
|
131
|
+
formatUniversalUrl(appUrl: string, wcUri: string, provider?: SocialProvider): LinkingRecord {
|
|
106
132
|
if (CoreHelperUtil.isLinkModeURL(wcUri)) {
|
|
107
133
|
return {
|
|
108
134
|
redirect: wcUri,
|
|
@@ -120,7 +146,9 @@ export const CoreHelperUtil = {
|
|
|
120
146
|
const encodedWcUrl = encodeURIComponent(wcUri);
|
|
121
147
|
|
|
122
148
|
return {
|
|
123
|
-
redirect:
|
|
149
|
+
redirect: provider
|
|
150
|
+
? `${safeAppUrl}wc?uri=${encodedWcUrl}&provider=${provider}`
|
|
151
|
+
: `${safeAppUrl}wc?uri=${encodedWcUrl}`,
|
|
124
152
|
href: safeAppUrl
|
|
125
153
|
};
|
|
126
154
|
},
|
|
@@ -149,8 +177,8 @@ export const CoreHelperUtil = {
|
|
|
149
177
|
return formattedBalance ? `${formattedBalance} ${symbol}` : `0.000 ${symbol || ''}`;
|
|
150
178
|
},
|
|
151
179
|
|
|
152
|
-
isAddress(address: string,
|
|
153
|
-
switch (
|
|
180
|
+
isAddress(address: string, namespace: ChainNamespace = 'eip155'): boolean {
|
|
181
|
+
switch (namespace) {
|
|
154
182
|
case 'eip155':
|
|
155
183
|
if (!/^(?:0x)?[0-9a-f]{40}$/iu.test(address)) {
|
|
156
184
|
return false;
|
|
@@ -191,7 +219,7 @@ export const CoreHelperUtil = {
|
|
|
191
219
|
const { timeZone } = new Intl.DateTimeFormat().resolvedOptions();
|
|
192
220
|
const country = ct.getCountryForTimezone(timeZone);
|
|
193
221
|
|
|
194
|
-
return country ? country.id : 'US'; // 'id' is the ISO country code (e.g., "
|
|
222
|
+
return country ? country.id : 'US'; // 'id' is the ISO country code (e.g., "US" for United States)
|
|
195
223
|
} catch (error) {
|
|
196
224
|
return 'US';
|
|
197
225
|
}
|
|
@@ -224,7 +252,7 @@ export const CoreHelperUtil = {
|
|
|
224
252
|
});
|
|
225
253
|
},
|
|
226
254
|
|
|
227
|
-
getBundleId() {
|
|
255
|
+
getBundleId(): string | undefined {
|
|
228
256
|
if ((global as any)?.Application?.applicationId) {
|
|
229
257
|
return (global as any)?.Application?.applicationId;
|
|
230
258
|
}
|
|
@@ -282,7 +310,7 @@ export const CoreHelperUtil = {
|
|
|
282
310
|
|
|
283
311
|
let sum = 0;
|
|
284
312
|
for (const item of array) {
|
|
285
|
-
sum += item
|
|
313
|
+
sum += item?.value ?? 0;
|
|
286
314
|
}
|
|
287
315
|
|
|
288
316
|
const roundedNumber = sum.toFixed(2);
|
|
@@ -322,5 +350,28 @@ export const CoreHelperUtil = {
|
|
|
322
350
|
func(...args);
|
|
323
351
|
}, wait);
|
|
324
352
|
};
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
generateSdkVersion(adapters: BlockchainAdapter[], version: string): SdkVersion {
|
|
356
|
+
const hasNoAdapters = adapters.length === 0;
|
|
357
|
+
const universalType: AdapterType = 'universal';
|
|
358
|
+
|
|
359
|
+
const adapterNames = hasNoAdapters
|
|
360
|
+
? universalType
|
|
361
|
+
: adapters
|
|
362
|
+
.sort((a, b) => a.adapterType.localeCompare(b.adapterType))
|
|
363
|
+
.map(adapter => adapter.adapterType)
|
|
364
|
+
.join(',');
|
|
365
|
+
|
|
366
|
+
return `react-native-${adapterNames}-${version}`;
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
getRequestedCaipNetworkIds() {
|
|
370
|
+
const chains = OptionsController.state.requestedNetworks;
|
|
371
|
+
if (!chains) return [];
|
|
372
|
+
|
|
373
|
+
const requestedIds = chains.map(caipNetwork => caipNetwork.caipNetworkId);
|
|
374
|
+
|
|
375
|
+
return requestedIds;
|
|
325
376
|
}
|
|
326
377
|
};
|
package/src/utils/EventUtil.ts
CHANGED
package/src/utils/FetchUtil.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { RequestCache } from '
|
|
1
|
+
import type { RequestCache } from '@reown/appkit-common-react-native';
|
|
2
|
+
import { LogController } from '../controllers/LogController';
|
|
2
3
|
|
|
3
4
|
// -- Types ----------------------------------------------------------------------
|
|
4
5
|
interface Options {
|
|
@@ -71,9 +72,13 @@ export class FetchUtil {
|
|
|
71
72
|
return this.processResponse<T>(response);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
public async fetchImage(
|
|
75
|
+
public async fetchImage(
|
|
76
|
+
path: string,
|
|
77
|
+
headers?: Record<string, string>,
|
|
78
|
+
params?: Record<string, string>
|
|
79
|
+
) {
|
|
75
80
|
try {
|
|
76
|
-
const url = this.createUrl({ path }).toString();
|
|
81
|
+
const url = this.createUrl({ path, params }).toString();
|
|
77
82
|
const response = await fetch(url, { headers });
|
|
78
83
|
const blob = await response.blob();
|
|
79
84
|
const reader = new FileReader();
|
|
@@ -87,30 +92,61 @@ export class FetchUtil {
|
|
|
87
92
|
}
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
public createUrl({ path, params }: RequestArguments) {
|
|
96
|
+
let fullUrl: string;
|
|
97
|
+
|
|
98
|
+
const isAbsoluteUrl = path.startsWith('http://') || path.startsWith('https://');
|
|
99
|
+
|
|
100
|
+
if (isAbsoluteUrl) {
|
|
101
|
+
fullUrl = path;
|
|
102
|
+
} else {
|
|
103
|
+
const baseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
|
|
104
|
+
const pathUrl = path.startsWith('/') ? path.substring(1) : path;
|
|
105
|
+
fullUrl = `${baseUrl}${pathUrl}`;
|
|
98
106
|
}
|
|
99
107
|
|
|
108
|
+
const allParams: Record<string, string | undefined> = { ...params };
|
|
100
109
|
if (this.clientId) {
|
|
101
|
-
|
|
110
|
+
allParams['clientId'] = this.clientId;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const queryParams: string[] = [];
|
|
114
|
+
for (const key in allParams) {
|
|
115
|
+
const value = allParams[key];
|
|
116
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
117
|
+
queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
118
|
+
}
|
|
102
119
|
}
|
|
103
120
|
|
|
104
|
-
|
|
121
|
+
if (queryParams.length > 0) {
|
|
122
|
+
const queryString = queryParams.join('&');
|
|
123
|
+
if (fullUrl.includes('?')) {
|
|
124
|
+
fullUrl = `${fullUrl}&${queryString}`;
|
|
125
|
+
} else {
|
|
126
|
+
fullUrl = `${fullUrl}?${queryString}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return fullUrl;
|
|
105
131
|
}
|
|
106
132
|
|
|
107
133
|
private async processResponse<T>(response: Response) {
|
|
108
134
|
if (!response.ok) {
|
|
109
135
|
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
110
|
-
|
|
136
|
+
try {
|
|
137
|
+
const errorData = await response.json();
|
|
138
|
+
LogController.sendError(JSON.stringify(errorData), 'FetchUtil.ts', 'processResponse');
|
|
139
|
+
|
|
140
|
+
return Promise.reject(errorData);
|
|
141
|
+
} catch (jsonError) {
|
|
142
|
+
LogController.sendError(jsonError, 'FetchUtil.ts', 'processResponse');
|
|
143
|
+
|
|
144
|
+
return Promise.reject(`Code: ${response.status} - ${response.statusText}`);
|
|
145
|
+
}
|
|
111
146
|
}
|
|
112
147
|
|
|
113
148
|
const errorText = await response.text();
|
|
149
|
+
LogController.sendError(errorText, 'FetchUtil.ts', 'processResponse');
|
|
114
150
|
|
|
115
151
|
return Promise.reject(`Code: ${response.status} - ${response.statusText} - ${errorText}`);
|
|
116
152
|
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// -- Constants ----------------------------------------- //
|
|
2
|
+
const SENSITIVE_KEYS = [
|
|
3
|
+
'password',
|
|
4
|
+
'pass',
|
|
5
|
+
'pwd',
|
|
6
|
+
'secret',
|
|
7
|
+
'token',
|
|
8
|
+
'key',
|
|
9
|
+
'auth',
|
|
10
|
+
'authorization',
|
|
11
|
+
'bearer',
|
|
12
|
+
'credential',
|
|
13
|
+
'api_key',
|
|
14
|
+
'apikey',
|
|
15
|
+
'access_token',
|
|
16
|
+
'refresh_token',
|
|
17
|
+
'private_key',
|
|
18
|
+
'privatekey',
|
|
19
|
+
'mnemonic',
|
|
20
|
+
'seed',
|
|
21
|
+
'phrase',
|
|
22
|
+
'wallet',
|
|
23
|
+
'address',
|
|
24
|
+
'email',
|
|
25
|
+
'phone',
|
|
26
|
+
'ssn',
|
|
27
|
+
'social',
|
|
28
|
+
'credit',
|
|
29
|
+
'card',
|
|
30
|
+
'cvv',
|
|
31
|
+
'connection_string',
|
|
32
|
+
'connection',
|
|
33
|
+
'user_token'
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const MAX_STRING_LENGTH = 480; // Maximum length for any string value (account for potential replacements)
|
|
37
|
+
const MAX_STACK_LINES = 10; // Maximum lines in stack trace
|
|
38
|
+
|
|
39
|
+
// -- Data Sanitization Functions ---------------------- //
|
|
40
|
+
export const sanitizeString = (value: string): string => {
|
|
41
|
+
if (typeof value !== 'string') {
|
|
42
|
+
value = String(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (value.length > MAX_STRING_LENGTH) {
|
|
46
|
+
return value.substring(0, MAX_STRING_LENGTH) + '... [truncated]';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const sanitizeStackTrace = (stack: string): string => {
|
|
53
|
+
if (typeof stack !== 'string') {
|
|
54
|
+
stack = String(stack);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const lines = stack.split('\n');
|
|
58
|
+
const sanitizedLines = lines.slice(0, MAX_STACK_LINES).map(line => {
|
|
59
|
+
// Remove file paths that might contain sensitive info
|
|
60
|
+
return line.replace(/\/[^\s]*\//g, '/[path]/');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (lines.length > MAX_STACK_LINES) {
|
|
64
|
+
sanitizedLines.push('... [stack trace truncated]');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return sanitizedLines.join('\n');
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const sanitizeUrl = (url: string): string => {
|
|
71
|
+
try {
|
|
72
|
+
const urlObj = new URL(url);
|
|
73
|
+
// Remove query parameters that might contain sensitive data
|
|
74
|
+
urlObj.search = '';
|
|
75
|
+
// Keep only the origin and pathname
|
|
76
|
+
|
|
77
|
+
return urlObj.origin + urlObj.pathname;
|
|
78
|
+
} catch {
|
|
79
|
+
// If URL parsing fails, just return sanitized string
|
|
80
|
+
|
|
81
|
+
return sanitizeString(url);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const isSensitiveKey = (key: string): boolean => {
|
|
86
|
+
const lowerKey = key.toLowerCase();
|
|
87
|
+
|
|
88
|
+
return SENSITIVE_KEYS.some(sensitiveKey => lowerKey.includes(sensitiveKey));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const sanitizeValue = (value: unknown, visited = new WeakSet()): unknown => {
|
|
92
|
+
if (value === null || value === undefined) {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof value === 'string') {
|
|
97
|
+
// Check if it looks like a URL
|
|
98
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
99
|
+
return sanitizeUrl(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return sanitizeString(value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
// Prevent circular references in arrays
|
|
111
|
+
if (visited.has(value)) {
|
|
112
|
+
return '[Circular Reference]';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
visited.add(value);
|
|
116
|
+
const result = value.slice(0, 10).map(item => sanitizeValue(item, visited));
|
|
117
|
+
visited.delete(value);
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof value === 'object') {
|
|
123
|
+
return sanitizeObject(value as Record<string, unknown>, visited);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// For other types, convert to string and sanitize
|
|
127
|
+
return sanitizeString(String(value));
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const sanitizeObject = (
|
|
131
|
+
obj: Record<string, unknown>,
|
|
132
|
+
visited = new WeakSet()
|
|
133
|
+
): Record<string, unknown> => {
|
|
134
|
+
// Prevent circular references
|
|
135
|
+
if (visited.has(obj)) {
|
|
136
|
+
return { '[Circular Reference]': true };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
visited.add(obj);
|
|
140
|
+
|
|
141
|
+
const sanitized: Record<string, unknown> = {};
|
|
142
|
+
const keys = Object.keys(obj).slice(0, 20); // Limit number of keys
|
|
143
|
+
|
|
144
|
+
for (const key of keys) {
|
|
145
|
+
if (isSensitiveKey(key)) {
|
|
146
|
+
sanitized[key] = '[REDACTED]';
|
|
147
|
+
} else {
|
|
148
|
+
sanitized[key] = sanitizeValue(obj[key], visited);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (Object.keys(obj).length > 20) {
|
|
153
|
+
sanitized['...'] = '[additional properties truncated]';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
visited.delete(obj);
|
|
157
|
+
|
|
158
|
+
return sanitized;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const sanitizeData = (
|
|
162
|
+
data?: Record<string, unknown>
|
|
163
|
+
): Record<string, unknown> | undefined => {
|
|
164
|
+
if (!data) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return sanitizeObject(data);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// -- Utility Functions --------------------------------- //
|
|
172
|
+
export const LogUtils = {
|
|
173
|
+
sanitizeString,
|
|
174
|
+
sanitizeStackTrace,
|
|
175
|
+
sanitizeUrl,
|
|
176
|
+
sanitizeValue,
|
|
177
|
+
sanitizeObject,
|
|
178
|
+
sanitizeData
|
|
179
|
+
};
|