Skip to content

Commit

Permalink
fixed gasPrice detect
Browse files Browse the repository at this point in the history
  • Loading branch information
Hicaru committed Oct 24, 2022
1 parent be13744 commit 2b5009e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
8 changes: 6 additions & 2 deletions core/background/background/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
6 changes: 4 additions & 2 deletions core/background/gas/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
6 changes: 4 additions & 2 deletions popup/store/gas.ts
Original file line number Diff line number Diff line change
@@ -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<GasState>({
gasLimit: 1,
multiplier: 1
gasLimit: GAS_LIMIT,
multiplier: MULTIPLIER,
gasPrice: GAS_PRICE
});
1 change: 1 addition & 0 deletions types/gas.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface GasState {
gasLimit: number;
gasPrice: number;
multiplier: number;
}

0 comments on commit 2b5009e

Please sign in to comment.