4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 17:55:51 +00:00

load ltc balance first

This commit is contained in:
AlphaX-Projects 2022-02-06 13:49:50 -08:00 committed by GitHub
parent 8096ec0a6f
commit a9c2314197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 = '<vaadin-grid-sorter path="price" direction="asc">Price (' + _this.listedCoins.get(_this.selectedCoin).coinCode + ')</vaadin-grid-sorter>'
}
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 = '<vaadin-grid-sorter path="price" direction="asc">Price (' + _this.listedCoins.get(_this.selectedCoin).coinCode + ')</vaadin-grid-sorter>'
}
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`<mwc-button id="${stateItem.atAddress}" ?disabled=${this.cancelBtnDisable} class="cancel" @click=${(e) => this.cancelAction(stateItem)}>CANCEL</mwc-button>`