From cc1cd84c1f809ce1a87b3504ee02ed0badd68150 Mon Sep 17 00:00:00 2001 From: apanizo Date: Fri, 29 Jun 2018 13:24:17 +0200 Subject: [PATCH] WA-232 Adding dummy token list to safe view --- src/routes/safe/component/Layout.jsx | 4 +- src/routes/safe/component/Layout.stories.js | 19 +++++-- src/routes/safe/component/Safe/Balance.jsx | 21 -------- .../safe/component/Safe/BalanceInfo.jsx | 49 +++++++++++++++++++ src/routes/safe/component/Safe/DailyLimit.jsx | 4 +- src/routes/safe/component/Safe/MultisigTx.jsx | 4 +- src/routes/safe/component/Safe/index.jsx | 32 ++++++++---- src/routes/safe/container/index.jsx | 4 +- src/routes/safe/container/selector.js | 3 +- 9 files changed, 96 insertions(+), 44 deletions(-) delete mode 100644 src/routes/safe/component/Safe/Balance.jsx create mode 100644 src/routes/safe/component/Safe/BalanceInfo.jsx diff --git a/src/routes/safe/component/Layout.jsx b/src/routes/safe/component/Layout.jsx index d818ec84..4ae7803f 100644 --- a/src/routes/safe/component/Layout.jsx +++ b/src/routes/safe/component/Layout.jsx @@ -7,11 +7,11 @@ import GnoSafe from './Safe' type Props = SelectorProps const Layout = ({ - safe, balance, provider, userAddress, + safe, balances, provider, userAddress, }: Props) => ( { safe - ? + ? : } diff --git a/src/routes/safe/component/Layout.stories.js b/src/routes/safe/component/Layout.stories.js index 97ec777a..0c1cb5e9 100644 --- a/src/routes/safe/component/Layout.stories.js +++ b/src/routes/safe/component/Layout.stories.js @@ -1,8 +1,10 @@ // @flow import { storiesOf } from '@storybook/react' import * as React from 'react' +import { Map } from 'immutable' import styles from '~/components/layout/PageFrame/index.scss' import { SafeFactory } from '~/routes/safe/store/test/builder/safe.builder' +import { makeBalance } from '~/routes/safe/store/model/balance' import Component from './Layout' @@ -12,6 +14,15 @@ const FrameDecorator = story => ( ) +const ethBalance = makeBalance({ + address: '0', + name: 'Ether', + symbol: 'ETH', + decimals: 18, + logoUrl: 'assets/icons/icon_etherTokens.svg', + funds: '2', +}) + storiesOf('Routes /safe:address', module) .addDecorator(FrameDecorator) .add('Safe undefined being connected', () => ( @@ -19,7 +30,7 @@ storiesOf('Routes /safe:address', module) userAddress="foo" safe={undefined} provider="METAMASK" - balance="0" + balances={Map()} fetchBalance={() => {}} /> )) @@ -28,7 +39,7 @@ storiesOf('Routes /safe:address', module) userAddress="foo" safe={undefined} provider="" - balance="0" + balances={Map()} fetchBalance={() => {}} /> )) @@ -40,7 +51,7 @@ storiesOf('Routes /safe:address', module) userAddress="foo" safe={safe} provider="METAMASK" - balance="2" + balances={Map().set('ETH', ethBalance)} fetchBalance={() => {}} /> ) @@ -53,7 +64,7 @@ storiesOf('Routes /safe:address', module) userAddress="foo" safe={safe} provider="METAMASK" - balance="2" + balances={Map().set('ETH', ethBalance)} fetchBalance={() => {}} /> ) diff --git a/src/routes/safe/component/Safe/Balance.jsx b/src/routes/safe/component/Safe/Balance.jsx deleted file mode 100644 index da301688..00000000 --- a/src/routes/safe/component/Safe/Balance.jsx +++ /dev/null @@ -1,21 +0,0 @@ -// @flow -import * as React from 'react' -import ListItem from '@material-ui/core/ListItem' -import ListItemText from '@material-ui/core/ListItemText' -import Avatar from '@material-ui/core/Avatar' -import AccountBalance from '@material-ui/icons/AccountBalance' - -type Props = { - balance: string, -} - -const Balance = ({ balance }: Props) => ( - - - - - - -) - -export default Balance diff --git a/src/routes/safe/component/Safe/BalanceInfo.jsx b/src/routes/safe/component/Safe/BalanceInfo.jsx new file mode 100644 index 00000000..6cd1d4b7 --- /dev/null +++ b/src/routes/safe/component/Safe/BalanceInfo.jsx @@ -0,0 +1,49 @@ +// @flow +import * as React from 'react' +import AccountBalance from '@material-ui/icons/AccountBalance' +import Avatar from '@material-ui/core/Avatar' +import Collapse from '@material-ui/core/Collapse' +import IconButton from '@material-ui/core/IconButton' +import List from '@material-ui/core/List' +import ListItem from '@material-ui/core/ListItem' +import ListItemIcon from '@material-ui/core/ListItemIcon' +import ListItemText from '@material-ui/core/ListItemText' +import ExpandLess from '@material-ui/icons/ExpandLess' +import ExpandMore from '@material-ui/icons/ExpandMore' +import { Map } from 'immutable' +import openHoc, { type Open } from '~/components/hoc/OpenHoc' +import { type Balance } from '~/routes/safe/store/model/balance' + +type Props = Open & { + balances: Map, +} + +const BalanceComponent = ({ open, toggle, balances }: Props) => ( + + + + + + + + {open + ? + : + } + + + + + {balances.valueSeq().map((balance: Balance) => { + const symbol = balance.get('symbol') + + return ( +
{symbol}
+ ) + })} +
+
+
+) + +export default openHoc(BalanceComponent) diff --git a/src/routes/safe/component/Safe/DailyLimit.jsx b/src/routes/safe/component/Safe/DailyLimit.jsx index fca2616e..53fdae2e 100644 --- a/src/routes/safe/component/Safe/DailyLimit.jsx +++ b/src/routes/safe/component/Safe/DailyLimit.jsx @@ -11,7 +11,7 @@ type Props = { dailyLimit: DailyLimit, onWithdraw: () => void, onEditDailyLimit: () => void, - balance: string, + balance: number, } export const EDIT_WITHDRAW = 'Edit' export const WITHDRAW_BUTTON_TEXT = 'Withdraw' @@ -26,7 +26,7 @@ const DailyLimitComponent = ({ const limit = dailyLimit.get('value') const spentToday = dailyLimit.get('spentToday') - const disabled = spentToday >= limit || Number(balance) === 0 + const disabled = spentToday >= limit || balance === 0 const text = `${limit} ETH (spent today: ${spentToday} ETH)` return ( diff --git a/src/routes/safe/component/Safe/MultisigTx.jsx b/src/routes/safe/component/Safe/MultisigTx.jsx index e41973d0..e2d62367 100644 --- a/src/routes/safe/component/Safe/MultisigTx.jsx +++ b/src/routes/safe/component/Safe/MultisigTx.jsx @@ -7,7 +7,7 @@ import Button from '~/components/layout/Button' import ListItemText from '~/components/List/ListItemText' type Props = { - balance: string, + balance: number, onAddTx: () => void, onSeeTxs: () => void, } @@ -21,7 +21,7 @@ const addStyle = { const DailyLimitComponent = ({ balance, onAddTx, onSeeTxs }: Props) => { const text = `Available ${balance} ETH` - const disabled = Number(balance) <= 0 + const disabled = balance <= 0 return ( diff --git a/src/routes/safe/component/Safe/index.jsx b/src/routes/safe/component/Safe/index.jsx index 6ab1fe5d..d0d5a2ac 100644 --- a/src/routes/safe/component/Safe/index.jsx +++ b/src/routes/safe/component/Safe/index.jsx @@ -1,5 +1,7 @@ // @flow +import List from '@material-ui/core/List' import * as React from 'react' +import { Map } from 'immutable' import Block from '~/components/layout/Block' import Col from '~/components/layout/Col' import Bold from '~/components/layout/Bold' @@ -7,7 +9,7 @@ import Img from '~/components/layout/Img' import Paragraph from '~/components/layout/Paragraph' import Row from '~/components/layout/Row' import { type Safe } from '~/routes/safe/store/model/safe' -import List from '@material-ui/core/List' +import { type Balance } from '~/routes/safe/store/model/balance' import Withdraw from '~/routes/safe/component/Withdraw' import Transactions from '~/routes/safe/component/Transactions' @@ -18,7 +20,7 @@ import RemoveOwner from '~/routes/safe/component/RemoveOwner' import EditDailyLimit from '~/routes/safe/component/EditDailyLimit' import Address from './Address' -import Balance from './Balance' +import BalanceInfo from './BalanceInfo' import Owners from './Owners' import Confirmations from './Confirmations' import DailyLimit from './DailyLimit' @@ -28,7 +30,7 @@ const safeIcon = require('./assets/gnosis_safe.svg') type SafeProps = { safe: Safe, - balance: string, + balances: Map, userAddress: string, } @@ -40,6 +42,15 @@ const listStyle = { width: '100%', } +const getEthBalanceFrom = (balances: Map) => { + const ethBalance = balances.get('ETH') + if (!ethBalance) { + return 0 + } + + return Number(ethBalance.get('funds')) +} + class GnoSafe extends React.PureComponent { state = { component: undefined, @@ -59,9 +70,11 @@ class GnoSafe extends React.PureComponent { } onAddTx = () => { - const { balance, safe } = this.props + const { balances, safe } = this.props + const ethBalance = getEthBalanceFrom(balances) + this.setState({ - component: , + component: , }) } @@ -90,14 +103,15 @@ class GnoSafe extends React.PureComponent { } render() { - const { safe, balance, userAddress } = this.props + const { safe, balances, userAddress } = this.props const { component } = this.state + const ethBalance = getEthBalanceFrom(balances) return ( - + { />
- - + + diff --git a/src/routes/safe/container/index.jsx b/src/routes/safe/container/index.jsx index 607cc5ed..f92184c9 100644 --- a/src/routes/safe/container/index.jsx +++ b/src/routes/safe/container/index.jsx @@ -45,13 +45,11 @@ class SafeView extends React.PureComponent { const { safe, provider, balances, granted, userAddress, } = this.props - const ethBalance = balances.get('ETH') - const balance = ethBalance ? ethBalance.get('funds') : '0' return ( { granted - ? + ? : } diff --git a/src/routes/safe/container/selector.js b/src/routes/safe/container/selector.js index 88ca76f5..45410f57 100644 --- a/src/routes/safe/container/selector.js +++ b/src/routes/safe/container/selector.js @@ -1,5 +1,5 @@ // @flow -import { List } from 'immutable' +import { List, Map } from 'immutable' import { createSelector, createStructuredSelector, type Selector } from 'reselect' import { balanceSelector, safeSelector, type RouterProps, type SafeSelectorProps } from '~/routes/safe/store/selectors' import { providerNameSelector, userAccountSelector } from '~/wallets/store/selectors/index' @@ -7,6 +7,7 @@ import { type Safe } from '~/routes/safe/store/model/safe' import { type Owner } from '~/routes/safe/store/model/owner' import { type GlobalState } from '~/store/index' import { sameAddress } from '~/wallets/ethAddresses' +import { type Balance } from '~/routes/safe/store/model/balance' export type SelectorProps = { safe: SafeSelectorProps,