Skip to content

Commit

Permalink
site: remove api errors from bell notification
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 authored and chappjc committed Aug 31, 2022
1 parent 1b50969 commit e9ef59e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 33 deletions.
21 changes: 5 additions & 16 deletions client/webserver/site/src/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ const constructors: Record<string, PageClass> = {
dexsettings: DexSettingsPage
}

// unathedPages are pages that don't require authorization to load.
// These are endpoints outside of the requireLogin block in webserver.New.
const unauthedPages = ['register', 'login', 'settings']

// Application is the main javascript web application for the Decred DEX client.
export default class Application {
notes: CoreNotePlus[]
Expand Down Expand Up @@ -219,9 +215,7 @@ export default class Application {
*/
async fetchUser (): Promise<User | void> {
const resp: APIResponse = await getJSON('/api/user')
// If it's not a page that requires auth, skip the error notification.
const skipNote = unauthedPages.indexOf(this.main.dataset.handler || '') > -1
if (!this.checkResponse(resp, skipNote)) return
if (!this.checkResponse(resp)) return
const user = (resp as any) as User
this.seedGenTime = user.seedgentime
this.user = user
Expand Down Expand Up @@ -876,16 +870,11 @@ export default class Application {

/*
* checkResponse checks the response object as returned from the functions in
* the http module. If the response indicates that the request failed, a
* message will be displayed in the drop-down notifications and false will be
* returned.
* the http module. If the response indicates that the request failed, it
* returns false, otherwise, true.
*/
checkResponse (resp: APIResponse, skipNote?: boolean): boolean {
if (!resp.requestSuccessful || !resp.ok) {
if (this.user.inited && !skipNote) this.notify(ntfn.make(intl.prep(intl.ID_API_ERROR), resp.msg, ntfn.ERROR))
return false
}
return true
checkResponse (resp: APIResponse): boolean {
return (resp.requestSuccessful && resp.ok)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions client/webserver/site/src/js/dexsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class DexSettingsPage extends BasePage {
const loaded = app().loading(this.body)
const res = await postJSON('/api/disableaccount', req)
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.disableAccountErr.textContent = res.msg
Doc.show(page.disableAccountErr)
return
Expand Down Expand Up @@ -165,7 +165,7 @@ export default class DexSettingsPage extends BasePage {
const loaded = app().loading(this.body)
const res = await postJSON('/api/updatecert', req)
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.errMsg.textContent = res.msg
Doc.show(page.errMsg)
} else {
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ export class DEXAddressForm {
const loaded = app().loading(this.form)
const res = await postJSON(endpoint, req)
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
if (res.msg === 'certificate required') {
Doc.show(page.needCert)
} else {
Expand Down
11 changes: 5 additions & 6 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ export default class MarketsPage extends BasePage {
...args
})
if (counter !== this.maxOrderUpdateCounter) return
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
console.warn('max order estimate not available:', res)
page.maxFromLots.textContent = intl.prep(intl.ID_ESTIMATE_UNAVAILABLE)
if (this.maxLoaded) {
Expand Down Expand Up @@ -1520,7 +1520,7 @@ export default class MarketsPage extends BasePage {
for (const assetID of assetIDs) {
req.assetID = assetID
const res = await postJSON('/api/openwallet', req)
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
return res.msg
}
}
Expand All @@ -1537,7 +1537,7 @@ export default class MarketsPage extends BasePage {
const loaded = app().loading(page.verifyForm)
const res = await postJSON('/api/preorder', wireOrder(order))
loaded()
if (!app().checkResponse(res, true)) return { err: res.msg }
if (!app().checkResponse(res)) return { err: res.msg }
this.preorderCache[cacheKey] = res.estimate
return res.estimate
}
Expand All @@ -1555,7 +1555,6 @@ export default class MarketsPage extends BasePage {

/* preOrder loads the options and fetches pre-order estimates */
async preOrder (order: TradeForm) {
// if (!this.validateOrder(order)) return
const page = this.page

// Add swap options.
Expand Down Expand Up @@ -1640,7 +1639,7 @@ export default class MarketsPage extends BasePage {
const res = await postJSON('/api/cancel', req)
loaded()
// Display error on confirmation modal.
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.cancelErr.textContent = res.msg
Doc.show(page.cancelErr)
return
Expand Down Expand Up @@ -1842,7 +1841,7 @@ export default class MarketsPage extends BasePage {
page.vSubmit.classList.remove('d-hide')
page.vLoader.classList.add('d-hide')
// If errors display error on confirmation modal.
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.vErr.textContent = res.msg
Doc.show(page.vErr)
return
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class RegistrationPage extends BasePage {
asset: assetID
})
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
return 0
}
return res.txfee
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export interface Application {
walletDefinition (assetID: number, walletType: string): WalletDefinition
currentWalletDefinition (assetID: number): WalletDefinition
fetchBalance (assetID: number): Promise<WalletBalance>
checkResponse (resp: APIResponse, skipNote?: boolean): boolean
checkResponse (resp: APIResponse): boolean
signOut (): Promise<void>
registerNoteFeeder (receivers: Record<string, (n: CoreNote) => void>): void
}
Expand Down
4 changes: 2 additions & 2 deletions client/webserver/site/src/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default class SettingsPage extends BasePage {
asset: assetID
})
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
return 0
}
return res.txfee
Expand Down Expand Up @@ -350,7 +350,7 @@ export default class SettingsPage extends BasePage {
clearValues()
const res = await postJSON('/api/changeapppass', req)
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.changePWErrMsg.textContent = res.msg
Doc.show(page.changePWErrMsg)
return
Expand Down
8 changes: 4 additions & 4 deletions client/webserver/site/src/js/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ export default class WalletsPage extends BasePage {
const loaded = app().loading(page.reconfigForm)
const res = await postJSON('/api/walletsettings', { assetID })
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.reconfigErr.textContent = res.msg
Doc.show(page.reconfigErr)
return
Expand Down Expand Up @@ -665,7 +665,7 @@ export default class WalletsPage extends BasePage {
assetID: this.selectedAssetID
})
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.depositErr.textContent = res.msg
Doc.show(page.depositErr)
return
Expand Down Expand Up @@ -745,7 +745,7 @@ export default class WalletsPage extends BasePage {
const loaded = app().loading(page.sendForm)
const res = await postJSON('/api/send', open)
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.sendErr.textContent = res.msg
Doc.show(page.sendErr)
return
Expand Down Expand Up @@ -782,7 +782,7 @@ export default class WalletsPage extends BasePage {
page.appPW.value = ''
page.newPW.value = ''
loaded()
if (!app().checkResponse(res, true)) {
if (!app().checkResponse(res)) {
page.reconfigErr.textContent = res.msg
Doc.show(page.reconfigErr)
return
Expand Down

0 comments on commit e9ef59e

Please sign in to comment.