From d4b106a98c78b5fbe2befd8f77971e4a2598b386 Mon Sep 17 00:00:00 2001 From: Andre Goncalves Date: Mon, 3 May 2021 10:01:02 +0100 Subject: [PATCH] feat: safe gas multiplier set to 1.5, configurable via env vars --- src/common/config.js | 4 +++- src/main/token/token-service.js | 12 +++++++++++- .../wallet-connect/transaction-container.jsx | 2 -- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/config.js b/src/common/config.js index a205010c1..1ecd5a31b 100644 --- a/src/common/config.js +++ b/src/common/config.js @@ -28,6 +28,8 @@ const REWARD_TOKEN = process.env.REWARD_TOKEN_OVERRIDE ? process.env.REWARD_TOKEN_OVERRIDE.toUpperCase() : null; +const SAFE_GAS_MULTIPLIER = +process.env.SAFE_GAS_MULTIPLIER; + // KYCC ENV variables const KYCC_API_OVERRIDE = process.env.KYCC_API_OVERRIDE; // Incorporations ENV variables @@ -43,7 +45,6 @@ const BANKACCOUNTS_API_URL = process.env.BANKACCOUNTS_API_URL; const PASSPORTS_TEMPLATE_OVERRIDE = process.env.PASSPORTS_TEMPLATE_OVERRIDE; const PASSPORTS_PRICE_OVERRIDE = process.env.PASSPORTS_PRICE_OVERRIDE; const PASSPORTS_API_URL = process.env.PASSPORTS_API_URL; - const COUNTRY_INFO_URL = process.env.COUNTRY_INFO_URL; const ALL_COUNTRIES_INFO_URL = process.env.ALL_COUNTRIES_INFO_URL; const MATOMO_SITE = process.env.MATOMO_SITE; @@ -64,6 +65,7 @@ const common = { defaultLanguage: 'en', forceUpdateAttributes: process.env.FORCE_UPDATE_ATTRIBUTES === 'true' && !isTestMode(), userAgent: `SelfKeyIDW/${pkg.version}`, + safeGasMultiplier: SAFE_GAS_MULTIPLIER || 1.5, airtableBaseUrl: 'https://airtable.selfkey.org/airtable?tableName=', exchangeRateApiUrl: 'https://api.exchangeratesapi.io', diff --git a/src/main/token/token-service.js b/src/main/token/token-service.js index 8c3319854..7fec4743b 100644 --- a/src/main/token/token-service.js +++ b/src/main/token/token-service.js @@ -1,4 +1,5 @@ 'use strict'; +import config from 'common/config'; import Token from './token'; import { getGlobalContext } from 'common/context'; import { BigNumber } from 'bignumber.js'; @@ -51,6 +52,15 @@ export class TokenService { }; } + /** + * + * @param {*} contractAddress + * @param {*} address + * @param {*} amount + * @param {*} decimal + * @param {*} fromAddress + * @returns + */ async getGasLimit(contractAddress, address, amount, decimal, fromAddress) { const tokenContract = new this.web3Service.web3.eth.Contract( this.contractABI, @@ -63,7 +73,7 @@ export class TokenService { const estimate = await tokenContract.methods .transfer(address, amountWithDecimals) .estimateGas({ from: fromAddress }); - return Math.round(Math.min(estimate * 1.1, MAX_GAS)); + return Math.round(Math.min(estimate * config.safeGasMultiplier, MAX_GAS)); } } diff --git a/src/renderer/wallet-connect/transaction-container.jsx b/src/renderer/wallet-connect/transaction-container.jsx index e08e51c7e..6f6074eb3 100644 --- a/src/renderer/wallet-connect/transaction-container.jsx +++ b/src/renderer/wallet-connect/transaction-container.jsx @@ -25,8 +25,6 @@ export const TransactionContainer = () => { walletConnectSelectors.selectWalletConnect ); - console.log(tx); - const [gasPrice, setGasPrice] = useState(tx.gasPrice); const [gasLimit, setGasLimit] = useState(tx.gas); const [nonce, setNonce] = useState(tx.nonce ? tx.nonce : defaultNonce);