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 page switching crash #1274

Merged
merged 10 commits into from
Sep 14, 2021
4 changes: 2 additions & 2 deletions atomic_defi_design/qml/Dashboard/NotificationsModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ DexPopup {
break
case "open_wallet_page":
api_wallet_page.ticker = notification.params.ticker
dashboard.current_page = idx_dashboard_wallet
dashboard.switchPage(idx_dashboard_wallet)
break
case "open_swaps_page":
dashboard.current_page = idx_dashboard_exchange
dashboard.switchPage(idx_dashboard_exchange)

dashboard.loader.onLoadComplete = () => {
dashboard.current_component.current_page = dashboard.isSwapDone(notification.params.new_swap_status) ? idx_exchange_history : idx_exchange_orders
Expand Down
13 changes: 3 additions & 10 deletions atomic_defi_design/qml/Exchange/Trade/CandleStickChart.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ DexBox {
height: graph_bg.height

property bool pair_supported: false
readonly property bool is_fetching: chart.loadProgress < 100
readonly property bool is_fetching: dashboard.webEngineView.loadProgress < 100

RowLayout {
visible: pair_supported && !chart.visible
visible: pair_supported && !dashboard.webEngineView.visible
anchors.centerIn: parent

DefaultBusyIndicator {
Expand Down Expand Up @@ -101,7 +101,7 @@ DexBox {
chart_base = atomic_qt_utilities.retrieve_main_ticker(base)
chart_rel = atomic_qt_utilities.retrieve_main_ticker(rel)

chart.loadHtml(`
dashboard.webEngineView.loadHtml(`
<style>
body { margin: 0; background: ${ graph_bg.color } }
</style>
Expand All @@ -128,12 +128,5 @@ DexBox {
</div>
<!-- TradingView Widget END -->`)
}

WebEngineView {
id: chart
anchors.fill: parent
anchors.margins: -1
visible: !is_fetching && pair_supported
}
}
}
17 changes: 14 additions & 3 deletions atomic_defi_design/qml/Exchange/Trade/ProView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.15

import QtGraphicalEffects 1.0
import Qt.labs.settings 1.0

import Qaterial 1.0 as Qaterial
import Qt.labs.settings 1.0

import AtomicDEX.MarketMode 1.0
import AtomicDEX.TradingError 1.0
Expand All @@ -30,7 +29,7 @@ import "BestOrder/" as BestOrder
// Orders (orders, history)
import "Orders/" as OrdersView

import "./" as Here
import "../../Screens"

ColumnLayout {
id: form
Expand Down Expand Up @@ -171,6 +170,18 @@ ColumnLayout {
color: 'transparent'
anchors.fill: parent
}

Component.onCompleted:
{
dashboard.webEngineView.parent = chart_view;
dashboard.webEngineView.anchors.fill = chart_view;
dashboard.webEngineView.visible = true;
}
Component.onDestruction:
{
dashboard.webEngineView.visible = false;
dashboard.webEngineView.stop();
}
}
}
DexTradeBox {
Expand Down
2 changes: 1 addition & 1 deletion atomic_defi_design/qml/Portfolio/AssetsList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Dex.DefaultListView
else
{
api_wallet_page.ticker = ticker
dashboard.current_page = idx_dashboard_wallet
dashboard.switchPage(idx_dashboard_wallet)
}
}
onPressAndHold:
Expand Down
2 changes: 1 addition & 1 deletion atomic_defi_design/qml/Portfolio/TableDex.qml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Item {
context_menu.popup()
else {
api_wallet_page.ticker = ticker
dashboard.current_page = idx_dashboard_wallet
dashboard.switchPage(idx_dashboard_wallet)
}
}
onPressAndHold: {
Expand Down
28 changes: 21 additions & 7 deletions atomic_defi_design/qml/Screens/Dashboard.qml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15

import QtQuick.Controls 2.1
import QtGraphicalEffects 1.0
import QtWebEngine 1.10

import "../Components"
import "../Constants"
import App 1.0

import "../Dashboard"
import "../Portfolio"
import "../Wallet"
Expand All @@ -15,13 +15,14 @@ import "../Settings"
import "../Support"
import "../Sidebar"
import "../Fiat"
import "../Settings"
as SettingsPage
import "../Settings" as SettingsPage


Item {
id: dashboard

property alias webEngineView: webEngineView

readonly property int idx_dashboard_portfolio: 0
readonly property int idx_dashboard_wallet: 1
readonly property int idx_dashboard_exchange: 2
Expand All @@ -39,8 +40,7 @@ Item {
readonly property int idx_exchange_orders: 1
readonly property int idx_exchange_history: 2

property
var current_ticker
property var current_ticker

Layout.fillWidth: true

Expand All @@ -57,6 +57,7 @@ Item {
readonly property alias loader: loader
readonly property alias current_component: loader.item
property int current_page: idx_dashboard_portfolio

onCurrent_pageChanged: {
app.deepPage = current_page * 10
}
Expand All @@ -68,6 +69,14 @@ Item {
return app.current_page === idx_dashboard
}

function switchPage(page)
{
if (loader.status === Loader.Ready)
current_page = page
else
console.warn("Tried to switch to page %1 when loader is not ready yet.".arg(page))
}

property
var notifications_list: ([])

Expand Down Expand Up @@ -194,6 +203,11 @@ Item {
}
}

WebEngineView
{
id: webEngineView
}

DefaultLoader {
id: loader

Expand Down
2 changes: 1 addition & 1 deletion atomic_defi_design/qml/Sidebar/Sidebar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Qaterial 1.0 as Qaterial

Item {
id: sidebar
property bool expanded: dashboard.current_page===dashboard.idx_dashboard_exchange? false : true
property bool expanded: dashboard.current_page === dashboard.idx_dashboard_exchange ? false : true
readonly property alias app_logo: app_logo

x: -top_rect.radius
Expand Down
2 changes: 1 addition & 1 deletion atomic_defi_design/qml/Sidebar/SidebarLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Item {
else if(dashboard_index === idx_dashboard_privacy_mode) {
togglePrivacyMode()
}
else dashboard.current_page = dashboard_index
else dashboard.switchPage(dashboard_index)
}
}

Expand Down
41 changes: 24 additions & 17 deletions atomic_defi_design/qml/Wallet/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,14 @@ Item {
// Price Graph
InnerBackground {
id: price_graph_bg

function initGraph()
{
dashboard.webEngineView.parent = price_graph_bg
dashboard.webEngineView.anchors.fill = price_graph_bg
dashboard.webEngineView.visible = true
}

Layout.fillWidth: true
Layout.fillHeight: true
Layout.leftMargin: layout_margin
Expand All @@ -448,9 +456,16 @@ Item {
shadowOff: true
color: DexTheme.contentColorTop

Component.onCompleted: initGraph()
Component.onDestruction:
{
dashboard.webEngineView.visible = false;
dashboard.webEngineView.stop();
}

content: Item {
property bool ticker_supported: false
readonly property bool is_fetching: chart.loadProgress < 100
readonly property bool is_fetching: dashboard.webEngineView.loadProgress < 100
readonly property string chartTheme: DexTheme.theme ?? "dark"
property color backgroundColor: DexTheme.contentColorTop
property var ticker: api_wallet_page.ticker
Expand All @@ -466,37 +481,37 @@ Item {
// Normal pair
let symbol = General.supported_pairs[pair]
if (!symbol) {
console.log("Symbol not found for", pair)
console.warn("Symbol not found for", pair)
symbol = General.supported_pairs[pair_reversed]
}

// Reversed pair
if (!symbol) {
console.log("Symbol not found for", pair_reversed)
console.warn("Symbol not found for", pair_reversed)
symbol = General.supported_pairs[pair_usd]
}

// Pair with USD
if (!symbol) {
console.log("Symbol not found for", pair_usd)
console.warn("Symbol not found for", pair_usd)
symbol = General.supported_pairs[pair_usd_reversed]
}

// Reversed pair with USD
if (!symbol) {
console.log("Symbol not found for", pair_usd_reversed)
console.warn("Symbol not found for", pair_usd_reversed)
symbol = General.supported_pairs[pair_busd]
}

// Pair with BUSD
if (!symbol) {
console.log("Symbol not found for", pair_busd)
console.warn("Symbol not found for", pair_busd)
symbol = General.supported_pairs[pair_busd_reversed]
}

// Reversed pair with BUSD
if (!symbol) {
console.log("Symbol not found for", pair_busd_reversed)
console.warn("Symbol not found for", pair_busd_reversed)
ticker_supported = false
return
}
Expand All @@ -505,7 +520,7 @@ Item {

console.debug("Wallet: Loading chart for %1".arg(symbol))

chart.loadHtml(`
dashboard.webEngineView.loadHtml(`
<style>
body { margin: 0; background: %1 }
</style>
Expand Down Expand Up @@ -546,7 +561,7 @@ Item {
}

RowLayout {
visible: ticker_supported && !chart.visible
visible: ticker_supported && !dashboard.webEngineView.visible
anchors.centerIn: parent

DefaultBusyIndicator {
Expand All @@ -566,14 +581,6 @@ Item {
text_value: qsTr("There is no chart data for this ticker yet")
anchors.centerIn: parent
}

WebEngineView {
id: chart
anchors.fill: parent
anchors.margins: -1
backgroundColor: DexTheme.contentColorTop
visible: !is_fetching && ticker_supported
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion atomic_defi_design/qml/Wallet/Wallet.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RowLayout
// Local
function onClickedSwap()
{
dashboard.current_page = idx_dashboard_exchange
dashboard.switchPage(idx_dashboard_exchange)
dashboard.current_ticker = api_wallet_page.ticker
API.app.trading_pg.set_pair(true, api_wallet_page.ticker)
}
Expand Down