|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -import { ChangeEvent, Dispatch } from 'react'; |
19 |
| -import { useState } from 'react'; |
| 18 | +import { Dispatch, useContext, useState } from 'react'; |
20 | 19 | import { useTranslation } from 'react-i18next';
|
| 20 | +import type { TConfig } from '@/routes/settings/advanced-settings'; |
| 21 | +import { AppContext } from '@/contexts/AppContext'; |
21 | 22 | import { SettingsItem } from '@/routes/settings/components/settingsItem/settingsItem';
|
22 |
| -import { Toggle } from '@/components/toggle/toggle'; |
23 |
| -import { TConfig, TBackendConfig } from '@/routes/settings/advanced-settings'; |
24 |
| -import { Message } from '@/components/message/message'; |
| 23 | +import { View, ViewButtons, ViewContent, ViewHeader } from '@/components/view/view'; |
| 24 | +import { PointToBitBox02 } from '@/components/icon'; |
| 25 | +import { Button } from '@/components/forms'; |
25 | 26 | import { setConfig } from '@/utils/config';
|
26 |
| -import styles from './enable-tor-proxy-setting.module.css'; |
| 27 | +import { UseBackButton } from '@/hooks/backbutton'; |
27 | 28 |
|
28 | 29 | type TProps = {
|
29 |
| - backendConfig?: TBackendConfig; |
30 | 30 | onChangeConfig: Dispatch<TConfig>;
|
31 | 31 | }
|
32 | 32 |
|
33 |
| -export const RestartInTestnetSetting = ({ backendConfig, onChangeConfig }: TProps) => { |
| 33 | +export const RestartInTestnetSetting = ({ onChangeConfig }: TProps) => { |
34 | 34 | const { t } = useTranslation();
|
35 | 35 | const [showRestartMessage, setShowRestartMessage] = useState(false);
|
| 36 | + const { isTesting } = useContext(AppContext); |
36 | 37 |
|
37 |
| - |
38 |
| - const handleToggleRestartInTestnet = async (e: ChangeEvent<HTMLInputElement>) => { |
39 |
| - setShowRestartMessage(e.target.checked); |
| 38 | + const handleRestart = async () => { |
| 39 | + setShowRestartMessage(true); |
40 | 40 | const config = await setConfig({
|
41 | 41 | backend: {
|
42 |
| - 'startInTestnet': e.target.checked |
| 42 | + startInTestnet: !isTesting |
43 | 43 | },
|
44 |
| - }) as TConfig; |
| 44 | + }); |
45 | 45 | onChangeConfig(config);
|
46 | 46 | };
|
47 |
| - return ( |
48 |
| - <> |
49 |
| - { showRestartMessage ? ( |
50 |
| - <Message type="warning"> |
51 |
| - {t('settings.restart')} |
52 |
| - </Message> |
53 |
| - ) : null } |
| 47 | + |
| 48 | + const handleReset = async () => { |
| 49 | + setShowRestartMessage(false); |
| 50 | + if (!isTesting) { |
| 51 | + const config = await setConfig({ |
| 52 | + backend: { |
| 53 | + startInTestnet: false |
| 54 | + }, |
| 55 | + }); |
| 56 | + onChangeConfig(config); |
| 57 | + } |
| 58 | + }; |
| 59 | + |
| 60 | + if (showRestartMessage) { |
| 61 | + return ( |
| 62 | + <View fullscreen textCenter verticallyCentered> |
| 63 | + <UseBackButton handler={() => { |
| 64 | + handleReset(); |
| 65 | + return false; |
| 66 | + }} /> |
| 67 | + <ViewHeader title={ |
| 68 | + isTesting |
| 69 | + ? t('testnet.deactivate.title') |
| 70 | + : t('testnet.activate.title') |
| 71 | + }> |
| 72 | + {isTesting |
| 73 | + ? t('testnet.deactivate.prompt') |
| 74 | + : t('testnet.activate.prompt') |
| 75 | + } |
| 76 | + </ViewHeader> |
| 77 | + <ViewContent minHeight="260px"> |
| 78 | + <PointToBitBox02 /> |
| 79 | + </ViewContent> |
| 80 | + <ViewButtons> |
| 81 | + <Button secondary onClick={handleReset}> |
| 82 | + {t('dialog.cancel')} |
| 83 | + </Button> |
| 84 | + </ViewButtons> |
| 85 | + </View> |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + if (isTesting) { |
| 90 | + return ( |
54 | 91 | <SettingsItem
|
55 |
| - className={styles.settingItem} |
56 |
| - settingName={t('settings.expert.restartInTestnet')} |
57 |
| - secondaryText={t('newSettings.advancedSettings.restartInTestnet.description')} |
58 |
| - extraComponent={ |
59 |
| - backendConfig !== undefined ? ( |
60 |
| - <Toggle |
61 |
| - checked={backendConfig?.startInTestnet || false} |
62 |
| - onChange={handleToggleRestartInTestnet} |
63 |
| - /> |
64 |
| - ) : null |
65 |
| - } |
| 92 | + settingName={t('testnet.deactivate.title')} |
| 93 | + secondaryText={t('testnet.deactivate.description')} |
| 94 | + onClick={handleRestart} |
66 | 95 | />
|
67 |
| - </> |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + return ( |
| 100 | + <SettingsItem |
| 101 | + settingName={t('testnet.activate.title')} |
| 102 | + secondaryText={t('testnet.activate.description')} |
| 103 | + onClick={handleRestart} |
| 104 | + /> |
68 | 105 | );
|
69 | 106 | };
|
0 commit comments