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

Merge pull request #1069 from MetaMask/i1066

Introduce Preferences Controller
This commit is contained in:
Frankie 2017-01-30 15:57:49 -08:00 committed by GitHub
commit 8257853819
49 changed files with 170 additions and 128 deletions

View File

@ -50,9 +50,9 @@ reloadStream.once('data', triggerReload)
// })
// endOfStream(pingStream, triggerReload)
// set web3 defaultAcount
// set web3 defaultAccount
inpageProvider.publicConfigStore.subscribe(function (state) {
web3.eth.defaultAccount = state.selectedAccount
web3.eth.defaultAccount = state.selectedAddress
})
//

View File

@ -88,8 +88,6 @@ class KeyringController extends EventEmitter {
keyringTypes: this.keyringTypes.map(krt => krt.type),
// memStore
identities: this.identities,
// diskStore
selectedAccount: state.selectedAccount,
// configManager
seedWords: this.configManager.getSeedWords(),
isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
@ -152,7 +150,7 @@ class KeyringController extends EventEmitter {
const firstAccount = accounts[0]
if (!firstAccount) throw new Error('KeyringController - First Account not found.')
const hexAccount = normalizeAddress(firstAccount)
this.setSelectedAccount(hexAccount)
this.emit('newAccount', hexAccount)
return this.setupAccounts(accounts)
})
.then(this.persistAllKeyrings.bind(this, password))
@ -231,28 +229,6 @@ class KeyringController extends EventEmitter {
.then(this.fullUpdate.bind(this))
}
// Set Selected Account
// @string address
//
// returns Promise( @string address )
//
// Sets the state's `selectedAccount` value
// to the specified address.
setSelectedAccount (account) {
var address = normalizeAddress(account)
this.store.updateState({ selectedAccount: address })
return this.fullUpdate()
}
// Get Selected Account
//
// returns String
//
// Gets the state's `selectedAccount` value
getSelectedAccount () {
return this.store.getState().selectedAccount
}
// Save Account Label
// @string account
// @string label
@ -415,7 +391,6 @@ class KeyringController extends EventEmitter {
const firstAccount = accounts[0]
if (!firstAccount) throw new Error('KeyringController - No account found on keychain.')
const hexAccount = normalizeAddress(firstAccount)
this.setSelectedAccount(hexAccount)
this.emit('newAccount', hexAccount)
return this.setupAccounts(accounts)
})
@ -662,7 +637,6 @@ class KeyringController extends EventEmitter {
this.keyrings = []
this.identities = {}
this.setSelectedAccount()
}
}

View File

@ -0,0 +1,33 @@
const ObservableStore = require('obs-store')
const normalizeAddress = require('../sig-util').normalize
class PreferencesController {
constructor (opts = {}) {
const initState = opts.initState || {}
this.store = new ObservableStore(initState)
}
//
// PUBLIC METHODS
//
setSelectedAddress(_address) {
return new Promise((resolve, reject) => {
const address = normalizeAddress(_address)
this.store.updateState({ selectedAddress: address })
resolve()
})
}
getSelectedAddress(_address) {
return this.store.getState().selectedAddress
}
//
// PRIVATE METHODS
//
}
module.exports = PreferencesController

View File

