diff --git a/src/logic/tokens/store/reducer/tokens.js b/src/logic/tokens/store/reducer/tokens.js index 1bec30e9..e94cda97 100644 --- a/src/logic/tokens/store/reducer/tokens.js +++ b/src/logic/tokens/store/reducer/tokens.js @@ -1,7 +1,7 @@ // @flow import { Map } from 'immutable' import { handleActions, type ActionType } from 'redux-actions' -import { type Token } from '~/logic/tokens/store/model/token' +import { type Token, makeToken } from '~/logic/tokens/store/model/token' import { ADD_TOKEN } from '~/logic/tokens/store/actions/addToken' import { REMOVE_TOKEN } from '~/logic/tokens/store/actions/removeToken' import { ADD_TOKENS } from '~/logic/tokens/store/actions/saveTokens' @@ -27,7 +27,7 @@ export default handleActions( const { token } = action.payload const { address: tokenAddress } = token - return state.set(tokenAddress, token) + return state.set(tokenAddress, makeToken(token)) }, [REMOVE_TOKEN]: (state: State, action: ActionType): State => { const { token } = action.payload diff --git a/src/routes/safe/components/Balances/Tokens/actions.js b/src/routes/safe/components/Balances/Tokens/actions.js index cf7ed193..652873f5 100644 --- a/src/routes/safe/components/Balances/Tokens/actions.js +++ b/src/routes/safe/components/Balances/Tokens/actions.js @@ -1,13 +1,16 @@ // @flow import fetchTokens from '~/logic/tokens/store/actions/fetchTokens' +import { addToken } from '~/logic/tokens/store/actions/addToken' import updateActiveTokens from '~/routes/safe/store/actions/updateActiveTokens' export type Actions = { fetchTokens: Function, updateActiveTokens: Function, + addToken: Function, } export default { fetchTokens, + addToken, updateActiveTokens, } diff --git a/src/routes/safe/components/Balances/Tokens/index.jsx b/src/routes/safe/components/Balances/Tokens/index.jsx index fd8d87fc..21c57cc1 100644 --- a/src/routes/safe/components/Balances/Tokens/index.jsx +++ b/src/routes/safe/components/Balances/Tokens/index.jsx @@ -35,6 +35,23 @@ class Tokens extends React.Component { activeScreen, }) + onTokenAdd = (formValues) => { + const { + addToken, updateActiveTokens, safeAddress, activeTokens, + } = this.props + + const activeTokensAddresses = List(activeTokens.map(({ address }) => address)) + const token = { + address: formValues.tokenAddress, + decimals: formValues.tokenDecimals, + symbol: formValues.tokenSymbol, + name: formValues.tokenSymbol, + } + + addToken(token) + updateActiveTokens(safeAddress, activeTokensAddresses.push(token.address)) + } + render() { const { onClose, classes, tokens, activeTokens, fetchTokens, updateActiveTokens, safeAddress, @@ -62,7 +79,9 @@ class Tokens extends React.Component { setActiveScreen={this.setActiveScreen} /> )} - {activeScreen === 'addCustomToken' && } + {activeScreen === 'addCustomToken' && ( + + )} ) } diff --git a/src/routes/safe/components/Balances/Tokens/screens/AddCustomToken/index.jsx b/src/routes/safe/components/Balances/Tokens/screens/AddCustomToken/index.jsx index 8fc9a345..e8c3aa2f 100644 --- a/src/routes/safe/components/Balances/Tokens/screens/AddCustomToken/index.jsx +++ b/src/routes/safe/components/Balances/Tokens/screens/AddCustomToken/index.jsx @@ -1,5 +1,5 @@ // @flow -import React, { Component } from 'react' +import React from 'react' import { withStyles } from '@material-ui/core/styles' import Block from '~/components/layout/Block' import Paragraph from '~/components/layout/Paragraph' @@ -18,83 +18,91 @@ import { import TokenPlaceholder from '~/routes/safe/components/Balances/assets/token_placeholder.svg' import { styles } from './style' -class AddCustomToken extends Component { - handleSubmit = (values) => { - console.log(values) +type Props = { + classes: Object, + onTokenAdd: Function, + setActiveScreen: Function, + onClose: Function, +} + +const AddCustomToken = (props: Props) => { + const { + classes, setActiveScreen, onTokenAdd, onClose, + } = props + + const goBackToTokenList = () => { + setActiveScreen('tokenList') + } + const handleSubmit = (values) => { + onTokenAdd(values) + onClose() } - render() { - const { classes, setActiveScreen } = this.props - const goBackToTokenList = () => { - setActiveScreen('tokenList') - } - - return ( - - - {(submitting: boolean, validating: boolean, ...rest: any) => ( - - - - Add custom token - - - - - - - - - - Display token for all safes - - - - - Token Image - Token image - - - - - - - + return ( + + + {() => ( + + + + Add custom token + + + + + + + + + + Display token for all safes + + + + + Token Image + Token image + - - )} - - - ) - } + + + + + + + + )} + + + ) } const AddCustomTokenComponent = withStyles(styles)(AddCustomToken)