1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

balances working

This commit is contained in:
Bruno 2018-06-10 21:10:22 -04:00
parent f6b27fa9eb
commit d1880073f6
3 changed files with 22 additions and 6 deletions

View File

@ -8,7 +8,7 @@ const keyringType = 'Trezor Hardware'
const TrezorConnect = require('./trezor-connect.js')
const HDKey = require('hdkey')
const TREZOR_FIRMWARE_VERSION = '1.4.0'
//const log = require('loglevel')
const log = require('loglevel')
class TrezorKeyring extends EventEmitter {
constructor (opts = {}) {
@ -111,6 +111,7 @@ class TrezorKeyring extends EventEmitter {
index: i,
})
}
log.debug(accounts)
resolve(accounts)
})
.catch(e => {

View File

@ -549,10 +549,10 @@ module.exports = class MetamaskController extends EventEmitter {
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
}
const accounts = page === -1 ? await keyring.getPrevAccountSet() : await keyring.getNextAccountSet()
const accounts = page === -1 ? await keyring.getPrevAccountSet(this.provider) : await keyring.getNextAccountSet(this.provider)
this.accountTracker.syncWithAddresses(accounts.map(a => a.address))
return accounts
}
/**
@ -570,7 +570,6 @@ module.exports = class MetamaskController extends EventEmitter {
}
keyring.setAccountToUnlock(index)
const oldAccounts = await keyringController.getAccounts()
const keyState = await keyringController.addNewAccount(keyring)
const newAccounts = await keyringController.getAccounts()

View File

@ -6,6 +6,7 @@ const actions = require('../../../actions')
const genAccountLink = require('../../../../lib/account-link.js')
const log = require('loglevel')
const { DEFAULT_ROUTE } = require('../../../routes')
const { formatBalance } = require('../../../util')
class ConnectHardwareForm extends Component {
constructor (props, context) {
@ -57,10 +58,22 @@ class ConnectHardwareForm extends Component {
})
}
getBalance (address) {
// Get the balance
log.debug('getBalance : ', address)
const { accounts } = this.props
const balanceValue = accounts && accounts[address] ? accounts[address].balance : ''
log.debug('balanceValue : ', balanceValue)
const formattedBalance = balanceValue ? formatBalance(balanceValue, 6) : '...'
log.debug('formattedBalance : ', formattedBalance)
return formattedBalance
}
renderAccounts () {
if (!this.state.accounts.length) {
return null
}
log.debug('ACCOUNTS : ', this.state.accounts)
log.debug('SELECTED?', this.state.selectedAccount)
@ -70,6 +83,7 @@ class ConnectHardwareForm extends Component {
h('div.hw-account-list__device', {}, ['Trezor - ETH']),
]),
this.state.accounts.map((a, i) => {
return h('div.hw-account-list__item', { key: a.address }, [
h('span.hw-account-list__item__index', a.index + 1),
h('div.hw-account-list__item__radio', [
@ -88,7 +102,7 @@ class ConnectHardwareForm extends Component {
`${a.address.slice(0, 4)}...${a.address.slice(-4)}`
),
]),
h('span.hw-account-list__item__balance', `${a.balance} ETH`),
h('span.hw-account-list__item__balance', `${this.getBalance(a.address)}`),
h(
'a.hw-account-list__item__link',
{
@ -194,16 +208,18 @@ ConnectHardwareForm.propTypes = {
history: PropTypes.object,
t: PropTypes.func,
network: PropTypes.string,
accounts: PropTypes.object,
}
const mapStateToProps = state => {
const {
metamask: { network, selectedAddress, identities = {} },
metamask: { network, selectedAddress, identities = {}, accounts = [] },
} = state
const numberOfExistingAccounts = Object.keys(identities).length
return {
network,
accounts,
address: selectedAddress,
numberOfExistingAccounts,
}