From 2b5009ee15cab2f22dddc09580e466f365b13773 Mon Sep 17 00:00:00 2001 From: Hicaru Date: Mon, 24 Oct 2022 13:27:54 +0300 Subject: [PATCH] fixed gasPrice detect --- core/background/background/transaction.ts | 8 ++++++-- core/background/gas/gas.ts | 6 ++++-- popup/store/gas.ts | 6 ++++-- types/gas.d.ts | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/core/background/background/transaction.ts b/core/background/background/transaction.ts index 01acf6e..0791989 100644 --- a/core/background/background/transaction.ts +++ b/core/background/background/transaction.ts @@ -91,16 +91,20 @@ export class BackgroundTransaction { }; } + + if (!params.gasPrice) { + params.gasPrice = this.#core.gas.state.gasPrice * this.#core.gas.state.multiplier; + } + const prompt = new PromptService( this.#core.settings.popup.enabledPopup && Boolean(params.uuid) ); const gasLimit = params.gasLimit ?? this.#core.gas.state.gasLimit; - const gasPrice = params.gasPrice ?? this.#core.gas.state.multiplier; const confirmParams: ConfirmParams = { ...params, tokenAmount: String(params.amount), - fee: gasLimit * gasPrice, + fee: Number(gasLimit) * Number(params.gasPrice), recipient: params.toAddr }; diff --git a/core/background/gas/gas.ts b/core/background/gas/gas.ts index 82c157e..c576fb2 100644 --- a/core/background/gas/gas.ts +++ b/core/background/gas/gas.ts @@ -2,19 +2,21 @@ import type { GasState } from 'types/gas'; import { Fields } from 'config/fields'; import { BrowserStorage, buildObject } from 'lib/storage'; -import { GAS_LIMIT, MULTIPLIER } from 'config/gas'; +import { GAS_LIMIT, GAS_PRICE, MULTIPLIER } from 'config/gas'; import { TypeOf } from 'lib/type'; import { GasError, INVALID_STATE, INVALID_GAS_LIMIT, INVALID_MULTIPLIER } from './errors'; export class GasControl { #gasLimit = GAS_LIMIT; + #gasPrice = GAS_PRICE; #multiplier = MULTIPLIER; get state(): GasState { return { gasLimit: this.#gasLimit, - multiplier: this.#multiplier + multiplier: this.#multiplier, + gasPrice: this.#gasPrice }; } diff --git a/popup/store/gas.ts b/popup/store/gas.ts index 5e618d6..5b0f8fa 100644 --- a/popup/store/gas.ts +++ b/popup/store/gas.ts @@ -1,9 +1,11 @@ import type { GasState } from 'types'; import { writable } from 'svelte/store'; +import { GAS_LIMIT, GAS_PRICE, MULTIPLIER } from 'config/gas'; export default writable({ - gasLimit: 1, - multiplier: 1 + gasLimit: GAS_LIMIT, + multiplier: MULTIPLIER, + gasPrice: GAS_PRICE }); diff --git a/types/gas.d.ts b/types/gas.d.ts index 5934d67..68e0a6d 100644 --- a/types/gas.d.ts +++ b/types/gas.d.ts @@ -1,4 +1,5 @@ export interface GasState { gasLimit: number; + gasPrice: number; multiplier: number; }