@reown/appkit-core-react-native 0.0.0-accounts-canary.1-20251023174733
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 +410 -0
- package/lib/commonjs/controllers/ApiController.js.map +1 -0
- package/lib/commonjs/controllers/AssetController.js +30 -0
- package/lib/commonjs/controllers/AssetController.js.map +1 -0
- package/lib/commonjs/controllers/BlockchainApiController.js +384 -0
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -0
- package/lib/commonjs/controllers/ConnectionsController.js +425 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +37 -0
- package/lib/commonjs/controllers/EnsController.js.map +1 -0
- package/lib/commonjs/controllers/EventsController.js +122 -0
- package/lib/commonjs/controllers/EventsController.js.map +1 -0
- package/lib/commonjs/controllers/LogController.js +188 -0
- package/lib/commonjs/controllers/LogController.js.map +1 -0
- package/lib/commonjs/controllers/ModalController.js +68 -0
- package/lib/commonjs/controllers/ModalController.js.map +1 -0
- package/lib/commonjs/controllers/OnRampController.js +502 -0
- package/lib/commonjs/controllers/OnRampController.js.map +1 -0
- package/lib/commonjs/controllers/OptionsController.js +96 -0
- package/lib/commonjs/controllers/OptionsController.js.map +1 -0
- package/lib/commonjs/controllers/PublicStateController.js +33 -0
- package/lib/commonjs/controllers/PublicStateController.js.map +1 -0
- package/lib/commonjs/controllers/RouterController.js +63 -0
- package/lib/commonjs/controllers/RouterController.js.map +1 -0
- package/lib/commonjs/controllers/SendController.js +192 -0
- package/lib/commonjs/controllers/SendController.js.map +1 -0
- package/lib/commonjs/controllers/SnackController.js +83 -0
- package/lib/commonjs/controllers/SnackController.js.map +1 -0
- package/lib/commonjs/controllers/SwapController.js +674 -0
- package/lib/commonjs/controllers/SwapController.js.map +1 -0
- package/lib/commonjs/controllers/ThemeController.js +45 -0
- package/lib/commonjs/controllers/ThemeController.js.map +1 -0
- package/lib/commonjs/controllers/TransactionsController.js +118 -0
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -0
- 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 +202 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ApiUtil.js +43 -0
- package/lib/commonjs/utils/ApiUtil.js.map +1 -0
- package/lib/commonjs/utils/AssetUtil.js +27 -0
- package/lib/commonjs/utils/AssetUtil.js.map +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +226 -0
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -0
- package/lib/commonjs/utils/CoreHelperUtil.js +298 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -0
- package/lib/commonjs/utils/EventUtil.js +25 -0
- package/lib/commonjs/utils/EventUtil.js.map +1 -0
- package/lib/commonjs/utils/FetchUtil.js +158 -0
- package/lib/commonjs/utils/FetchUtil.js.map +1 -0
- package/lib/commonjs/utils/LogUtils.js +131 -0
- package/lib/commonjs/utils/LogUtils.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +319 -0
- package/lib/commonjs/utils/StorageUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapApiUtil.js +75 -0
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js +97 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/commonjs/utils/WalletUtil.js +23 -0
- package/lib/commonjs/utils/WalletUtil.js.map +1 -0
- package/lib/module/controllers/ApiController.js +407 -0
- package/lib/module/controllers/ApiController.js.map +1 -0
- package/lib/module/controllers/AssetController.js +27 -0
- package/lib/module/controllers/AssetController.js.map +1 -0
- package/lib/module/controllers/BlockchainApiController.js +381 -0
- package/lib/module/controllers/BlockchainApiController.js.map +1 -0
- package/lib/module/controllers/ConnectionsController.js +422 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +34 -0
- package/lib/module/controllers/EnsController.js.map +1 -0
- package/lib/module/controllers/EventsController.js +118 -0
- package/lib/module/controllers/EventsController.js.map +1 -0
- package/lib/module/controllers/LogController.js +185 -0
- package/lib/module/controllers/LogController.js.map +1 -0
- package/lib/module/controllers/ModalController.js +65 -0
- package/lib/module/controllers/ModalController.js.map +1 -0
- package/lib/module/controllers/OnRampController.js +499 -0
- package/lib/module/controllers/OnRampController.js.map +1 -0
- package/lib/module/controllers/OptionsController.js +93 -0
- package/lib/module/controllers/OptionsController.js.map +1 -0
- package/lib/module/controllers/PublicStateController.js +30 -0
- package/lib/module/controllers/PublicStateController.js.map +1 -0
- package/lib/module/controllers/RouterController.js +60 -0
- package/lib/module/controllers/RouterController.js.map +1 -0
- package/lib/module/controllers/SendController.js +189 -0
- package/lib/module/controllers/SendController.js.map +1 -0
- package/lib/module/controllers/SnackController.js +80 -0
- package/lib/module/controllers/SnackController.js.map +1 -0
- package/lib/module/controllers/SwapController.js +671 -0
- package/lib/module/controllers/SwapController.js.map +1 -0
- package/lib/module/controllers/ThemeController.js +42 -0
- package/lib/module/controllers/ThemeController.js.map +1 -0
- package/lib/module/controllers/TransactionsController.js +115 -0
- package/lib/module/controllers/TransactionsController.js.map +1 -0
- 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 +38 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/ApiUtil.js +39 -0
- package/lib/module/utils/ApiUtil.js.map +1 -0
- package/lib/module/utils/AssetUtil.js +23 -0
- package/lib/module/utils/AssetUtil.js.map +1 -0
- package/lib/module/utils/ConstantsUtil.js +222 -0
- package/lib/module/utils/ConstantsUtil.js.map +1 -0
- package/lib/module/utils/CoreHelperUtil.js +294 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -0
- package/lib/module/utils/EventUtil.js +21 -0
- package/lib/module/utils/EventUtil.js.map +1 -0
- package/lib/module/utils/FetchUtil.js +154 -0
- package/lib/module/utils/FetchUtil.js.map +1 -0
- package/lib/module/utils/LogUtils.js +121 -0
- package/lib/module/utils/LogUtils.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +315 -0
- package/lib/module/utils/StorageUtil.js.map +1 -0
- package/lib/module/utils/SwapApiUtil.js +71 -0
- package/lib/module/utils/SwapApiUtil.js.map +1 -0
- package/lib/module/utils/SwapCalculationUtil.js +94 -0
- package/lib/module/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/module/utils/WalletUtil.js +19 -0
- package/lib/module/utils/WalletUtil.js.map +1 -0
- package/lib/typescript/controllers/ApiController.d.ts +40 -0
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/AssetController.d.ts +12 -0
- package/lib/typescript/controllers/AssetController.d.ts.map +1 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts +55 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EnsController.d.ts +10 -0
- package/lib/typescript/controllers/EnsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EventsController.d.ts +25 -0
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -0
- 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 +17 -0
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -0
- 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 +46 -0
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/PublicStateController.d.ts +12 -0
- package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -0
- package/lib/typescript/controllers/RouterController.d.ts +21 -0
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -0
- package/lib/typescript/controllers/SendController.d.ts +39 -0
- package/lib/typescript/controllers/SendController.d.ts.map +1 -0
- package/lib/typescript/controllers/SnackController.d.ts +20 -0
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -0
- package/lib/typescript/controllers/SwapController.d.ts +116 -0
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -0
- package/lib/typescript/controllers/ThemeController.d.ts +14 -0
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -0
- package/lib/typescript/controllers/TransactionsController.d.ts +21 -0
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -0
- 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 +29 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/ApiUtil.d.ts +7 -0
- package/lib/typescript/utils/ApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/AssetUtil.d.ts +6 -0
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts +79 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts +43 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -0
- package/lib/typescript/utils/EventUtil.d.ts +5 -0
- package/lib/typescript/utils/EventUtil.d.ts.map +1 -0
- package/lib/typescript/utils/FetchUtil.d.ts +29 -0
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -0
- 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 +36 -0
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts +11 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +24 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -0
- package/lib/typescript/utils/WalletUtil.d.ts +5 -0
- package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
- package/package.json +57 -0
- package/readme.md +9 -0
- package/src/controllers/ApiController.ts +454 -0
- package/src/controllers/AssetController.ts +32 -0
- package/src/controllers/BlockchainApiController.ts +418 -0
- package/src/controllers/ConnectionsController.ts +575 -0
- package/src/controllers/EnsController.ts +41 -0
- package/src/controllers/EventsController.ts +146 -0
- package/src/controllers/LogController.ts +250 -0
- package/src/controllers/ModalController.ts +68 -0
- package/src/controllers/OnRampController.ts +698 -0
- package/src/controllers/OptionsController.ts +143 -0
- package/src/controllers/PublicStateController.ts +37 -0
- package/src/controllers/RouterController.ts +112 -0
- package/src/controllers/SendController.ts +270 -0
- package/src/controllers/SnackController.ts +95 -0
- package/src/controllers/SwapController.ts +863 -0
- package/src/controllers/ThemeController.ts +47 -0
- package/src/controllers/TransactionsController.ts +150 -0
- 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 +70 -0
- package/src/utils/ApiUtil.ts +50 -0
- package/src/utils/AssetUtil.ts +27 -0
- package/src/utils/ConstantsUtil.ts +303 -0
- package/src/utils/CoreHelperUtil.ts +377 -0
- package/src/utils/EventUtil.ts +22 -0
- package/src/utils/FetchUtil.ts +164 -0
- package/src/utils/LogUtils.ts +179 -0
- package/src/utils/StorageUtil.ts +405 -0
- package/src/utils/SwapApiUtil.ts +101 -0
- package/src/utils/SwapCalculationUtil.ts +145 -0
- package/src/utils/WalletUtil.ts +14 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { subscribeKey as subKey } from 'valtio/utils';
|
|
3
|
+
import { proxy } from 'valtio';
|
|
4
|
+
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
5
|
+
import { FetchUtil } from '../utils/FetchUtil';
|
|
6
|
+
import { StorageUtil } from '../utils/StorageUtil';
|
|
7
|
+
import {
|
|
8
|
+
type ApiGetAnalyticsConfigResponse,
|
|
9
|
+
type ApiGetDataWalletsResponse,
|
|
10
|
+
type ApiGetWalletsRequest,
|
|
11
|
+
type ApiGetWalletsResponse,
|
|
12
|
+
type CustomWallet,
|
|
13
|
+
type WcWallet,
|
|
14
|
+
PresetsUtil
|
|
15
|
+
} from '@reown/appkit-common-react-native';
|
|
16
|
+
import { AssetController } from './AssetController';
|
|
17
|
+
import { OptionsController } from './OptionsController';
|
|
18
|
+
import { WcController } from './WcController';
|
|
19
|
+
import { ApiUtil } from '../utils/ApiUtil';
|
|
20
|
+
import { SnackController } from './SnackController';
|
|
21
|
+
import { ConnectionsController } from './ConnectionsController';
|
|
22
|
+
import { LogController } from './LogController';
|
|
23
|
+
|
|
24
|
+
// -- Helpers ------------------------------------------- //
|
|
25
|
+
const baseUrl = CoreHelperUtil.getApiUrl();
|
|
26
|
+
const api = new FetchUtil({ baseUrl });
|
|
27
|
+
const defaultEntries = '48';
|
|
28
|
+
const recommendedEntries = '4';
|
|
29
|
+
|
|
30
|
+
// -- Types --------------------------------------------- //
|
|
31
|
+
export interface ApiControllerState {
|
|
32
|
+
prefetchPromise?: Promise<unknown>;
|
|
33
|
+
prefetchError?: boolean;
|
|
34
|
+
prefetchLoading?: boolean;
|
|
35
|
+
page: number;
|
|
36
|
+
count: number;
|
|
37
|
+
featured: WcWallet[];
|
|
38
|
+
recommended: WcWallet[];
|
|
39
|
+
installed: WcWallet[];
|
|
40
|
+
wallets: WcWallet[];
|
|
41
|
+
search: WcWallet[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type StateKey = keyof ApiControllerState;
|
|
45
|
+
|
|
46
|
+
// -- State --------------------------------------------- //
|
|
47
|
+
const state = proxy<ApiControllerState>({
|
|
48
|
+
page: 1,
|
|
49
|
+
count: 0,
|
|
50
|
+
featured: [],
|
|
51
|
+
recommended: [],
|
|
52
|
+
wallets: [],
|
|
53
|
+
search: [],
|
|
54
|
+
installed: []
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// -- Controller ---------------------------------------- //
|
|
58
|
+
export const ApiController = {
|
|
59
|
+
state,
|
|
60
|
+
|
|
61
|
+
platform() {
|
|
62
|
+
return Platform.select({ default: 'ios', android: 'android' });
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
subscribeKey<K extends StateKey>(key: K, callback: (value: ApiControllerState[K]) => void) {
|
|
66
|
+
return subKey(state, key, callback);
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
_getApiParams() {
|
|
70
|
+
const { projectId, sdkType, sdkVersion } = OptionsController.state;
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
projectId,
|
|
74
|
+
st: sdkType,
|
|
75
|
+
sv: sdkVersion
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
_getApiHeaders() {
|
|
80
|
+
return {
|
|
81
|
+
'User-Agent': ApiUtil.getUserAgent(),
|
|
82
|
+
'origin': ApiUtil.getOrigin()
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async _fetchWalletImage(imageId: string) {
|
|
87
|
+
const headers = ApiController._getApiHeaders();
|
|
88
|
+
const url = await api.fetchImage(
|
|
89
|
+
`/getWalletImage/${imageId}`,
|
|
90
|
+
headers,
|
|
91
|
+
ApiController._getApiParams()
|
|
92
|
+
);
|
|
93
|
+
if (url) {
|
|
94
|
+
AssetController.setWalletImage(imageId, url);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
async _fetchNetworkImage(networkId: string) {
|
|
99
|
+
const imageId = PresetsUtil.NetworkImageIds[networkId];
|
|
100
|
+
if (!imageId) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const headers = ApiController._getApiHeaders();
|
|
105
|
+
const url = await api.fetchImage(
|
|
106
|
+
`/public/getAssetImage/${imageId}`,
|
|
107
|
+
headers,
|
|
108
|
+
ApiController._getApiParams()
|
|
109
|
+
);
|
|
110
|
+
if (url) {
|
|
111
|
+
AssetController.setNetworkImage(networkId, url);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
async fetchNetworkImages() {
|
|
116
|
+
const networks = ConnectionsController.state.networks;
|
|
117
|
+
if (networks) {
|
|
118
|
+
await CoreHelperUtil.allSettled(
|
|
119
|
+
networks.map(network => ApiController._fetchNetworkImage(network.id as string))
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
async fetchInstalledWallets() {
|
|
125
|
+
// Add timeout to prevent hanging
|
|
126
|
+
const controller = new AbortController();
|
|
127
|
+
let timeoutId: NodeJS.Timeout | undefined;
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const { includeWalletIds, customWallets } = OptionsController.state;
|
|
131
|
+
const path = Platform.select({ default: 'getIosData', android: 'getAndroidData' });
|
|
132
|
+
const response = await api.get<ApiGetDataWalletsResponse>({
|
|
133
|
+
path,
|
|
134
|
+
params: ApiController._getApiParams(),
|
|
135
|
+
headers: ApiController._getApiHeaders()
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (!response) return;
|
|
139
|
+
|
|
140
|
+
let { data: walletData } = response;
|
|
141
|
+
|
|
142
|
+
if (includeWalletIds?.length) {
|
|
143
|
+
walletData = walletData.filter(({ id }) => includeWalletIds.includes(id));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const promises = walletData.map(async item => {
|
|
147
|
+
return {
|
|
148
|
+
id: item.id,
|
|
149
|
+
isInstalled: await CoreHelperUtil.checkInstalled(item)
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const customPromises = customWallets?.map(async item => {
|
|
154
|
+
return {
|
|
155
|
+
id: item.id,
|
|
156
|
+
isInstalled: await CoreHelperUtil.checkInstalled(item)
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const results = await Promise.all(promises);
|
|
161
|
+
const installed = results.filter(({ isInstalled }) => isInstalled).map(({ id }) => id);
|
|
162
|
+
const { excludeWalletIds } = OptionsController.state;
|
|
163
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
164
|
+
|
|
165
|
+
// Add timeout to prevent hanging
|
|
166
|
+
timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
167
|
+
|
|
168
|
+
// Collect API-sourced installed wallets
|
|
169
|
+
let apiInstalledWallets: WcWallet[] = [];
|
|
170
|
+
if (installed.length > 0) {
|
|
171
|
+
const walletResponse = await api.get<ApiGetWalletsResponse>({
|
|
172
|
+
path: '/getWallets',
|
|
173
|
+
headers: ApiController._getApiHeaders(),
|
|
174
|
+
params: {
|
|
175
|
+
...ApiController._getApiParams(),
|
|
176
|
+
page: '1',
|
|
177
|
+
platform: this.platform(),
|
|
178
|
+
entries: installed?.length.toString(),
|
|
179
|
+
include: installed?.join(','),
|
|
180
|
+
exclude: excludeWalletIds?.join(','),
|
|
181
|
+
chains: chains.join(',')
|
|
182
|
+
},
|
|
183
|
+
signal: controller.signal
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
if (walletResponse?.data) {
|
|
187
|
+
const walletImages = walletResponse.data.map(d => d.image_id).filter(Boolean);
|
|
188
|
+
await CoreHelperUtil.allSettled(
|
|
189
|
+
(walletImages as string[]).map(id => ApiController._fetchWalletImage(id))
|
|
190
|
+
);
|
|
191
|
+
apiInstalledWallets = walletResponse.data;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
clearTimeout(timeoutId);
|
|
196
|
+
|
|
197
|
+
// Collect custom installed wallets
|
|
198
|
+
let customInstalledWallets: CustomWallet[] = [];
|
|
199
|
+
if (customPromises?.length) {
|
|
200
|
+
const customResults = await Promise.all(customPromises);
|
|
201
|
+
const customInstalled = customResults
|
|
202
|
+
.filter(({ isInstalled }) => isInstalled)
|
|
203
|
+
.map(({ id }) => id);
|
|
204
|
+
customInstalledWallets =
|
|
205
|
+
customWallets?.filter(wallet => customInstalled.includes(wallet.id)) ?? [];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Merge and de-duplicate by id, preserving order (API first, then custom)
|
|
209
|
+
const byId = new Map<string, WcWallet>();
|
|
210
|
+
[...apiInstalledWallets, ...customInstalledWallets].forEach(wallet => {
|
|
211
|
+
if (!byId.has(wallet.id)) {
|
|
212
|
+
byId.set(wallet.id, wallet);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const combinedInstalled = Array.from(byId.values());
|
|
216
|
+
state.installed = combinedInstalled;
|
|
217
|
+
if (combinedInstalled.length) {
|
|
218
|
+
this.updateRecentWalletsInfo(combinedInstalled);
|
|
219
|
+
}
|
|
220
|
+
} catch (error) {
|
|
221
|
+
state.installed = [];
|
|
222
|
+
clearTimeout(timeoutId);
|
|
223
|
+
LogController.sendError(error, 'ApiController.ts', 'fetchInstalledWallets');
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
async fetchFeaturedWallets() {
|
|
228
|
+
const { featuredWalletIds } = OptionsController.state;
|
|
229
|
+
const exclude = state.installed.map(({ id }) => id);
|
|
230
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
231
|
+
|
|
232
|
+
if (featuredWalletIds?.length) {
|
|
233
|
+
const response = await api.get<ApiGetWalletsResponse>({
|
|
234
|
+
path: '/getWallets',
|
|
235
|
+
headers: ApiController._getApiHeaders(),
|
|
236
|
+
params: {
|
|
237
|
+
...ApiController._getApiParams(),
|
|
238
|
+
page: '1',
|
|
239
|
+
platform: this.platform(),
|
|
240
|
+
entries: featuredWalletIds?.length
|
|
241
|
+
? String(featuredWalletIds.length)
|
|
242
|
+
: recommendedEntries,
|
|
243
|
+
include: featuredWalletIds?.join(','),
|
|
244
|
+
exclude: exclude?.join(','),
|
|
245
|
+
chains: chains.join(',')
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (!response) return;
|
|
249
|
+
const { data } = response;
|
|
250
|
+
|
|
251
|
+
this.updateRecentWalletsInfo(data);
|
|
252
|
+
|
|
253
|
+
data.sort((a, b) => featuredWalletIds.indexOf(a.id) - featuredWalletIds.indexOf(b.id));
|
|
254
|
+
const images = data.map(d => d.image_id).filter(Boolean);
|
|
255
|
+
await CoreHelperUtil.allSettled(
|
|
256
|
+
(images as string[]).map(id => ApiController._fetchWalletImage(id))
|
|
257
|
+
);
|
|
258
|
+
state.featured = data;
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
async fetchCustomWalletImages() {
|
|
263
|
+
const { customWallets } = OptionsController.state;
|
|
264
|
+
if (!customWallets?.length) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const images = customWallets.map(w => w.image_id).filter(Boolean);
|
|
269
|
+
await CoreHelperUtil.allSettled(
|
|
270
|
+
(images as string[]).map(id => ApiController._fetchWalletImage(id))
|
|
271
|
+
);
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
async fetchRecommendedWallets() {
|
|
275
|
+
const { installed } = ApiController.state;
|
|
276
|
+
const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
|
|
277
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
278
|
+
|
|
279
|
+
const exclude = [
|
|
280
|
+
...installed.map(({ id }) => id),
|
|
281
|
+
...(excludeWalletIds ?? []),
|
|
282
|
+
...(featuredWalletIds ?? [])
|
|
283
|
+
].filter(Boolean);
|
|
284
|
+
|
|
285
|
+
const response = await api.get<ApiGetWalletsResponse>({
|
|
286
|
+
path: '/getWallets',
|
|
287
|
+
headers: ApiController._getApiHeaders(),
|
|
288
|
+
params: {
|
|
289
|
+
...ApiController._getApiParams(),
|
|
290
|
+
page: '1',
|
|
291
|
+
platform: this.platform(),
|
|
292
|
+
entries: recommendedEntries,
|
|
293
|
+
include: includeWalletIds?.join(','),
|
|
294
|
+
exclude: exclude?.join(','),
|
|
295
|
+
chains: chains.join(',')
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
if (!response) return;
|
|
300
|
+
const { data, count } = response;
|
|
301
|
+
|
|
302
|
+
this.updateRecentWalletsInfo(data);
|
|
303
|
+
|
|
304
|
+
const recent = await StorageUtil.getRecentWallets();
|
|
305
|
+
const recommendedImages = data.map(d => d.image_id).filter(Boolean);
|
|
306
|
+
const recentImages = recent.map(r => r.image_id).filter(Boolean);
|
|
307
|
+
await CoreHelperUtil.allSettled(
|
|
308
|
+
([...recommendedImages, ...recentImages] as string[]).map(id =>
|
|
309
|
+
ApiController._fetchWalletImage(id)
|
|
310
|
+
)
|
|
311
|
+
);
|
|
312
|
+
state.recommended = data;
|
|
313
|
+
state.count = count ?? 0;
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
async fetchWallets({ page }: Pick<ApiGetWalletsRequest, 'page'>) {
|
|
317
|
+
const { includeWalletIds, excludeWalletIds, featuredWalletIds } = OptionsController.state;
|
|
318
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
319
|
+
const exclude = [
|
|
320
|
+
...state.installed.map(({ id }) => id),
|
|
321
|
+
...state.recommended.map(({ id }) => id),
|
|
322
|
+
...(excludeWalletIds ?? []),
|
|
323
|
+
...(featuredWalletIds ?? [])
|
|
324
|
+
].filter(Boolean);
|
|
325
|
+
const response = await api.get<ApiGetWalletsResponse>({
|
|
326
|
+
path: '/getWallets',
|
|
327
|
+
headers: ApiController._getApiHeaders(),
|
|
328
|
+
params: {
|
|
329
|
+
...ApiController._getApiParams(),
|
|
330
|
+
page: String(page),
|
|
331
|
+
platform: this.platform(),
|
|
332
|
+
entries: String(defaultEntries),
|
|
333
|
+
include: includeWalletIds?.join(','),
|
|
334
|
+
exclude: exclude.join(','),
|
|
335
|
+
chains: chains.join(',')
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
if (!response) return;
|
|
340
|
+
const { data, count } = response;
|
|
341
|
+
|
|
342
|
+
if (page === 1) {
|
|
343
|
+
this.updateRecentWalletsInfo(data);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const images = data.map(w => w.image_id).filter(Boolean);
|
|
347
|
+
await CoreHelperUtil.allSettled([
|
|
348
|
+
...(images as string[]).map(id => ApiController._fetchWalletImage(id)),
|
|
349
|
+
CoreHelperUtil.wait(300)
|
|
350
|
+
]);
|
|
351
|
+
state.wallets = [...state.wallets, ...data];
|
|
352
|
+
state.count = count > state.count ? count : state.count;
|
|
353
|
+
state.page = page;
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
async searchWallet({ search }: Pick<ApiGetWalletsRequest, 'search'>) {
|
|
357
|
+
const { includeWalletIds, excludeWalletIds } = OptionsController.state;
|
|
358
|
+
const chains = CoreHelperUtil.getRequestedCaipNetworkIds();
|
|
359
|
+
state.search = [];
|
|
360
|
+
const response = await api.get<ApiGetWalletsResponse>({
|
|
361
|
+
path: '/getWallets',
|
|
362
|
+
headers: ApiController._getApiHeaders(),
|
|
363
|
+
params: {
|
|
364
|
+
...ApiController._getApiParams(),
|
|
365
|
+
page: '1',
|
|
366
|
+
platform: this.platform(),
|
|
367
|
+
entries: String(defaultEntries),
|
|
368
|
+
search,
|
|
369
|
+
include: includeWalletIds?.join(','),
|
|
370
|
+
exclude: excludeWalletIds?.join(','),
|
|
371
|
+
chains: chains.join(',')
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
if (!response) return;
|
|
376
|
+
const { data } = response;
|
|
377
|
+
|
|
378
|
+
const images = data.map(w => w.image_id).filter(Boolean);
|
|
379
|
+
await CoreHelperUtil.allSettled([
|
|
380
|
+
...(images as string[]).map(id => ApiController._fetchWalletImage(id)),
|
|
381
|
+
CoreHelperUtil.wait(300)
|
|
382
|
+
]);
|
|
383
|
+
state.search = data;
|
|
384
|
+
},
|
|
385
|
+
|
|
386
|
+
async updateRecentWalletsInfo(wallets: WcWallet[]) {
|
|
387
|
+
let update = false;
|
|
388
|
+
const recent = await StorageUtil.getRecentWallets();
|
|
389
|
+
if (!recent.length) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const updatedRecent = recent.map(r => {
|
|
394
|
+
const wallet = wallets.find(w => w.id === r.id);
|
|
395
|
+
if (wallet && JSON.stringify(wallet) !== JSON.stringify(r)) {
|
|
396
|
+
update = true;
|
|
397
|
+
|
|
398
|
+
return wallet;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return r;
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
if (update) {
|
|
405
|
+
await StorageUtil.setRecentWallets(updatedRecent);
|
|
406
|
+
WcController.setRecentWallets(updatedRecent);
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
|
|
410
|
+
async prefetch() {
|
|
411
|
+
try {
|
|
412
|
+
state.prefetchError = false;
|
|
413
|
+
state.prefetchLoading = true;
|
|
414
|
+
|
|
415
|
+
const promises = [
|
|
416
|
+
ApiController.fetchNetworkImages(),
|
|
417
|
+
ApiController.fetchCustomWalletImages()
|
|
418
|
+
];
|
|
419
|
+
|
|
420
|
+
if (OptionsController.state.enableAnalytics === undefined) {
|
|
421
|
+
promises.push(ApiController.fetchAnalyticsConfig());
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// this fetch must resolve first so we filter them in the other wallet requests
|
|
425
|
+
await ApiController.fetchInstalledWallets();
|
|
426
|
+
|
|
427
|
+
promises.push(ApiController.fetchFeaturedWallets());
|
|
428
|
+
promises.push(ApiController.fetchRecommendedWallets());
|
|
429
|
+
|
|
430
|
+
state.prefetchPromise = Promise.race([
|
|
431
|
+
CoreHelperUtil.allSettled(promises),
|
|
432
|
+
CoreHelperUtil.wait(3000)
|
|
433
|
+
]);
|
|
434
|
+
|
|
435
|
+
state.prefetchPromise.then(() => {
|
|
436
|
+
state.prefetchLoading = false;
|
|
437
|
+
});
|
|
438
|
+
} catch (error) {
|
|
439
|
+
state.prefetchError = true;
|
|
440
|
+
state.prefetchLoading = false;
|
|
441
|
+
SnackController.showError('Failed to load wallets');
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
async fetchAnalyticsConfig() {
|
|
446
|
+
const response = await api.get<ApiGetAnalyticsConfigResponse>({
|
|
447
|
+
path: '/getAnalyticsConfig',
|
|
448
|
+
params: ApiController._getApiParams(),
|
|
449
|
+
headers: ApiController._getApiHeaders()
|
|
450
|
+
});
|
|
451
|
+
if (!response) return;
|
|
452
|
+
OptionsController.setEnableAnalytics(response.isAnalyticsEnabled);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { proxy } from 'valtio';
|
|
2
|
+
|
|
3
|
+
// -- Types --------------------------------------------- //
|
|
4
|
+
export interface AssetControllerState {
|
|
5
|
+
walletImages: Record<string, string>;
|
|
6
|
+
networkImages: Record<string, string>;
|
|
7
|
+
tokenImages: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// -- State --------------------------------------------- //
|
|
11
|
+
const state = proxy<AssetControllerState>({
|
|
12
|
+
walletImages: {},
|
|
13
|
+
networkImages: {},
|
|
14
|
+
tokenImages: {}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// -- Controller ---------------------------------------- //
|
|
18
|
+
export const AssetController = {
|
|
19
|
+
state,
|
|
20
|
+
|
|
21
|
+
setWalletImage(key: string, value: string) {
|
|
22
|
+
state.walletImages[key] = value;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
setNetworkImage(key: string, value: string) {
|
|
26
|
+
state.networkImages[key] = value;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
setTokenImage(key: string, value: string) {
|
|
30
|
+
state.tokenImages[key] = value;
|
|
31
|
+
}
|
|
32
|
+
};
|