From 3afefea0a73e84018b5ecd4a0f033f3280f9faa9 Mon Sep 17 00:00:00 2001 From: apanizo Date: Tue, 10 Jul 2018 16:48:20 +0200 Subject: [PATCH] WA-232 Displaying safe's token in settings route --- src/routes/index.js | 9 ++++ .../safe/component/Safe/BalanceInfo.jsx | 12 ++++- src/routes/safe/component/Safe/index.jsx | 5 ++- src/routes/safe/component/SendToken/index.jsx | 3 +- src/routes/tokens/component/Layout.jsx | 4 +- src/routes/tokens/component/Token/index.jsx | 44 +++++++------------ src/routes/tokens/container/actions.js | 2 + src/routes/tokens/container/index.jsx | 14 +++++- src/routes/tokens/container/selector.js | 3 +- src/utils/tokens.js | 2 + 10 files changed, 63 insertions(+), 35 deletions(-) create mode 100644 src/utils/tokens.js diff --git a/src/routes/index.js b/src/routes/index.js index 4bc05bb0..109198db 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -11,6 +11,11 @@ const Safe = Loadable({ loading: Loader, }) +const Settings = Loadable({ + loader: () => import('./tokens/container'), + loading: Loader, +}) + const SafeList = Loadable({ loader: () => import('./safeList/container'), loading: Loader, @@ -22,6 +27,9 @@ const Open = Loadable({ }) const SAFE_ADDRESS = `${SAFELIST_ADDRESS}/:${SAFE_PARAM_ADDRESS}` +const SAFE_SETTINGS = `${SAFE_ADDRESS}/settings` + +export const settingsUrlFrom = (safeAddress: string) => `${SAFELIST_ADDRESS}/${safeAddress}/settings` const Routes = () => ( @@ -30,6 +38,7 @@ const Routes = () => ( + ) diff --git a/src/routes/safe/component/Safe/BalanceInfo.jsx b/src/routes/safe/component/Safe/BalanceInfo.jsx index 7f4c04f4..98110ed1 100644 --- a/src/routes/safe/component/Safe/BalanceInfo.jsx +++ b/src/routes/safe/component/Safe/BalanceInfo.jsx @@ -1,7 +1,9 @@ // @flow import * as React from 'react' import classNames from 'classnames' +import Link from '~/components/layout/Link' import AccountBalance from '@material-ui/icons/AccountBalance' +import Settings from '@material-ui/icons/Settings' import Avatar from '@material-ui/core/Avatar' import Collapse from '@material-ui/core/Collapse' import IconButton from '@material-ui/core/IconButton' @@ -18,8 +20,10 @@ import Button from '~/components/layout/Button' import openHoc, { type Open } from '~/components/hoc/OpenHoc' import { type WithStyles } from '~/theme/mui' import { type Token } from '~/routes/tokens/store/model/token' +import { settingsUrlFrom } from '~/routes' type Props = Open & WithStyles & { + safeAddress: string, tokens: Map, onMoveFunds: (token: Token) => void, } @@ -33,9 +37,10 @@ const styles = { export const MOVE_FUNDS_BUTTON_TEXT = 'Move' const BalanceComponent = openHoc(({ - open, toggle, tokens, classes, onMoveFunds, + open, toggle, tokens, classes, onMoveFunds, safeAddress, }: Props) => { const hasBalances = tokens.count() > 0 + const settingsUrl = settingsUrlFrom(safeAddress) return ( @@ -44,6 +49,11 @@ const BalanceComponent = openHoc(({ + + + + + {open ? diff --git a/src/routes/safe/component/Safe/index.jsx b/src/routes/safe/component/Safe/index.jsx index bc800860..666cceb7 100644 --- a/src/routes/safe/component/Safe/index.jsx +++ b/src/routes/safe/component/Safe/index.jsx @@ -110,12 +110,13 @@ class GnoSafe extends React.PureComponent { const { safe, tokens, userAddress } = this.props const { component } = this.state const ethBalance = getEthBalanceFrom(tokens) + const address = safe.get('address') return ( - + { onRemoveOwner={this.onRemoveOwner} /> -
+
diff --git a/src/routes/safe/component/SendToken/index.jsx b/src/routes/safe/component/SendToken/index.jsx index 84d2f999..0258f977 100644 --- a/src/routes/safe/component/SendToken/index.jsx +++ b/src/routes/safe/component/SendToken/index.jsx @@ -10,6 +10,7 @@ import { type Token } from '~/routes/tokens/store/model/token' import { createTransaction } from '~/wallets/createTransactions' import { EMPTY_DATA } from '~/wallets/ethTransactions' import { toNative } from '~/wallets/tokens' +import { isEther } from '~/utils/tokens' import actions, { type Actions } from './actions' import selector, { type SelectorProps } from './selector' import SendTokenForm, { TKN_DESTINATION_PARAM, TKN_VALUE_PARAM } from './SendTokenForm' @@ -31,8 +32,6 @@ type State = { export const SEE_TXS_BUTTON_TEXT = 'VISIT TXS' -const isEther = (symbol: string) => symbol === 'ETH' - const getTransferData = async (tokenAddress: string, to: string, amount: BigNumber) => { const StandardToken = await getStandardTokenContract() const myToken = await StandardToken.at(tokenAddress) diff --git a/src/routes/tokens/component/Layout.jsx b/src/routes/tokens/component/Layout.jsx index 90b461be..69c04d48 100644 --- a/src/routes/tokens/component/Layout.jsx +++ b/src/routes/tokens/component/Layout.jsx @@ -1,5 +1,5 @@ // @flow -import * as MuiList from '@material-ui/core/List' +import MuiList from '@material-ui/core/List' import * as React from 'react' import Block from '~/components/layout/Block' import Col from '~/components/layout/Col' @@ -24,6 +24,7 @@ type State = { const listStyle = { width: '100%', + paddingBottom: 0, } class TokenLayout extends React.PureComponent { @@ -64,6 +65,7 @@ class TokenLayout extends React.PureComponent { {tokens.map((token: Token) => ( ({ +const styles = () => ({ card: { display: 'flex', }, @@ -36,18 +36,9 @@ const styles = theme => ({ flex: '1 0 auto', }, cover: { - width: 45, - height: 45, - }, - controls: { - display: 'flex', - alignItems: 'center', - paddingLeft: theme.spacing.unit, - paddingBottom: theme.spacing.unit, - }, - playIcon: { - height: 38, - width: 38, + width: 150, + margin: 10, + backgroundSize: '50%', }, }) @@ -60,14 +51,15 @@ class TokenComponent extends React.Component { handleChange = (e: SyntheticInputEvent) => { const { checked } = e.target - const callback = checked ? this.props.onDisableToken : this.props.onDisableToken - this.setState(() => ({ checked: e.target.checked }), () => callback(this.props.token)) + const callback = checked ? this.props.onEnableToken : this.props.onDisableToken + this.setState(() => ({ checked }), () => callback(this.props.token)) } render() { const { classes, token } = this.props const name = token.get('name') const symbol = token.get('symbol') + const disabled = isEther(symbol) return ( @@ -75,25 +67,23 @@ class TokenComponent extends React.Component { {name} + {symbol} + + {/* - - {symbol} - - - {/* - */} - + */} { + componentDidUpdate() { + const { safeAddress } = this.props + + if (this.props.tokens.count() === 0) { + this.props.fetchTokens(safeAddress) + } + } + render() { const { tokens, addresses, safe, disableToken, enableToken, diff --git a/src/routes/tokens/container/selector.js b/src/routes/tokens/container/selector.js index aac3a947..de805afc 100644 --- a/src/routes/tokens/container/selector.js +++ b/src/routes/tokens/container/selector.js @@ -3,7 +3,7 @@ import { List } from 'immutable' import { createStructuredSelector } from 'reselect' import { tokenListSelector, tokenAddressesSelector } from '~/routes/tokens/store/selectors' import { type Safe } from '~/routes/safe/store/model/safe' -import { safeSelector } from '~/routes/safe/store/selectors' +import { safeSelector, safeParamAddressSelector } from '~/routes/safe/store/selectors' import { type Token } from '~/routes/tokens/store/model/token' export type SelectorProps = { @@ -14,6 +14,7 @@ export type SelectorProps = { export default createStructuredSelector({ safe: safeSelector, + safeAddress: safeParamAddressSelector, tokens: tokenListSelector, addresses: tokenAddressesSelector, }) diff --git a/src/utils/tokens.js b/src/utils/tokens.js new file mode 100644 index 00000000..16d5c169 --- /dev/null +++ b/src/utils/tokens.js @@ -0,0 +1,2 @@ +// @flow +export const isEther = (symbol: string) => symbol === 'ETH'