aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/config-manager.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-06-22 04:18:32 +0800
committerDan Finlay <dan@danfinlay.com>2016-06-22 04:18:32 +0800
commita08c3bc01b11fbd0e3a243359befbe9fc909edf4 (patch)
treeb79b7324139945c429ca4b6c74715d8040fdf4e1 /app/scripts/lib/config-manager.js
parentf7f8f8b1c50be39db22a7b10c6c6db007fe590aa (diff)
downloadtangerine-wallet-browser-a08c3bc01b11fbd0e3a243359befbe9fc909edf4.tar
tangerine-wallet-browser-a08c3bc01b11fbd0e3a243359befbe9fc909edf4.tar.gz
tangerine-wallet-browser-a08c3bc01b11fbd0e3a243359befbe9fc909edf4.tar.bz2
tangerine-wallet-browser-a08c3bc01b11fbd0e3a243359befbe9fc909edf4.tar.lz
tangerine-wallet-browser-a08c3bc01b11fbd0e3a243359befbe9fc909edf4.tar.xz
tangerine-wallet-browser-a08c3bc01b11fbd0e3a243359befbe9fc909edf4.tar.zst
tangerine-wallet-browser-a08c3bc01b11fbd0e3a243359befbe9fc909edf4.zip
Auto linted
Diffstat (limited to 'app/scripts/lib/config-manager.js')
-rw-r--r--app/scripts/lib/config-manager.js115
1 files changed, 56 insertions, 59 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 24571748f..a3ff0bdfb 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -7,7 +7,6 @@ const STORAGE_KEY = 'metamask-config'
const TESTNET_RPC = MetamaskConfig.network.testnet
const MAINNET_RPC = MetamaskConfig.network.mainnet
-
/* The config-manager is a convenience object
* wrapping a pojo-migrator.
*
@@ -16,7 +15,7 @@ const MAINNET_RPC = MetamaskConfig.network.mainnet
* particular portions of the state.
*/
module.exports = ConfigManager
-function ConfigManager() {
+function ConfigManager () {
// ConfigManager is observable and will emit updates
this._subs = []
@@ -26,7 +25,7 @@ function ConfigManager() {
* getData(), which returns the app-consumable data object
* saveData(), which persists the app-consumable data object.
*/
- this.migrator = new Migrator({
+ this.migrator = new Migrator({
// Migrations must start at version 1 or later.
// They are objects with a `version` number
@@ -41,20 +40,20 @@ function ConfigManager() {
loadData: loadData,
// How to persist migrated config.
- setData: function(data) {
+ setData: function (data) {
window.localStorage[STORAGE_KEY] = JSON.stringify(data)
},
})
}
-ConfigManager.prototype.setConfig = function(config) {
+ConfigManager.prototype.setConfig = function (config) {
var data = this.migrator.getData()
data.config = config
this.setData(data)
this._emitUpdates(config)
}
-ConfigManager.prototype.getConfig = function() {
+ConfigManager.prototype.getConfig = function () {
var data = this.migrator.getData()
if ('config' in data) {
return data.config
@@ -62,12 +61,12 @@ ConfigManager.prototype.getConfig = function() {
return {
provider: {
type: 'testnet',
- }
+ },
}
}
}
-ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
+ConfigManager.prototype.setRpcTarget = function (rpcUrl) {
var config = this.getConfig()
config.provider = {
type: 'rpc',
@@ -76,7 +75,7 @@ ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
this.setConfig(config)
}
-ConfigManager.prototype.setProviderType = function(type) {
+ConfigManager.prototype.setProviderType = function (type) {
var config = this.getConfig()
config.provider = {
type: type,
@@ -84,7 +83,7 @@ ConfigManager.prototype.setProviderType = function(type) {
this.setConfig(config)
}
-ConfigManager.prototype.useEtherscanProvider = function() {
+ConfigManager.prototype.useEtherscanProvider = function () {
var config = this.getConfig()
config.provider = {
type: 'etherscan',
@@ -92,75 +91,75 @@ ConfigManager.prototype.useEtherscanProvider = function() {
this.setConfig(config)
}
-ConfigManager.prototype.getProvider = function() {
+ConfigManager.prototype.getProvider = function () {
var config = this.getConfig()
return config.provider
}
-ConfigManager.prototype.setData = function(data) {
+ConfigManager.prototype.setData = function (data) {
this.migrator.saveData(data)
}
-ConfigManager.prototype.getData = function() {
+ConfigManager.prototype.getData = function () {
return this.migrator.getData()
}
-ConfigManager.prototype.setWallet = function(wallet) {
+ConfigManager.prototype.setWallet = function (wallet) {
var data = this.migrator.getData()
data.wallet = wallet
this.setData(data)
}
-ConfigManager.prototype.getSelectedAccount = function() {
+ConfigManager.prototype.getSelectedAccount = function () {
var config = this.getConfig()
return config.selectedAccount
}
-ConfigManager.prototype.setSelectedAccount = function(address) {
+ConfigManager.prototype.setSelectedAccount = function (address) {
var config = this.getConfig()
config.selectedAccount = address
this.setConfig(config)
}
-ConfigManager.prototype.getWallet = function() {
+ConfigManager.prototype.getWallet = function () {
return this.migrator.getData().wallet
}
// Takes a boolean
-ConfigManager.prototype.setShowSeedWords = function(should) {
+ConfigManager.prototype.setShowSeedWords = function (should) {
var data = this.migrator.getData()
data.showSeedWords = should
this.setData(data)
}
-ConfigManager.prototype.getShouldShowSeedWords = function() {
+ConfigManager.prototype.getShouldShowSeedWords = function () {
var data = this.migrator.getData()
return data.showSeedWords
}
-ConfigManager.prototype.getCurrentRpcAddress = function() {
+ConfigManager.prototype.getCurrentRpcAddress = function () {
var provider = this.getProvider()
if (!provider) return null
- switch (provider.type) {
+ switch (provider.type) {
- case 'mainnet':
- return MAINNET_RPC
+ case 'mainnet':
+ return MAINNET_RPC
- case 'testnet':
- return TESTNET_RPC
+ case 'testnet':
+ return TESTNET_RPC
- default:
- return provider && provider.rpcTarget ? provider.rpcTarget : TESTNET_RPC
- }
+ default:
+ return provider && provider.rpcTarget ? provider.rpcTarget : TESTNET_RPC
+ }
}
-ConfigManager.prototype.clearWallet = function() {
+ConfigManager.prototype.clearWallet = function () {
var data = this.getConfig()
delete data.wallet
this.setData(data)
}
-ConfigManager.prototype.setData = function(data) {
+ConfigManager.prototype.setData = function (data) {
this.migrator.saveData(data)
}
@@ -168,7 +167,7 @@ ConfigManager.prototype.setData = function(data) {
// Tx
//
-ConfigManager.prototype.getTxList = function() {
+ConfigManager.prototype.getTxList = function () {
var data = this.migrator.getData()
if (data.transactions !== undefined) {
return data.transactions
@@ -177,45 +176,45 @@ ConfigManager.prototype.getTxList = function() {
}
}
-ConfigManager.prototype.unconfirmedTxs = function() {
+ConfigManager.prototype.unconfirmedTxs = function () {
var transactions = this.getTxList()
return transactions.filter(tx => tx.status === 'unconfirmed')
.reduce((result, tx) => { result[tx.id] = tx; return result }, {})
}
-ConfigManager.prototype._saveTxList = function(txList) {
+ConfigManager.prototype._saveTxList = function (txList) {
var data = this.migrator.getData()
data.transactions = txList
this.setData(data)
}
-ConfigManager.prototype.addTx = function(tx) {
+ConfigManager.prototype.addTx = function (tx) {
var transactions = this.getTxList()
transactions.push(tx)
this._saveTxList(transactions)
}
-ConfigManager.prototype.getTx = function(txId) {
+ConfigManager.prototype.getTx = function (txId) {
var transactions = this.getTxList()
var matching = transactions.filter(tx => tx.id === txId)
return matching.length > 0 ? matching[0] : null
}
-ConfigManager.prototype.confirmTx = function(txId) {
+ConfigManager.prototype.confirmTx = function (txId) {
this._setTxStatus(txId, 'confirmed')
}
-ConfigManager.prototype.rejectTx = function(txId) {
+ConfigManager.prototype.rejectTx = function (txId) {
this._setTxStatus(txId, 'rejected')
}
-ConfigManager.prototype._setTxStatus = function(txId, status) {
+ConfigManager.prototype._setTxStatus = function (txId, status) {
var tx = this.getTx(txId)
tx.status = status
this.updateTx(tx)
}
-ConfigManager.prototype.updateTx = function(tx) {
+ConfigManager.prototype.updateTx = function (tx) {
var transactions = this.getTxList()
var found, index
transactions.forEach((otherTx, i) => {
@@ -232,19 +231,19 @@ ConfigManager.prototype.updateTx = function(tx) {
// wallet nickname methods
-ConfigManager.prototype.getWalletNicknames = function() {
+ConfigManager.prototype.getWalletNicknames = function () {
var data = this.getData()
- let nicknames = ('walletNicknames' in data) ? data.walletNicknames : {}
+ const nicknames = ('walletNicknames' in data) ? data.walletNicknames : {}
return nicknames
}
-ConfigManager.prototype.nicknameForWallet = function(account) {
- let nicknames = this.getWalletNicknames()
+ConfigManager.prototype.nicknameForWallet = function (account) {
+ const nicknames = this.getWalletNicknames()
return nicknames[account]
}
-ConfigManager.prototype.setNicknameForWallet = function(account, nickname) {
- let nicknames = this.getWalletNicknames()
+ConfigManager.prototype.setNicknameForWallet = function (account, nickname) {
+ const nicknames = this.getWalletNicknames()
nicknames[account] = nickname
var data = this.getData()
data.walletNicknames = nicknames
@@ -253,37 +252,35 @@ ConfigManager.prototype.setNicknameForWallet = function(account, nickname) {
// observable
-ConfigManager.prototype.subscribe = function(fn){
+ConfigManager.prototype.subscribe = function (fn) {
this._subs.push(fn)
var unsubscribe = this.unsubscribe.bind(this, fn)
return unsubscribe
}
-ConfigManager.prototype.unsubscribe = function(fn){
+ConfigManager.prototype.unsubscribe = function (fn) {
var index = this._subs.indexOf(fn)
if (index !== -1) this._subs.splice(index, 1)
}
-ConfigManager.prototype._emitUpdates = function(state){
- this._subs.forEach(function(handler){
+ConfigManager.prototype._emitUpdates = function (state) {
+ this._subs.forEach(function (handler) {
handler(state)
})
}
-ConfigManager.prototype.setConfirmed = function(confirmed) {
+ConfigManager.prototype.setConfirmed = function (confirmed) {
var data = this.getData()
data.isConfirmed = confirmed
this.setData(data)
}
-ConfigManager.prototype.getConfirmed = function() {
+ConfigManager.prototype.getConfirmed = function () {
var data = this.getData()
return ('isConfirmed' in data) && data.isConfirmed
}
-
-function loadData() {
-
+function loadData () {
var oldData = getOldStyleData()
var newData
try {
@@ -298,14 +295,14 @@ function loadData() {
config: {
provider: {
type: 'testnet',
- }
- }
- }
- }, oldData ? oldData : null, newData ? newData : null)
+ },
+ },
+ },
+ }, oldData || null, newData || null)
return data
}
-function getOldStyleData() {
+function getOldStyleData () {
var config, wallet, seedWords
var result = {