1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

rename selectedAccount to selectedAddress

This commit is contained in:
kumavis 2017-01-30 15:08:31 -08:00
parent b1de2cdefa
commit f9b31fe2c3
17 changed files with 35 additions and 49 deletions

View File

@ -150,7 +150,7 @@ class KeyringController extends EventEmitter {
const firstAccount = accounts[0] const firstAccount = accounts[0]
if (!firstAccount) throw new Error('KeyringController - First Account not found.') if (!firstAccount) throw new Error('KeyringController - First Account not found.')
const hexAccount = normalizeAddress(firstAccount) const hexAccount = normalizeAddress(firstAccount)
this.setSelectedAccount(hexAccount) this.emit('newAccount', hexAccount)
return this.setupAccounts(accounts) return this.setupAccounts(accounts)
}) })
.then(this.persistAllKeyrings.bind(this, password)) .then(this.persistAllKeyrings.bind(this, password))
@ -391,7 +391,6 @@ class KeyringController extends EventEmitter {
const firstAccount = accounts[0] const firstAccount = accounts[0]
if (!firstAccount) throw new Error('KeyringController - No account found on keychain.') if (!firstAccount) throw new Error('KeyringController - No account found on keychain.')
const hexAccount = normalizeAddress(firstAccount) const hexAccount = normalizeAddress(firstAccount)
this.setSelectedAccount(hexAccount)
this.emit('newAccount', hexAccount) this.emit('newAccount', hexAccount)
return this.setupAccounts(accounts) return this.setupAccounts(accounts)
}) })
@ -638,7 +637,6 @@ class KeyringController extends EventEmitter {
this.keyrings = [] this.keyrings = []
this.identities = {} this.identities = {}
this.setSelectedAccount()
} }
} }

View File

@ -13,8 +13,11 @@ class PreferencesController {
// //
setSelectedAddress(_address) { setSelectedAddress(_address) {
const address = normalizeAddress(_address) return new Promise((resolve, reject) => {
this.store.updateState({ selectedAddress: address }) const address = normalizeAddress(_address)
this.store.updateState({ selectedAddress: address })
resolve()
})
} }
getSelectedAddress(_address) { getSelectedAddress(_address) {

View File

@ -62,8 +62,9 @@ module.exports = class MetamaskController extends EventEmitter {
configManager: this.configManager, configManager: this.configManager,
getNetwork: this.getStateNetwork.bind(this), getNetwork: this.getStateNetwork.bind(this),
}) })
this.keyringController.on('newAccount', (account) => { this.keyringController.on('newAccount', (address) => {
autoFaucet(account) this.preferencesController.setSelectedAddress(address)
autoFaucet(address)
}) })
// tx mgmt // tx mgmt
@ -176,6 +177,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.configManager.getConfig(), this.configManager.getConfig(),
this.txManager.getState(), this.txManager.getState(),
keyringControllerState, keyringControllerState,
this.preferencesController.store.getState(),
this.noticeController.getState(), this.noticeController.getState(),
{ {
shapeShiftTxList: this.configManager.getShapeShiftTxList(), shapeShiftTxList: this.configManager.getShapeShiftTxList(),
@ -223,7 +225,7 @@ module.exports = class MetamaskController extends EventEmitter {
submitPassword: this.submitPassword.bind(this), submitPassword: this.submitPassword.bind(this),
// PreferencesController // PreferencesController
setSelectedAccount: nodeify(preferencesController.setSelectedAccount).bind(preferencesController), setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
// KeyringController // KeyringController
setLocked: nodeify(keyringController.setLocked).bind(keyringController), setLocked: nodeify(keyringController.setLocked).bind(keyringController),
@ -351,7 +353,7 @@ module.exports = class MetamaskController extends EventEmitter {
return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ]) return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
}) })
.then(keyring => keyring.getAccounts()) .then(keyring => keyring.getAccounts())
.then((accounts) => this.preferencesController.setSelectedAccount(accounts[0])) .then((accounts) => this.preferencesController.setSelectedAddress(accounts[0]))
.then(() => { cb(null, this.keyringController.fullUpdate()) }) .then(() => { cb(null, this.keyringController.fullUpdate()) })
.catch((reason) => { cb(reason) }) .catch((reason) => { cb(reason) })
} }

