aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/metamask-controller.js258
1 files changed, 130 insertions, 128 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 31c0bed58..cbdf757c6 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -267,7 +267,7 @@ module.exports = class MetamaskController extends EventEmitter {
}
/**
- * Constructor helper: initialize a public confi store.
+ * Constructor helper: initialize a public config store.
*/
initPublicConfigStore () {
// get init state
@@ -290,12 +290,11 @@ module.exports = class MetamaskController extends EventEmitter {
return publicConfigStore
}
- //
- // State Management
- //
/**
- * ?
+ * The metamask-state of the various controllers, made available to the UI
+ *
+ * @returns {Object} status
*/
getState () {
const wallet = this.configManager.getWallet()
@@ -331,12 +330,10 @@ module.exports = class MetamaskController extends EventEmitter {
)
}
- //
- // Remote Features
- //
-
/**
- * ?
+ * Returns an api-object which is consumed by the UI
+ *
+ * @returns {Object}
*/
getApi () {
const keyringController = this.keyringController
@@ -656,7 +653,7 @@ module.exports = class MetamaskController extends EventEmitter {
/**
* Verifies the validity of the current vault's seed phrase.
*
- * Validity: seed phrase can restore the accounts belonging to the current vault.
+ * Validity: seed phrase restores the accounts belonging to the current vault.
*
* Called when the first account is created and on unlocking the vault.
*/
@@ -722,81 +719,9 @@ module.exports = class MetamaskController extends EventEmitter {
.catch((reason) => { cb(reason) })
}
-//=============================================================================
-// END (VAULT / KEYRING RELATED METHODS)
-//=============================================================================
-
-
-
-//=============================================================================
-// Identity Management
-//=============================================================================
-
- async retryTransaction (txId, cb) {
- await this.txController.retryTransaction(txId)
- const state = await this.getState()
- return state
- }
-
-
- newUnsignedMessage (msgParams, cb) {
- const msgId = this.messageManager.addUnapprovedMessage(msgParams)
- this.sendUpdate()
- this.opts.showUnconfirmedMessage()
- this.messageManager.once(`${msgId}:finished`, (data) => {
- switch (data.status) {
- case 'signed':
- return cb(null, data.rawSig)
- case 'rejected':
- return cb(new Error('MetaMask Message Signature: User denied message signature.'))
- default:
- return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
- }
- })
- }
-
- newUnsignedPersonalMessage (msgParams, cb) {
- if (!msgParams.from) {
- return cb(new Error('MetaMask Message Signature: from field is required.'))
- }
-
- const msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
- this.sendUpdate()
- this.opts.showUnconfirmedMessage()
- this.personalMessageManager.once(`${msgId}:finished`, (data) => {
- switch (data.status) {
- case 'signed':
- return cb(null, data.rawSig)
- case 'rejected':
- return cb(new Error('MetaMask Message Signature: User denied message signature.'))
- default:
- return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
- }
- })
- }
-
- newUnsignedTypedMessage (msgParams, cb) {
- let msgId
- try {
- msgId = this.typedMessageManager.addUnapprovedMessage(msgParams)
- this.sendUpdate()
- this.opts.showUnconfirmedMessage()
- } catch (e) {
- return cb(e)
- }
+ // ---------------------------------------------------------------------------
+ // Identity Management (sign)
- this.typedMessageManager.once(`${msgId}:finished`, (data) => {
- switch (data.status) {
- case 'signed':
- return cb(null, data.rawSig)
- case 'rejected':
- return cb(new Error('MetaMask Message Signature: User denied message signature.'))
- default:
- return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
- }
- })
- }
-
/**
* @param {} msgParams
* @param {} cb
@@ -820,14 +745,6 @@ module.exports = class MetamaskController extends EventEmitter {
})
}
- cancelMessage (msgId, cb) {
- const messageManager = this.messageManager
- messageManager.rejectMsg(msgId)
- if (cb && typeof cb === 'function') {
- cb(null, this.getState())
- }
- }
-
// Prefixed Style Message Signing Methods:
/**
@@ -892,41 +809,10 @@ module.exports = class MetamaskController extends EventEmitter {
return this.getState()
})
}
-
- cancelPersonalMessage (msgId, cb) {
- const messageManager = this.personalMessageManager
- messageManager.rejectMsg(msgId)
- if (cb && typeof cb === 'function') {
- cb(null, this.getState())
- }
- }
-
- cancelTypedMessage (msgId, cb) {
- const messageManager = this.typedMessageManager
- messageManager.rejectMsg(msgId)
- if (cb && typeof cb === 'function') {
- cb(null, this.getState())
- }
- }
-
- markAccountsFound (cb) {
- this.configManager.setLostAccounts([])
- this.sendUpdate()
- cb(null, this.getState())
- }
-
- markPasswordForgotten(cb) {
- this.configManager.setPasswordForgotten(true)
- this.sendUpdate()
- cb()
- }
-
- unMarkPasswordForgotten(cb) {
- this.configManager.setPasswordForgotten(false)
- this.sendUpdate()
- cb()
- }
+ // ---------------------------------------------------------------------------
+ // Account Restauration
+
/**
* ?
*
@@ -952,7 +838,6 @@ module.exports = class MetamaskController extends EventEmitter {
return Promise.resolve(migratorOutput)
}
-
/**
* Import (lost) Accounts
*
@@ -970,6 +855,123 @@ module.exports = class MetamaskController extends EventEmitter {
}
//=============================================================================
+// END (VAULT / KEYRING RELATED METHODS)
+//=============================================================================
+
+
+
+//=============================================================================
+// MESSAGES
+//=============================================================================
+
+ async retryTransaction (txId, cb) {
+ await this.txController.retryTransaction(txId)
+ const state = await this.getState()
+ return state
+ }
+
+
+ newUnsignedMessage (msgParams, cb) {
+ const msgId = this.messageManager.addUnapprovedMessage(msgParams)
+ this.sendUpdate()
+ this.opts.showUnconfirmedMessage()
+ this.messageManager.once(`${msgId}:finished`, (data) => {
+ switch (data.status) {
+ case 'signed':
+ return cb(null, data.rawSig)
+ case 'rejected':
+ return cb(new Error('MetaMask Message Signature: User denied message signature.'))
+ default:
+ return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
+ }
+ })
+ }
+
+ newUnsignedPersonalMessage (msgParams, cb) {
+ if (!msgParams.from) {
+ return cb(new Error('MetaMask Message Signature: from field is required.'))
+ }
+
+ const msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
+ this.sendUpdate()
+ this.opts.showUnconfirmedMessage()
+ this.personalMessageManager.once(`${msgId}:finished`, (data) => {
+ switch (data.status) {
+ case 'signed':
+ return cb(null, data.rawSig)
+ case 'rejected':
+ return cb(new Error('MetaMask Message Signature: User denied message signature.'))
+ default:
+ return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
+ }
+ })
+ }
+
+ newUnsignedTypedMessage (msgParams, cb) {
+ let msgId
+ try {
+ msgId = this.typedMessageManager.addUnapprovedMessage(msgParams)
+ this.sendUpdate()
+ this.opts.showUnconfirmedMessage()
+ } catch (e) {
+ return cb(e)
+ }
+
+ this.typedMessageManager.once(`${msgId}:finished`, (data) => {
+ switch (data.status) {
+ case 'signed':
+ return cb(null, data.rawSig)
+ case 'rejected':
+ return cb(new Error('MetaMask Message Signature: User denied message signature.'))
+ default:
+ return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
+ }
+ })
+ }
+
+ cancelMessage (msgId, cb) {
+ const messageManager = this.messageManager
+ messageManager.rejectMsg(msgId)
+ if (cb && typeof cb === 'function') {
+ cb(null, this.getState())
+ }
+ }
+
+ cancelPersonalMessage (msgId, cb) {
+ const messageManager = this.personalMessageManager
+ messageManager.rejectMsg(msgId)
+ if (cb && typeof cb === 'function') {
+ cb(null, this.getState())
+ }
+ }
+
+ cancelTypedMessage (msgId, cb) {
+ const messageManager = this.typedMessageManager
+ messageManager.rejectMsg(msgId)
+ if (cb && typeof cb === 'function') {
+ cb(null, this.getState())
+ }
+ }
+
+ markAccountsFound (cb) {
+ this.configManager.setLostAccounts([])
+ this.sendUpdate()
+ cb(null, this.getState())
+ }
+
+ markPasswordForgotten(cb) {
+ this.configManager.setPasswordForgotten(true)
+ this.sendUpdate()
+ cb()
+ }
+
+ unMarkPasswordForgotten(cb) {
+ this.configManager.setPasswordForgotten(false)
+ this.sendUpdate()
+ cb()
+ }
+
+//=============================================================================
// CONFIG
//=============================================================================