From db48f8984f8e16b2831aab36cd538d241cb41402 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 21 Feb 2017 12:32:13 -0800 Subject: Basic infrasture for RPC list added. --- app/scripts/lib/controllers/preferences.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'app/scripts/lib/controllers/preferences.js') diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js index dc9464c4e..2d5a1addd 100644 --- a/app/scripts/lib/controllers/preferences.js +++ b/app/scripts/lib/controllers/preferences.js @@ -4,7 +4,7 @@ const normalizeAddress = require('../sig-util').normalize class PreferencesController { constructor (opts = {}) { - const initState = opts.initState || {} + const initState = opts.initState || { frequentRPCList: [] } this.store = new ObservableStore(initState) } @@ -12,7 +12,7 @@ class PreferencesController { // PUBLIC METHODS // - setSelectedAddress(_address) { + setSelectedAddress (_address) { return new Promise((resolve, reject) => { const address = normalizeAddress(_address) this.store.updateState({ selectedAddress: address }) @@ -20,10 +20,30 @@ class PreferencesController { }) } - getSelectedAddress(_address) { + getSelectedAddress (_address) { return this.store.getState().selectedAddress } + addToFrequentRPCList (_url) { + return new Promise((resolve, reject) => { + let rpcList = this.getFrequentRPCList() + let index = rpcList.findIndex((element) => { element === _url }) + if (index) { + rpcList.splice(index, 1) + } + if (rpcList.length >= 3) { + rpcList.shift() + } + rpcList.push(_url) + this.store.updateState({ frequentRPCList: rpcList }) + resolve() + }) + } + + getFrequentRPCList () { + return this.store.getState().frequentRPCList + } + // // PRIVATE METHODS // -- cgit v1.2.3 From 026e0e3383cedf290b2cb55e663f158e7f1c1a68 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 21 Feb 2017 12:51:46 -0800 Subject: Fix naming --- app/scripts/lib/controllers/preferences.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/controllers/preferences.js') diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js index 2d5a1addd..b28f31b4b 100644 --- a/app/scripts/lib/controllers/preferences.js +++ b/app/scripts/lib/controllers/preferences.js @@ -24,7 +24,7 @@ class PreferencesController { return this.store.getState().selectedAddress } - addToFrequentRPCList (_url) { + addToFrequentRpcList (_url) { return new Promise((resolve, reject) => { let rpcList = this.getFrequentRPCList() let index = rpcList.findIndex((element) => { element === _url }) @@ -40,7 +40,7 @@ class PreferencesController { }) } - getFrequentRPCList () { + getFrequentRpcList () { return this.store.getState().frequentRPCList } -- cgit v1.2.3 From 7a0ce31bd31a3d6f1a92bbaded71b040ca765065 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 22 Feb 2017 15:12:56 -0800 Subject: Implemented functionality for displaying recent custom RPCs --- app/scripts/lib/controllers/preferences.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'app/scripts/lib/controllers/preferences.js') diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js index b28f31b4b..8cc320179 100644 --- a/app/scripts/lib/controllers/preferences.js +++ b/app/scripts/lib/controllers/preferences.js @@ -1,10 +1,11 @@ const ObservableStore = require('obs-store') const normalizeAddress = require('../sig-util').normalize +const extend = require('xtend') class PreferencesController { constructor (opts = {}) { - const initState = opts.initState || { frequentRPCList: [] } + const initState = extend({ frequentRpcList: [] }, opts.initState) this.store = new ObservableStore(initState) } @@ -25,23 +26,23 @@ class PreferencesController { } addToFrequentRpcList (_url) { - return new Promise((resolve, reject) => { - let rpcList = this.getFrequentRPCList() - let index = rpcList.findIndex((element) => { element === _url }) - if (index) { - rpcList.splice(index, 1) - } - if (rpcList.length >= 3) { - rpcList.shift() - } + let rpcList = this.getFrequentRpcList() + let index = rpcList.findIndex((element) => { return element === _url }) + if (index !== -1) { + rpcList.splice(index, 1) + } + if (_url !== 'http://localhost:8545') { rpcList.push(_url) - this.store.updateState({ frequentRPCList: rpcList }) - resolve() - }) + } + if (rpcList.length > 2) { + rpcList.shift() + } + this.store.updateState({ frequentRpcList: rpcList }) + return Promise.resolve() } getFrequentRpcList () { - return this.store.getState().frequentRPCList + return this.store.getState().frequentRpcList } // -- cgit v1.2.3 From 62854398f1d3c72a82ae9d4feb03d9a1a947534e Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 23 Feb 2017 13:56:58 -0800 Subject: Tested against code to play nice with unit tests. --- app/scripts/lib/controllers/preferences.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'app/scripts/lib/controllers/preferences.js') diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js index 8cc320179..7bd2e5631 100644 --- a/app/scripts/lib/controllers/preferences.js +++ b/app/scripts/lib/controllers/preferences.js @@ -25,6 +25,14 @@ class PreferencesController { return this.store.getState().selectedAddress } + updateFrequentRpcList (_url) { + return this.addToFrequentRpcList(_url) + .then((rpcList) => { + this.store.updateState({ frequentRpcList: rpcList }) + return rpcList + }) + } + addToFrequentRpcList (_url) { let rpcList = this.getFrequentRpcList() let index = rpcList.findIndex((element) => { return element === _url }) @@ -37,8 +45,7 @@ class PreferencesController { if (rpcList.length > 2) { rpcList.shift() } - this.store.updateState({ frequentRpcList: rpcList }) - return Promise.resolve() + return Promise.resolve(rpcList) } getFrequentRpcList () { @@ -49,6 +56,8 @@ class PreferencesController { // PRIVATE METHODS // + + } module.exports = PreferencesController -- cgit v1.2.3 From b5d03cd52418cfd09ce51a23c01e78262d3ffc9b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 27 Feb 2017 10:39:48 -0800 Subject: add controllers to root scripts folder --- app/scripts/lib/controllers/preferences.js | 64 ------------------------------ 1 file changed, 64 deletions(-) delete mode 100644 app/scripts/lib/controllers/preferences.js (limited to 'app/scripts/lib/controllers/preferences.js') diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js deleted file mode 100644 index 9343fe67b..000000000 --- a/app/scripts/lib/controllers/preferences.js +++ /dev/null @@ -1,64 +0,0 @@ -const ObservableStore = require('obs-store') -const normalizeAddress = require('eth-sig-util').normalize -const extend = require('xtend') - - -class PreferencesController { - - constructor (opts = {}) { - const initState = extend({ frequentRpcList: [] }, 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 - } - - updateFrequentRpcList (_url) { - return this.addToFrequentRpcList(_url) - .then((rpcList) => { - this.store.updateState({ frequentRpcList: rpcList }) - return rpcList - }) - } - - addToFrequentRpcList (_url) { - let rpcList = this.getFrequentRpcList() - let index = rpcList.findIndex((element) => { return element === _url }) - if (index !== -1) { - rpcList.splice(index, 1) - } - if (_url !== 'http://localhost:8545') { - rpcList.push(_url) - } - if (rpcList.length > 2) { - rpcList.shift() - } - return Promise.resolve(rpcList) - } - - getFrequentRpcList () { - return this.store.getState().frequentRpcList - } - - // - // PRIVATE METHODS - // - - - -} - -module.exports = PreferencesController -- cgit v1.2.3