From b7bd508856f37dea27413bf78a88980c57bf8103 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:48:55 -0800 Subject: [PATCH] devop: evm-disable send if estimate fail --- .../ethereum/ui/send-transaction/index.vue | 86 ++++++++++--------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue index 03fe200c5..c493c7713 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue @@ -201,6 +201,7 @@ const selected: string = route.params.id as string; const accountAssets = ref([]); const selectedAsset = ref>(loadingAsset); const amount = ref(""); +const isEstimateValid = ref(true); const hasEnoughBalance = computed(() => { if (!isValidDecimals(sendAmount.value, selectedAsset.value.decimals!)) { return false; @@ -319,45 +320,51 @@ const nativeBalanceAfterTransaction = computed(() => { }); const setTransactionFees = (tx: Transaction) => { - return tx.getGasCosts().then(async (gasvals) => { - const getConvertedVal = (type: GasPriceTypes) => - fromBase(gasvals[type], props.network.decimals); - const nativeVal = accountAssets.value[0].price || "0"; - gasCostValues.value = { - [GasPriceTypes.ECONOMY]: { - nativeValue: getConvertedVal(GasPriceTypes.ECONOMY), - fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.ECONOMY)) - .times(nativeVal!) - .toString(), - nativeSymbol: props.network.currencyName, - fiatSymbol: "USD", - }, - [GasPriceTypes.REGULAR]: { - nativeValue: getConvertedVal(GasPriceTypes.REGULAR), - fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.REGULAR)) - .times(nativeVal!) - .toString(), - nativeSymbol: props.network.currencyName, - fiatSymbol: "USD", - }, - [GasPriceTypes.FAST]: { - nativeValue: getConvertedVal(GasPriceTypes.FAST), - fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.FAST)) - .times(nativeVal!) - .toString(), - nativeSymbol: props.network.currencyName, - fiatSymbol: "USD", - }, - [GasPriceTypes.FASTEST]: { - nativeValue: getConvertedVal(GasPriceTypes.FASTEST), - fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.FASTEST)) - .times(nativeVal!) - .toString(), - nativeSymbol: props.network.currencyName, - fiatSymbol: "USD", - }, - }; - }); + return tx + .getGasCosts() + .then(async (gasvals) => { + const getConvertedVal = (type: GasPriceTypes) => + fromBase(gasvals[type], props.network.decimals); + const nativeVal = accountAssets.value[0].price || "0"; + gasCostValues.value = { + [GasPriceTypes.ECONOMY]: { + nativeValue: getConvertedVal(GasPriceTypes.ECONOMY), + fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.ECONOMY)) + .times(nativeVal!) + .toString(), + nativeSymbol: props.network.currencyName, + fiatSymbol: "USD", + }, + [GasPriceTypes.REGULAR]: { + nativeValue: getConvertedVal(GasPriceTypes.REGULAR), + fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.REGULAR)) + .times(nativeVal!) + .toString(), + nativeSymbol: props.network.currencyName, + fiatSymbol: "USD", + }, + [GasPriceTypes.FAST]: { + nativeValue: getConvertedVal(GasPriceTypes.FAST), + fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.FAST)) + .times(nativeVal!) + .toString(), + nativeSymbol: props.network.currencyName, + fiatSymbol: "USD", + }, + [GasPriceTypes.FASTEST]: { + nativeValue: getConvertedVal(GasPriceTypes.FASTEST), + fiatValue: new BigNumber(getConvertedVal(GasPriceTypes.FASTEST)) + .times(nativeVal!) + .toString(), + nativeSymbol: props.network.currencyName, + fiatSymbol: "USD", + }, + }; + isEstimateValid.value = true; + }) + .catch(() => { + isEstimateValid.value = false; + }); }; const setBaseCosts = () => { @@ -400,6 +407,7 @@ const sendButtonTitle = computed(() => { }); const isInputsValid = computed(() => { + if (!isEstimateValid.value) return false; if (!props.network.isAddress(addressTo.value)) return false; if (!isValidDecimals(sendAmount.value, selectedAsset.value.decimals!)) { return false;