diff --git a/app/src/main/java/com/alphawallet/app/service/GasService.java b/app/src/main/java/com/alphawallet/app/service/GasService.java index db891d9ab7..c00f431dc3 100644 --- a/app/src/main/java/com/alphawallet/app/service/GasService.java +++ b/app/src/main/java/com/alphawallet/app/service/GasService.java @@ -380,6 +380,8 @@ public Single calculateGasEstimateInternal(byte[] transactionBytes, updateChainId(chainId); String finalTxData = txData; + BigInteger useGasLimit = defaultLimit.equals(BigInteger.ZERO) ? EthereumNetworkBase.getMaxGasLimit(chainId) : defaultLimit; + if ((toAddress.equals("") || toAddress.equals(ZERO_ADDRESS)) && txData.length() > 0) //Check gas for constructor { return networkRepository.getLastTransactionNonce(web3j, wallet.address) @@ -389,7 +391,7 @@ public Single calculateGasEstimateInternal(byte[] transactionBytes, else { return networkRepository.getLastTransactionNonce(web3j, wallet.address) - .flatMap(nonce -> ethEstimateGas(chainId, wallet.address, nonce, toAddress, amount, finalTxData)) + .flatMap(nonce -> ethEstimateGas(chainId, wallet.address, useGasLimit, nonce, toAddress, amount, finalTxData)) .flatMap(estimate -> handleOutOfGasError(estimate, chainId, toAddress, amount, finalTxData)) .map(estimate -> convertToGasLimit(estimate, defaultLimit)); } @@ -427,7 +429,7 @@ private Single handleOutOfGasError(@NonNull EthEstimateGas estim { if (!estimate.hasError() || chainId != 1) return Single.fromCallable(() -> estimate); else return networkRepository.getLastTransactionNonce(web3j, WHALE_ACCOUNT) - .flatMap(nonce -> ethEstimateGas(chainId, WHALE_ACCOUNT, nonce, toAddress, amount, finalTxData)); + .flatMap(nonce -> ethEstimateGas(chainId, WHALE_ACCOUNT, EthereumNetworkBase.getMaxGasLimit(chainId), nonce, toAddress, amount, finalTxData)); } private BigInteger getLowGasPrice() @@ -443,14 +445,14 @@ private Single ethEstimateGas(String fromAddress, BigInteger non return Single.fromCallable(() -> web3j.ethEstimateGas(transaction).send()); } - private Single ethEstimateGas(long chainId, String fromAddress, BigInteger nonce, String toAddress, + private Single ethEstimateGas(long chainId, String fromAddress, BigInteger limit, BigInteger nonce, String toAddress, BigInteger amount, String txData) { final Transaction transaction = new Transaction ( fromAddress, nonce, currentGasPrice, - EthereumNetworkBase.getMaxGasLimit(chainId), + limit, toAddress, amount, txData); diff --git a/app/src/main/java/com/alphawallet/app/service/TickerService.java b/app/src/main/java/com/alphawallet/app/service/TickerService.java index 2524498b3e..785737dce6 100644 --- a/app/src/main/java/com/alphawallet/app/service/TickerService.java +++ b/app/src/main/java/com/alphawallet/app/service/TickerService.java @@ -4,6 +4,7 @@ import static com.alphawallet.ethereum.EthereumNetworkBase.ARBITRUM_MAIN_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.AURORA_MAINNET_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.AVALANCHE_ID; +import static com.alphawallet.ethereum.EthereumNetworkBase.BASE_MAINNET_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.BINANCE_MAIN_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.CLASSIC_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.CRONOS_MAIN_ID; @@ -837,6 +838,7 @@ private void resetTickerUpdate() put(CRONOS_MAIN_ID, "cronos"); put(ROOTSTOCK_MAINNET_ID, "rootstock"); put(LINEA_ID, "linea"); + put(BASE_MAINNET_ID, "base"); }}; // For now, don't use Dexguru unless we obtain API key @@ -875,6 +877,7 @@ public void deleteTickers() put(OKX_ID, "okb"); put(ROOTSTOCK_MAINNET_ID, "rootstock"); put(LINEA_ID, "ethereum"); + put(BASE_MAINNET_ID, "base"); }}; public static boolean validateCoinGeckoAPI(Token token) diff --git a/app/src/main/java/com/alphawallet/app/ui/widget/entity/GasWidgetInterface.java b/app/src/main/java/com/alphawallet/app/ui/widget/entity/GasWidgetInterface.java index 27b30c6a11..90689dc04b 100644 --- a/app/src/main/java/com/alphawallet/app/ui/widget/entity/GasWidgetInterface.java +++ b/app/src/main/java/com/alphawallet/app/ui/widget/entity/GasWidgetInterface.java @@ -23,6 +23,7 @@ public interface GasWidgetInterface BigInteger getPriorityFee(); BigInteger getGasPrice(); void setGasEstimate(BigInteger estimate); + void setGasEstimateExact(BigInteger estimate); void onDestroy(); boolean checkSufficientGas(); void setupResendSettings(ActionSheetMode mode, BigInteger gasPrice); diff --git a/app/src/main/java/com/alphawallet/app/web3/entity/Web3Transaction.java b/app/src/main/java/com/alphawallet/app/web3/entity/Web3Transaction.java index 140555e078..265945e97d 100644 --- a/app/src/main/java/com/alphawallet/app/web3/entity/Web3Transaction.java +++ b/app/src/main/java/com/alphawallet/app/web3/entity/Web3Transaction.java @@ -197,7 +197,8 @@ public Web3Transaction( public Web3Transaction(WCEthereumTransaction wcTx, long callbackId, SignType signType) { String gasPrice = wcTx.getGasPrice() != null ? wcTx.getGasPrice() : "0"; - String gasLimit = wcTx.getGasLimit() != null ? wcTx.getGasLimit() : "0"; + //WC2 uses "gas" for gas limit + String gasLimit = wcTx.getGas() != null ? wcTx.getGas() : "0"; String nonce = wcTx.getNonce() != null ? wcTx.getNonce() : ""; this.recipient = TextUtils.isEmpty(wcTx.getTo()) ? Address.EMPTY : new Address(wcTx.getTo()); diff --git a/app/src/main/java/com/alphawallet/app/widget/ActionSheetDialog.java b/app/src/main/java/com/alphawallet/app/widget/ActionSheetDialog.java index 61790836a2..b3b2cc3a3c 100644 --- a/app/src/main/java/com/alphawallet/app/widget/ActionSheetDialog.java +++ b/app/src/main/java/com/alphawallet/app/widget/ActionSheetDialog.java @@ -156,7 +156,8 @@ public ActionSheetDialog(@NonNull Activity activity, Web3Transaction tx, Token t if (!tx.gasLimit.equals(BigInteger.ZERO)) { - setGasEstimate(new GasEstimate(tx.gasLimit)); + gasWidgetInterface.setGasEstimateExact(tx.gasLimit); + functionBar.setPrimaryButtonEnabled(true); } updateAmount(); diff --git a/app/src/main/java/com/alphawallet/app/widget/GasWidget.java b/app/src/main/java/com/alphawallet/app/widget/GasWidget.java index 1b0d57d372..b6b595a0c1 100644 --- a/app/src/main/java/com/alphawallet/app/widget/GasWidget.java +++ b/app/src/main/java/com/alphawallet/app/widget/GasWidget.java @@ -580,6 +580,12 @@ public void setGasEstimate(BigInteger estimate) estimate = estimate.multiply(BigInteger.valueOf(6)).divide(BigInteger.valueOf(5)); // increase estimate by 20% to be safe } + setGasEstimateExact(estimate); + } + + @Override + public void setGasEstimateExact(BigInteger estimate) + { //Override custom gas limit if (customGasLimit.equals(baseLineGasLimit)) { diff --git a/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java b/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java index 477326a40c..b4b740ead4 100644 --- a/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java +++ b/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java @@ -534,12 +534,17 @@ public long getExpectedTransactionTime() */ public void setGasEstimate(BigInteger estimate) { - if (estimate.longValue() > C.GAS_LIMIT_MIN) //some kind of contract interaction + if (!customGasLimit.equals(estimate) && estimate.longValue() > C.GAS_LIMIT_MIN) //some kind of contract interaction { estimate = estimate.multiply(BigInteger.valueOf(6)).divide(BigInteger.valueOf(5)); // increase estimate by 20% to be safe } - //Override custom gas limit if required + setGasEstimateExact(estimate); + } + + @Override + public void setGasEstimateExact(BigInteger estimate) + { if (customGasLimit.equals(presetGasLimit)) { customGasLimit = estimate;