implement add custom token modal

This commit is contained in:
Mikhail Mikheev 2019-04-22 16:23:58 +04:00
parent edbec8e3ab
commit 7dc2f235f8
5 changed files with 78 additions and 66 deletions

View File

@ -10,7 +10,7 @@ const styles = {
}
type Props = {
minWidth?: number
minWidth?: number,
}
const calculateStyleBased = minWidth => ({

View File

@ -1,14 +1,10 @@
// @flow
import { createAction } from 'redux-actions'
import { type Token } from '~/logic/tokens/store/model/token'
import { saveActiveTokens, getActiveTokens, setToken } from '~/logic/tokens/utils/tokensStorage'
import type { Dispatch as ReduxDispatch } from 'redux'
import { type GlobalState } from '~/store/'
export const ADD_TOKEN = 'ADD_TOKEN'
type AddTokenProps = {
safeAddress: string,
token: Token,
}
@ -18,13 +14,3 @@ export const addToken = createAction<string, *, *>(
token,
}),
)
const saveToken = (safeAddress: string, token: Token) => async (dispatch: ReduxDispatch<GlobalState>) => {
dispatch(addToken(token))
const activeTokens = await getActiveTokens(safeAddress)
await saveActiveTokens(safeAddress, activeTokens.push(token.toJS()))
setToken(safeAddress, token)
}
export default saveToken

View File

@ -62,7 +62,7 @@ class Tokens extends React.Component<Props, State> {
setActiveScreen={this.setActiveScreen}
/>
)}
{activeScreen === 'addCustomToken' && <AddCustomToken />}
{activeScreen === 'addCustomToken' && <AddCustomToken setActiveScreen={this.setActiveScreen} />}
</React.Fragment>
)
}

View File

@ -6,72 +6,90 @@ import Paragraph from '~/components/layout/Paragraph'
import Row from '~/components/layout/Row'
import Col from '~/components/layout/Col'
import Img from '~/components/layout/Img'
import Button from '~/components/layout/Button'
import Field from '~/components/forms/Field'
import Checkbox from '~/components/forms/Checkbox'
import GnoForm from '~/components/forms/GnoForm'
import TextField from '~/components/forms/TextField'
import { composeValidators, required, mustBeEthereumAddress } from '~/components/forms/validator'
import Hairline from '~/components/layout/Hairline'
import {
composeValidators, required, mustBeEthereumAddress, mustBeInteger,
} from '~/components/forms/validator'
import TokenPlaceholder from '~/routes/safe/components/Balances/assets/token_placeholder.svg'
import { styles } from './style'
class AddCustomToken extends Component {
handleSubmit = () => {
console.log('form submitted')
handleSubmit = (values) => {
console.log(values)
}
render() {
const { classes } = this.props
const { classes, setActiveScreen } = this.props
const goBackToTokenList = () => {
setActiveScreen('tokenList')
}
return (
<React.Fragment>
<Paragraph noMargin className={classes.title} weight="bolder" size="lg">
Add custom token
</Paragraph>
<GnoForm onSubmit={this.handleSubmit}>
{(submitting: boolean, validating: boolean, ...rest: any) => (
<Block className={classes.formContainer}>
<Field
name="tokenAddress"
component={TextField}
type="text"
validate={composeValidators(required, mustBeEthereumAddress)}
placeholder="Token contract address*"
text="Token contract address*"
className={classes.addressInput}
/>
<Row>
<Col xs={6} layout="column">
<Field
name="tokenSymbol"
component={TextField}
type="text"
validate={composeValidators(required, mustBeEthereumAddress)}
placeholder="Token symbol*"
text="Token symbol"
className={classes.addressInput}
/>
<Field
name="tokenDecimals"
component={TextField}
type="text"
validate={composeValidators(required, mustBeEthereumAddress)}
placeholder="Token decimals*"
text="Token decimals*"
className={classes.addressInput}
/>
<Block align="left">
<Field name="showForAllSafes" component={Checkbox} type="checkbox" className={classes.checkbox} />
<Paragraph weight="bolder" size="md" className={classes.checkboxLabel}>
Display token for all safes
</Paragraph>
</Block>
</Col>
<Col xs={6} layout="column" align="center">
<Paragraph className={classes.tokenImageHeading}>Token Image</Paragraph>
<Img src={TokenPlaceholder} alt="Token image" height={100} />
</Col>
<React.Fragment>
<Block className={classes.formContainer}>
<Paragraph noMargin className={classes.title} weight="bolder" size="lg">
Add custom token
</Paragraph>
<Field
name="tokenAddress"
component={TextField}
type="text"
validate={composeValidators(required, mustBeEthereumAddress)}
placeholder="Token contract address*"
text="Token contract address*"
className={classes.addressInput}
/>
<Row>
<Col xs={6} layout="column">
<Field
name="tokenSymbol"
component={TextField}
type="text"
validate={required}
placeholder="Token symbol*"
text="Token symbol"
className={classes.addressInput}
/>
<Field
name="tokenDecimals"
component={TextField}
type="text"
validate={composeValidators(required, mustBeInteger)}
placeholder="Token decimals*"
text="Token decimals*"
className={classes.addressInput}
/>
<Block align="left">
<Field name="showForAllSafes" component={Checkbox} type="checkbox" className={classes.checkbox} />
<Paragraph weight="bolder" size="md" className={classes.checkboxLabel}>
Display token for all safes
</Paragraph>
</Block>
</Col>
<Col xs={6} layout="column" align="center">
<Paragraph className={classes.tokenImageHeading}>Token Image</Paragraph>
<Img src={TokenPlaceholder} alt="Token image" height={100} />
</Col>
</Row>
</Block>
<Hairline />
<Row align="center" className={classes.buttonRow}>
<Button className={classes.button} minWidth={140} onClick={goBackToTokenList}>
Cancel
</Button>
<Button type="submit" className={classes.button} variant="contained" minWidth={140} color="primary">
Save
</Button>
</Row>
</Block>
</React.Fragment>
)}
</GnoForm>
</React.Fragment>

View File

@ -3,11 +3,12 @@ import { lg } from '~/theme/variables'
export const styles = () => ({
title: {
padding: `${lg} 20px 20px`,
padding: `${lg} 0 20px`,
fontSize: '16px',
},
formContainer: {
padding: '0 20px',
minHeight: '369px',
},
addressInput: {
marginBottom: '15px',
@ -23,4 +24,11 @@ export const styles = () => ({
checkboxLabel: {
letterSpacing: '-0.5px',
},
buttonRow: {
height: '84px',
justifyContent: 'center',
},
button: {
height: '42px',
},
})