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:
parent
f6b27fa9eb
commit
d1880073f6
@ -8,7 +8,7 @@ const keyringType = 'Trezor Hardware'
|
|||||||
const TrezorConnect = require('./trezor-connect.js')
|
const TrezorConnect = require('./trezor-connect.js')
|
||||||
const HDKey = require('hdkey')
|
const HDKey = require('hdkey')
|
||||||
const TREZOR_FIRMWARE_VERSION = '1.4.0'
|
const TREZOR_FIRMWARE_VERSION = '1.4.0'
|
||||||
//const log = require('loglevel')
|
const log = require('loglevel')
|
||||||
|
|
||||||
class TrezorKeyring extends EventEmitter {
|
class TrezorKeyring extends EventEmitter {
|
||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
@ -111,6 +111,7 @@ class TrezorKeyring extends EventEmitter {
|
|||||||
index: i,
|
index: i,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
log.debug(accounts)
|
||||||
resolve(accounts)
|
resolve(accounts)
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
|
@ -549,10 +549,10 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
throw new Error('MetamaskController - No Trezor Hardware Keyring found')
|
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
|
return accounts
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,7 +570,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keyring.setAccountToUnlock(index)
|
keyring.setAccountToUnlock(index)
|
||||||
|
|
||||||
const oldAccounts = await keyringController.getAccounts()
|
const oldAccounts = await keyringController.getAccounts()
|
||||||
const keyState = await keyringController.addNewAccount(keyring)
|
const keyState = await keyringController.addNewAccount(keyring)
|
||||||
const newAccounts = await keyringController.getAccounts()
|
const newAccounts = await keyringController.getAccounts()
|
||||||
|
@ -6,6 +6,7 @@ const actions = require('../../../actions')
|
|||||||
const genAccountLink = require('../../../../lib/account-link.js')
|
const genAccountLink = require('../../../../lib/account-link.js')
|
||||||
const log = require('loglevel')
|
const log = require('loglevel')
|
||||||
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) {
|
||||||
@ -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 () {
|
renderAccounts () {
|
||||||
if (!this.state.accounts.length) {
|
if (!this.state.accounts.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug('ACCOUNTS : ', this.state.accounts)
|
log.debug('ACCOUNTS : ', this.state.accounts)
|
||||||
log.debug('SELECTED?', this.state.selectedAccount)
|
log.debug('SELECTED?', this.state.selectedAccount)
|
||||||
|
|
||||||
@ -70,6 +83,7 @@ class ConnectHardwareForm extends Component {
|
|||||||
h('div.hw-account-list__device', {}, ['Trezor - ETH']),
|
h('div.hw-account-list__device', {}, ['Trezor - ETH']),
|
||||||
]),
|
]),
|
||||||
this.state.accounts.map((a, i) => {
|
this.state.accounts.map((a, i) => {
|
||||||
|
|
||||||
return h('div.hw-account-list__item', { key: a.address }, [
|
return h('div.hw-account-list__item', { key: a.address }, [
|
||||||
h('span.hw-account-list__item__index', a.index + 1),
|
h('span.hw-account-list__item__index', a.index + 1),
|
||||||
h('div.hw-account-list__item__radio', [
|
h('div.hw-account-list__item__radio', [
|
||||||
@ -88,7 +102,7 @@ class ConnectHardwareForm 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', `${a.balance} ETH`),
|
h('span.hw-account-list__item__balance', `${this.getBalance(a.address)}`),
|
||||||
h(
|
h(
|
||||||
'a.hw-account-list__item__link',
|
'a.hw-account-list__item__link',
|
||||||
{
|
{
|
||||||
@ -194,16 +208,18 @@ ConnectHardwareForm.propTypes = {
|
|||||||
history: PropTypes.object,
|
history: PropTypes.object,
|
||||||
t: PropTypes.func,
|
t: PropTypes.func,
|
||||||
network: PropTypes.string,
|
network: PropTypes.string,
|
||||||
|
accounts: PropTypes.object,
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
const {
|
const {
|
||||||
metamask: { network, selectedAddress, identities = {} },
|
metamask: { network, selectedAddress, identities = {}, accounts = [] },
|
||||||
} = state
|
} = state
|
||||||
const numberOfExistingAccounts = Object.keys(identities).length
|
const numberOfExistingAccounts = Object.keys(identities).length
|
||||||
|
|
||||||
return {
|
return {
|
||||||
network,
|
network,
|
||||||
|
accounts,
|
||||||
address: selectedAddress,
|
address: selectedAddress,
|
||||||
numberOfExistingAccounts,
|
numberOfExistingAccounts,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user