setDefaultSafe action

This commit is contained in:
Mikhail Mikheev 2019-09-18 17:51:38 +04:00
parent 138f462021
commit a699012a52
3 changed files with 24 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import ListItemText from '@material-ui/core/ListItemText'
import Link from '~/components/layout/Link' import Link from '~/components/layout/Link'
import Hairline from '~/components/layout/Hairline' import Hairline from '~/components/layout/Hairline'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import ButtonLink from '~/components/layout/ButtonLink'
import Identicon from '~/components/Identicon' import Identicon from '~/components/Identicon'
import { import {
mediumFontSize, sm, secondary, primary, mediumFontSize, sm, secondary, primary,
@ -20,6 +21,7 @@ import { SAFELIST_ADDRESS } from '~/routes/routes'
type SafeListProps = { type SafeListProps = {
safes: List<Safe>, safes: List<Safe>,
onSafeClick: Function, onSafeClick: Function,
setDefaultSafe: Function,
} }
const useStyles = makeStyles({ const useStyles = makeStyles({
@ -39,7 +41,7 @@ const useStyles = makeStyles({
}, },
}) })
const SafeList = ({ safes, onSafeClick }: SafeListProps) => { const SafeList = ({ safes, onSafeClick, setDefaultSafe }: SafeListProps) => {
const classes = useStyles() const classes = useStyles()
return ( return (
@ -59,9 +61,16 @@ const SafeList = ({ safes, onSafeClick }: SafeListProps) => {
<Paragraph size="lg" color="primary"> <Paragraph size="lg" color="primary">
{safe.ethBalance} {safe.ethBalance}
{' '} {' '}
ETH ETH
</Paragraph> </Paragraph>
Make default <ButtonLink
size="sm"
onClick={() => {
setDefaultSafe(safe.address)
}}
>
Make default
</ButtonLink>
</ListItem> </ListItem>
</Link> </Link>
<Hairline /> <Hairline />

View File

@ -14,6 +14,7 @@ import Hairline from '~/components/layout/Hairline'
import Row from '~/components/layout/Row' import Row from '~/components/layout/Row'
import { type Safe } from '~/routes/safe/store/models/safe' import { type Safe } from '~/routes/safe/store/models/safe'
import { safesListSelector } from '~/routes/safeList/store/selectors' import { safesListSelector } from '~/routes/safeList/store/selectors'
import setDefaultSafe from '~/routes/safe/store/actions/setDefaultSafe'
import useSidebarStyles from './style' import useSidebarStyles from './style'
import SafeList from './SafeList' import SafeList from './SafeList'
import { WELCOME_ADDRESS } from '~/routes/routes' import { WELCOME_ADDRESS } from '~/routes/routes'
@ -33,6 +34,7 @@ export const SidebarContext = React.createContext<TSidebarContext>({
type SidebarProps = { type SidebarProps = {
children: React.Node, children: React.Node,
safes: List<Safe>, safes: List<Safe>,
setDefaultSafeAction: Function,
} }
const filterBy = (filter: string, safes: List<Safe>): List<Safe> => safes.filter( const filterBy = (filter: string, safes: List<Safe>): List<Safe> => safes.filter(
@ -41,7 +43,7 @@ const filterBy = (filter: string, safes: List<Safe>): List<Safe> => safes.filter
|| safe.name.toLowerCase().includes(filter.toLowerCase()), || safe.name.toLowerCase().includes(filter.toLowerCase()),
) )
const Sidebar = ({ children, safes }: SidebarProps) => { const Sidebar = ({ children, safes, setDefaultSafeAction }: SidebarProps) => {
const [isOpen, setIsOpen] = useState<boolean>(false) const [isOpen, setIsOpen] = useState<boolean>(false)
const [filter, setFilter] = useState<string>('') const [filter, setFilter] = useState<string>('')
const classes = useSidebarStyles() const classes = useSidebarStyles()
@ -110,7 +112,7 @@ const Sidebar = ({ children, safes }: SidebarProps) => {
<Spacer /> <Spacer />
</Row> </Row>
<Hairline /> <Hairline />
<SafeList safes={filteredSafes} onSafeClick={toggleSidebar} /> <SafeList safes={filteredSafes} onSafeClick={toggleSidebar} setDefaultSafe={setDefaultSafeAction} />
</Drawer> </Drawer>
</ClickAwayListener> </ClickAwayListener>
{children} {children}
@ -121,5 +123,5 @@ const Sidebar = ({ children, safes }: SidebarProps) => {
export default connect<Object, Object, ?Function, ?Object>( export default connect<Object, Object, ?Function, ?Object>(
// $FlowFixMe // $FlowFixMe
(state) => ({ safes: safesListSelector(state) }), (state) => ({ safes: safesListSelector(state) }),
null, { setDefaultSafeAction: setDefaultSafe },
)(Sidebar) )(Sidebar)

View File

@ -5,6 +5,8 @@ import { type GlobalState } from '~/store/index'
import { type Safe } from '~/routes/safe/store/models/safe' import { type Safe } from '~/routes/safe/store/models/safe'
import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe' import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe'
const safesStateSelector = (state: GlobalState): Map<string, *> => state[SAFE_REDUCER_ID]
export const safesMapSelector = (state: GlobalState): Map<string, Safe> => state[SAFE_REDUCER_ID].get('safes') export const safesMapSelector = (state: GlobalState): Map<string, Safe> => state[SAFE_REDUCER_ID].get('safes')
export const safesListSelector: Selector<GlobalState, {}, List<Safe>> = createSelector( export const safesListSelector: Selector<GlobalState, {}, List<Safe>> = createSelector(
@ -16,3 +18,8 @@ export const safesCountSelector: Selector<GlobalState, {}, number> = createSelec
safesMapSelector, safesMapSelector,
(safes: Map<string, Safe>): number => safes.size, (safes: Map<string, Safe>): number => safes.size,
) )
export const defaultSafeSelector: Selector<GlobalState, {}, string> = createSelector(
safesStateSelector,
(safeState: Map<string, *>): string => safeState.get('defaultSafe'),
)