Skip to content

Commit c662e48

Browse files
committed
frontend: improve restart in testnet
The testnet toggle was not active in testnet. Changing this settings require an app restart, this was only communicated by an inline message and could be easily missed. This commit improves the UX by: - changing the toggle to a normal settings item - showing activate / deactivate instructions - adding a blocking view that calls to restart the app
1 parent 4f60863 commit c662e48

File tree

3 files changed

+82
-33
lines changed

3 files changed

+82
-33
lines changed

frontends/web/src/locales/en/app.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,18 @@
18441844
"title": "Unlock test wallet"
18451845
}
18461846
},
1847+
"testnet": {
1848+
"activate": {
1849+
"description": "Restart the app in testnet mode to explore and test features.",
1850+
"prompt": "Please close the app and start again to enter testnet mode",
1851+
"title": "Start testnet mode"
1852+
},
1853+
"deactivate": {
1854+
"description": "Restart app to exit testnet mode.",
1855+
"prompt": "Please close the app to exit testnet mode",
1856+
"title": "Exit testnet mode"
1857+
}
1858+
},
18471859
"transaction": {
18481860
"confirmation": "Confirmations",
18491861
"details": {

frontends/web/src/routes/settings/advanced-settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const AdvancedSettings = ({ devices, hasAccounts }: TPagePropsWithSetting
9898
<EnableCoinControlSetting frontendConfig={frontendConfig} onChangeConfig={setConfig} />
9999
<EnableAuthSetting backendConfig={backendConfig} onChangeConfig={setConfig} />
100100
<EnableTorProxySetting proxyConfig={proxyConfig} onChangeConfig={setConfig} />
101-
<RestartInTestnetSetting backendConfig={backendConfig} onChangeConfig={setConfig} />
101+
<RestartInTestnetSetting onChangeConfig={setConfig} />
102102
<UnlockSoftwareKeystore deviceIDs={deviceIDs}/>
103103
<ConnectFullNodeSetting />
104104
<ExportLogSetting />

frontends/web/src/routes/settings/components/advanced-settings/restart-in-testnet-setting.tsx

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,92 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { ChangeEvent, Dispatch } from 'react';
19-
import { useState } from 'react';
18+
import { Dispatch, useContext, useState } from 'react';
2019
import { useTranslation } from 'react-i18next';
20+
import type { TConfig } from '@/routes/settings/advanced-settings';
21+
import { AppContext } from '@/contexts/AppContext';
2122
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';
2526
import { setConfig } from '@/utils/config';
26-
import styles from './enable-tor-proxy-setting.module.css';
27+
import { UseBackButton } from '@/hooks/backbutton';
2728

2829
type TProps = {
29-
backendConfig?: TBackendConfig;
3030
onChangeConfig: Dispatch<TConfig>;
3131
}
3232

33-
export const RestartInTestnetSetting = ({ backendConfig, onChangeConfig }: TProps) => {
33+
export const RestartInTestnetSetting = ({ onChangeConfig }: TProps) => {
3434
const { t } = useTranslation();
3535
const [showRestartMessage, setShowRestartMessage] = useState(false);
36+
const { isTesting } = useContext(AppContext);
3637

37-
38-
const handleToggleRestartInTestnet = async (e: ChangeEvent<HTMLInputElement>) => {
39-
setShowRestartMessage(e.target.checked);
38+
const handleRestart = async () => {
39+
setShowRestartMessage(true);
4040
const config = await setConfig({
4141
backend: {
42-
'startInTestnet': e.target.checked
42+
startInTestnet: !isTesting
4343
},
44-
}) as TConfig;
44+
});
4545
onChangeConfig(config);
4646
};
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 (
5491
<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}
6695
/>
67-
</>
96+
);
97+
}
98+
99+
return (
100+
<SettingsItem
101+
settingName={t('testnet.activate.title')}
102+
secondaryText={t('testnet.activate.description')}
103+
onClick={handleRestart}
104+
/>
68105
);
69106
};

0 commit comments

Comments
 (0)