diff --git a/qortal-ui-plugins/plugins/core/trade-portal/trade-portal.src.js b/qortal-ui-plugins/plugins/core/trade-portal/trade-portal.src.js index 8ad72b1b..ffdd0fa3 100644 --- a/qortal-ui-plugins/plugins/core/trade-portal/trade-portal.src.js +++ b/qortal-ui-plugins/plugins/core/trade-portal/trade-portal.src.js @@ -825,44 +825,11 @@ class TradePortal extends LitElement { `; } - setForeignCoin(coin) { - let _this = this - this.selectedCoin = coin - this.isLoadingHistoricTrades = true - this.isLoadingOpenTrades = true - this.createConnection() - this._openOrdersGrid.querySelector('#priceColumn').headerRenderer = function (root) { - root.innerHTML = 'Price (' + _this.listedCoins.get(_this.selectedCoin).coinCode + ')' - } - this.clearSellForm() - this.clearBuyForm() - this.updateWalletBalance() - } - - displayTabContent(tab) { - const tabBuyContent = this.shadowRoot.getElementById('tab-buy-content') - const tabSellContent = this.shadowRoot.getElementById('tab-sell-content') - tabBuyContent.style.display = (tab === 'buy') ? 'block' : 'none' - tabSellContent.style.display = (tab === 'sell') ? 'block' : 'none' - } - - reRenderHistoricTrades() { - this.requestUpdate() - this.isLoadingHistoricTrades = false - } - - reRenderOpenFilteredOrders() { - this.requestUpdate() - this.isLoadingOpenTrades = false - } - - reRenderMyOpenOrders() { - this.requestUpdate() - this.isLoadingMyOpenOrders = false - } - firstUpdated() { let _this = this + + this.updateWalletBalance() + setTimeout(() => { this.displayTabContent('buy') }, 0) @@ -882,7 +849,6 @@ class TradePortal extends LitElement { this._myHistoricTradesGrid = this.shadowRoot.getElementById('myHistoricTradesGrid') this._stuckOrdersGrid = this.shadowRoot.getElementById('stuckOrdersGrid') - // call getOpenOrdersGrid this.getOpenOrdersGrid() window.addEventListener( @@ -940,6 +906,73 @@ class TradePortal extends LitElement { setTimeout(() => this.shadowRoot.querySelector('[slot="vaadin-grid-cell-content-3"]').setAttribute('title', 'Last Seen'), 3000) } + updateWalletBalance() { + let _url = `` + let _body = null + + switch (this.selectedCoin) { + case 'LITECOIN': + _url = `/crosschain/ltc/walletbalance?apiKey=${this.getApiKey()}` + _body = window.parent.reduxStore.getState().app.selectedAddress.ltcWallet.derivedMasterPublicKey + break + case 'DOGECOIN': + _url = `/crosschain/doge/walletbalance?apiKey=${this.getApiKey()}` + _body = window.parent.reduxStore.getState().app.selectedAddress.dogeWallet.derivedMasterPublicKey + break + default: + break + } + + parentEpml.request('apiCall', { + url: _url, + method: 'POST', + body: _body, + }) + .then((res) => { + if (isNaN(Number(res))) { + parentEpml.request('showSnackBar', 'Failed to Fetch Balance. Try again!') + } else { + this.listedCoins.get(this.selectedCoin).balance = (Number(res) / 1e8).toFixed(8) + } + }) + } + + setForeignCoin(coin) { + let _this = this + this.selectedCoin = coin + this.isLoadingHistoricTrades = true + this.isLoadingOpenTrades = true + this.createConnection() + this._openOrdersGrid.querySelector('#priceColumn').headerRenderer = function (root) { + root.innerHTML = 'Price (' + _this.listedCoins.get(_this.selectedCoin).coinCode + ')' + } + this.clearSellForm() + this.clearBuyForm() + this.updateWalletBalance() + } + + displayTabContent(tab) { + const tabBuyContent = this.shadowRoot.getElementById('tab-buy-content') + const tabSellContent = this.shadowRoot.getElementById('tab-sell-content') + tabBuyContent.style.display = (tab === 'buy') ? 'block' : 'none' + tabSellContent.style.display = (tab === 'sell') ? 'block' : 'none' + } + + reRenderHistoricTrades() { + this.requestUpdate() + this.isLoadingHistoricTrades = false + } + + reRenderOpenFilteredOrders() { + this.requestUpdate() + this.isLoadingOpenTrades = false + } + + reRenderMyOpenOrders() { + this.requestUpdate() + this.isLoadingMyOpenOrders = false + } + fillBuyForm(sellerRequest) { this.shadowRoot.getElementById('buyAmountInput').value = parseFloat(sellerRequest.qortAmount) this.shadowRoot.getElementById('buyPriceInput').value = this.round(parseFloat(sellerRequest.foreignAmount) / parseFloat(sellerRequest.qortAmount)) @@ -1652,37 +1685,6 @@ class TradePortal extends LitElement { }) } - updateWalletBalance() { - let _url = `` - let _body = null - - switch (this.selectedCoin) { - case 'LITECOIN': - _url = `/crosschain/ltc/walletbalance?apiKey=${this.getApiKey()}` - _body = window.parent.reduxStore.getState().app.selectedAddress.ltcWallet.derivedMasterPublicKey - break - case 'DOGECOIN': - _url = `/crosschain/doge/walletbalance?apiKey=${this.getApiKey()}` - _body = window.parent.reduxStore.getState().app.selectedAddress.dogeWallet.derivedMasterPublicKey - break - default: - break - } - - parentEpml.request('apiCall', { - url: _url, - method: 'POST', - body: _body, - }) - .then((res) => { - if (isNaN(Number(res))) { - parentEpml.request('showSnackBar', 'Failed to Fetch Balance. Try again!') - } else { - this.listedCoins.get(this.selectedCoin).balance = (Number(res) / 1e8).toFixed(8) - } - }) - } - renderCancelButton(stateItem) { if (stateItem.tradeState === 'BOB_WAITING_FOR_MESSAGE') { return html` this.cancelAction(stateItem)}>CANCEL`