mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
fix account duplication
This commit is contained in:
parent
7cca7ace2e
commit
2de3039b6b
@ -550,7 +550,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge with existing accounts
|
// 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
|
return accounts
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -37,7 +37,6 @@ class ConnectHardwareForm extends Component {
|
|||||||
const { accounts } = this.props
|
const { accounts } = this.props
|
||||||
const balanceValue = accounts && accounts[address.toLowerCase()] ? accounts[address.toLowerCase()].balance : ''
|
const balanceValue = accounts && accounts[address.toLowerCase()] ? accounts[address.toLowerCase()].balance : ''
|
||||||
const formattedBalance = balanceValue !== null ? formatBalance(balanceValue, 6) : '...'
|
const formattedBalance = balanceValue !== null ? formatBalance(balanceValue, 6) : '...'
|
||||||
console.log('[TREZOR]: got balance', address, accounts, balanceValue, formattedBalance)
|
|
||||||
return formattedBalance
|
return formattedBalance
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,21 +44,17 @@ class ConnectHardwareForm extends Component {
|
|||||||
this.props
|
this.props
|
||||||
.connectHardware('trezor', page)
|
.connectHardware('trezor', page)
|
||||||
.then(accounts => {
|
.then(accounts => {
|
||||||
console.log('[TREZOR]: GOT PAGE!', accounts)
|
|
||||||
if (accounts.length) {
|
if (accounts.length) {
|
||||||
const newState = {}
|
const newState = {}
|
||||||
// Default to the first account
|
// Default to the first account
|
||||||
if (this.state.selectedAccount === null) {
|
if (this.state.selectedAccount === null) {
|
||||||
const firstAccount = accounts[0]
|
const firstAccount = accounts[0]
|
||||||
newState.selectedAccount = firstAccount.index.toString() === '0' ? firstAccount.index.toString() : null
|
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
|
// 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) {
|
} else if (!accounts.filter(a => a.index.toString() === this.state.selectedAccount).length) {
|
||||||
newState.selectedAccount = null
|
newState.selectedAccount = null
|
||||||
console.log('[TREZOR]: just removed default account', newState.selectedAccount)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[TREZOR]: mapping balances')
|
|
||||||
|
|
||||||
// Map accounts with balances
|
// Map accounts with balances
|
||||||
newState.accounts = accounts.map(account => {
|
newState.accounts = accounts.map(account => {
|
||||||
@ -67,7 +62,6 @@ class ConnectHardwareForm extends Component {
|
|||||||
return account
|
return account
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('[TREZOR]: ABOUT TO RENDER ACCOUNTS: ', page, newState.accounts)
|
|
||||||
this.setState(newState)
|
this.setState(newState)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user