Skip to content

Commit

Permalink
app: Fix market page form close (#3053)
Browse files Browse the repository at this point in the history
Fixes a bug related to closing popups on the market page.
  • Loading branch information
martonp authored Nov 11, 2024
1 parent 4d8aeca commit 54f51cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
7 changes: 4 additions & 3 deletions client/webserver/site/src/js/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ interface WalletConfig {
}

interface FormsConfig {
closed?: () => void
closed?: (closedForm: PageElement | undefined) => void
}

export class Forms {
formsDiv: PageElement
currentForm: PageElement | undefined
currentFormID: string | undefined
keyup: (e: KeyboardEvent) => void
closed?: () => void
closed?: (closedForm: PageElement | undefined) => void

constructor (formsDiv: PageElement, cfg?: FormsConfig) {
this.formsDiv = formsDiv
Expand Down Expand Up @@ -110,9 +110,10 @@ export class Forms {

close (): void {
Doc.hide(this.formsDiv)
const closedForm = this.currentForm
this.currentForm = undefined
this.currentFormID = undefined
if (this.closed) this.closed()
if (this.closed) this.closed(closedForm)
}

exit () {
Expand Down
17 changes: 7 additions & 10 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ export default class MarketsPage extends BasePage {
maxLoaded: (() => void) | null
maxOrderUpdateCounter: number
market: CurrentMarket
currentForm: HTMLElement
openAsset: SupportedAsset
currentCreate: SupportedAsset
maxEstimateTimer: number | null
Expand Down Expand Up @@ -215,7 +214,13 @@ export default class MarketsPage extends BasePage {
this.recentMatchesSortDirection = -1
// store original title so we can re-append it when updating market value.
this.ogTitle = document.title
this.forms = new Forms(page.forms)
this.forms = new Forms(page.forms, {
closed: (closedForm: PageElement | undefined) => {
if (closedForm === page.vDetailPane) {
this.showVerifyForm()
}
}
})

const depthReporters = {
click: (x: number) => { this.reportDepthClick(x) },
Expand Down Expand Up @@ -421,14 +426,6 @@ export default class MarketsPage extends BasePage {
this.forms.close()
}

// If the user clicks outside of a form, it should close the page overlay.
bind(page.forms, 'mousedown', (e: MouseEvent) => {
if (Doc.isDisplayed(page.vDetailPane) && !Doc.mouseInElement(e, page.vDetailPane)) return this.showVerifyForm()
if (!Doc.mouseInElement(e, this.currentForm)) {
closePopups()
}
})

this.keyup = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
closePopups()
Expand Down

0 comments on commit 54f51cb

Please sign in to comment.