-
Notifications
You must be signed in to change notification settings - Fork 44
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
Also, in modals, improve handling of danger, and add delays.
- Loading branch information
Showing
11 changed files
with
260 additions
and
9 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
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,80 @@ | ||
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 { selectAllowDangerousSetting } 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(selectAllowDangerousSetting) | ||
|
||
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> | ||
<strong> | ||
{t( | ||
'dangerMode.description', | ||
'Dangerous mode: should the wallet let the user shoot himself in the foot?', | ||
)} | ||
</strong> | ||
</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.setAllowDangerous(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 = { | ||
allowDangerous: false, | ||
} | ||
|
||
const slice = createSlice({ | ||
name: 'settings', | ||
initialState, | ||
reducers: { | ||
setAllowDangerous(state, action: PayloadAction<boolean>) { | ||
state.allowDangerous = 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,8 @@ | ||
import { createSelector } from '@reduxjs/toolkit' | ||
|
||
import { RootState } from 'types' | ||
import { initialState } from '.' | ||
|
||
const selectSlice = (state: RootState) => state.settings || initialState | ||
|
||
export const selectAllowDangerousSetting = createSelector([selectSlice], settings => settings.allowDangerous) |
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 { | ||
allowDangerous: 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