1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

fix account duplication

This commit is contained in:
brunobar79 2018-07-09 17:55:37 -04:00
parent 7cca7ace2e
commit 2de3039b6b
2 changed files with 3 additions and 7 deletions

View File

@ -550,7 +550,9 @@ module.exports = class MetamaskController extends EventEmitter {
}
// Merge with existing accounts
this.accountTracker.syncWithAddresses(oldAccounts.concat(accounts.map(a => a.address)))
// and make sure addresses are not repeated
const accountsToTrack = [...new Set(oldAccounts.concat(accounts.map(a => a.address.toLowerCase())))]
this.accountTracker.syncWithAddresses(accountsToTrack)
return accounts
default:

View File

@ -37,7 +37,6 @@ class ConnectHardwareForm extends Component {
const { accounts } = this.props
const balanceValue = accounts && accounts[address.toLowerCase()] ? accounts[address.toLowerCase()].balance : ''
const formattedBalance = balanceValue !== null ? formatBalance(balanceValue, 6) : '...'
console.log('[TREZOR]: got balance', address, accounts, balanceValue, formattedBalance)
return formattedBalance
}
@ -45,21 +44,17 @@ class ConnectHardwareForm extends Component {
this.props
.connectHardware('trezor', page)
.then(accounts => {
console.log('[TREZOR]: GOT PAGE!', accounts)
if (accounts.length) {
const newState = {}
// Default to the first account
if (this.state.selectedAccount === null) {
const firstAccount = accounts[0]
newState.selectedAccount = firstAccount.index.toString() === '0' ? firstAccount.index.toString() : null
console.log('[TREZOR]: just defaulted to account', newState.selectedAccount)
// If the page doesn't contain the selected account, let's deselect it
} else if (!accounts.filter(a => a.index.toString() === this.state.selectedAccount).length) {
newState.selectedAccount = null
console.log('[TREZOR]: just removed default account', newState.selectedAccount)
}
console.log('[TREZOR]: mapping balances')
// Map accounts with balances
newState.accounts = accounts.map(account => {
@ -67,7 +62,6 @@ class ConnectHardwareForm extends Component {
return account
})
console.log('[TREZOR]: ABOUT TO RENDER ACCOUNTS: ', page, newState.accounts)
this.setState(newState)
}
})