diff --git a/atomic_defi_design/Dex/Components/DexSwitch.qml b/atomic_defi_design/Dex/Components/DexSwitch.qml index fc3c507334..0d9799dd2a 100644 --- a/atomic_defi_design/Dex/Components/DexSwitch.qml +++ b/atomic_defi_design/Dex/Components/DexSwitch.qml @@ -112,28 +112,28 @@ Switch { id: _label Layout.fillHeight: true - + Layout.alignment: Qt.AlignVCenter + visible: _label.text != '' font: control.font color: control.textColor leftPadding: _indicator.width + control.spacing horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: _label2.text != '' ? control.verticalCenter : undefined wrapMode: Label.Wrap - } DefaultText { id: _label2 Layout.fillHeight: true - + visible: _label2.text != '' font: DexTypo.caption color: control.textColor leftPadding: _indicator.width + control.spacing horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter wrapMode: Label.Wrap - } } diff --git a/atomic_defi_design/Dex/Constants/General.qml b/atomic_defi_design/Dex/Constants/General.qml index c5ac44e5e5..c75cc53bad 100644 --- a/atomic_defi_design/Dex/Constants/General.qml +++ b/atomic_defi_design/Dex/Constants/General.qml @@ -526,15 +526,20 @@ QtObject { } function tokenUnitName(type) { - return type === "ERC-20" ? "Gwei" : "Satoshi" + return type === "QRC-20" ? "Satoshi" : "Gwei" } function isParentCoin(ticker) { - return ticker === "KMD" || ticker === "ETH" || ticker === "QTUM" + return ["KMD", "ETH", "MATIC", "AVAX", "FTM", "QTUM"].includes(ticker) } function isTokenType(type) { - return type === "ERC-20" || type === "QRC-20" + return ["ERC-20", "QRC-20", "PLG-20", "AVX-20", "FTM-20"].includes(type) + } + + function getFeesTicker(coin_info) { + if (coin_info.has_parent_fees_ticker) + return coin_info.fees_ticker } function getParentCoin(type) { diff --git a/atomic_defi_design/Dex/Wallet/SendModal.qml b/atomic_defi_design/Dex/Wallet/SendModal.qml index bebdbc5077..288baadbee 100644 --- a/atomic_defi_design/Dex/Wallet/SendModal.qml +++ b/atomic_defi_design/Dex/Wallet/SendModal.qml @@ -69,7 +69,9 @@ MultipageModal } function isSpecialToken() { - return General.isTokenType(current_ticker_infos.type) + if (current_ticker_infos.hasOwnProperty("has_parent_fees_ticker")) + return current_ticker_infos.has_parent_fees_ticker + return false } function isERC20() { @@ -96,47 +98,41 @@ MultipageModal } function feeIsHigherThanAmount() { - if(!custom_fees_switch.checked) return false - - const amt = parseFloat(getCryptoAmount()) - const fee_amt = parseFloat(input_custom_fees.text) - return amt < fee_amt - } + if(!custom_fees_switch.checked) return false - function hasFunds() { - if(!General.hasEnoughFunds(true, api_wallet_page.ticker, "", "", _preparePage.cryptoSendMode ? input_amount.text : equivalentAmount.value)) - return false + const amount = parseFloat(getCryptoAmount()) - if(custom_fees_switch.checked) { - if(isSpecialToken()) { - const gas_limit = parseFloat(input_custom_fees_gas.text) - const gas_price = parseFloat(input_custom_fees_gas_price.text) + if(isSpecialToken()) { + const parent_ticker = General.getFeesTicker(current_ticker_infos) + const gas_limit = parseFloat(input_custom_fees_gas.text) + const gas_price = parseFloat(input_custom_fees_gas_price.text) + if (isNaN(gas_price) || isNaN(gas_limit)) return false - const unit = current_ticker_infos.type === "ERC-20" ? 1000000000 : 100000000 - const fee_parent_token = (gas_limit * gas_price)/unit + const unit = current_ticker_infos.type === "ERC-20" ? 1000000000 : 100000000 + const fee_parent_token = (gas_limit * gas_price)/unit - const parent_ticker = current_ticker_infos.type === "ERC-20" ? "ETH" : "QTUM" - if(api_wallet_page.ticker === parent_ticker) { - const amount = parseFloat(getCryptoAmount()) - const total_needed = amount + fee_parent_token - if(!General.hasEnoughFunds(true, parent_ticker, "", "", total_needed.toString())) - return false - } - else { - if(!General.hasEnoughFunds(true, parent_ticker, "", "", fee_parent_token.toString())) - return false - } + if(api_wallet_page.ticker === parent_ticker) { + const total_needed = amount + fee_parent_token + if(General.hasEnoughFunds(true, parent_ticker, "", "", total_needed.toString())) + return false } else { - if(feeIsHigherThanAmount()) return false - - if(!General.hasEnoughFunds(true, api_wallet_page.ticker, "", "", input_custom_fees.text)) + if(General.hasEnoughFunds(true, parent_ticker, "", "", fee_parent_token.toString())) return false } + return true + } + else { + const fee_amt = parseFloat(input_custom_fees.text) + return amount < fee_amt } + } - return true + function hasFunds() { + if(!General.hasEnoughFunds(true, api_wallet_page.ticker, "", "", _preparePage.cryptoSendMode ? input_amount.text : equivalentAmount.value)) + return false + return true } function feesAreFilled() { @@ -334,13 +330,15 @@ MultipageModal visible: errorView && input_address.text !== "" Layout.alignment: Qt.AlignHCenter Layout.fillWidth: true + spacing: 4 + + Item { Layout.fillWidth: true } DefaultText { id: reason Layout.alignment: Qt.AlignVCenter - Layout.fillWidth: true wrapMode: Text.WrapAtWordBoundaryOrAnywhere color: Dex.CurrentTheme.noColor @@ -361,6 +359,8 @@ MultipageModal onClicked: api_wallet_page.convert_address(input_address.text, address_data.to_address_format) } + + Item { Layout.fillWidth: true } } // Amount to send @@ -566,15 +566,18 @@ MultipageModal { Layout.preferredWidth: 380 Layout.alignment: Qt.AlignHCenter + Layout.topMargin: 32 // Custom fees switch DefaultSwitch { id: custom_fees_switch enabled: !root.is_send_busy - Layout.topMargin: 32 - label.text: qsTr("Enable Custom Fees") + Layout.preferredWidth: 260 onCheckedChanged: input_custom_fees.text = "" + labelWidth: 200 + label.text: qsTr("Enable Custom Fees") + label.wrapMode: Label.NoWrap } // Custom fees warning @@ -582,6 +585,8 @@ MultipageModal { visible: custom_fees_switch.checked font.pixelSize: 14 + Layout.alignment: Qt.AlignHCenter + horizontalAlignment: DefaultText.AlignHCenter color: Dex.CurrentTheme.noColor text_value: qsTr("Only use custom fees if you know what you are doing!") } @@ -593,12 +598,13 @@ MultipageModal visible: custom_fees_switch.checked Layout.preferredWidth: parent.width + Layout.alignment: Qt.AlignHCenter Layout.topMargin: 8 // Normal coins, Custom fees input AmountField { - visible: !isSpecialToken() + visible: !isSpecialToken() && !isParentCoin(api_wallet_page.ticker) id: input_custom_fees @@ -651,10 +657,12 @@ MultipageModal visible: feeIsHigherThanAmount() Layout.alignment: Qt.AlignHCenter + horizontalAlignment: DefaultText.AlignHCenter wrapMode: Text.Wrap color: Style.colorRed - text_value: qsTr("Custom Fee can't be higher than the amount") + text_value: qsTr("Custom Fee can't be higher than the amount") + "\n" + + qsTr("You have %1", "AMT TICKER").arg(General.formatCrypto("", API.app.get_balance(General.getFeesTicker(current_ticker_infos)), General.getFeesTicker(current_ticker_infos))) } } @@ -662,12 +670,15 @@ MultipageModal DefaultText { Layout.topMargin: 16 + Layout.alignment: Qt.AlignHCenter + horizontalAlignment: DefaultText.AlignHCenter wrapMode: Text.Wrap visible: !fee_error.visible && !hasFunds() color: Dex.CurrentTheme.noColor - text_value: qsTr("Not enough funds.") + "\n" + qsTr("You have %1", "AMT TICKER").arg(General.formatCrypto("", API.app.get_balance(api_wallet_page.ticker), api_wallet_page.ticker)) + text_value: qsTr("Not enough funds.") + "\n" + + qsTr("You have %1", "AMT TICKER").arg(General.formatCrypto("", API.app.get_balance(api_wallet_page.ticker), api_wallet_page.ticker)) } DexBusyIndicator { visible: root.is_send_busy } diff --git a/src/core/atomicdex/api/mm2/rpc.withdraw.cpp b/src/core/atomicdex/api/mm2/rpc.withdraw.cpp index fbbb291aa0..dd4b51b052 100644 --- a/src/core/atomicdex/api/mm2/rpc.withdraw.cpp +++ b/src/core/atomicdex/api/mm2/rpc.withdraw.cpp @@ -24,6 +24,12 @@ namespace mm2::api j["gas_limit"] = cfg.gas_limit.value_or(40); j["gas_price"] = std::stoi(cfg.gas_price.value()); } + else if (cfg.type == "otherGas") + { + j["type"] = "EthGas"; + j["gas"] = cfg.gas_limit.value_or(55000); + j["gas_price"] = std::stoi(cfg.gas_price.value()); + } else { j["amount"] = cfg.amount.value(); diff --git a/src/core/atomicdex/pages/qt.wallet.page.cpp b/src/core/atomicdex/pages/qt.wallet.page.cpp index 2b801f81b9..57532f71a3 100644 --- a/src/core/atomicdex/pages/qt.wallet.page.cpp +++ b/src/core/atomicdex/pages/qt.wallet.page.cpp @@ -274,6 +274,8 @@ namespace atomic_dex obj["type"] = QString::fromStdString(coin_info.type); obj["segwit_supported"] = coin_info.segwit; obj["is_segwit_on"] = coin_info.is_segwit_on; + obj["has_parent_fees_ticker"] = coin_info.has_parent_fees_ticker; + obj["fees_ticker"] = QString::fromStdString(coin_info.fees_ticker); obj["is_claimable"] = coin_info.is_claimable; obj["address"] = QString::fromStdString(mm2_system.address(ticker, ec)); obj["minimal_balance_for_asking_rewards"] = QString::fromStdString(coin_info.minimal_claim_amount); @@ -496,6 +498,10 @@ namespace atomic_dex { withdraw_req.fees->type = "Qrc20Gas"; } + else if (coin_info.has_parent_fees_ticker) + { + withdraw_req.fees->type = "otherGas"; + } } nlohmann::json json_data = ::mm2::api::template_request("withdraw", true); ::mm2::api::to_json(json_data, withdraw_req);