-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a settings dialog, with "dangerous mode" setting
- Loading branch information
Showing
10 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { useState } from 'react' | ||
import { SidebarButton } from '../Sidebar' | ||
import { Configure } from 'grommet-icons/icons' | ||
import { useTranslation } from 'react-i18next' | ||
import { SettingsDialog } from '../SettingsDialog' | ||
|
||
export const SettingsButton = () => { | ||
const [layerVisibility, setLayerVisibility] = useState(false) | ||
const { t } = useTranslation() | ||
return ( | ||
<> | ||
<SidebarButton | ||
icon={<Configure />} | ||
label={t('menu.settings', 'Settings')} | ||
onClick={() => { | ||
setLayerVisibility(true) | ||
}} | ||
/> | ||
{layerVisibility && <SettingsDialog closeHandler={() => setLayerVisibility(false)} />} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useContext } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { ResponsiveLayer } from '../ResponsiveLayer' | ||
import { Box, Button, Heading, Paragraph, RadioButtonGroup, ResponsiveContext } from 'grommet' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { selectDangerousModeSetting } from './slice/selectors' | ||
import { Threats } from 'grommet-icons' | ||
import { settingsActions } from './slice' | ||
|
||
interface SettingsDialogProps { | ||
closeHandler: () => void | ||
} | ||
|
||
export const SettingsDialog = (props: SettingsDialogProps) => { | ||
const { t } = useTranslation() | ||
const size = useContext(ResponsiveContext) | ||
|
||
const dispatch = useDispatch() | ||
const dangerousMode = useSelector(selectDangerousModeSetting) | ||
|
||
return ( | ||
<ResponsiveLayer | ||
onClickOutside={props.closeHandler} | ||
onEsc={props.closeHandler} | ||
animation="slide" | ||
background="background-front" | ||
modal | ||
> | ||
<Box pad={{ vertical: 'small' }} margin="medium" width={size === 'small' ? 'auto' : '700px'}> | ||
<Heading size="1" margin={{ vertical: 'small' }}> | ||
{t('settings.dialog.title', 'Wallet settings')} | ||
</Heading> | ||
<Paragraph fill> | ||
{t( | ||
'settings.dialog.description', | ||
'This is where you can configure the behavior of the Oasis Wallet.', | ||
)} | ||
</Paragraph> | ||
<Box | ||
gap="small" | ||
pad={{ vertical: 'medium', right: 'small' }} | ||
overflow={{ vertical: 'auto' }} | ||
height={{ max: '400px' }} | ||
> | ||
<Paragraph fill> | ||
<b>{t('dangerMode.title', 'Dangerous mode')}:</b>{' '} | ||
{t('dangerMode.description', 'should the wallet let the user shoot himself in the foot?')} | ||
</Paragraph> | ||
<RadioButtonGroup | ||
name="doc" | ||
options={[ | ||
{ | ||
value: false, | ||
label: t('dangerMode.off', 'Off - Refuse to execute nonsensical actions'), | ||
}, | ||
{ | ||
value: true, | ||
label: ( | ||
<span> | ||
{t('dangerMode.on', "On - Allow executing nonsensical actions. Don't blame Oasis!")}{' '} | ||
<Threats size={'large'} /> | ||
</span> | ||
), | ||
}, | ||
]} | ||
value={dangerousMode} | ||
onChange={event => dispatch(settingsActions.setDangerousMode(event.target.value === 'true'))} | ||
/> | ||
</Box> | ||
<Box align="end" pad={{ top: 'medium' }}> | ||
<Button primary label={t('settings.dialog.close', 'Close')} onClick={props.closeHandler} /> | ||
</Box> | ||
</Box> | ||
</ResponsiveLayer> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { PayloadAction } from '@reduxjs/toolkit' | ||
import { createSlice } from 'utils/@reduxjs/toolkit' | ||
|
||
import { SettingsState } from './types' | ||
|
||
export const initialState: SettingsState = { | ||
dangerousMode: false, | ||
} | ||
|
||
const slice = createSlice({ | ||
name: 'settings', | ||
initialState, | ||
reducers: { | ||
setDangerousMode(state, action: PayloadAction<boolean>) { | ||
state.dangerousMode = action.payload | ||
}, | ||
}, | ||
}) | ||
|
||
export const { actions: settingsActions } = slice | ||
|
||
export default slice.reducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createSelector } from '@reduxjs/toolkit' | ||
|
||
import { RootState } from 'types' | ||
import { initialState } from '.' | ||
import { useSelector } from 'react-redux' | ||
|
||
const selectSlice = (state: RootState) => state.settings || initialState | ||
|
||
export const selectDangerousModeSetting = createSelector([selectSlice], settings => settings.dangerousMode) | ||
|
||
export const useDangerModeSetting = () => useSelector(selectDangerousModeSetting) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface SettingsState { | ||
dangerousMode: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters