diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-05-23 07:48:10 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-05-23 07:48:10 +0800 |
commit | 13a41f3129299844c908965a25996ec5cd190eb1 (patch) | |
tree | a2b0241aa0db2732cb1afe680831768731e9d49a /app/scripts/lib | |
parent | f87ea49b5ac2d66d8f281f08f42e8cfd2d701ba7 (diff) | |
parent | c7fd9f424087b20bfc356d360d2a2246ca0e5ad7 (diff) | |
download | tangerine-wallet-browser-13a41f3129299844c908965a25996ec5cd190eb1.tar tangerine-wallet-browser-13a41f3129299844c908965a25996ec5cd190eb1.tar.gz tangerine-wallet-browser-13a41f3129299844c908965a25996ec5cd190eb1.tar.bz2 tangerine-wallet-browser-13a41f3129299844c908965a25996ec5cd190eb1.tar.lz tangerine-wallet-browser-13a41f3129299844c908965a25996ec5cd190eb1.tar.xz tangerine-wallet-browser-13a41f3129299844c908965a25996ec5cd190eb1.tar.zst tangerine-wallet-browser-13a41f3129299844c908965a25996ec5cd190eb1.zip |
Merge branch 'master' into networkController
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/config-manager.js | 34 | ||||
-rw-r--r-- | app/scripts/lib/migrator/index.js | 33 |
2 files changed, 47 insertions, 20 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 1098cc474..6ca9bd9ea 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -1,6 +1,14 @@ const ethUtil = require('ethereumjs-util') const normalize = require('eth-sig-util').normalize +<<<<<<< HEAD +======= +const MAINNET_RPC = MetamaskConfig.network.mainnet +const ROPSTEN_RPC = MetamaskConfig.network.ropsten +const KOVAN_RPC = MetamaskConfig.network.kovan +const RINKEBY_RPC = MetamaskConfig.network.rinkeby + +>>>>>>> master /* The config-manager is a convenience object * wrapping a pojo-migrator. * @@ -101,6 +109,32 @@ ConfigManager.prototype.getSeedWords = function () { return data.seedWords } +ConfigManager.prototype.getCurrentRpcAddress = function () { + var provider = this.getProvider() + if (!provider) return null + switch (provider.type) { + + case 'mainnet': + return MAINNET_RPC + + case 'ropsten': + return ROPSTEN_RPC + + case 'kovan': + return KOVAN_RPC + + case 'rinkeby': + return RINKEBY_RPC + + default: + return provider && provider.rpcTarget ? provider.rpcTarget : RINKEBY_RPC + } +} + +// +// Tx +// + ConfigManager.prototype.getTxList = function () { var data = this.getData() if (data.transactions !== undefined) { diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index c40c347b5..de6f5d5cd 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -1,42 +1,35 @@ -const asyncQ = require('async-q') - class Migrator { constructor (opts = {}) { const migrations = opts.migrations || [] + // sort migrations by version this.migrations = migrations.sort((a, b) => a.version - b.version) + // grab migration with highest version const lastMigration = this.migrations.slice(-1)[0] // use specified defaultVersion or highest migration version this.defaultVersion = opts.defaultVersion || (lastMigration && lastMigration.version) || 0 } // run all pending migrations on meta in place - migrateData (versionedData = this.generateInitialState()) { - const remaining = this.migrations.filter(migrationIsPending) + async migrateData (versionedData = this.generateInitialState()) { + const pendingMigrations = this.migrations.filter(migrationIsPending) + + for (let index in pendingMigrations) { + let migration = pendingMigrations[index] + versionedData = await migration.migrate(versionedData) + if (!versionedData.data) throw new Error('Migrator - migration returned empty data') + if (versionedData.version !== undefined && versionedData.meta.version !== migration.version) throw new Error('Migrator - Migration did not update version number correctly') + } - return ( - asyncQ.eachSeries(remaining, (migration) => this.runMigration(versionedData, migration)) - .then(() => versionedData) - ) + return versionedData - // migration is "pending" if hit has a higher + // migration is "pending" if it has a higher // version number than currentVersion function migrationIsPending (migration) { return migration.version > versionedData.meta.version } } - runMigration (versionedData, migration) { - return ( - migration.migrate(versionedData) - .then((versionedData) => { - if (!versionedData.data) return Promise.reject(new Error('Migrator - Migration returned empty data')) - if (migration.version !== undefined && versionedData.meta.version !== migration.version) return Promise.reject(new Error('Migrator - Migration did not update version number correctly')) - return Promise.resolve(versionedData) - }) - ) - } - generateInitialState (initState) { return { meta: { |