aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-03-09 01:28:36 +0800
committerGitHub <noreply@github.com>2017-03-09 01:28:36 +0800
commit86f71d504cc3acd758958f883520fe913903a2c2 (patch)
tree7d6bcabbde524f5bad1d6f45802af77a12778c07 /app
parent0ee8ca178e9240ab25454bafc88c58ebef6b69c3 (diff)
parentde5a30c5ff3acbcda7a46a3caba70a622308dbb2 (diff)
downloadtangerine-wallet-browser-86f71d504cc3acd758958f883520fe913903a2c2.tar.gz
tangerine-wallet-browser-86f71d504cc3acd758958f883520fe913903a2c2.tar.zst
tangerine-wallet-browser-86f71d504cc3acd758958f883520fe913903a2c2.zip
Merge branch 'master' into i1144-moarrpc
Diffstat (limited to 'app')
-rw-r--r--app/scripts/keyring-controller.js23
-rw-r--r--app/scripts/lib/tx-utils.js13
2 files changed, 30 insertions, 6 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index e1b1c4335..72f613641 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -164,8 +164,11 @@ class KeyringController extends EventEmitter {
return keyring.getAccounts()
})
.then((accounts) => {
+ return this.checkForDuplicate(type, accounts)
+ })
+ .then((checkedAccounts) => {
this.keyrings.push(keyring)
- return this.setupAccounts(accounts)
+ return this.setupAccounts(checkedAccounts)
})
.then(() => this.persistAllKeyrings())
.then(() => this.fullUpdate())
@@ -175,6 +178,24 @@ class KeyringController extends EventEmitter {
})
}
+ // For now just checks for simple key pairs
+ // but in the future
+ // should possibly add HD and other types
+ //
+ checkForDuplicate (type, newAccount) {
+ return this.getAccounts()
+ .then((accounts) => {
+ switch (type) {
+ case 'Simple Key Pair':
+ let isNotIncluded = !accounts.find((key) => key === newAccount[0] || key === ethUtil.stripHexPrefix(newAccount[0]))
+ return (isNotIncluded) ? Promise.resolve(newAccount) : Promise.reject(new Error('The account you\'re are trying to import is a duplicate'))
+ default:
+ return Promise.resolve(newAccount)
+ }
+ })
+ }
+
+
// Add New Account
// @number keyRingNum
//
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 19a2d430e..f5051eb8f 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -55,7 +55,7 @@ module.exports = class txProviderUtils {
// try adding an additional gas buffer to our estimation for safety
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
- const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn), 16)
+ const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16)
// added gas buffer is too high
if (estimationWithBuffer.gt(blockGasLimitBn)) {
txParams.gas = txData.estimatedGas
@@ -68,11 +68,14 @@ module.exports = class txProviderUtils {
return
}
- addGasBuffer (gas) {
- const gasBuffer = new BN('100000', 10)
+ addGasBuffer (gas, blockGasLimitHex) {
+ const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
- const correct = bnGas.add(gasBuffer)
- return ethUtil.addHexPrefix(correct.toString(16))
+ const bufferedGas = bnGas.muln(1.5)
+
+ if (bnGas.gt(blockGasLimitBn)) return gas
+ if (bufferedGas.lt(blockGasLimitBn)) return ethUtil.addHexPrefix(bufferedGas.toString(16))
+ return ethUtil.addHexPrefix(blockGasLimitBn.toString(16))
}
fillInTxParams (txParams, cb) {