@ -63,20 +63,20 @@ function MetamaskInpageProvider (connectionStream) {
MetamaskInpageProvider.prototype.send = function (payload) {
const self = this
let selectedAccount
let selectedAddress
let result = null
switch (payload.method) {
case 'eth_accounts':
// read from localStorage
selectedAccount = self.publicConfigStore.getState().selectedAccount
result = selectedAccount ? [selectedAccount] : []
selectedAddress = self.publicConfigStore.getState().selectedAddress
result = selectedAddress ? [selectedAddress] : []
break
case 'eth_coinbase':
// read from localStorage
selectedAccount = self.publicConfigStore.getState().selectedAccount
result = selectedAccount || '0x0000000000000000000000000000000000000000'
selectedAddress = self.publicConfigStore.getState().selectedAddress
result = selectedAddress
break
case 'eth_uninstallFilter':

View File

@ -11,6 +11,7 @@ const streamIntoProvider = require('web3-stream-provider/handler')
const MetaMaskProvider = require('web3-provider-engine/zero.js')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const KeyringController = require('./keyring-controller')
const PreferencesController = require('./lib/controllers/preferences')
const NoticeController = require('./notice-controller')
const messageManager = require('./lib/message-manager')
const TxManager = require('./transaction-manager')
@ -40,6 +41,11 @@ module.exports = class MetamaskController extends EventEmitter {
})
this.configManager.updateConversionRate()
// preferences controller
this.preferencesController = new PreferencesController({
initState: initState.PreferencesController,
})
// rpc provider
this.provider = this.initializeProvider(opts)
this.provider.on('block', this.logBlock.bind(this))
@ -56,8 +62,9 @@ module.exports = class MetamaskController extends EventEmitter {
configManager: this.configManager,
getNetwork: this.getStateNetwork.bind(this),
})
this.keyringController.on('newAccount', (account) => {
autoFaucet(account)
this.keyringController.on('newAccount', (address) => {
this.preferencesController.setSelectedAddress(address)
autoFaucet(address)
})
// tx mgmt
@ -65,7 +72,7 @@ module.exports = class MetamaskController extends EventEmitter {
txList: this.configManager.getTxList(),
txHistoryLimit: 40,
setTxList: this.configManager.setTxList.bind(this.configManager),
getSelectedAccount: this.keyringController.getSelectedAccount.bind(this.keyringController),
getSelectedAddress: this.preferencesController.getSelectedAddress.bind(this.preferencesController),
getGasMultiplier: this.configManager.getGasMultiplier.bind(this.configManager),
getNetwork: this.getStateNetwork.bind(this),
signTransaction: this.keyringController.signTransaction.bind(this.keyringController),
@ -101,6 +108,9 @@ module.exports = class MetamaskController extends EventEmitter {
this.keyringController.store.subscribe((state) => {
this.store.updateState({ KeyringController: state })
})
this.preferencesController.store.subscribe((state) => {
this.store.updateState({ PreferencesController: state })
})
}
//
@ -116,8 +126,8 @@ module.exports = class MetamaskController extends EventEmitter {
rpcUrl: this.configManager.getCurrentRpcAddress(),
// account mgmt
getAccounts: (cb) => {
let selectedAccount = this.keyringController.getSelectedAccount()
let result = selectedAccount ? [selectedAccount] : []
let selectedAddress = this.preferencesController.getSelectedAddress()
let result = selectedAddress ? [selectedAddress] : []
cb(null, result)
},
// tx signing
@ -144,9 +154,9 @@ module.exports = class MetamaskController extends EventEmitter {
)
function selectPublicState(state) {
const result = { selectedAccount: undefined }
const result = { selectedAddress: undefined }
try {
result.selectedAccount = state.KeyringController.selectedAccount
result.selectedAddress = state.PreferencesController.selectedAddress
} catch (_) {}
return result
}
@ -167,6 +177,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.configManager.getConfig(),
this.txManager.getState(),
keyringControllerState,
this.preferencesController.store.getState(),
this.noticeController.getState(),
{
shapeShiftTxList: this.configManager.getShapeShiftTxList(),
@ -182,6 +193,7 @@ module.exports = class MetamaskController extends EventEmitter {
getApi () {
const keyringController = this.keyringController
const preferencesController = this.preferencesController
const txManager = this.txManager
const noticeController = this.noticeController
@ -212,12 +224,14 @@ module.exports = class MetamaskController extends EventEmitter {
// vault management
submitPassword: this.submitPassword.bind(this),
// PreferencesController
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
// KeyringController
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController),
addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController),
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
exportAccount: nodeify(keyringController.exportAccount).bind(keyringController),
@ -330,7 +344,7 @@ module.exports = class MetamaskController extends EventEmitter {
// ensuring they are only ever available in the background process.
clearSeedWordCache (cb) {
this.configManager.setSeedWords(null)
cb(null, this.keyringController.getSelectedAccount())
cb(null, this.preferencesController.getSelectedAddress())
}
importAccountWithStrategy (strategy, args, cb) {
@ -339,7 +353,7 @@ module.exports = class MetamaskController extends EventEmitter {
return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
})
.then(keyring => keyring.getAccounts())
.then((accounts) => this.keyringController.setSelectedAccount(accounts[0]))
.then((accounts) => this.preferencesController.setSelectedAddress(accounts[0]))
.then(() => { cb(null, this.keyringController.fullUpdate()) })
.catch((reason) => { cb(reason) })
}

View File

@ -0,0 +1,41 @@
const version = 6
/*
This migration moves KeyringController.selectedAddress to PreferencesController.selectedAddress
*/
const extend = require('xtend')
module.exports = {
version,
migrate: function (versionedData) {
versionedData.meta.version = version
try {
const state = versionedData.data
const newState = migrateState(state)
versionedData.data = newState
} catch (err) {
console.warn(`MetaMask Migration #${version}` + err.stack)
}
return Promise.resolve(versionedData)
},
}
function migrateState (state) {
const keyringSubstate = state.KeyringController
// add new state
const newState = extend(state, {
PreferencesController: {
selectedAddress: keyringSubstate.selectedAccount,
},
})
// rm old state
delete newState.KeyringController.selectedAccount
return newState
}

View File

@ -16,4 +16,5 @@ module.exports = [
require('./003'),
require('./004'),
require('./005'),
require('./006'),
]

View File

@ -13,7 +13,7 @@ module.exports = class TransactionManager extends EventEmitter {
this.txList = opts.txList || []
this._setTxList = opts.setTxList
this.txHistoryLimit = opts.txHistoryLimit
this.getSelectedAccount = opts.getSelectedAccount
this.getSelectedAddress = opts.getSelectedAddress
this.provider = opts.provider
this.blockTracker = opts.blockTracker
this.txProviderUtils = new TxProviderUtil(this.provider)
@ -25,11 +25,11 @@ module.exports = class TransactionManager extends EventEmitter {
}
getState () {
var selectedAccount = this.getSelectedAccount()
var selectedAddress = this.getSelectedAddress()
return {
transactions: this.getTxList(),
unconfTxs: this.getUnapprovedTxList(),
selectedAccountTxList: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAccount}),
selectedAddressTxList: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAddress}),
}
}

File diff suppressed because one or more lines are too long

View File

@ -133,7 +133,7 @@
"address": "0x704107d04affddd9b66ab9de3dd7b095852e9b69"
}
},
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"network": "1",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -142,7 +142,7 @@
"provider": {
"type": "mainnet"
},
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
},
"appState": {
"menuOpen": false,

View File

@ -99,7 +99,7 @@
"status": "confirmed",
"containsDelegateCall": false
}],
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"network": "2",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -108,7 +108,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
},
"appState": {
"menuOpen": false,

View File

@ -57,7 +57,7 @@
}
},
"transactions": [],
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"network": "2",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -66,7 +66,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
},
"appState": {
"menuOpen": false,

View File

@ -37,7 +37,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x9858e7d8b79fc3e6d989636721584498926da38a",
"selectedAddress": "0x9858e7d8b79fc3e6d989636721584498926da38a",
"selectedAccountTxList": [],
"isDisclaimerConfirmed": true,
"unconfMsgs": {},

View File

@ -77,7 +77,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x87658c15aefe7448008a28513a11b6b130ef4cd0",
"selectedAddress": "0x87658c15aefe7448008a28513a11b6b130ef4cd0",
"isDisclaimerConfirmed": true,
"unconfMsgs": {},
"messages": [],

View File

@ -89,7 +89,6 @@
}
},
"transactions": [],
"selectedAccount": "0x0abdd95cafcabec9b3e99dcd09fc4b441037cb80",
"network": "2",
"isDisclaimerConfirmed": true,
"unconfMsgs": {},
@ -98,7 +97,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x0abdd95cafcabec9b3e99dcd09fc4b441037cb80",
"selectedAddress": "0x0abdd95cafcabec9b3e99dcd09fc4b441037cb80",
"seedWords": null
},
"appState": {

View File

@ -95,7 +95,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9",
"selectedAddress": "0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9",
"seedWords": false,
"isDisclaimerConfirmed": true,
"unconfMsgs": {},

View File

@ -57,7 +57,6 @@
}
},
"transactions": [],
"selectedAccount": "0x843963b837841dad3b0f5969ff271108776616df",
"network": "2",
"isDisclaimerConfirmed": true,
"unconfMsgs": {},
@ -65,7 +64,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x843963b837841dad3b0f5969ff271108776616df",
"selectedAddress": "0x843963b837841dad3b0f5969ff271108776616df",
"seedWords": null
},
"appState": {

View File

@ -157,7 +157,6 @@
"estimatedGas": "0x5208"
}
],
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"network": "166",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -167,7 +166,7 @@
"type": "rpc",
"rpcTarget": "555.203.16.244"
},
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
},
"appState": {
"menuOpen": false,

View File

@ -54,7 +54,7 @@
}
},
"transactions": [],
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"network": "2",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -63,7 +63,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
},
"appState": {
"menuOpen": false,

View File

@ -61,8 +61,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"seedWords": null
},
"appState": {

View File

@ -27,7 +27,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x01208723ba84e15da2e71656544a2963b0c06d40",
"selectedAddress": "0x01208723ba84e15da2e71656544a2963b0c06d40",
"selectedAccountTxList": [],
"seedWords": false,
"isDisclaimerConfirmed": true,

View File

@ -27,7 +27,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x01208723ba84e15da2e71656544a2963b0c06d40",
"selectedAddress": "0x01208723ba84e15da2e71656544a2963b0c06d40",
"selectedAccountTxList": [],
"seedWords": null,
"isDisclaimerConfirmed": true,

View File

@ -11,7 +11,7 @@
"conversionDate": 1473358355,
"accounts": {},
"transactions": [],
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"network": "1473186153102",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -22,7 +22,7 @@
"type": "rpc",
"rpcTarget": "http://localhost:8545"
},
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
},
"appState": {
"menuOpen": false,

View File

@ -61,7 +61,7 @@
}
},
"transactions": [],
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
"network": "2",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -70,7 +70,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
"selectedAddress": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"
},
"appState": {
"menuOpen": false,

View File

@ -36,7 +36,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0xa6ef573d60594731178b7f85d80da13cc2af52dd",
"selectedAddress": "0xa6ef573d60594731178b7f85d80da13cc2af52dd",
"isConfirmed": true,
"unconfMsgs": {},
"messages": [],

View File

@ -33,7 +33,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x24a1d059462456aa332d6da9117aa7f91a46f2ac",
"selectedAddress": "0x24a1d059462456aa332d6da9117aa7f91a46f2ac",
"seedWords": null,
"isDisclaimerConfirmed": true,
"unconfMsgs": {},

File diff suppressed because one or more lines are too long

View File

@ -351,7 +351,7 @@
"hash": "0xb6e6ff57e7b5f6bd7f2e6dc44c39f4e858a227c9509586634ca547179345a13e"
}
],
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"network": "1471904489432",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -384,7 +384,7 @@
"type": "rpc",
"rpcTarget": "http://localhost:8545"
},
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
},
"appState": {
"menuOpen": false,

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"metamask":{"isInitialized":true,"isUnlocked":true,"currentDomain":"example.com","rpcTarget":"https://rawtestrpc.metamask.io/","identities":{"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825":{"name":"Wallet 1","address":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825","mayBeFauceting":false},"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb":{"name":"Wallet 2","address":"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb","mayBeFauceting":false},"0x2f8d4a878cfa04a6e60d46362f5644deab66572d":{"name":"Wallet 3","address":"0x2f8d4a878cfa04a6e60d46362f5644deab66572d","mayBeFauceting":false}},"unconfTxs":{"1467868023090690":{"id":1467868023090690,"txParams":{"data":"0xa9059cbb0000000000000000000000008deb4d106090c3eb8f1950f727e87c4f884fb06f0000000000000000000000000000000000000000000000000000000000000064","from":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825","value":"0x16345785d8a0000","to":"0xbeb0ed3034c4155f3d16a64a5c5e7c8d4ea9e9c9","origin":"MetaMask","metamaskId":1467868023090690,"metamaskNetworkId":"2"},"time":1467868023090,"status":"unconfirmed","containsDelegateCall":false}},"accounts":{"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825":{"code":"0x","balance":"0x38326dc32cf80800","nonce":"0x10000c","address":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"},"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb":{"code":"0x","balance":"0x15e578bd8e9c8000","nonce":"0x100000","address":"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb"},"0x2f8d4a878cfa04a6e60d46362f5644deab66572d":{"code":"0x","nonce":"0x100000","balance":"0x2386f26fc10000","address":"0x2f8d4a878cfa04a6e60d46362f5644deab66572d"}},"transactions":[],"selectedAccount":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825","network":"2","seedWords":null,"isDisclaimerConfirmed":true,"unconfMsgs":{},"messages":[],"provider":{"type":"testnet"},"selectedAccount":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"},"appState":{"menuOpen":false,"currentView":{"name":"confTx","context":0},"accountDetail":{"subview":"transactions"},"currentDomain":"extensions","transForward":true,"isLoading":false,"warning":null},"identities":{}}
{"metamask":{"isInitialized":true,"isUnlocked":true,"currentDomain":"example.com","rpcTarget":"https://rawtestrpc.metamask.io/","identities":{"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825":{"name":"Wallet 1","address":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825","mayBeFauceting":false},"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb":{"name":"Wallet 2","address":"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb","mayBeFauceting":false},"0x2f8d4a878cfa04a6e60d46362f5644deab66572d":{"name":"Wallet 3","address":"0x2f8d4a878cfa04a6e60d46362f5644deab66572d","mayBeFauceting":false}},"unconfTxs":{"1467868023090690":{"id":1467868023090690,"txParams":{"data":"0xa9059cbb0000000000000000000000008deb4d106090c3eb8f1950f727e87c4f884fb06f0000000000000000000000000000000000000000000000000000000000000064","from":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825","value":"0x16345785d8a0000","to":"0xbeb0ed3034c4155f3d16a64a5c5e7c8d4ea9e9c9","origin":"MetaMask","metamaskId":1467868023090690,"metamaskNetworkId":"2"},"time":1467868023090,"status":"unconfirmed","containsDelegateCall":false}},"accounts":{"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825":{"code":"0x","balance":"0x38326dc32cf80800","nonce":"0x10000c","address":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"},"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb":{"code":"0x","balance":"0x15e578bd8e9c8000","nonce":"0x100000","address":"0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb"},"0x2f8d4a878cfa04a6e60d46362f5644deab66572d":{"code":"0x","nonce":"0x100000","balance":"0x2386f26fc10000","address":"0x2f8d4a878cfa04a6e60d46362f5644deab66572d"}},"transactions":[],"selectedAddress":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825","network":"2","seedWords":null,"isDisclaimerConfirmed":true,"unconfMsgs":{},"messages":[],"provider":{"type":"testnet"},"selectedAddress":"0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"},"appState":{"menuOpen":false,"currentView":{"name":"confTx","context":0},"accountDetail":{"subview":"transactions"},"currentDomain":"extensions","transForward":true,"isLoading":false,"warning":null},"identities":{}}

File diff suppressed because one or more lines are too long

View File

@ -52,7 +52,7 @@
"hash": "0xad609a6931f54a575ad71222ffc27cd6746017106d5b89f4ad300b37b273f8ac"
}
],
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"network": "1479753732793",
"isConfirmed": true,
"isEthConfirmed": true,
@ -64,7 +64,7 @@
"type": "rpc",
"rpcTarget": "http://localhost:8545"
},
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"isDisclaimerConfirmed": true
},
"appState": {

View File

@ -55,7 +55,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
},
"appState": {
"menuOpen": false,

View File

@ -46,7 +46,7 @@
}
},
"transactions": [],
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825",
"network": "1",
"seedWords": null,
"isDisclaimerConfirmed": true,
@ -56,7 +56,7 @@
"provider": {
"type": "mainnet"
},
"selectedAccount": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
"selectedAddress": "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
},
"appState": {
"menuOpen": false,

View File

@ -13,7 +13,7 @@
"provider": {
"type": "testnet"
},
"selectedAccount": "0x4dd5d356c5a016a220bcd69e82e5af680a430d00"
"selectedAddress": "0x4dd5d356c5a016a220bcd69e82e5af680a430d00"
},
"showSeedWords": false,
"isEthConfirmed": true

