blob: b28f31b4b20845f249d585a844c93cde19f9c440 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
const ObservableStore = require('obs-store')
const normalizeAddress = require('../sig-util').normalize
class PreferencesController {
constructor (opts = {}) {
const initState = opts.initState || { frequentRPCList: [] }
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
}
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
//
}
module.exports = PreferencesController
|