From 5d49bb946e0b74219fda0f968b0afb63b4566327 Mon Sep 17 00:00:00 2001 From: apanizo Date: Wed, 18 Jul 2018 10:05:44 +0200 Subject: [PATCH] WA-232 Add custom token logic --- .../tokens/component/AddToken/FirstPage.jsx | 4 +- .../tokens/component/AddToken/SecondPage.jsx | 16 +++---- .../tokens/component/AddToken/index.jsx | 43 +++++++++++++------ src/routes/tokens/component/Layout.jsx | 9 ++-- src/routes/tokens/container/actions.js | 3 ++ src/routes/tokens/container/index.jsx | 3 +- 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/src/routes/tokens/component/AddToken/FirstPage.jsx b/src/routes/tokens/component/AddToken/FirstPage.jsx index 8d191de8..d2f4697a 100644 --- a/src/routes/tokens/component/AddToken/FirstPage.jsx +++ b/src/routes/tokens/component/AddToken/FirstPage.jsx @@ -10,7 +10,7 @@ type Props = { addresses: string[], } -export const TOKEN_PARAM = 'tokenAddress' +export const TOKEN_ADRESS_PARAM = 'tokenAddress' const FirstPage = ({ addresses }: Props) => () => ( @@ -19,7 +19,7 @@ const FirstPage = ({ addresses }: Props) => () => ( () => ( @@ -18,7 +18,7 @@ const SecondPage = () => () => ( () => ( () => ( () => ( [ 'Fill Add Token Form', 'Check optional attributes', 'Review Information', @@ -14,6 +15,7 @@ export const getSteps = () => [ type Props = { tokens: string[], safeAddress: string, + addToken: typeof addTokenAction } type State = { @@ -22,7 +24,25 @@ type State = { export const ADD_TOKEN_RESET_BUTTON_TEXT = 'RESET' -export const addToken = async (values: Object) => Promise.reject(values) +export const addTokenFnc = async (values: Object, addToken, safeAddress: string) => { + const address = values[TOKEN_ADDRESS_PARAM] + const name = values[TOKEN_NAME_PARAM] + const symbol = values[TOKEN_SYMBOL_PARAM] + const decimals = values[TOKEN_DECIMALS_PARAM] + const logo = values[TOKEN_LOGO_URL_PARAM] + + const token: Token = makeToken({ + address, + name, + symbol, + decimals: Number(decimals), + logoUrl: logo, + status: true, + removable: true, + }) + + return addToken(safeAddress, token) +} class AddToken extends React.Component { state = { @@ -30,10 +50,9 @@ class AddToken extends React.Component { } onAddToken = async (values: Object) => { - // eslint-disable-next-line - console.log("onAddToken...") - // eslint-disable-next-line - console.log(values) + const { addToken, safeAddress } = this.props + + return addTokenFnc(values, addToken, safeAddress) } onReset = () => { @@ -41,7 +60,7 @@ class AddToken extends React.Component { } fetchInitialPropsSecondPage = async (values: Object) => { - const tokenAddress = values[TOKEN_PARAM] + const tokenAddress = values[TOKEN_ADDRESS_PARAM] const erc20Token = await getHumanFriendlyToken() const instance = await erc20Token.at(tokenAddress) @@ -50,9 +69,9 @@ class AddToken extends React.Component { const decimals = await instance.decimals() return ({ - [SYMBOL_PARAM]: symbol, - [DECIMALS_PARAM]: `${decimals}`, - [NAME_PARAM]: name, + [TOKEN_SYMBOL_PARAM]: symbol, + [TOKEN_DECIMALS_PARAM]: `${decimals}`, + [TOKEN_NAME_PARAM]: name, }) } diff --git a/src/routes/tokens/component/Layout.jsx b/src/routes/tokens/component/Layout.jsx index 42ad5cda..71bddea8 100644 --- a/src/routes/tokens/component/Layout.jsx +++ b/src/routes/tokens/component/Layout.jsx @@ -37,9 +37,12 @@ class TokenLayout extends React.PureComponent { component: undefined, } - onAddToken = () => () => { - const { addresses, safeAddress } = this.props - this.setState({ component: }) + onAddToken = () => { + const { addresses, safeAddress, addToken } = this.props + + this.setState({ + component: , + }) } /* diff --git a/src/routes/tokens/container/actions.js b/src/routes/tokens/container/actions.js index d59f86bc..bc886ee9 100644 --- a/src/routes/tokens/container/actions.js +++ b/src/routes/tokens/container/actions.js @@ -1,4 +1,5 @@ // @flow +import addToken from '~/routes/tokens/store/actions/addTokens' import enableToken from '~/routes/tokens/store/actions/enableToken' import disableToken from '~/routes/tokens/store/actions/disableToken' import { fetchTokens } from '~/routes/tokens/store/actions/fetchTokens' @@ -6,9 +7,11 @@ import { fetchTokens } from '~/routes/tokens/store/actions/fetchTokens' export type Actions = { enableToken: typeof enableToken, disableToken: typeof disableToken, + addToken: typeof addToken, } export default { + addToken, enableToken, disableToken, fetchTokens, diff --git a/src/routes/tokens/container/index.jsx b/src/routes/tokens/container/index.jsx index 8a83a93e..9b369c83 100644 --- a/src/routes/tokens/container/index.jsx +++ b/src/routes/tokens/container/index.jsx @@ -22,7 +22,7 @@ class TokensView extends React.PureComponent { render() { const { - tokens, addresses, safe, safeAddress, disableToken, enableToken, + tokens, addresses, safe, safeAddress, disableToken, enableToken, addToken, } = this.props return ( @@ -34,6 +34,7 @@ class TokensView extends React.PureComponent { safeAddress={safeAddress} disableToken={disableToken} enableToken={enableToken} + addToken={addToken} /> )