Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix custom fees #1843

Merged
merged 2 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions atomic_defi_design/Dex/Components/DexSwitch.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
}

Expand Down
11 changes: 8 additions & 3 deletions atomic_defi_design/Dex/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
85 changes: 48 additions & 37 deletions atomic_defi_design/Dex/Wallet/SendModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -566,22 +566,27 @@ 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
DefaultText
{
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!")
}
Expand All @@ -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

Expand Down Expand Up @@ -651,23 +657,28 @@ 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)))
}
}

// Not enough funds error
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 }
Expand Down
6 changes: 6 additions & 0 deletions src/core/atomicdex/api/mm2/rpc.withdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/core/atomicdex/pages/qt.wallet.page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down