1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00

fix account balance bug

This commit is contained in:
brunobar79 2018-07-13 00:09:42 -04:00
parent 5710e648bd
commit 289795fb12
2 changed files with 16 additions and 10 deletions

View File

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

View File

@ -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 () {
const unlocked = await this.props.checkHardwareStatus('trezor')
if (unlocked) {
@ -38,14 +50,6 @@ class ConnectHardwareForm extends Component {
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) => {
this.props
.connectHardware('trezor', page)
@ -64,7 +68,9 @@ class ConnectHardwareForm extends Component {
// Map accounts with balances
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
})