View File

@ -30,7 +30,7 @@ function migrateState (state) {
// add new state // add new state
const newState = extend(state, { const newState = extend(state, {
PreferencesController: { PreferencesController: {
selectedAccount: config.selectedAccount, selectedAddress: config.selectedAccount,
}, },
}) })

View File

@ -24,7 +24,7 @@ function mapStateToProps (state) {
metamask: state.metamask, metamask: state.metamask,
identities: state.metamask.identities, identities: state.metamask.identities,
accounts: state.metamask.accounts, accounts: state.metamask.accounts,
address: state.metamask.selectedAccount, address: state.metamask.selectedAddress,
accountDetail: state.appState.accountDetail, accountDetail: state.appState.accountDetail,
network: state.metamask.network, network: state.metamask.network,
unconfMsgs: valuesFor(state.metamask.unconfMsgs), unconfMsgs: valuesFor(state.metamask.unconfMsgs),

View File

@ -15,10 +15,10 @@ function AccountListItem () {
} }
AccountListItem.prototype.render = function () { AccountListItem.prototype.render = function () {
const { identity, selectedAccount, accounts, onShowDetail } = this.props const { identity, selectedAddress, accounts, onShowDetail } = this.props
const checksumAddress = identity && identity.address && ethUtil.toChecksumAddress(identity.address) const checksumAddress = identity && identity.address && ethUtil.toChecksumAddress(identity.address)
const isSelected = selectedAccount === identity.address const isSelected = selectedAddress === identity.address
const account = accounts[identity.address] const account = accounts[identity.address]
const selectedClass = isSelected ? '.selected' : '' const selectedClass = isSelected ? '.selected' : ''

View File

@ -19,7 +19,7 @@ function mapStateToProps (state) {
accounts: state.metamask.accounts, accounts: state.metamask.accounts,
identities: state.metamask.identities, identities: state.metamask.identities,
unconfTxs: state.metamask.unconfTxs, unconfTxs: state.metamask.unconfTxs,
selectedAccount: state.metamask.selectedAccount, selectedAddress: state.metamask.selectedAddress,
scrollToBottom: state.appState.scrollToBottom, scrollToBottom: state.appState.scrollToBottom,
pending, pending,
keyrings: state.metamask.keyrings, keyrings: state.metamask.keyrings,
@ -80,7 +80,7 @@ AccountsScreen.prototype.render = function () {
return h(AccountListItem, { return h(AccountListItem, {
key: `acct-panel-${identity.address}`, key: `acct-panel-${identity.address}`,
identity, identity,
selectedAccount: this.props.selectedAccount, selectedAddress: this.props.selectedAddress,
accounts: this.props.accounts, accounts: this.props.accounts,
onShowDetail: this.onShowDetail.bind(this), onShowDetail: this.onShowDetail.bind(this),
pending, pending,
@ -139,13 +139,6 @@ AccountsScreen.prototype.navigateToConfTx = function () {
this.props.dispatch(actions.showConfTxPage()) this.props.dispatch(actions.showConfTxPage())
} }
AccountsScreen.prototype.onSelect = function (address, event) {
event.stopPropagation()
// if already selected, deselect
if (this.props.selectedAccount === address) address = null
this.props.dispatch(actions.setSelectedAccount(address))
}
AccountsScreen.prototype.onShowDetail = function (address, event) { AccountsScreen.prototype.onShowDetail = function (address, event) {
event.stopPropagation() event.stopPropagation()
this.props.dispatch(actions.showAccountDetail(address)) this.props.dispatch(actions.showAccountDetail(address))

View File

@ -90,7 +90,6 @@ var actions = {
TRANSACTION_ERROR: 'TRANSACTION_ERROR', TRANSACTION_ERROR: 'TRANSACTION_ERROR',
NEXT_TX: 'NEXT_TX', NEXT_TX: 'NEXT_TX',
PREVIOUS_TX: 'PREV_TX', PREVIOUS_TX: 'PREV_TX',
setSelectedAccount: setSelectedAccount,
signMsg: signMsg, signMsg: signMsg,
cancelMsg: cancelMsg, cancelMsg: cancelMsg,
sendTx: sendTx, sendTx: sendTx,
@ -287,7 +286,7 @@ function importNewAccount (strategy, args) {
dispatch(actions.updateMetamaskState(newState)) dispatch(actions.updateMetamaskState(newState))
dispatch({ dispatch({
type: actions.SHOW_ACCOUNT_DETAIL, type: actions.SHOW_ACCOUNT_DETAIL,
value: newState.selectedAccount, value: newState.selectedAddress,
}) })
}) })
} }
@ -309,10 +308,6 @@ function showInfoPage () {
} }
} }
function setSelectedAccount (address) {
return callBackgroundThenUpdate(background.setSelectedAccount, address)
}
function setCurrentFiat (fiat) { function setCurrentFiat (fiat) {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(this.showLoadingIndication())
@ -508,16 +503,14 @@ function lockMetamask () {
function showAccountDetail (address) { function showAccountDetail (address) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
background.setSelectedAccount(address, (err, newState) => { background.setSelectedAddress(address, (err) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) { if (err) {
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))
} }
dispatch(actions.updateMetamaskState(newState))
dispatch({ dispatch({
type: actions.SHOW_ACCOUNT_DETAIL, type: actions.SHOW_ACCOUNT_DETAIL,
value: newState.selectedAccount, value: address,
}) })
}) })
} }

View File

@ -13,7 +13,6 @@ module.exports = connect(mapStateToProps)(BuyButtonSubview)
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
selectedAccount: state.selectedAccount,
warning: state.appState.warning, warning: state.appState.warning,
buyView: state.appState.buyView, buyView: state.appState.buyView,
network: state.metamask.network, network: state.metamask.network,

View File

@ -9,7 +9,6 @@ module.exports = connect(mapStateToProps)(CoinbaseForm)
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
selectedAccount: state.selectedAccount,
warning: state.appState.warning, warning: state.appState.warning,
} }
} }

