fix checkbox displaying in manage tokens modal

This commit is contained in:
mmv 2019-04-15 17:59:31 +04:00
parent 81e05c132d
commit 0b6be00632
3 changed files with 29 additions and 19 deletions

View File

@ -65,8 +65,7 @@ class Tokens extends React.Component<Props, State> {
this.setState(() => ({ filter: value })) this.setState(() => ({ filter: value }))
} }
onSwitch = (token: Token) => (e: SyntheticInputEvent<HTMLInputElement>) => { onSwitch = (token: Token) => () => {
const { checked } = e.target
const { safeAddress, updateActiveTokens } = this.props const { safeAddress, updateActiveTokens } = this.props
updateActiveTokens(safeAddress, token.address) updateActiveTokens(safeAddress, token.address)
@ -78,7 +77,9 @@ class Tokens extends React.Component<Props, State> {
} }
render() { render() {
const { onClose, classes, tokens } = this.props const {
onClose, classes, tokens, activeTokens,
} = this.props
const { filter } = this.state const { filter } = this.state
const searchClasses = { const searchClasses = {
input: classes.searchInput, input: classes.searchInput,
@ -120,19 +121,23 @@ class Tokens extends React.Component<Props, State> {
<Hairline /> <Hairline />
</Block> </Block>
<MuiList className={classes.list}> <MuiList className={classes.list}>
{filteredTokens.map((token: Token) => ( {filteredTokens.map((token: Token) => {
<ListItem key={token.address} className={classes.token}> const isActive = activeTokens.findIndex(({ address }) => address === token.address) !== -1
<ListItemIcon>
<Img src={token.logoUri} height={28} alt={token.name} onError={this.setImageToPlaceholder} /> return (
</ListItemIcon> <ListItem key={token.address} className={classes.token}>
<ListItemText primary={token.symbol} secondary={token.name} /> <ListItemIcon>
{token.address !== ETH_ADDRESS && ( <Img src={token.logoUri} height={28} alt={token.name} onError={this.setImageToPlaceholder} />
<ListItemSecondaryAction> </ListItemIcon>
<Switch onChange={this.onSwitch(token)} checked={token.status} /> <ListItemText primary={token.symbol} secondary={token.name} />
</ListItemSecondaryAction> {token.address !== ETH_ADDRESS && (
)} <ListItemSecondaryAction>
</ListItem> <Switch onChange={this.onSwitch(token)} checked={isActive} />
))} </ListItemSecondaryAction>
)}
</ListItem>
)
})}
</MuiList> </MuiList>
</React.Fragment> </React.Fragment>
) )

View File

@ -102,7 +102,12 @@ class Balances extends React.Component<Props, State> {
handleClose={this.onHide('Token')} handleClose={this.onHide('Token')}
open={showToken} open={showToken}
> >
<Tokens tokens={tokens} onClose={this.onHide('Token')} safeAddress={safeAddress} /> <Tokens
tokens={tokens}
onClose={this.onHide('Token')}
safeAddress={safeAddress}
activeTokens={activeTokens}
/>
</Modal> </Modal>
</Col> </Col>
</Row> </Row>

View File

@ -25,7 +25,7 @@ export const buildSafe = (storedSafe: SafeProps) => {
owners, owners,
} }
return SafeRecord(safe) return safe
} }
const buildSafesFrom = (loadedSafes: Object): Map<string, Safe> => { const buildSafesFrom = (loadedSafes: Object): Map<string, Safe> => {
@ -36,7 +36,7 @@ const buildSafesFrom = (loadedSafes: Object): Map<string, Safe> => {
const safeRecords = keys.map((address: string) => buildSafe(loadedSafes[address])) const safeRecords = keys.map((address: string) => buildSafe(loadedSafes[address]))
return safes.withMutations(async (map) => { return safes.withMutations(async (map) => {
safeRecords.forEach((safe: Safe) => map.set(safe.get('address'), safe)) safeRecords.forEach((safe: SafeProps) => map.set(safe.address, safe))
}) })
} catch (err) { } catch (err) {
// eslint-disable-next-line // eslint-disable-next-line