Skip to content

Commit

Permalink
Merge pull request #2114 from KomodoPlatform/debug_fees
Browse files Browse the repository at this point in the history
fix infinite fees loading issue
  • Loading branch information
smk762 authored Dec 1, 2022
2 parents fdf097c + 3ac5962 commit 06f1c20
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 69 deletions.
131 changes: 128 additions & 3 deletions atomic_defi_design/Dex/Exchange/ProView/PlaceOrderForm/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,65 @@ import "../../../Constants"
import Dex.Themes 1.0 as Dex
import Dex.Components 1.0 as Dex
import AtomicDEX.MarketMode 1.0
import AtomicDEX.TradingError 1.0

Widget
{
title: qsTr("Place Order")
property int loop_count: 0
property bool show_waiting_for_trade_preimage: false;
property var fees: API.app.trading_pg.fees
property var preimage_rpc_busy: API.app.trading_pg.preimage_rpc_busy
property string protocolIcon: General.platformIcon(General.coinPlatform(left_ticker))
property var trade_preimage_error: fees.hasOwnProperty('error') ? fees["error"].split("] ").slice(-1) : ""
readonly property bool trade_preimage_ready: fees.hasOwnProperty('base_transaction_fees_ticker')
readonly property bool can_submit_trade: last_trading_error === TradingError.None

margins: 15
collapsable: false

Connections {
target: API.app.trading_pg

function onFeesChanged() {
// console.log("onFeesChanged::fees: " + JSON.stringify(fees))
}

function onPreImageRpcStatusChanged(){
// console.log("onPreImageRpcStatusChanged::preimage_rpc_busy: " + API.app.trading_pg.preimage_rpc_busy)
}
function onPrefferedOrderChanged(){
reset_fees_state()
}
}

Connections
{
target: app
function onPairChanged(left, right)
{
reset_fees_state()
}
}

Connections
{
target: exchange_trade
function onOrderSelected()
{
reset_fees_state()
}
}

function reset_fees_state()
{
show_waiting_for_trade_preimage = false;
check_trade_preimage.stop()
loop_count = 0
API.app.trading_pg.reset_fees()
errors.text_value = ""
}

// Market mode selector
RowLayout
{
Expand Down Expand Up @@ -125,7 +175,10 @@ Widget
Layout.preferredWidth: 30
Layout.rightMargin: 5
foregroundColor: Dex.CurrentTheme.noColor
onClicked: API.app.trading_pg.reset_order()
onClicked: {
API.app.trading_pg.reset_order()
reset_fees_state()
}

Qaterial.ColorIcon
{
Expand Down Expand Up @@ -191,14 +244,86 @@ Widget

DexGradientAppButton
{
id: swap_btn
height: 40
Layout.preferredWidth: parent.width - 20
Layout.alignment: Qt.AlignHCenter

radius: 18
text: qsTr("START SWAP")
font.weight: Font.Medium
enabled: formBase.can_submit_trade
onClicked: confirm_trade_modal.open()
enabled: can_submit_trade && !show_waiting_for_trade_preimage && errors.text_value == ""
onClicked:
{
console.log("Getting fees info...")
API.app.trading_pg.determine_fees()
show_waiting_for_trade_preimage = true;
}

Item
{
visible: show_waiting_for_trade_preimage
height: parent.height - 10
width: parent.width - 10
anchors.fill: parent
anchors.centerIn: parent

DefaultBusyIndicator
{
id: preimage_BusyIndicator
anchors.fill: parent
anchors.centerIn: parent
indicatorSize: 32
indicatorDotSize: 5
}
}

DexMouseArea
{
id: areaAlert
hoverEnabled: true
anchors.fill: parent
onClicked:
{
console.log("Getting fees info...")
API.app.trading_pg.determine_fees()
show_waiting_for_trade_preimage = true;
check_trade_preimage.start()
}
}
}

Timer {
id: check_trade_preimage
interval: 500;
running: false;
repeat: true;
triggeredOnStart: true;
onTriggered: {
loop_count++;
console.log("Getting fees info... " + loop_count + "/50")
if (trade_preimage_ready)
{
show_waiting_for_trade_preimage = false
loop_count = 0
stop()
confirm_trade_modal.open()
}
else if (trade_preimage_error != "")
{
loop_count = 0
errors.text_value = trade_preimage_error.toString()
show_waiting_for_trade_preimage = false
stop()

}
else if (loop_count > 50)
{
loop_count = 0
show_waiting_for_trade_preimage = false
trade_preimage_error = "Trade preimage timed out, try again."
stop()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.0

import AtomicDEX.MarketMode 1.0
import AtomicDEX.TradingError 1.0
import "../../../Components"
import App 1.0
import Dex.Themes 1.0 as Dex
Expand All @@ -23,7 +21,6 @@ ColumnLayout
readonly property int input_height: 70
readonly property int subfield_margin: 5

readonly property bool can_submit_trade: last_trading_error === TradingError.None

// Will move to backend: Minimum Fee
function getMaxBalance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import Qaterial 1.0 as Qaterial

import "../../../Components"
import "../../../Constants"
import Dex.Themes 1.0 as Dex
import AtomicDEX.MarketMode 1.0
import App 1.0 as App
import Dex.Themes 1.0 as Dex
import Dex.Components 1.0 as Dex
import AtomicDEX.MarketMode 1.0

Item
{
Expand Down Expand Up @@ -177,7 +177,6 @@ Item
app.pairChanged(base_ticker, coin)
}
API.app.trading_pg.orderbook.select_best_order(uuid)
orderSelected()
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions atomic_defi_design/Dex/Exchange/Trade/ConfirmTradeModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MultipageModal
width: 720
horizontalPadding: 30
verticalPadding: 30
closePolicy: Popup.NoAutoClose

MultipageModalContent
{
Expand Down Expand Up @@ -164,6 +165,21 @@ MultipageModal
}
}

ColumnLayout
{
id: fees_error
width: parent.width - 20
anchors.centerIn: parent
visible: root.fees.hasOwnProperty('error') // Should be handled before this modal, but leaving here as a fallback

DefaultText
{
width: parent.width
text_value: root.fees.hasOwnProperty('error') ? root.fees["error"].split("] ").slice(-1) : ""
Layout.bottomMargin: 8
}
}

ColumnLayout
{
id: fees_detail
Expand Down Expand Up @@ -391,7 +407,10 @@ MultipageModal
leftPadding: 45
rightPadding: 45
radius: 10
onClicked: root.close()
onClicked: {
root.close()
API.app.trading_pg.reset_fees()
}
},

Item { Layout.fillWidth: true },
Expand All @@ -410,7 +429,8 @@ MultipageModal
is_dpow_configurable: config_section.is_dpow_configurable,
enable_dpow_confs: enable_dpow_confs.checked,
required_confirmation_count: required_confirmation_count.value, },
config_section.default_config)
config_section.default_config)
API.app.trading_pg.reset_fees()
}
},

Expand Down
34 changes: 0 additions & 34 deletions atomic_defi_design/Dex/Exchange/Trade/DefaultSweetModal.qml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import QtQuick.Controls 2.15
import Qaterial 1.0 as Qaterial

import "../../../Components"
import "../../../Constants"
import App 1.0
import bignumberjs 1.0
import "../../../Constants"
import Dex.Themes 1.0 as Dex
import Dex.Components 1.0 as Dex
import AtomicDEX.MarketMode 1.0
Expand Down
12 changes: 7 additions & 5 deletions atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ClipRRect // Trade Card
{
id: _tradeCard

readonly property var fees: API.app.trading_pg.fees
property string selectedTicker: API.app.get_balance(left_ticker) > 0 ? left_ticker : ""
property var selectedOrder: undefined
property bool best: false
Expand All @@ -32,7 +33,6 @@ ClipRRect // Trade Card
if (typeof selectedOrder !== 'undefined' && selectedOrder.from_best_order) Constants.API.app.trading_pg.orderbook.select_best_order(selectedOrder.uuid)
else if (typeof selectedOrder !== 'undefined') Constants.API.app.trading_pg.preffered_order = selectedOrder
else Constants.API.app.trading_pg.reset_order()

Constants.API.app.trading_pg.determine_fees()
}

Expand Down Expand Up @@ -65,6 +65,7 @@ ClipRRect // Trade Card
return
if (parseFloat(_fromValue.text) > Constants.API.app.trading_pg.max_volume)
_fromValue.text = Constants.API.app.trading_pg.max_volume
Constants.API.app.trading_pg.determine_fees()
}

function onVolumeChanged()
Expand Down Expand Up @@ -480,7 +481,7 @@ ClipRRect // Trade Card

DefaultText // Amount In Fiat
{
enabled: parseFloat(_toValue.text) > 0
enabled: parseFloat(_toValue.text) > 0 && _toValue.text != ""
anchors.top: _toValue.bottom
anchors.topMargin: -3
anchors.left: _toValue.left
Expand Down Expand Up @@ -914,7 +915,7 @@ ClipRRect // Trade Card
}

enabled: parent.enabled
model: Constants.API.app.trading_pg.fees.total_fees
model: _tradeCard.fees.hasOwnProperty('base_transaction_fees_ticker') ? _tradeCard.fees.total_fees : []

delegate: RowLayout
{
Expand Down Expand Up @@ -946,9 +947,10 @@ ClipRRect // Trade Card
DefaultBusyIndicator
{
id: fees_busy
width: 30
height: 30
anchors.fill: parent
anchors.centerIn: parent
indicatorSize: 32
indicatorDotSize: 5
visible: Constants.API.app.trading_pg.preimage_rpc_busy || _feesList.count == 0
}
}
Expand Down
Loading

0 comments on commit 06f1c20

Please sign in to comment.