From e51f5c9572736d58da816e4a8ab1fed7fd8c1a66 Mon Sep 17 00:00:00 2001 From: mmv Date: Thu, 23 May 2019 16:27:02 +0400 Subject: [PATCH] fix token pre-population --- package.json | 1 + src/index.js | 6 +++ .../SendFunds/TokenSelectField/index.jsx | 53 +++++++++++-------- src/routes/safe/components/Balances/index.jsx | 4 +- yarn.lock | 19 ++++++- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 7f9296f1..8320cd18 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "@gnosis.pm/util-contracts": "2.0.1", "@material-ui/core": "^3.9.3", "@material-ui/icons": "^3.0.1", + "@welldone-software/why-did-you-render": "^3.0.9", "axios": "^0.18.0", "bignumber.js": "^8.1.1", "connected-react-router": "^6.3.1", diff --git a/src/index.js b/src/index.js index 9b33ff72..1d831f27 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,12 @@ import { store } from '~/store' import loadSafesFromStorage from '~/routes/safe/store/actions/loadSafesFromStorage' import loadActiveTokens from '~/logic/tokens/store/actions/loadActiveTokens' +if (process.env.NODE_ENV !== 'production') { + // eslint-disable-next-line + const whyDidYouRender = require('@welldone-software/why-did-you-render') + whyDidYouRender(React) +} + store.dispatch(loadActiveTokens()) store.dispatch(loadSafesFromStorage()) diff --git a/src/routes/safe/components/Balances/SendModal/screens/SendFunds/TokenSelectField/index.jsx b/src/routes/safe/components/Balances/SendModal/screens/SendFunds/TokenSelectField/index.jsx index fb186476..873df0d0 100644 --- a/src/routes/safe/components/Balances/SendModal/screens/SendFunds/TokenSelectField/index.jsx +++ b/src/routes/safe/components/Balances/SendModal/screens/SendFunds/TokenSelectField/index.jsx @@ -1,5 +1,5 @@ // @flow -import React from 'react' +import React, { useEffect, useState } from 'react' import { List } from 'immutable' import { withStyles } from '@material-ui/core/styles' import MenuItem from '@material-ui/core/MenuItem' @@ -48,25 +48,36 @@ const SelectedToken = ({ token, classes }: SelectedTokenProps) => ( const SelectedTokenStyled = withStyles(selectedTokenStyles)(SelectedToken) -const TokenSelectField = ({ tokens, classes, initialValue }: SelectFieldProps) => ( - } - initialValue={tokens.find(token => token.name === initialValue) || ''} - displayEmpty - > - {tokens.map(token => ( - - - {token.name} - - - - ))} - -) +type InitialTokenType = Token | string + +const TokenSelectField = ({ tokens, classes, initialValue }: SelectFieldProps) => { + const [initialToken, setInitialToken] = useState('') + + useEffect(() => { + const selectedToken = tokens.find(token => token.name === initialValue) + setInitialToken(selectedToken || '') + }, [initialValue]) + + return ( + } + initialValue={initialToken} + displayEmpty + > + {tokens.map(token => ( + + + {token.name} + + + + ))} + + ) +} export default withStyles(selectStyles)(TokenSelectField) diff --git a/src/routes/safe/components/Balances/index.jsx b/src/routes/safe/components/Balances/index.jsx index 1ddfecb7..f89f5289 100644 --- a/src/routes/safe/components/Balances/index.jsx +++ b/src/routes/safe/components/Balances/index.jsx @@ -80,7 +80,7 @@ class Balances extends React.Component { selectedToken: undefined, }, }) - } + } handleChange = (e: SyntheticInputEvent) => { const { checked } = e.target @@ -189,7 +189,7 @@ class Balances extends React.Component { safeName={safeName} ethBalance={ethBalance} tokens={activeTokens} - selectedToken={sendFunds.selectedToken} + selectedToken={sendFunds.selectedToken} /> 4.17.4, "lodash@>=3.5 <5", lodash@^4.0.1, lodash@^4.1.0, lodash@^4.11.2, lodash@^4.15.0, lodash@^4.17.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0: +lodash@4.17.11, lodash@>4.17.4, "lodash@>=3.5 <5", lodash@^4, lodash@^4.0.1, lodash@^4.1.0, lodash@^4.11.2, lodash@^4.15.0, lodash@^4.17.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== @@ -13664,7 +13671,7 @@ react-event-listener@^0.6.2: prop-types "^15.6.0" warning "^4.0.1" -react-fast-compare@^2.0.2: +react-fast-compare@^2.0.2, react-fast-compare@^2.0.3: version "2.0.4" resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9" integrity sha512-suNP+J1VU1MWFKcyt7RtjiSWUjvidmQSlqu+eHslq+342xCbGTYmC0mEhPCOHxlW0CywylOC1u2DFAT+bv4dBw== @@ -18364,6 +18371,14 @@ which@^1.2.14, which@^1.2.9, which@^1.3.0, which@^1.3.1: dependencies: isexe "^2.0.0" +why-did-you-update@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/why-did-you-update/-/why-did-you-update-1.0.6.tgz#2e2c6a04291e715755ecdff1ac8272f721df6f04" + integrity sha512-XVrdHhdrPBDuSW8b/uH6DCb1/0984qv8KElpE8NZiRvWZX8nw49av577+ZyIrxSNesi6r2cQEhpxQTKFFHTj8A== + dependencies: + lodash "^4.17.11" + react-fast-compare "^2.0.3" + wide-align@^1.1.0: version "1.1.3" resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457"