aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-02-03 12:20:13 +0800
committerkumavis <aaron@kumavis.me>2017-02-03 12:20:13 +0800
commit99fa9ab13aaf69cb8602612816a4df49209fa8a6 (patch)
tree251c246d4b31187ff27a8c3c1537a5ff6a5d8358
parentbcb86f38cbe91fb814d30b3129de76dba45bff66 (diff)
downloadtangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar.gz
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar.zst
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.zip
migration 7 - break off TransactionManager substate
-rw-r--r--app/scripts/metamask-controller.js21
-rw-r--r--app/scripts/migrations/007.js38
-rw-r--r--app/scripts/migrations/index.js1
-rw-r--r--app/scripts/transaction-manager.js54
-rw-r--r--test/integration/index.html2
-rw-r--r--test/unit/tx-manager-test.js112
-rw-r--r--ui/app/actions.js30
7 files changed, 179 insertions, 79 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index b6a096488..468e7d285 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -68,11 +68,9 @@ module.exports = class MetamaskController extends EventEmitter {
// tx mgmt
this.txManager = new TxManager({
- txList: this.configManager.getTxList(),
+ initState: initState.TxManager,
txHistoryLimit: 40,
- setTxList: this.configManager.setTxList.bind(this.configManager),
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),
provider: this.provider,
@@ -107,11 +105,14 @@ module.exports = class MetamaskController extends EventEmitter {
this.preferencesController.store.subscribe((state) => {
this.store.updateState({ PreferencesController: state })
})
+ this.txManager.store.subscribe((state) => {
+ this.store.updateState({ TransactionManager: state })
+ })
// manual mem state subscriptions
this.ethStore.on('update', this.sendUpdate.bind(this))
this.keyringController.memStore.subscribe(this.sendUpdate.bind(this))
- this.txManager.on('update', this.sendUpdate.bind(this))
+ this.txManager.memStore.subscribe(this.sendUpdate.bind(this))
this.messageManager.memStore.subscribe(this.sendUpdate.bind(this))
}
@@ -177,7 +178,7 @@ module.exports = class MetamaskController extends EventEmitter {
},
this.state,
this.ethStore.getState(),
- this.txManager.getState(),
+ this.txManager.memStore.getState(),
this.messageManager.memStore.getState(),
this.keyringController.memStore.getState(),
this.preferencesController.store.getState(),
@@ -245,11 +246,13 @@ module.exports = class MetamaskController extends EventEmitter {
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
exportAccount: nodeify(keyringController.exportAccount).bind(keyringController),
- // signing methods
+ // txManager
approveTransaction: txManager.approveTransaction.bind(txManager),
cancelTransaction: txManager.cancelTransaction.bind(txManager),
- signMessage: this.signMessage.bind(this),
- cancelMessage: messageManager.rejectMsg.bind(messageManager),
+
+ // messageManager
+ signMessage: this.signMessage.bind(this),
+ cancelMessage: messageManager.rejectMsg.bind(messageManager),
// notices
checkNotices: noticeController.updateNoticesList.bind(noticeController),
@@ -586,7 +589,7 @@ module.exports = class MetamaskController extends EventEmitter {
setGasMultiplier (gasMultiplier, cb) {
try {
- this.configManager.setGasMultiplier(gasMultiplier)
+ this.txManager.setGasMultiplier(gasMultiplier)
cb()
} catch (err) {
cb(err)
diff --git a/app/scripts/migrations/007.js b/app/scripts/migrations/007.js
new file mode 100644
index 000000000..3ae8cdc2d
--- /dev/null
+++ b/app/scripts/migrations/007.js
@@ -0,0 +1,38 @@
+const version = 7
+
+/*
+
+This migration breaks out the TransactionManager substate
+
+*/
+
+const extend = require('xtend')
+
+module.exports = {
+ version,
+
+ migrate: function (versionedData) {
+ versionedData.meta.version = version
+ try {
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ } catch (err) {
+ console.warn(`MetaMask Migration #${version}` + err.stack)
+ }
+ return Promise.resolve(versionedData)
+ },
+}
+
+function transformState (state) {
+ const newState = extend(state, {
+ TransactionManager: {
+ transactions: state.transactions || [],
+ gasMultiplier: state.gasMultiplier || 1,
+ },
+ })
+ delete newState.transactions
+ delete newState.gasMultiplier
+
+ return newState
+}
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index 17c191448..d608f5314 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -17,4 +17,5 @@ module.exports = [
require('./004'),
require('./005'),
require('./006'),
+ require('./007'),
]
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js
index 6fecdba39..7949fb854 100644
--- a/app/scripts/transaction-manager.js
+++ b/app/scripts/transaction-manager.js
@@ -2,6 +2,7 @@ const EventEmitter = require('events')
const async = require('async')
const extend = require('xtend')
const Semaphore = require('semaphore')
+const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const BN = require('ethereumjs-util').BN
const TxProviderUtil = require('./lib/tx-utils')
@@ -10,33 +11,46 @@ const createId = require('./lib/random-id')
module.exports = class TransactionManager extends EventEmitter {
constructor (opts) {
super()
- this.txList = opts.txList || []
- this._setTxList = opts.setTxList
+ this.store = new ObservableStore(extend({
+ txList: [],
+ gasMultiplier: 1,
+ }, opts.initState))
+ this.memStore = new ObservableStore({})
+ // this.networkStore = opts.networkStore || new ObservableStore({})
+ this.getNetwork = opts.getNetwork
+
this.txHistoryLimit = opts.txHistoryLimit
this.getSelectedAddress = opts.getSelectedAddress
this.provider = opts.provider
this.blockTracker = opts.blockTracker
this.txProviderUtils = new TxProviderUtil(this.provider)
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
- this.getGasMultiplier = opts.getGasMultiplier
- this.getNetwork = opts.getNetwork
this.signEthTx = opts.signTransaction
this.nonceLock = Semaphore(1)
+
+ // memstore is computed from diskStore
+ this._updateMemstore()
+ this.store.subscribe(() => this._updateMemstore() )
+ // this.networkStore.subscribe(() => this._updateMemstore() )
}
getState () {
- var selectedAddress = this.getSelectedAddress()
- return {
- transactions: this.getTxList(),
- unapprovedTxs: this.getUnapprovedTxList(),
- selectedAddressTxList: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAddress}),
- }
+ return this.memStore.getState()
}
-// Returns the tx list
+ // Returns the tx list
getTxList () {
let network = this.getNetwork()
- return this.txList.filter(txMeta => txMeta.metamaskNetworkId === network)
+ let fullTxList = this.store.getState().txList
+ return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network)
+ }
+
+ getGasMultiplier () {
+ return this.store.getState().gasMultiplier
+ }
+
+ setGasMultiplier (gasMultiplier) {
+ return this.store.updateState({ gasMultiplier })
}
// Adds a tx to the txlist
@@ -108,7 +122,7 @@ module.exports = class TransactionManager extends EventEmitter {
id: txId,
time: time,
status: 'unapproved',
- gasMultiplier: this.getGasMultiplier() || 1,
+ gasMultiplier: this.getGasMultiplier(),
metamaskNetworkId: this.getNetwork(),
txParams: txParams,
}
@@ -239,7 +253,7 @@ module.exports = class TransactionManager extends EventEmitter {
getTxsByMetaData (key, value, txList = this.getTxList()) {
return txList.filter((txMeta) => {
- if (key in txMeta.txParams) {
+ if (txMeta.txParams[key]) {
return txMeta.txParams[key] === value
} else {
return txMeta[key] === value
@@ -352,8 +366,16 @@ module.exports = class TransactionManager extends EventEmitter {
// Saves the new/updated txList.
// Function is intended only for internal use
_saveTxList (txList) {
- this.txList = txList
- this._setTxList(txList)
+ this.store.updateState({ txList })
+ }
+
+ _updateMemstore () {
+ const unapprovedTxs = this.getUnapprovedTxList()
+ const selectedAddressTxList = this.getFilteredTxList({
+ from: this.getSelectedAddress(),
+ metamaskNetworkId: this.getNetwork(),
+ })
+ this.memStore.updateState({ unapprovedTxs, selectedAddressTxList })
}
}
diff --git a/test/integration/index.html b/test/integration/index.html
index 8a54cb829..430814a8a 100644
--- a/test/integration/index.html
+++ b/test/integration/index.html
@@ -15,7 +15,7 @@
<script src="bundle.js"></script>
<script src="/testem.js"></script>
- <iframe src="/development/test.html" height="500px" width="360px">
+ <iframe src="/development/test.html" height="800px" width="500px">
<p>Your browser does not support iframes</p>
</iframe>
</body>
diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js
index a66003f85..f03294ce3 100644
--- a/test/unit/tx-manager-test.js
+++ b/test/unit/tx-manager-test.js
@@ -3,19 +3,18 @@ const extend = require('xtend')
const EventEmitter = require('events')
const STORAGE_KEY = 'metamask-persistance-key'
const TransactionManager = require('../../app/scripts/transaction-manager')
+const noop = () => true
describe('Transaction Manager', function() {
let txManager
- const onTxDoneCb = () => true
beforeEach(function() {
txManager = new TransactionManager ({
- txList: [],
- setTxList: () => {},
provider: "testnet",
txHistoryLimit: 10,
blockTracker: new EventEmitter(),
- getNetwork: function(){ return 'unit test' }
+ getNetwork: function(){ return 'unit test' },
+ getSelectedAddress: function(){ return '0xabcd' },
})
})
@@ -53,7 +52,7 @@ describe('Transaction Manager', function() {
describe('#_saveTxList', function() {
it('saves the submitted data to the tx list', function() {
- var target = [{ foo: 'bar', metamaskNetworkId: 'unit test' }]
+ var target = [{ foo: 'bar', metamaskNetworkId: 'unit test', txParams: {} }]
txManager._saveTxList(target)
var result = txManager.getTxList()
assert.equal(result[0].foo, 'bar')
@@ -62,8 +61,8 @@ describe('Transaction Manager', function() {
describe('#addTx', function() {
it('adds a tx returned in getTxList', function() {
- var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test' }
- txManager.addTx(tx, onTxDoneCb)
+ var tx = { id: 1, status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }
+ txManager.addTx(tx, noop)
var result = txManager.getTxList()
assert.ok(Array.isArray(result))
assert.equal(result.length, 1)
@@ -73,8 +72,8 @@ describe('Transaction Manager', function() {
it('cuts off early txs beyond a limit', function() {
const limit = txManager.txHistoryLimit
for (let i = 0; i < limit + 1; i++) {
- let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' }
- txManager.addTx(tx, onTxDoneCb)
+ let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }
+ txManager.addTx(tx, noop)
}
var result = txManager.getTxList()
assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
@@ -84,8 +83,8 @@ describe('Transaction Manager', function() {
it('cuts off early txs beyond a limit whether or not it is confirmed or rejected', function() {
const limit = txManager.txHistoryLimit
for (let i = 0; i < limit + 1; i++) {
- let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: 'unit test' }
- txManager.addTx(tx, onTxDoneCb)
+ let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: 'unit test', txParams: {} }
+ txManager.addTx(tx, noop)
}
var result = txManager.getTxList()
assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
@@ -93,12 +92,12 @@ describe('Transaction Manager', function() {
})
it('cuts off early txs beyond a limit but does not cut unapproved txs', function() {
- var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: 'unit test' }
- txManager.addTx(unconfirmedTx, onTxDoneCb)
+ var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }
+ txManager.addTx(unconfirmedTx, noop)
const limit = txManager.txHistoryLimit
for (let i = 1; i < limit + 1; i++) {
- let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test' }
- txManager.addTx(tx, onTxDoneCb)
+ let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }
+ txManager.addTx(tx, noop)
}
var result = txManager.getTxList()
assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
@@ -110,8 +109,8 @@ describe('Transaction Manager', function() {
describe('#setTxStatusSigned', function() {
it('sets the tx status to signed', function() {
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
- txManager.addTx(tx, onTxDoneCb)
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }
+ txManager.addTx(tx, noop)
txManager.setTxStatusSigned(1)
var result = txManager.getTxList()
assert.ok(Array.isArray(result))
@@ -121,20 +120,20 @@ describe('Transaction Manager', function() {
it('should emit a signed event to signal the exciton of callback', (done) => {
this.timeout(10000)
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
- let onTxDoneCb = function () {
- assert(true, 'event listener has been triggered and onTxDoneCb executed')
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }
+ let noop = function () {
+ assert(true, 'event listener has been triggered and noop executed')
done()
}
txManager.addTx(tx)
- txManager.on('1:signed', onTxDoneCb)
+ txManager.on('1:signed', noop)
txManager.setTxStatusSigned(1)
})
})
describe('#setTxStatusRejected', function() {
it('sets the tx status to rejected', function() {
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }
txManager.addTx(tx)
txManager.setTxStatusRejected(1)
var result = txManager.getTxList()
@@ -145,13 +144,13 @@ describe('Transaction Manager', function() {
it('should emit a rejected event to signal the exciton of callback', (done) => {
this.timeout(10000)
- var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test' }
+ var tx = { id: 1, status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }
txManager.addTx(tx)
- let onTxDoneCb = function (err, txId) {
- assert(true, 'event listener has been triggered and onTxDoneCb executed')
+ let noop = function (err, txId) {
+ assert(true, 'event listener has been triggered and noop executed')
done()
}
- txManager.on('1:rejected', onTxDoneCb)
+ txManager.on('1:rejected', noop)
txManager.setTxStatusRejected(1)
})
@@ -159,9 +158,9 @@ describe('Transaction Manager', function() {
describe('#updateTx', function() {
it('replaces the tx with the same id', function() {
- txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb)
- txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb)
- txManager.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test' })
+ txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }, noop)
+ txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }, noop)
+ txManager.updateTx({ id: '1', status: 'blah', hash: 'foo', metamaskNetworkId: 'unit test', txParams: {} })
var result = txManager.getTx('1')
assert.equal(result.hash, 'foo')
})
@@ -169,8 +168,8 @@ describe('Transaction Manager', function() {
describe('#getUnapprovedTxList', function() {
it('returns unapproved txs in a hash', function() {
- txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb)
- txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb)
+ txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }, noop)
+ txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }, noop)
let result = txManager.getUnapprovedTxList()
assert.equal(typeof result, 'object')
assert.equal(result['1'].status, 'unapproved')
@@ -180,8 +179,8 @@ describe('Transaction Manager', function() {
describe('#getTx', function() {
it('returns a tx with the requested id', function() {
- txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test' }, onTxDoneCb)
- txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test' }, onTxDoneCb)
+ txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: 'unit test', txParams: {} }, noop)
+ txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: 'unit test', txParams: {} }, noop)
assert.equal(txManager.getTx('1').status, 'unapproved')
assert.equal(txManager.getTx('2').status, 'confirmed')
})
@@ -189,26 +188,33 @@ describe('Transaction Manager', function() {
describe('#getFilteredTxList', function() {
it('returns a tx with the requested data', function() {
- var foop = 0
- var zoop = 0
- for (let i = 0; i < 10; ++i ){
- let everyOther = i % 2
- txManager.addTx({ id: i,
- status: everyOther ? 'unapproved' : 'confirmed',
- metamaskNetworkId: 'unit test',
- txParams: {
- from: everyOther ? 'foop' : 'zoop',
- to: everyOther ? 'zoop' : 'foop',
- }
- }, onTxDoneCb)
- everyOther ? ++foop : ++zoop
- }
- assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'zoop'}).length, zoop)
- assert.equal(txManager.getFilteredTxList({status: 'confirmed', to: 'foop'}).length, zoop)
- assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'foop'}).length, 0)
- assert.equal(txManager.getFilteredTxList({status: 'confirmed'}).length, zoop)
- assert.equal(txManager.getFilteredTxList({from: 'foop'}).length, foop)
- assert.equal(txManager.getFilteredTxList({from: 'zoop'}).length, zoop)
+ let txMetas = [
+ { id: 0, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' },
+ { id: 1, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' },
+ { id: 2, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' },
+ { id: 3, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' },
+ { id: 4, status: 'unapproved', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' },
+ { id: 5, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' },
+ { id: 6, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: 'unit test' },
+ { id: 7, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' },
+ { id: 8, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' },
+ { id: 9, status: 'confirmed', txParams: { from: '0xbb', to: '0xaa' }, metamaskNetworkId: 'unit test' },
+ ]
+ txMetas.forEach((txMeta) => txManager.addTx(txMeta, noop))
+ let filterParams
+
+ filterParams = { status: 'unapproved', from: '0xaa' }
+ assert.equal(txManager.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { status: 'unapproved', to: '0xaa' }
+ assert.equal(txManager.getFilteredTxList(filterParams).length, 2, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { status: 'confirmed', from: '0xbb' }
+ assert.equal(txManager.getFilteredTxList(filterParams).length, 3, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { status: 'confirmed' }
+ assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { from: '0xaa' }
+ assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
+ filterParams = { to: '0xaa' }
+ assert.equal(txManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
})
})
diff --git a/ui/app/actions.js b/ui/app/actions.js
index a27ab2c14..228adcf18 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -180,6 +180,7 @@ function tryUnlockMetamask (password) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
dispatch(actions.unlockInProgress())
+ if (global.METAMASK_DEBUG) console.log(`background.submitPassword`)
background.submitPassword(password, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -207,6 +208,7 @@ function transitionBackward () {
function confirmSeedWords () {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.clearSeedWordCache`)
background.clearSeedWordCache((err, account) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -222,6 +224,7 @@ function confirmSeedWords () {
function createNewVaultAndRestore (password, seed) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.createNewVaultAndRestore`)
background.createNewVaultAndRestore(password, seed, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message))
@@ -233,10 +236,12 @@ function createNewVaultAndRestore (password, seed) {
function createNewVaultAndKeychain (password) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.createNewVaultAndKeychain`)
background.createNewVaultAndKeychain(password, (err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
}
+ if (global.METAMASK_DEBUG) console.log(`background.placeSeedWords`)
background.placeSeedWords((err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
@@ -257,8 +262,10 @@ function revealSeedConfirmation () {
function requestRevealSeed (password) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.submitPassword`)
background.submitPassword(password, (err) => {
if (err) return dispatch(actions.displayWarning(err.message))
+ if (global.METAMASK_DEBUG) console.log(`background.placeSeedWords`)
background.placeSeedWords((err) => {
if (err) return dispatch(actions.displayWarning(err.message))
dispatch(actions.hideLoadingIndication())
@@ -270,6 +277,7 @@ function requestRevealSeed (password) {
function addNewKeyring (type, opts) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.addNewKeyring`)
background.addNewKeyring(type, opts, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message))
@@ -281,9 +289,11 @@ function addNewKeyring (type, opts) {
function importNewAccount (strategy, args) {
return (dispatch) => {
dispatch(actions.showLoadingIndication('This may take a while, be patient.'))
+ if (global.METAMASK_DEBUG) console.log(`background.importAccountWithStrategy`)
background.importAccountWithStrategy(strategy, args, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message))
+ if (global.METAMASK_DEBUG) console.log(`background.getState`)
background.getState((err, newState) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
@@ -305,6 +315,7 @@ function navigateToNewAccountScreen() {
}
function addNewAccount () {
+ if (global.METAMASK_DEBUG) console.log(`background.addNewAccount`)
return callBackgroundThenUpdate(background.addNewAccount)
}
@@ -317,6 +328,7 @@ function showInfoPage () {
function setCurrentFiat (fiat) {
return (dispatch) => {
dispatch(this.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.setCurrentFiat`)
background.setCurrentFiat(fiat, (data, err) => {
dispatch(this.hideLoadingIndication())
dispatch({
@@ -335,6 +347,7 @@ function signMsg (msgData) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.signMessage`)
background.signMessage(msgData, (err) => {
dispatch(actions.hideLoadingIndication())
@@ -346,6 +359,7 @@ function signMsg (msgData) {
function signTx (txData) {
return (dispatch) => {
+ if (global.METAMASK_DEBUG) console.log(`background.setGasMultiplier`)
background.setGasMultiplier(txData.gasMultiplier, (err) => {
if (err) return dispatch(actions.displayWarning(err.message))
web3.eth.sendTransaction(txData, (err, data) => {
@@ -361,6 +375,7 @@ function signTx (txData) {
function sendTx (txData) {
return (dispatch) => {
+ if (global.METAMASK_DEBUG) console.log(`background.approveTransaction`)
background.approveTransaction(txData.id, (err) => {
if (err) {
alert(err.message)
@@ -387,11 +402,13 @@ function txError (err) {
}
function cancelMsg (msgData) {
+ if (global.METAMASK_DEBUG) console.log(`background.cancelMessage`)
background.cancelMessage(msgData.id)
return actions.completedTx(msgData.id)
}
function cancelTx (txData) {
+ if (global.METAMASK_DEBUG) console.log(`background.cancelTransaction`)
background.cancelTransaction(txData.id)
return actions.completedTx(txData.id)
}
@@ -433,6 +450,7 @@ function showImportPage () {
function agreeToDisclaimer () {
return (dispatch) => {
dispatch(this.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.agreeToDisclaimer`)
background.agreeToDisclaimer((err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
@@ -503,12 +521,14 @@ function updateMetamaskState (newState) {
}
function lockMetamask () {
+ if (global.METAMASK_DEBUG) console.log(`background.setLocked`)
return callBackgroundThenUpdate(background.setLocked)
}
function showAccountDetail (address) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.setSelectedAddress`)
background.setSelectedAddress(address, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -581,6 +601,7 @@ function goBackToInitView () {
function markNoticeRead (notice) {
return (dispatch) => {
dispatch(this.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.markNoticeRead`)
background.markNoticeRead(notice, (err, notice) => {
dispatch(this.hideLoadingIndication())
if (err) {
@@ -612,6 +633,7 @@ function clearNotices () {
}
function markAccountsFound() {
+ if (global.METAMASK_DEBUG) console.log(`background.markAccountsFound`)
return callBackgroundThenUpdate(background.markAccountsFound)
}
@@ -620,6 +642,7 @@ function markAccountsFound() {
//
function setRpcTarget (newRpc) {
+ if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
background.setRpcTarget(newRpc)
return {
type: actions.SET_RPC_TARGET,
@@ -628,6 +651,7 @@ function setRpcTarget (newRpc) {
}
function setProviderType (type) {
+ if (global.METAMASK_DEBUG) console.log(`background.setProviderType`)
background.setProviderType(type)
return {
type: actions.SET_PROVIDER_TYPE,
@@ -636,6 +660,7 @@ function setProviderType (type) {
}
function useEtherscanProvider () {
+ if (global.METAMASK_DEBUG) console.log(`background.useEtherscanProvider`)
background.useEtherscanProvider()
return {
type: actions.USE_ETHERSCAN_PROVIDER,
@@ -692,6 +717,7 @@ function exportAccount (address) {
return function (dispatch) {
dispatch(self.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.exportAccount`)
background.exportAccount(address, function (err, result) {
dispatch(self.hideLoadingIndication())
@@ -715,6 +741,7 @@ function showPrivateKey (key) {
function saveAccountLabel (account, label) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.saveAccountLabel`)
background.saveAccountLabel(account, label, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -736,6 +763,7 @@ function showSendPage () {
function buyEth (address, amount) {
return (dispatch) => {
+ if (global.METAMASK_DEBUG) console.log(`background.buyEth`)
background.buyEth(address, amount)
dispatch({
type: actions.BUY_ETH,
@@ -814,6 +842,7 @@ function coinShiftRquest (data, marketData) {
if (response.error) return dispatch(actions.displayWarning(response.error))
var message = `
Deposit your ${response.depositType} to the address bellow:`
+ if (global.METAMASK_DEBUG) console.log(`background.createShapeShiftTx`)
background.createShapeShiftTx(response.deposit, response.depositType)
dispatch(actions.showQrView(response.deposit, [message].concat(marketData)))
})
@@ -893,6 +922,7 @@ function callBackgroundThenUpdate (method, ...args) {
}
function forceUpdateMetamaskState(dispatch){
+ if (global.METAMASK_DEBUG) console.log(`background.getState`)
background.getState((err, newState) => {
if (err) {
return dispatch(actions.displayWarning(err.message))