Skip to content

Commit

Permalink
fix: celo and default network fee
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed Dec 12, 2023
1 parent 42c2093 commit 455f011
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
38 changes: 14 additions & 24 deletions packages/extension/src/providers/ethereum/libs/transaction/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Web3Eth from "web3-eth";
import Web3Eth, { FeeHistoryResult } from "web3-eth";
import {
EthereumTransaction,
FinalizedFeeMarketEthereumTransaction,
Expand Down Expand Up @@ -69,26 +69,19 @@ class Transaction {
gasLimit: string;
formattedFeeHistory?: FormattedFeeHistory;
}> {
const { isFeeMarketNetwork, baseFeePerGas } = await this.web3
.getBlock("pending", false)
.then((block) => {
if (block) {
return {
isFeeMarketNetwork: !!block.baseFeePerGas,
baseFeePerGas: block.baseFeePerGas?.toString(),
};
}
// some networks such as zksync era pending block is null
return this.web3.getBlock("latest", false).then((block) => {
return {
isFeeMarketNetwork: !!block.baseFeePerGas,
baseFeePerGas: block.baseFeePerGas?.toString(),
};
});
});
const gasPrice = await this.web3.getGasPrice();
const { isFeeMarketNetwork, feeHistory } = await this.web3
.getFeeHistory(6, "latest", GAS_PERCENTILES)
.then((history) => ({
isFeeMarketNetwork: true,
feeHistory: history,
}))
.catch(() => ({
isFeeMarketNetwork: false,
feeHistory: {} as FeeHistoryResult,
}));
const nonce = await this.web3.getTransactionCount(this.tx.from, "pending");
if (!isFeeMarketNetwork) {
const gasPrice = await this.web3.getGasPrice();
const gasLimit =
this.tx.gasLimit ||
(numberToHex(await this.estimateGas()) as `0x${string}`);
Expand All @@ -114,11 +107,8 @@ class Transaction {
gasLimit: legacyTx.gasLimit,
};
} else {
const feeHistory = await this.web3.getFeeHistory(
6,
"latest",
GAS_PERCENTILES
);
const baseFeePerGas =
feeHistory.baseFeePerGas[feeHistory.baseFeePerGas.length - 2]; // -2 since -1 is the pending block
const formattedFeeHistory = formatFeeHistory(feeHistory);
const feeMarket = this.getFeeMarketGasInfo(
baseFeePerGas!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import { bigIntToBuffer, bigIntToHex, fromBase } from "@enkryptcom/utils";
import broadcastTx from "../libs/tx-broadcaster";
import TokenSigs from "../libs/transaction/lists/tokenSigs";
import AlertIcon from "@action/icons/send/alert-icon.vue";
import { NetworkNames } from "@enkryptcom/types";
const isProcessing = ref(false);
const isOpenSelectFee = ref(false);
Expand All @@ -182,7 +183,7 @@ const Options = ref<ProviderRequestOptions>({
url: "",
tabId: 0,
});
const selectedFee = ref<GasPriceTypes>(GasPriceTypes.REGULAR);
const selectedFee = ref<GasPriceTypes>(GasPriceTypes.ECONOMY);
defineExpose({ providerVerifyTransactionScrollRef });
Expand All @@ -191,6 +192,10 @@ onBeforeMount(async () => {
network.value = (await getNetworkByName(
Request.value.params![2]
)) as EvmNetwork;
selectedFee.value =
network.value.name === NetworkNames.Ethereum
? GasPriceTypes.REGULAR
: GasPriceTypes.ECONOMY;
account.value = Request.value.params![1] as EnkryptAccount;
identicon.value = network.value.identicon(account.value.address);
Options.value = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ import Browser from "webextension-polyfill";
import { ProviderName } from "@/types/provider";
import PublicKeyRing from "@/libs/keyring/public-keyring";
import { GenericNameResolver, CoinType } from "@/libs/name-resolver";
import { NetworkNames } from "@enkryptcom/types";
const props = defineProps({
network: {
Expand Down Expand Up @@ -214,7 +215,11 @@ const sendAmount = computed(() => {
return "0";
});
const isMaxSelected = ref<boolean>(false);
const selectedFee = ref<GasPriceTypes>(GasPriceTypes.REGULAR);
const selectedFee = ref<GasPriceTypes>(
props.network.name === NetworkNames.Ethereum
? GasPriceTypes.REGULAR
: GasPriceTypes.ECONOMY
);
const gasCostValues = ref<GasFeeType>(defaultGasCostVals);
const addressFrom = ref<string>(
props.accountInfo.selectedAccount?.address ?? ""
Expand Down

1 comment on commit 455f011

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.