-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathSettingsNFT.tsx
More file actions
264 lines (240 loc) · 9.2 KB
/
Copy pathSettingsNFT.tsx
File metadata and controls
264 lines (240 loc) · 9.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// import { usePrefs } from '@chia-network/api-react';
import {
Flex,
SettingsHR,
SettingsSection,
SettingsText,
SettingsTitle,
// AlertDialog,
useOpenDialog,
FormatBytes,
ConfirmDialog,
} from '@chia-network/core';
import { Trans } from '@lingui/macro';
import { Grid, Button, Switch, FormControlLabel, Typography } from '@mui/material';
import React from 'react';
import useAllowUnverifiedNFTPreviews from '../../hooks/useAllowUnverifiedNFTPreviews';
import useCache from '../../hooks/useCache';
import useHideObjectionableContent from '../../hooks/useHideObjectionableContent';
import useIpfsGateway from '../../hooks/useIpfsGateway';
import useNFTImageFittingMode from '../../hooks/useNFTImageFittingMode';
import { useNFTVideoLoopGlobal } from '../../hooks/useNFTVideoLoop';
import LimitCacheSize from './LimitCacheSize';
/* todo it is deprecated we should remove it from users local storage
Object.keys(localStorage).forEach((key) => {
if (key.indexOf('content-cache-') > -1) localStorage.removeItem(key);
if (key.indexOf('thumb-cache-') > -1) localStorage.removeItem(key);
if (key.indexOf('metadata-cache-') > -1) localStorage.removeItem(key);
if (key.indexOf('force-reload-') > -1) localStorage.removeItem(key);
});
*/
export default function SettingsGeneral() {
const [hideObjectionableContent, setHideObjectionableContent] = useHideObjectionableContent();
function handleChangeHideObjectionableContent(event: React.ChangeEvent<HTMLInputElement>) {
setHideObjectionableContent(event.target.checked);
}
const { cacheSize, clearCache, cacheDirectory, setCacheDirectory } = useCache();
const [nftImageFittingMode, setNFTImageFittingMode] = useNFTImageFittingMode();
const [nftVideoLoop, setNFTVideoLoop] = useNFTVideoLoopGlobal();
const [ipfsGateway, setIpfsGateway] = useIpfsGateway();
const [allowUnverifiedPreviews, setAllowUnverifiedPreviews] = useAllowUnverifiedNFTPreviews();
// const [, setCacheFolder] = usePrefs('cacheFolder', '');
const openDialog = useOpenDialog();
function handleScalePreviewImages(event: React.ChangeEvent<HTMLInputElement>) {
setNFTImageFittingMode(event.target.checked ? 'contain' : 'cover');
}
function handleChangeVideoLoop(event: React.ChangeEvent<HTMLInputElement>) {
setNFTVideoLoop(event.target.checked);
}
function handleChangeIpfsGateway(event: React.ChangeEvent<HTMLInputElement>) {
setIpfsGateway(event.target.checked);
}
function handleChangeAllowUnverifiedPreviews(event: React.ChangeEvent<HTMLInputElement>) {
setAllowUnverifiedPreviews(event.target.checked);
}
async function clearNFTCache() {
openDialog(
<ConfirmDialog
title={<Trans>Clear NFT cache</Trans>}
confirmTitle={<Trans>Yes, delete</Trans>}
confirmColor="danger"
onConfirm={() => {
clearCache();
}}
>
<Trans>Are you sure you want to delete the NFT cache?</Trans>
</ConfirmDialog>,
);
}
async function chooseAnotherFolder() {
setCacheDirectory();
}
return (
<Grid container style={{ maxWidth: '624px' }} gap={3}>
<Grid item>
<Flex flexDirection="column" gap={1}>
<SettingsSection>
<Trans>NFT</Trans>
</SettingsSection>
<SettingsText>
<Trans>Choose what you want to see and how you want to view it.</Trans>
</SettingsText>
</Flex>
</Grid>
<Grid item xs={12} sm={12} lg={12}>
<SettingsHR />
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Hide objectionable content</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end" marginTop="-6px">
<FormControlLabel
control={<Switch checked={hideObjectionableContent} onChange={handleChangeHideObjectionableContent} />}
/>
</Grid>
<Grid item style={{ width: '400px' }}>
<SettingsText>
<Trans>
NFTs that have been categorized by the creator as objectionable content will be hidden by default.
</Trans>
</SettingsText>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Fit images to cards</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end" marginTop="-6px">
<FormControlLabel
control={<Switch checked={nftImageFittingMode === 'contain'} onChange={handleScalePreviewImages} />}
/>
</Grid>
<Grid item style={{ width: '400px' }}>
<SettingsText>
<Trans>Images will be scaled to fill the NFT card and ignore their original proportions.</Trans>
</SettingsText>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Loop videos</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end" marginTop="-6px">
<FormControlLabel control={<Switch checked={nftVideoLoop} onChange={handleChangeVideoLoop} />} />
</Grid>
<Grid item style={{ width: '400px' }}>
<SettingsText>
<Trans>
All NFT videos will restart automatically when they finish playing. When disabled, looping can still be
turned on for individual videos from their detail page.
</Trans>
</SettingsText>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Fetch IPFS content through a gateway</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end" marginTop="-6px">
<FormControlLabel control={<Switch checked={ipfsGateway} onChange={handleChangeIpfsGateway} />} />
</Grid>
<Grid item style={{ width: '400px' }}>
<SettingsText>
<Trans>
NFT files published with ipfs:// addresses will be downloaded through the public ipfs.io HTTPS gateway.
The requested URL differs from the address recorded on chain, but downloaded content is still verified
against the NFT's on-chain hash. When disabled, ipfs:// files are not fetched.
</Trans>
</SettingsText>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Show unverified previews</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end" marginTop="-6px">
<FormControlLabel
control={<Switch checked={allowUnverifiedPreviews} onChange={handleChangeAllowUnverifiedPreviews} />}
/>
</Grid>
<Grid item style={{ width: '400px' }}>
<SettingsText>
<Trans>
When an NFT image is too large to verify against its on-chain hash, load the transaction confirmation
preview directly from its source URL without verification. When disabled, no preview is shown for these
NFTs.
</Trans>
</SettingsText>
</Grid>
</Grid>
<Grid item style={{ maxWidth: '400px' }}>
<Flex flexDirection="column" gap={1}>
<SettingsSection>
<Trans>Cache</Trans>
</SettingsSection>
<SettingsText>
<Trans>Manage how and where files are stored on this computer.</Trans>
</SettingsText>
</Flex>
</Grid>
<Grid item xs={12} sm={12} lg={12}>
<SettingsHR />
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Occupied space</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end">
<Button onClick={clearNFTCache} color="primary" variant="outlined" size="small">
<Trans>Clear NFT cache</Trans>
</Button>
</Grid>
<Grid item style={{ width: '400px' }}>
<Typography variant="body2" fontWeight="500" component="div">
<FormatBytes value={cacheSize} precision={3} />
</Typography>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Local folder</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end">
<Button onClick={chooseAnotherFolder} color="primary" variant="outlined" size="small">
<Trans>Change</Trans>
</Button>
</Grid>
<Grid item style={{ width: '400px' }}>
<Typography variant="body2" fontWeight="500" component="div">
{cacheDirectory}
</Typography>
</Grid>
</Grid>
<Grid container>
<Grid item style={{ width: '400px' }}>
<SettingsTitle>
<Trans>Limit cache size</Trans>
</SettingsTitle>
</Grid>
<Grid item container xs justifyContent="flex-end">
<LimitCacheSize />
</Grid>
</Grid>
</Grid>
);
}