View File

@ -31,7 +31,7 @@ describe('SHOW_ACCOUNT_DETAIL', function() {
it('updates metamask state', function() {
var initialState = {
metamask: {
selectedAccount: 'foo'
selectedAddress: 'foo'
}
}
freeze(initialState)
@ -43,6 +43,6 @@ describe('SHOW_ACCOUNT_DETAIL', function() {
freeze(action)
var resultingState = reducers(initialState, action)
assert.equal(resultingState.metamask.selectedAccount, action.value)
assert.equal(resultingState.metamask.selectedAddress, action.value)
})
})

View File

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

View File

@ -15,10 +15,10 @@ function AccountListItem () {
}
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 isSelected = selectedAccount === identity.address
const isSelected = selectedAddress === identity.address
const account = accounts[identity.address]
const selectedClass = isSelected ? '.selected' : ''

View File

@ -19,7 +19,7 @@ function mapStateToProps (state) {
accounts: state.metamask.accounts,
identities: state.metamask.identities,
unconfTxs: state.metamask.unconfTxs,
selectedAccount: state.metamask.selectedAccount,
selectedAddress: state.metamask.selectedAddress,
scrollToBottom: state.appState.scrollToBottom,
pending,
keyrings: state.metamask.keyrings,
@ -80,7 +80,7 @@ AccountsScreen.prototype.render = function () {
return h(AccountListItem, {
key: `acct-panel-${identity.address}`,
identity,
selectedAccount: this.props.selectedAccount,
selectedAddress: this.props.selectedAddress,
accounts: this.props.accounts,
onShowDetail: this.onShowDetail.bind(this),
pending,
@ -139,13 +139,6 @@ AccountsScreen.prototype.navigateToConfTx = function () {
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) {
event.stopPropagation()
this.props.dispatch(actions.showAccountDetail(address))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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