View File

@ -16,7 +16,7 @@ PendingMsgDetails.prototype.render = function () {
var msgData = state.txData var msgData = state.txData
var msgParams = msgData.msgParams || {} var msgParams = msgData.msgParams || {}
var address = msgParams.from || state.selectedAccount var address = msgParams.from || state.selectedAddress
var identity = state.identities[address] || { address: address } var identity = state.identities[address] || { address: address }
var account = state.accounts[address] || { address: address } var account = state.accounts[address] || { address: address }

View File

@ -22,7 +22,7 @@ PTXP.render = function () {
var txData = props.txData var txData = props.txData
var txParams = txData.txParams || {} var txParams = txData.txParams || {}
var address = txParams.from || props.selectedAccount var address = txParams.from || props.selectedAddress
var identity = props.identities[address] || { address: address } var identity = props.identities[address] || { address: address }
var account = props.accounts[address] var account = props.accounts[address]
var balance = account ? account.balance : '0x0' var balance = account ? account.balance : '0x0'

View File

@ -10,7 +10,6 @@ module.exports = connect(mapStateToProps)(ShapeshiftForm)
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
selectedAccount: state.selectedAccount,
warning: state.appState.warning, warning: state.appState.warning,
isSubLoading: state.appState.isSubLoading, isSubLoading: state.appState.isSubLoading,
qrRequested: state.appState.qrRequested, qrRequested: state.appState.qrRequested,

View File

@ -19,7 +19,7 @@ function mapStateToProps (state) {
return { return {
identities: state.metamask.identities, identities: state.metamask.identities,
accounts: state.metamask.accounts, accounts: state.metamask.accounts,
selectedAccount: state.metamask.selectedAccount, selectedAddress: state.metamask.selectedAddress,
unconfTxs: state.metamask.unconfTxs, unconfTxs: state.metamask.unconfTxs,
unconfMsgs: state.metamask.unconfMsgs, unconfMsgs: state.metamask.unconfMsgs,
index: state.appState.currentView.context, index: state.appState.currentView.context,
@ -99,12 +99,12 @@ ConfirmTxScreen.prototype.render = function () {
// Properties // Properties
txData: txData, txData: txData,
key: txData.id, key: txData.id,
selectedAccount: state.selectedAccount, selectedAddress: state.selectedAddress,
accounts: state.accounts, accounts: state.accounts,
identities: state.identities, identities: state.identities,
insufficientBalance: this.checkBalanceAgainstTx(txData), insufficientBalance: this.checkBalanceAgainstTx(txData),
// Actions // Actions
buyEth: this.buyEth.bind(this, txParams.from || state.selectedAccount), buyEth: this.buyEth.bind(this, txParams.from || state.selectedAddress),
sendTransaction: this.sendTransaction.bind(this, txData), sendTransaction: this.sendTransaction.bind(this, txData),
cancelTransaction: this.cancelTransaction.bind(this, txData), cancelTransaction: this.cancelTransaction.bind(this, txData),
signMessage: this.signMessage.bind(this, txData), signMessage: this.signMessage.bind(this, txData),
@ -131,7 +131,7 @@ function currentTxView (opts) {
ConfirmTxScreen.prototype.checkBalanceAgainstTx = function (txData) { ConfirmTxScreen.prototype.checkBalanceAgainstTx = function (txData) {
if (!txData.txParams) return false if (!txData.txParams) return false
var state = this.props var state = this.props
var address = txData.txParams.from || state.selectedAccount var address = txData.txParams.from || state.selectedAddress
var account = state.accounts[address] var account = state.accounts[address]
var balance = account ? account.balance : '0x0' var balance = account ? account.balance : '0x0'
var maxCost = new BN(txData.maxCost, 16) var maxCost = new BN(txData.maxCost, 16)

View File

@ -7,10 +7,10 @@ module.exports = reduceApp
function reduceApp (state, action) { function reduceApp (state, action) {
// clone and defaults // clone and defaults
const selectedAccount = state.metamask.selectedAccount const selectedAddress = state.metamask.selectedAddress
const pendingTxs = hasPendingTxs(state) const pendingTxs = hasPendingTxs(state)
let name = 'accounts' let name = 'accounts'
if (selectedAccount) { if (selectedAddress) {
name = 'accountDetail' name = 'accountDetail'
} }
if (pendingTxs) { if (pendingTxs) {
@ -20,7 +20,7 @@ function reduceApp (state, action) {
var defaultView = { var defaultView = {
name, name,
detailView: null, detailView: null,
context: selectedAccount, context: selectedAddress,
} }
// confirm seed words // confirm seed words
@ -331,7 +331,7 @@ function reduceApp (state, action) {
warning: null, warning: null,
currentView: { currentView: {
name: 'accountDetail', name: 'accountDetail',
context: state.metamask.selectedAccount, context: state.metamask.selectedAddress,
}, },
accountDetail: { accountDetail: {
subview: 'transactions', subview: 'transactions',

View File

@ -50,7 +50,7 @@ function reduceMetamask (state, action) {
return extend(metamaskState, { return extend(metamaskState, {
isUnlocked: true, isUnlocked: true,
isInitialized: true, isInitialized: true,
selectedAccount: action.value, selectedAddress: action.value,
}) })
case actions.LOCK_METAMASK: case actions.LOCK_METAMASK:
@ -101,7 +101,7 @@ function reduceMetamask (state, action) {
newState = extend(metamaskState, { newState = extend(metamaskState, {
isUnlocked: true, isUnlocked: true,
isInitialized: true, isInitialized: true,
selectedAccount: action.value, selectedAddress: action.value,
}) })
delete newState.seedWords delete newState.seedWords
return newState return newState
@ -110,7 +110,7 @@ function reduceMetamask (state, action) {
newState = extend(metamaskState, { newState = extend(metamaskState, {
isUnlocked: true, isUnlocked: true,
isInitialized: true, isInitialized: true,
selectedAccount: action.value, selectedAddress: action.value,
}) })
delete newState.seedWords delete newState.seedWords
return newState return newState

View File

@ -16,7 +16,7 @@ module.exports = connect(mapStateToProps)(SendTransactionScreen)
function mapStateToProps (state) { function mapStateToProps (state) {
var result = { var result = {
address: state.metamask.selectedAccount, address: state.metamask.selectedAddress,
accounts: state.metamask.accounts, accounts: state.metamask.accounts,
identities: state.metamask.identities, identities: state.metamask.identities,
warning: state.appState.warning, warning: state.appState.warning,