fix account balance bug

feature/default_network_editable
brunobar79 6 years ago
parent 5710e648bd
commit 289795fb12
  1. 2
      ui/app/components/modals/index.scss
  2. 24
      ui/app/components/pages/create-account/connect-hardware/index.js

@ -53,7 +53,7 @@
} }
&__link { &__link {
margin-top: 16px; margin-top: 14px;
img { img {
width: 15px; width: 15px;

@ -19,6 +19,18 @@ class ConnectHardwareForm extends Component {
} }
} }
componentWillReceiveProps (nextProps) {
const { accounts } = nextProps
const newAccounts = this.state.accounts.map(a => {
const normalizedAddress = a.address.toLowerCase()
const balanceValue = accounts[normalizedAddress] && accounts[normalizedAddress].balance || null
a.balance = balanceValue ? formatBalance(balanceValue, 6) : '...'
return a
})
this.setState({accounts: newAccounts})
}
async componentDidMount () { async componentDidMount () {
const unlocked = await this.props.checkHardwareStatus('trezor') const unlocked = await this.props.checkHardwareStatus('trezor')
if (unlocked) { if (unlocked) {
@ -38,14 +50,6 @@ class ConnectHardwareForm extends Component {
this.setState({selectedAccount: account.toString(), error: null}) this.setState({selectedAccount: account.toString(), error: null})
} }
getBalance (address) {
// Get the balance
const { accounts } = this.props
const balanceValue = accounts && accounts[address.toLowerCase()] ? accounts[address.toLowerCase()].balance : ''
const formattedBalance = balanceValue !== null ? formatBalance(balanceValue, 6) : '...'
return formattedBalance
}
getPage = (page) => { getPage = (page) => {
this.props this.props
.connectHardware('trezor', page) .connectHardware('trezor', page)
@ -64,7 +68,9 @@ class ConnectHardwareForm extends Component {
// Map accounts with balances // Map accounts with balances
newState.accounts = accounts.map(account => { newState.accounts = accounts.map(account => {
account.balance = this.getBalance(account.address) const normalizedAddress = account.address.toLowerCase()
const balanceValue = this.props.accounts[normalizedAddress] && this.props.accounts[normalizedAddress].balance || null
account.balance = balanceValue ? formatBalance(balanceValue, 6) : '...'
return account return account
}) })

Loading…
Cancel
Save