Merge pull request #369 from poanetwork/vb-rsk-gas-price

RSK: fix GasPrice calculation (changed output of minimumGasPrice)
This commit is contained in:
Victor Baranov 2020-04-29 17:15:51 +03:00 committed by GitHub
commit 13dc7f5ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View File

@ -2,6 +2,7 @@
## Current Master ## Current Master
- [#369](https://github.com/poanetwork/nifty-wallet/pull/369) - (Fix) RSK: fix GasPrice calculation (changed interface of minimumGasPrice - hex instead of integer)
- [#368](https://github.com/poanetwork/nifty-wallet/pull/368) - (Fix) Ability to import Keystore file if it is not secured by password - [#368](https://github.com/poanetwork/nifty-wallet/pull/368) - (Fix) Ability to import Keystore file if it is not secured by password
- [#366](https://github.com/poanetwork/nifty-wallet/pull/366) - (Fix) Increase max token symbol length up to 12 - [#366](https://github.com/poanetwork/nifty-wallet/pull/366) - (Fix) Increase max token symbol length up to 12
- [#363](https://github.com/poanetwork/nifty-wallet/pull/363) - (Fix) token decimals display in pending tx screen - [#363](https://github.com/poanetwork/nifty-wallet/pull/363) - (Fix) token decimals display in pending tx screen

View File

@ -1886,7 +1886,7 @@ module.exports = class MetamaskController extends EventEmitter {
resolve(gasPrice) resolve(gasPrice)
} }
} else if (isRSK) { } else if (isRSK) {
gasPrice = this.getGasPriceFromLastBlockRSK(networkId) gasPrice = this.getGasPriceFromLastBlockRSK()
resolve(gasPrice) resolve(gasPrice)
} else { } else {
gasPrice = this.getGasPriceFromBlocks(networkId) gasPrice = this.getGasPriceFromBlocks(networkId)
@ -1937,19 +1937,17 @@ module.exports = class MetamaskController extends EventEmitter {
* Related issue: https://github.com/poanetwork/nifty-wallet/issues/301 * Related issue: https://github.com/poanetwork/nifty-wallet/issues/301
* @returns {string} A hex representation of the suggested wei gas price. * @returns {string} A hex representation of the suggested wei gas price.
*/ */
getGasPriceFromLastBlockRSK (networkId) { getGasPriceFromLastBlockRSK () {
const { recentBlocksController } = this const { recentBlocksController } = this
const { recentBlocks } = recentBlocksController.store.getState() const { recentBlocks } = recentBlocksController.store.getState()
const recentBlock = recentBlocks const recentBlock = recentBlocks
.sort((block1, block2) => block1.number - block2.number)[recentBlocks.length - 1] .sort((block1, block2) => block1.number - block2.number)[recentBlocks.length - 1]
const gasPrice = recentBlock && recentBlock.minimumGasPrice const gasPrice = recentBlock && recentBlock.minimumGasPrice && recentBlock.minimumGasPrice.toString()
const gasPriceInt = parseInt(gasPrice, 10) if (gasPrice !== '0x' && gasPrice !== '0x0' && gasPrice !== '') {
return gasPrice
if (gasPriceInt !== 0) {
return '0x' + gasPriceInt.toString(16)
} else { } else {
return '0x' + GWEI_BN.toString(16) return '0x' + GWEI_BN.toString(16)
} }

View File

@ -161,9 +161,9 @@ describe('MetaMaskController', function () {
getState: () => { getState: () => {
return { return {
recentBlocks: [ recentBlocks: [
{ number: '0x1', minimumGasPrice: '59240010' }, { number: '0x1', minimumGasPrice: '0x387ee48' },
{ number: '0x2', minimumGasPrice: '59240005' }, { number: '0x2', minimumGasPrice: '0x387ee42' },
{ number: '0x3', minimumGasPrice: '59240000' }, { number: '0x3', minimumGasPrice: '0x387ee40' },
], ],
} }
}, },
@ -175,7 +175,7 @@ describe('MetaMaskController', function () {
getState: () => { getState: () => {
return { return {
recentBlocks: [ recentBlocks: [
{ number: '0x4', minimumGasPrice: '0' }, { number: '0x4', minimumGasPrice: '0x' },
], ],
} }
}, },