This repository was archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathsettings.js
More file actions
223 lines (192 loc) · 7.2 KB
/
Copy pathsettings.js
File metadata and controls
223 lines (192 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// @flow
import { useCallback } from "react";
import type { Dispatch } from "redux";
import { useDispatch, useSelector } from "react-redux";
import { useTranslation } from "react-i18next";
import type { DeviceModelId } from "@ledgerhq/devices";
import type { PortfolioRange } from "@ledgerhq/live-common/lib/portfolio/v2/types";
import type { Currency } from "@ledgerhq/live-common/lib/types";
import type { DeviceModelInfo } from "@ledgerhq/live-common/lib/types/manager";
import { setEnvOnAllThreads } from "~/helpers/env";
import type { SettingsState as Settings } from "~/renderer/reducers/settings";
import {
hideEmptyTokenAccountsSelector,
selectedTimeRangeSelector,
} from "~/renderer/reducers/settings";
import { useRefreshAccountsOrdering } from "~/renderer/actions/general";
export type SaveSettings = ($Shape<Settings>) => { type: string, payload: $Shape<Settings> };
export const saveSettings: SaveSettings = payload => ({
type: "DB:SAVE_SETTINGS",
payload,
});
export const setCountervalueFirst = (countervalueFirst: boolean) =>
saveSettings({ countervalueFirst });
export const setAccountsViewMode = (accountsViewMode: *) => saveSettings({ accountsViewMode });
export const setNftsViewMode = (nftsViewMode: *) => saveSettings({ nftsViewMode });
export const setSelectedTimeRange = (selectedTimeRange: PortfolioRange) =>
saveSettings({ selectedTimeRange });
export const setDeveloperMode = (developerMode: boolean) => saveSettings({ developerMode });
export const setDiscreetMode = (discreetMode: boolean) => saveSettings({ discreetMode });
export const setCarouselVisibility = (carouselVisibility: number) =>
saveSettings({ carouselVisibility });
export const setSentryLogs = (sentryLogs: boolean) => saveSettings({ sentryLogs });
export const setFullNodeEnabled = (fullNodeEnabled: boolean) => saveSettings({ fullNodeEnabled });
export const setShareAnalytics = (shareAnalytics: boolean) => saveSettings({ shareAnalytics });
export const setMarketIndicator = (marketIndicator: *) => saveSettings({ marketIndicator });
export const setAutoLockTimeout = (autoLockTimeout: *) => saveSettings({ autoLockTimeout });
export const setHasInstalledApps = (hasInstalledApps: boolean) =>
saveSettings({ hasInstalledApps });
// developer
export const setAllowDebugApps = (allowDebugApps: boolean) => saveSettings({ allowDebugApps });
export const setAllowExperimentalApps = (allowExperimentalApps: boolean) =>
saveSettings({ allowExperimentalApps });
export const setEnablePlatformDevTools = (enablePlatformDevTools: boolean) =>
saveSettings({ enablePlatformDevTools });
export const setCatalogProvider = (catalogProvider: string) => saveSettings({ catalogProvider });
export const setEnableLearnPageStagingUrl = (enableLearnPageStagingUrl: boolean) =>
saveSettings({ enableLearnPageStagingUrl });
export const setCounterValue = (counterValue: string) =>
saveSettings({
counterValue,
pairExchanges: {},
});
export const setLanguage = (language: ?string) => saveSettings({ language });
export const setTheme = (theme: ?string) => saveSettings({ theme });
export const setLocale = (locale: string) => saveSettings({ locale });
export const setUSBTroubleshootingIndex = (USBTroubleshootingIndex?: number) =>
saveSettings({ USBTroubleshootingIndex });
export function useHideEmptyTokenAccounts() {
const dispatch = useDispatch();
const value = useSelector(hideEmptyTokenAccountsSelector);
const refreshAccountsOrdering = useRefreshAccountsOrdering();
const setter = useCallback(
(hideEmptyTokenAccounts: boolean) => {
if (setEnvOnAllThreads("HIDE_EMPTY_TOKEN_ACCOUNTS", hideEmptyTokenAccounts)) {
dispatch(saveSettings({ hideEmptyTokenAccounts }));
refreshAccountsOrdering();
}
},
[dispatch, refreshAccountsOrdering],
);
return [value, setter];
}
type PortfolioRangeOption = {
key: PortfolioRange,
value: string,
label: string,
};
export function useTimeRange() {
const { t } = useTranslation();
const dispatch = useDispatch();
const val = useSelector(selectedTimeRangeSelector);
const setter = useCallback(
(_range: PortfolioRange | PortfolioRangeOption) => {
const range = typeof _range === "string" ? _range : _range.key;
dispatch(setSelectedTimeRange(range));
},
[dispatch],
);
const ranges: PortfolioRange[] = ["day", "week", "month", "year", "all"];
const options: PortfolioRangeOption[] = ranges.map(key => ({
key,
value: t(`time.range.${key}`),
label: t(`time.range.${key}`),
}));
return [val, setter, options];
}
export const setShowClearCacheBanner = (showClearCacheBanner: boolean) =>
saveSettings({ showClearCacheBanner });
export const setSidebarCollapsed = (sidebarCollapsed: boolean) =>
saveSettings({ sidebarCollapsed });
export const blacklistToken = (tokenId: string) => ({
type: "BLACKLIST_TOKEN",
payload: tokenId,
});
export const hideNftCollection = (collectionId: string) => ({
type: "HIDE_NFT_COLLECTION",
payload: collectionId,
});
export const swapAcceptProvider = (providerId: string) => ({
type: "ACCEPT_SWAP_PROVIDER",
payload: providerId,
});
export const showToken = (tokenId: string) => ({
type: "SHOW_TOKEN",
payload: tokenId,
});
export const unhideNftCollection = (collectionId: string) => ({
type: "UNHIDE_NFT_COLLECTION",
payload: collectionId,
});
type FetchSettings = (*) => (Dispatch<*>) => void;
export const fetchSettings: FetchSettings = (settings: *) => dispatch => {
dispatch({
type: "FETCH_SETTINGS",
payload: settings,
});
};
type SetExchangePairs = (
Array<{
from: Currency,
to: Currency,
exchange: ?string,
}>,
) => *;
export const setExchangePairsAction: SetExchangePairs = pairs => ({
type: "SETTINGS_SET_PAIRS",
pairs,
});
export const dismissBanner = (bannerKey: string) => ({
type: "SETTINGS_DISMISS_BANNER",
payload: bannerKey,
});
export const setPreferredDeviceModel = (preferredDeviceModel: DeviceModelId) =>
saveSettings({ preferredDeviceModel });
export const setLastSeenDeviceInfo = ({
lastSeenDevice,
latestFirmware,
}: {
lastSeenDevice: DeviceModelInfo,
latestFirmware: any,
}) => ({
type: "LAST_SEEN_DEVICE_INFO",
payload: { lastSeenDevice, latestFirmware },
});
export const setDeepLinkUrl = (url: ?string) => ({
type: "SET_DEEPLINK_URL",
payload: url,
});
export const setFirstTimeLend = () => ({
type: "SET_FIRST_TIME_LEND",
});
export const setSwapSelectableCurrencies = (selectableCurrencies: string[]) => ({
type: "SET_SWAP_SELECTABLE_CURRENCIES",
payload: selectableCurrencies,
});
export const setSwapHasAcceptedIPSharing = (hasAcceptedIPSharing: boolean) => ({
type: "SET_SWAP_ACCEPTED_IP_SHARING",
payload: hasAcceptedIPSharing,
});
export const setSwapKYCStatus = (payload: {
provider: string,
id?: string,
status?: string | null,
}) => ({
type: "SET_SWAP_KYC",
payload,
});
export const resetSwapLoginAndKYCData = () => ({
type: "RESET_SWAP_LOGIN_AND_KYC_DATA",
});
export const addStarredMarketCoins = (payload: string) => ({
type: "ADD_STARRED_MARKET_COINS",
payload,
});
export const removeStarredMarketCoins = (payload: string) => ({
type: "REMOVE_STARRED_MARKET_COINS",
payload,
});
export const toggleStarredMarketCoins = (payload: string) => ({
type: "TOGGLE_STARRED_MARKET_COINS",
payload,
});