Skip to content

Commit

Permalink
actually, fetch maxsell when rate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Jun 24, 2022
1 parent 220494d commit 608921a
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ interface CurrentMarket {
quote: SupportedAsset
baseUnitInfo: UnitInfo
quoteUnitInfo: UnitInfo
maxSellRequested: boolean
maxSell: MaxOrderEstimate | null
maxSells: Record<number, MaxOrderEstimate>
sellBalance: number
buyBalance: number
maxBuys: Record<number, MaxOrderEstimate>
Expand Down Expand Up @@ -296,11 +295,8 @@ export default class MarketsPage extends BasePage {
this.drawChartLines()
})
bind(page.maxOrd, 'click', () => {
if (this.isSell()) {
const maxSell = this.market.maxSell
if (!maxSell) return
page.lotField.value = String(maxSell.swap.lots)
} else page.lotField.value = String(this.market.maxBuys[this.adjustedRate()].swap.lots)
if (this.isSell()) page.lotField.value = String(this.market.maxSells[this.adjustedRate()].swap.lots)
else page.lotField.value = String(this.market.maxBuys[this.adjustedRate()].swap.lots)
this.lotChanged()
})
bind(page.depthBttn, 'click', () => {
Expand Down Expand Up @@ -707,9 +703,8 @@ export default class MarketsPage extends BasePage {
quote: app().assets[quote],
baseUnitInfo: bui,
quoteUnitInfo: qui,
maxSell: null,
maxSells: {},
maxBuys: {},
maxSellRequested: false,
candleCaches: {},
baseCfg,
quoteCfg,
Expand Down Expand Up @@ -881,17 +876,15 @@ export default class MarketsPage extends BasePage {
this.setMaxOrder(null)
return
}
if (mkt.maxSell) {
this.setMaxOrder(mkt.maxSell.swap)
const rate = this.isLimit() ? this.adjustedRate() : 0
if (mkt.maxSells[rate]) {
this.setMaxOrder(mkt.maxSells[rate].swap)
return
}
if (mkt.maxSellRequested) return
mkt.maxSellRequested = true
// We only fetch pre-sell once per balance update, so don't delay.
const rate = this.isLimit() ? this.adjustedRate() : 0
this.scheduleMaxEstimate('/api/maxsell', { rate }, 0, (res: MaxSell) => {
mkt.maxSellRequested = false
mkt.maxSell = res.maxSell
const delay = Object.keys(mkt.maxSells).length ? 350 : 0
this.scheduleMaxEstimate('/api/maxsell', { rate }, delay, (res: MaxSell) => {
mkt.maxSells[rate] = res.maxSell
mkt.sellBalance = baseWallet.balance.available
this.setMaxOrder(res.maxSell.swap)
})
Expand Down Expand Up @@ -1780,8 +1773,8 @@ export default class MarketsPage extends BasePage {
switch (note.assetID) {
case mkt.baseCfg.id:
// If we're not showing the max order panel yet, don't do anything.
if (!mkt.maxSell) break
if (typeof mkt.sellBalance === 'number' && mkt.sellBalance !== avail) mkt.maxSell = null
if (!Object.keys(mkt.maxSells).length) break
if (typeof mkt.sellBalance === 'number' && mkt.sellBalance !== avail) mkt.maxSells = {}
if (this.isSell()) this.preSell()
break
case mkt.quoteCfg.id:
Expand Down

0 comments on commit 608921a

Please sign in to comment.