Skip to content

Commit

Permalink
fix busyindicator on sell coin when balance is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
smk762 committed Dec 1, 2022
1 parent 77ab47a commit 91e6b53
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 42 deletions.
31 changes: 13 additions & 18 deletions atomic_defi_design/Dex/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ QtObject {
return coin_info.is_zhtlc_family
}

function isZhtlcReady(ticker, progress=100)
function isZhtlcReady(ticker)
{
if (!isZhtlc(ticker)) return true
let activation_status = API.app.get_zhtlc_status(ticker)
let progress = zhtlcActivationProgress(activation_status, ticker)
if (progress == 100) return true
const coin_info = API.app.portfolio_pg.global_cfg_mdl.get_coin_info(ticker)
if (!coin_info.is_zhtlc_family) return true
return false
}

Expand Down Expand Up @@ -385,30 +386,24 @@ QtObject {
)
}

function getSimpleFromPlaceholder(selectedTicker, selectedOrder) {
if (isZhtlc(selectedTicker))
function getSimpleFromPlaceholder(selectedTicker, selectedOrder, sell_ticker_balance) {
if (sell_ticker_balance == 0)
{
let activation_status = API.app.get_zhtlc_status(selectedTicker)
let progress = zhtlcActivationProgress(activation_status, selectedTicker)

if (!isZhtlcReady(selectedTicker, progress))
{
return qsTr("Activating %1 (%2%)").arg(atomic_qt_utilities.retrieve_main_ticker(selectedTicker)).arg(progress)
}
return qsTr("%1 balance is zero").arg(selectedTicker)
}
if (!isZhtlcReady(selectedTicker))
{
return qsTr("Activating %1 (%2%)").arg(atomic_qt_utilities.retrieve_main_ticker(selectedTicker)).arg(progress)
}

if (API.app.trading_pg.max_volume == 0)
{
return qsTr("Loading wallet...")
}
else if (typeof selectedOrder !== 'undefined')
if (typeof selectedOrder !== 'undefined')
{
return qsTr("Min: %1").arg(API.app.trading_pg.min_trade_vol)
}
else
{
return qsTr("Enter an amount")
}
return qsTr("Enter an amount")
}

function arrayExclude(arr, excl) {
Expand Down
40 changes: 18 additions & 22 deletions atomic_defi_design/Dex/Exchange/Trade/SimpleView/Trade.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ 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 : ""
readonly property var fees: Constants.API.app.trading_pg.fees
readonly property var max_trade_volume: Constants.API.app.trading_pg.max_volume
readonly property var min_trade_volume: Constants.API.app.trading_pg.min_trade_vol
readonly property var sell_ticker_balance: parseFloat(API.app.get_balance(left_ticker))
readonly property bool coin_tradable: selectedTicker !== "" && sell_ticker_balance > 0
readonly property bool waiting_for_sell_coin_info: (API.app.trading_pg.max_volume == 0 || !Constants.General.isZhtlcReady(left_ticker)) && sell_ticker_balance != 0

property string selectedTicker: sell_ticker_balance > 0 ? left_ticker : ""
property var selectedOrder: undefined
property bool best: false
property bool coinSelection: false
Expand Down Expand Up @@ -63,8 +69,8 @@ ClipRRect // Trade Card
{
if (typeof selectedOrder === 'undefined')
return
if (parseFloat(_fromValue.text) > Constants.API.app.trading_pg.max_volume)
_fromValue.text = Constants.API.app.trading_pg.max_volume
if (parseFloat(_fromValue.text) > max_trade_volume)
_fromValue.text = max_trade_volume
Constants.API.app.trading_pg.determine_fees()
}

Expand Down Expand Up @@ -246,7 +252,7 @@ ClipRRect // Trade Card
anchors.verticalCenter: _fromTitle.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 17
text: qsTr("%1").arg(Constants.API.app.trading_pg.max_volume) // This is slow to appear
text: qsTr("%1").arg(max_trade_volume) // This is slow to appear
font.pixelSize: Constants.Style.textSizeSmall2
elide: Text.ElideRight
color: DexTheme.foregroundColorLightColor1
Expand Down Expand Up @@ -289,13 +295,12 @@ ClipRRect // Trade Card
AmountField // Amount
{
id: _fromValue
enabled: selectedTicker !== ""
visible: enabled
enabled: !waiting_for_sell_coin_info
anchors.bottom: parent.bottom
anchors.bottomMargin: 19
anchors.left: parent.left
anchors.leftMargin: 2
placeholderText: Constants.General.getSimpleFromPlaceholder(selectedTicker, selectedOrder)
placeholderText: Constants.General.getSimpleFromPlaceholder(selectedTicker, selectedOrder, sell_ticker_balance)
font.pixelSize: Constants.Style.textSizeSmall3
background: Rectangle { color: swap_from_card.color}

Expand All @@ -311,9 +316,9 @@ ClipRRect // Trade Card

onFocusChanged:
{
if (!focus && parseFloat(text) < parseFloat(Constants.API.app.trading_pg.min_trade_vol))
if (!focus && parseFloat(text) < parseFloat(min_trade_volume))
{
text = Constants.API.app.trading_pg.min_trade_vol
text = min_trade_volume
}
}
Component.onCompleted: text = ""
Expand Down Expand Up @@ -432,20 +437,13 @@ ClipRRect // Trade Card
text: qsTr("MAX")
color: Dex.CurrentTheme.foregroundColor2

onClicked: _fromValue.text = Constants.API.app.trading_pg.max_volume
onClicked: _fromValue.text = max_trade_volume
}

DefaultBusyIndicator
{
anchors.centerIn: parent
visible:
{
console.log("selectedTicker: " + selectedTicker)
console.log("Constants.API.app.trading_pg.max_volume: " + Constants.API.app.trading_pg.max_volume)
console.log("_fromValue.placeholderText: " + _fromValue.placeholderText)
console.log("_fromValue.placeholderText.search(Activating): " + _fromValue.placeholderText.search("Activating"))
selectedTicker !== "" && Constants.API.app.trading_pg.max_volume == 0 && _fromValue.placeholderText.search("Activating") == -1
}
visible: waiting_for_sell_coin_info
}
}

Expand Down Expand Up @@ -712,17 +710,15 @@ ClipRRect // Trade Card
function getAlert()
{
console.log("_fromValue.text: " + _fromValue.text)
var left_ticker = Constants.API.app.trading_pg.market_pairs_mdl.left_selected_coin
var right_ticker = Constants.API.app.trading_pg.market_pairs_mdl.right_selected_coin
var base_ticker = Constants.API.app.trading_pg.market_pairs_mdl.base_selected_coin
var rel_ticker = Constants.API.app.trading_pg.market_pairs_mdl.rel_selected_coin
var fee_info = Constants.API.app.trading_pg.fees

if (_fromValue.text === "" || parseFloat(_fromValue.text) === 0)
return qsTr("Entered amount must be higher than 0.")
if (typeof selectedOrder === 'undefined')
return qsTr("Select an order.")
return Constants.General.getTradingError(last_trading_error, fee_info, base_ticker, rel_ticker, left_ticker, right_ticker)
return Constants.General.getTradingError(last_trading_error, fees, base_ticker, rel_ticker, left_ticker, right_ticker)
}

tooltipText: _swapAlert.getAlert()
Expand Down
4 changes: 2 additions & 2 deletions atomic_defi_design/Dex/Wallet/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ Item
DefaultButton
{
// Address wont display until activated
enabled: General.isZhtlcReady(api_wallet_page.ticker, activation_progress)
enabled: General.isZhtlcReady(api_wallet_page.ticker)
anchors.fill: parent
radius: 18

Expand All @@ -556,7 +556,7 @@ Item
// Receive button error icon
DefaultAlertIcon
{
visible: !General.isZhtlcReady(api_wallet_page.ticker, activation_progress)
visible: !General.isZhtlcReady(api_wallet_page.ticker)
tooltipText: api_wallet_page.ticker + qsTr(" Activation: " + activation_progress + "%")
}
}
Expand Down

0 comments on commit 91e6b53

Please sign in to comment.