Skip to content

Commit 76c08cf

Browse files
committed
Merge branch 'frontend-testnet-uiimprovements'
2 parents a6f72b4 + 72dce28 commit 76c08cf

File tree

4 files changed

+83
-34
lines changed

4 files changed

+83
-34
lines changed

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

+12
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

+1-1
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

+69-32
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
};

frontends/web/src/routes/settings/components/advanced-settings/unlock-software-keystore.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const UnlockSoftwareKeystore = ({
4545
settingName={t('testWallet.disconnect.title')}
4646
secondaryText={t('testWallet.disconnect.description')}
4747
onClick={() => deregisterTest()}
48+
hideChevron
4849
extraComponent={
4950
<Eject
5051
className={styles.ejectIconRight}
@@ -61,7 +62,6 @@ export const UnlockSoftwareKeystore = ({
6162
<SettingsItem
6263
settingName={t('testWallet.connect.title')}
6364
secondaryText={t('testWallet.connect.description')}
64-
hideChevron
6565
extraComponent={
6666
<ChevronRightDark
6767
className={styles.chevronRight}

0 commit comments

Comments
 (0)