diff options
author | Lazaridis <info@lazaridis.com> | 2018-03-16 08:29:53 +0800 |
---|---|---|
committer | Lazaridis <info@lazaridis.com> | 2018-03-16 08:29:53 +0800 |
commit | 904f00e8acf40a72d233d1776c8aa760026e1bd3 (patch) | |
tree | a1ccc2f4ae65e3bfea118eae21f6e14b4a5092a2 | |
parent | d8f5150aa5bf4b04310f887504428f1caa13cbf4 (diff) | |
download | tangerine-wallet-browser-904f00e8acf40a72d233d1776c8aa760026e1bd3.tar tangerine-wallet-browser-904f00e8acf40a72d233d1776c8aa760026e1bd3.tar.gz tangerine-wallet-browser-904f00e8acf40a72d233d1776c8aa760026e1bd3.tar.bz2 tangerine-wallet-browser-904f00e8acf40a72d233d1776c8aa760026e1bd3.tar.lz tangerine-wallet-browser-904f00e8acf40a72d233d1776c8aa760026e1bd3.tar.xz tangerine-wallet-browser-904f00e8acf40a72d233d1776c8aa760026e1bd3.tar.zst tangerine-wallet-browser-904f00e8acf40a72d233d1776c8aa760026e1bd3.zip |
group all vault/keyring related methods together, re #3568
-rw-r--r-- | app/scripts/metamask-controller.js | 258 |
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 //============================================================================= |