fix all the account related bugs
This commit is contained in:
parent
5127601545
commit
7cca7ace2e
|
@ -529,17 +529,28 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||||
switch (deviceName) {
|
switch (deviceName) {
|
||||||
case 'trezor':
|
case 'trezor':
|
||||||
const keyringController = this.keyringController
|
const keyringController = this.keyringController
|
||||||
|
const oldAccounts = await keyringController.getAccounts()
|
||||||
let keyring = await keyringController.getKeyringsByType(
|
let keyring = await keyringController.getKeyringsByType(
|
||||||
'Trezor Hardware'
|
'Trezor Hardware'
|
||||||
)[0]
|
)[0]
|
||||||
if (!keyring) {
|
if (!keyring) {
|
||||||
keyring = await this.keyringController.addNewKeyring('Trezor Hardware')
|
keyring = await this.keyringController.addNewKeyring('Trezor Hardware')
|
||||||
}
|
}
|
||||||
if (page === 0) {
|
let accounts = []
|
||||||
keyring.page = 0
|
|
||||||
|
switch (page) {
|
||||||
|
case -1:
|
||||||
|
accounts = await keyring.getPreviousPage()
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
accounts = await keyring.getNextPage()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
accounts = await keyring.getFirstPage()
|
||||||
}
|
}
|
||||||
const accounts = page === -1 ? await keyring.getPreviousPage() : await keyring.getNextPage()
|
|
||||||
this.accountTracker.syncWithAddresses(accounts.map(a => a.address))
|
// Merge with existing accounts
|
||||||
|
this.accountTracker.syncWithAddresses(oldAccounts.concat(accounts.map(a => a.address)))
|
||||||
return accounts
|
return accounts
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2,21 +2,12 @@ const { Component } = require('react')
|
||||||
const PropTypes = require('prop-types')
|
const PropTypes = require('prop-types')
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
const genAccountLink = require('../../../../../lib/account-link.js')
|
const genAccountLink = require('../../../../../lib/account-link.js')
|
||||||
const { formatBalance } = require('../../../../util')
|
|
||||||
|
|
||||||
class AccountList extends Component {
|
class AccountList extends Component {
|
||||||
constructor (props, context) {
|
constructor (props, context) {
|
||||||
super(props)
|
super(props)
|
||||||
}
|
}
|
||||||
|
|
||||||
getBalance (address) {
|
|
||||||
// Get the balance
|
|
||||||
const { accounts } = this.props
|
|
||||||
const balanceValue = accounts && accounts[address] ? accounts[address].balance : ''
|
|
||||||
const formattedBalance = balanceValue ? formatBalance(balanceValue, 6) : '...'
|
|
||||||
return formattedBalance
|
|
||||||
}
|
|
||||||
|
|
||||||
renderAccounts () {
|
renderAccounts () {
|
||||||
return h('div.hw-account-list', [
|
return h('div.hw-account-list', [
|
||||||
h('div.hw-account-list__title_wrapper', [
|
h('div.hw-account-list__title_wrapper', [
|
||||||
|
@ -44,7 +35,7 @@ class AccountList extends Component {
|
||||||
`${a.address.slice(0, 4)}...${a.address.slice(-4)}`
|
`${a.address.slice(0, 4)}...${a.address.slice(-4)}`
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
h('span.hw-account-list__item__balance', `${this.getBalance(a.address)}`),
|
h('span.hw-account-list__item__balance', `${a.balance}`),
|
||||||
h(
|
h(
|
||||||
'a.hw-account-list__item__link',
|
'a.hw-account-list__item__link',
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@ const actions = require('../../../../actions')
|
||||||
const ConnectScreen = require('./connect-screen')
|
const ConnectScreen = require('./connect-screen')
|
||||||
const AccountList = require('./account-list')
|
const AccountList = require('./account-list')
|
||||||
const { DEFAULT_ROUTE } = require('../../../../routes')
|
const { DEFAULT_ROUTE } = require('../../../../routes')
|
||||||
|
const { formatBalance } = require('../../../../util')
|
||||||
|
|
||||||
class ConnectHardwareForm extends Component {
|
class ConnectHardwareForm extends Component {
|
||||||
constructor (props, context) {
|
constructor (props, context) {
|
||||||
|
@ -31,20 +32,42 @@ 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) : '...'
|
||||||
|
console.log('[TREZOR]: got balance', address, accounts, balanceValue, formattedBalance)
|
||||||
|
return formattedBalance
|
||||||
|
}
|
||||||
|
|
||||||
getPage = (page) => {
|
getPage = (page) => {
|
||||||
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 = { accounts: accounts }
|
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()
|
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() === '').lenght) {
|
} 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
|
||||||
|
newState.accounts = accounts.map(account => {
|
||||||
|
account.balance = this.getBalance(account.address)
|
||||||
|
return account
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('[TREZOR]: ABOUT TO RENDER ACCOUNTS: ', page, newState.accounts)
|
||||||
this.setState(newState)
|
this.setState(newState)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue