Skip to content

Commit

Permalink
Merge branch 'dev' into trade_error_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
smk762 committed Dec 1, 2022
2 parents d6c52d2 + 06f1c20 commit 77ab47a
Show file tree
Hide file tree
Showing 26 changed files with 199 additions and 272 deletions.
64 changes: 0 additions & 64 deletions atomic_defi_design/Dex/Dashboard/NotificationsModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ DexPopup
readonly property string enablingCoinFailedStatusNotification: "onEnablingCoinFailedStatus"
readonly property string disablingCoinFailedStatus: "onDisablingCoinFailedStatus"
readonly property string endpointNonReacheableStatus: "onEndpointNonReacheableStatus"
readonly property string mismatchCustomCoinConfigurationNotification: "onMismatchCustomCoinConfiguration"
readonly property string batchFailedNotification: "onBatchFailed"

readonly property string check_internet_connection_text: qsTr("Please check your internet connection (e.g. VPN service or firewall might block it).")

Expand Down Expand Up @@ -182,10 +180,6 @@ DexPopup
return qsTr("Failed to disable %1", "TICKER").arg(notification.params.coin)
case endpointNonReacheableStatus:
return qsTr("Endpoint not reachable")
case mismatchCustomCoinConfigurationNotification:
return qsTr("Mismatch at %1 custom asset configuration", "TICKER").arg(notification.params.asset)
case batchFailedNotification:
return qsTr("Batch %1 failed. Reason: %2").arg(notification.params.from).arg(notification.params.reason)
}
}

Expand All @@ -205,10 +199,6 @@ DexPopup
return ""
case endpointNonReacheableStatus:
return notification.params.base_uri
case mismatchCustomCoinConfigurationNotification:
return qsTr("Application needs to be restarted for %1 custom asset.", "TICKER").arg(notification.params.asset)
case batchFailedNotification:
return notification.params.reason
}
}

Expand Down Expand Up @@ -301,16 +291,6 @@ DexPopup
return
}

// Check if there is mismatch error, ignore this one
for (let n of notifications_list)
{
if (n.event_name === mismatchCustomCoinConfigurationNotification && n.params.asset === coin)
{
console.trace()
return
}
}

error = check_internet_connection_text + "\n\n" + error

newNotification(
Expand Down Expand Up @@ -361,37 +341,6 @@ DexPopup
toast.show(qsTr("Endpoint not reachable"), General.time_toast_important_error, error)
}

function onMismatchCustomCoinConfiguration(asset, human_date, timestamp)
{
newNotification(
mismatchCustomCoinConfigurationNotification,
{
asset,
human_date,
timestamp
},
timestamp,
human_date)

toast.show(title, General.time_toast_important_error, "", true, true)
}

function onBatchFailed(reason, from, human_date, timestamp)
{
newNotification(
batchFailedNotification,
{
human_date,
timestamp,
reason,
from
},
timestamp,
human_date)

toast.show(title, General.time_toast_important_error, reason)
}

Component.onCompleted:
{
API.app.notification_mgr.updateSwapStatus.connect(onUpdateSwapStatus)
Expand All @@ -400,8 +349,6 @@ DexPopup
API.app.notification_mgr.enablingCoinFailedStatus.connect(onEnablingCoinFailedStatus)
API.app.notification_mgr.disablingCoinFailedStatus.connect(onDisablingCoinFailedStatus)
API.app.notification_mgr.endpointNonReacheableStatus.connect(onEndpointNonReacheableStatus)
API.app.notification_mgr.mismatchCustomCoinConfiguration.connect(onMismatchCustomCoinConfiguration)
API.app.notification_mgr.batchFailed.connect(onBatchFailed)
}

Component.onDestruction:
Expand All @@ -412,8 +359,6 @@ DexPopup
API.app.notification_mgr.enablingCoinFailedStatus.disconnect(onEnablingCoinFailedStatus)
API.app.notification_mgr.disablingCoinFailedStatus.disconnect(onDisablingCoinFailedStatus)
API.app.notification_mgr.endpointNonReacheableStatus.disconnect(onEndpointNonReacheableStatus)
API.app.notification_mgr.mismatchCustomCoinConfiguration.disconnect(onMismatchCustomCoinConfiguration)
API.app.notification_mgr.batchFailed.disconnect(onBatchFailed)
}

SystemTrayIcon
Expand Down Expand Up @@ -622,9 +567,6 @@ DexPopup
case enablingCoinFailedStatusNotification:
name = "repeat"
break
case mismatchCustomCoinConfigurationNotification:
name = "restart-alert"
break
default:
name = "check"
break
Expand Down Expand Up @@ -653,12 +595,6 @@ DexPopup
API.app.enable_coins([event_before_removal.params.coin])
break

case mismatchCustomCoinConfigurationNotification:
console.log("Restarting for", event_before_removal.params.asset, "custom asset configuration mismatch...")
root.close()
restart_modal.open()
break

default:
removeNotification()
break
Expand Down
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
Loading

0 comments on commit 77ab47a

Please sign in to comment.