From e21dfd18622dd7f70dac51855a0052a56fb74e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mi=C3=B1o?= Date: Tue, 22 Jan 2019 15:22:56 -0300 Subject: Use Parity on-chain registry only when is needed (#6052) * add and use knownMethodData to avoid infura requests * dataMethod to methodData and check empty response --- app/scripts/controllers/preferences.js | 14 ++++++++++++++ app/scripts/metamask-controller.js | 1 + 2 files changed, 15 insertions(+) (limited to 'app') diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 2faf8220b..fa162c21f 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -19,6 +19,7 @@ class PreferencesController { * @property {boolean} store.useBlockie The users preference for blockie identicons within the UI * @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the * user wishes to see that feature + * @property {object} store.knownMethodData Contains all data methods known by the user * @property {string} store.currentLocale The preferred language locale key * @property {string} store.selectedAddress A hex string that matches the currently selected address in the app * @@ -36,6 +37,7 @@ class PreferencesController { betaUI: true, skipAnnounceBetaUI: true, }, + knownMethodData: {}, currentLocale: opts.initLangCode, identities: {}, lostIdentities: {}, @@ -98,6 +100,18 @@ class PreferencesController { this.store.updateState({ suggestedTokens: suggested }) } + /** + * Add new methodData to state, to avoid requesting this information again through Infura + * + * @param {string} fourBytePrefix Four-byte method signature + * @param {string} methodData Corresponding data method + */ + addKnownMethodData (fourBytePrefix, methodData) { + const knownMethodData = this.store.getState().knownMethodData + knownMethodData[fourBytePrefix] = methodData + this.store.updateState({ knownMethodData }) + } + /** * RPC engine middleware for requesting new asset added * diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index c7e9cfcc7..ea57582a0 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -425,6 +425,7 @@ module.exports = class MetamaskController extends EventEmitter { setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController), setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController), setPreference: nodeify(preferencesController.setPreference, preferencesController), + addKnownMethodData: nodeify(preferencesController.addKnownMethodData, preferencesController), // BlacklistController whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this), -- cgit v1.2.3