Browse Source

Filtering offers based on foreign chain

fixed an issue with websocket offers being shown even though it's not the correct selected coin
websocket-offer-filtering-based-on-foreign-chain
proto 2 years ago
parent
commit
669f652f87
  1. 199
      qortal-ui-plugins/plugins/core/trade-portal/trade-portal.src.js

199
qortal-ui-plugins/plugins/core/trade-portal/trade-portal.src.js

@ -1199,106 +1199,142 @@ class TradePortal extends LitElement {
} }
processOfferingTrade(offer) { processOfferingTrade(offer) {
const offerItem = { try{
...offer, if(this.listedCoins.get(offer.foreignBlockchain).name!=''){//check if the foreignBlockchain value is part of supported blockchains
qortAmount: parseFloat(offer.qortAmount), const offerItem = {
price: parseFloat(offer.foreignAmount) / parseFloat(offer.qortAmount), ...offer,
} qortAmount: parseFloat(offer.qortAmount),
const addOffer = () => { price: parseFloat(offer.foreignAmount) / parseFloat(offer.qortAmount),
this.listedCoins.get(this.selectedCoin).openOrders.unshift(offerItem) }
} const addOffer = () => {
const initOffer = () => { this.listedCoins.get(offer.foreignBlockchain).openOrders.unshift(offerItem)
this.listedCoins.get(this.selectedCoin).openOrders.push(offerItem) }
const initOffer = () => {
this.listedCoins.get(offer.foreignBlockchain).openOrders.push(offerItem)
}
this.listedCoins.get(offer.foreignBlockchain).openOrders.length === 0 ? initOffer() : addOffer()
this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? this._openOrdersGrid.clearCache() : null
}
}catch(e){
console.log("Error adding offer from "+offer.foreignBlockchain)
} }
this.listedCoins.get(this.selectedCoin).openOrders.length === 0 ? initOffer() : addOffer()
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._openOrdersGrid.clearCache() : null
} }
processRedeemedTrade(offer) { processRedeemedTrade(offer) {
// If trade is mine, add it to my historic trades and also add it to historic trades try{
if (offer.qortalCreator === this.selectedAddress.address) { if(this.listedCoins.get(offer.foreignBlockchain).name!=''){//check if the foreignBlockchain value is part of supported blockchains
// Check and Update Wallet Balance
if (this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1) { // If trade is mine, add it to my historic trades and also add it to historic trades
this.updateWalletBalance() if (offer.qortalCreator === this.selectedAddress.address) {
} // Check and Update Wallet Balance
const offerItem = { if (this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1) {
...offer, this.updateWalletBalance()
mode: 'SOLD', }
} const offerItem = {
// Add to my historic trades ...offer,
this._myHistoricTradesGrid.items.unshift(offerItem) mode: 'SOLD',
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null }
} else if (offer.partnerQortalReceivingAddress === this.selectedAddress.address) { // Add to my historic trades
// Check and Update Wallet Balance this._myHistoricTradesGrid.items.unshift(offerItem)
if (this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1) { this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null
this.updateWalletBalance() } else if (offer.partnerQortalReceivingAddress === this.selectedAddress.address) {
} // Check and Update Wallet Balance
const offerItem = { if (this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1) {
...offer, this.updateWalletBalance()
mode: 'BOUGHT', }
const offerItem = {
...offer,
mode: 'BOUGHT',
}
// Add to my historic trades
this._myHistoricTradesGrid.items.unshift(offerItem)
this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null
}
// Add to historic trades
const addNewHistoricTrade = () => {
this._historicTradesGrid.items.unshift(offer)
this._historicTradesGrid.clearCache()
}
this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? addNewHistoricTrade() : null
} }
// Add to my historic trades }catch(e){
this._myHistoricTradesGrid.items.unshift(offerItem) console.log("Error processing redeemed trade offer from "+offer.foreignBlockchain)
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null
}
// Add to historic trades
const addNewHistoricTrade = () => {
this._historicTradesGrid.items.unshift(offer)
this._historicTradesGrid.clearCache()
} }
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? addNewHistoricTrade() : null
} }
processTradingTrade(offer) { processTradingTrade(offer) {
// Remove from open market orders try{
if (offer.qortalCreator === this.selectedAddress.address && this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1) { if(this.listedCoins.get(offer.foreignBlockchain).name!=''){//check if the foreignBlockchain value is part of supported blockchains
// Check and Update Wallet Balance
this.updateWalletBalance() // Remove from open market orders
} if (offer.qortalCreator === this.selectedAddress.address && this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1) {
this._openOrdersGrid.items.forEach((item, index) => { // Check and Update Wallet Balance
if (item.qortalAtAddress === offer.qortalAtAddress) { this.updateWalletBalance()
this._openOrdersGrid.items.splice(index, 1) }
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._openOrdersGrid.clearCache() : null this._openOrdersGrid.items.forEach((item, index) => {
if (item.qortalAtAddress === offer.qortalAtAddress) {
this._openOrdersGrid.items.splice(index, 1)
this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? this._openOrdersGrid.clearCache() : null
}
})
this.listedCoins.get(offer.foreignBlockchain).openOrders = this.listedCoins.get(offer.foreignBlockchain).openOrders.filter((order) => order.qortalAtAddress !== offer.qortalAtAddress)
} }
}) }catch(e){
this.listedCoins.get(this.selectedCoin).openOrders = this.listedCoins.get(this.selectedCoin).openOrders.filter((order) => order.qortalAtAddress !== offer.qortalAtAddress) console.log("Error processing trading trade offer from "+offer.foreignBlockchain)
}
} }
processRefundedTrade(offer) { processRefundedTrade(offer) {
if (offer.qortalCreator === this.selectedAddress.address) { try{
// Check and Update Wallet Balance if(this.listedCoins.get(offer.foreignBlockchain).name!=''){//check if the foreignBlockchain value is part of supported blockchains
if (this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1) {
this.updateWalletBalance() if (offer.qortalCreator === this.selectedAddress.address) {
// Check and Update Wallet Balance
if (this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1) {
this.updateWalletBalance()
}
// Add to my historic trades
this._myHistoricTradesGrid.items.unshift(offer)
this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null
}
} }
// Add to my historic trades }catch(e){
this._myHistoricTradesGrid.items.unshift(offer) console.log("Error processing refunded trade offer from "+offer.foreignBlockchain)
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null
} }
} }
processCancelledTrade(offer) { processCancelledTrade(offer) {
if (offer.qortalCreator === this.selectedAddress.address) { try{
// Check and Update Wallet Balance if(this.listedCoins.get(offer.foreignBlockchain).name!=''){//check if the foreignBlockchain value is part of supported blockchains
if (this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1) {
this.updateWalletBalance() if (offer.qortalCreator === this.selectedAddress.address) {
} // Check and Update Wallet Balance
// Add to my historic trades if (this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1) {
this._myHistoricTradesGrid.items.unshift(offer) this.updateWalletBalance()
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null }
} // Add to my historic trades
this._openOrdersGrid.items.forEach((item, index) => { this._myHistoricTradesGrid.items.unshift(offer)
if (item.qortalAtAddress === offer.qortalAtAddress) { this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? this._myHistoricTradesGrid.clearCache() : null
this._openOrdersGrid.items.splice(index, 1) }
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._openOrdersGrid.clearCache() : null this._openOrdersGrid.items.forEach((item, index) => {
} if (item.qortalAtAddress === offer.qortalAtAddress) {
}) this._openOrdersGrid.items.splice(index, 1)
this.listedCoins.get(this.selectedCoin).openOrders = this.listedCoins.get(this.selectedCoin).openOrders.filter((order) => order.qortalAtAddress !== offer.qortalAtAddress) this.listedCoins.get(offer.foreignBlockchain).tradeOffersSocketCounter > 1 ? this._openOrdersGrid.clearCache() : null
this._stuckOrdersGrid.items.forEach((item, index) => { }
if (item.qortalAtAddress === offer.qortalAtAddress) { })
this._stuckOrdersGrid.items.splice(index, 1) this.listedCoins.get(offer.foreignBlockchain).openOrders = this.listedCoins.get(offer.foreignBlockchain).openOrders.filter((order) => order.qortalAtAddress !== offer.qortalAtAddress)
this._stuckOrdersGrid.clearCache() this._stuckOrdersGrid.items.forEach((item, index) => {
if (item.qortalAtAddress === offer.qortalAtAddress) {
this._stuckOrdersGrid.items.splice(index, 1)
this._stuckOrdersGrid.clearCache()
}
})
} }
}) }catch(e){
console.log("Error processing cancelled trade offer from "+offer.foreignBlockchain)
}
} }
/** /**
@ -1314,7 +1350,6 @@ class TradePortal extends LitElement {
offers.forEach((offer) => { offers.forEach((offer) => {
if (offer.mode === 'OFFERING') { if (offer.mode === 'OFFERING') {
this.processOfferingTrade(offer) this.processOfferingTrade(offer)
this.listedCoins.get(this.selectedCoin).tradeOffersSocketCounter > 1 ? this._openOrdersGrid.clearCache() : null
} else if (offer.mode === 'REDEEMED') { } else if (offer.mode === 'REDEEMED') {
this.processRedeemedTrade(offer) this.processRedeemedTrade(offer)
} else if (offer.mode === 'TRADING') { } else if (offer.mode === 'TRADING') {

Loading…
Cancel
Save