Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Add penalty comps message. #3188

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ func newDEXAccount(acctInfo *db.AccountInfo, viewOnly bool) *dexAccount {
targetTier: acctInfo.TargetTier,
maxBondedAmt: acctInfo.MaxBondedAmt,
bondAsset: acctInfo.BondAsset,
penaltyComps: acctInfo.PenaltyComps,
}
}

Expand Down
2 changes: 2 additions & 0 deletions client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ var EnUS = map[string]*intl.Translation{
"posting_bonds_shortly": {T: "Creating bonds..."},
"bond_creation_pending_msg": {T: `In order to trade at <span id="postingBondsDex" class="text-break"></span> bond(s) will be created shortly.`},
"action_required_to_trade": {T: "ACTION REQUIRED TO TRADE"},
"set_penalty_comps": {T: `Your account has <span id="acctPenalties"></span> penalties but is only authorized for <span id="acctPenaltyComps"></span> penalty comps.`},
"acct_tier_post_bond": {T: `Your account tier is <span id="acctTier"></span>. You need to post new bonds to trade.`},
"enable_bond_maintenance": {T: "Enable bond maintenance from DEX Settings page."},
"update_penalty_comps": {T: "Update penalty comps from DEX Settings page."},
"Buy": {T: "Buy"},
"Sell": {T: "Sell"},
"lot_size": {T: "Lot Size"},
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/dexsettings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</div>
<div class="col-6 text-end">
<span id="penaltyComps"></span>
<input id="penaltyCompInput" type="number" step="1" class="micro thin text-center d-hide fs14" {{if .Exchange.Disabled}}disabled{{end}}>
<input id="penaltyCompInput" type="number" step="1" class="micro thin text-center fs14" {{if .Exchange.Disabled}}disabled{{end}}>
</div>
</div>
<div id="penaltyCompsErr" class="d-hide flex-center text-danger fs15"></div>
Expand Down
11 changes: 11 additions & 0 deletions client/webserver/site/src/html/markets.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@
</div>
</div>

{{- /* PENALTY COMPS REQUIRED TO TRADE */ -}}
<div class="d-hide p-2 mt-2" id="penaltyCompsRequired">
<div class="p-3 flex-center fs16 grey">[[[action_required_to_trade]]]</div>
<div class="border-top border-bottom flex-center p-2">
<p class="text-center fs14 p-2 m-0">
[[[set_penalty_comps]]]
<a id="compsDexSettingsLink" class="fs15 hoverbg subtlelink">[[[update_penalty_comps]]]</a>
</p>
</div>
</div>

{{- /* BOND REQUIRED TO TRADE */ -}}
<div class="d-hide p-2 mt-2" id="bondRequired">
<div class="p-3 flex-center fs16 grey">[[[action_required_to_trade]]]</div>
Expand Down
17 changes: 1 addition & 16 deletions client/webserver/site/src/js/dexsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,17 @@ export default class DexSettingsPage extends BasePage {
if (!this.accountDisabled) page.toggleAutoRenew.click()
})

page.penaltyComps.textContent = String(xc.auth.penaltyComps)
const hideCompInput = () => {
Doc.hide(page.penaltyCompInput)
Doc.show(page.penaltyComps)
}
page.penaltyCompInput.value = String(xc.auth.penaltyComps)
Doc.bind(page.penaltyCompBox, 'click', (e: MouseEvent) => {
e.stopPropagation()
const xc = app().exchanges[this.host]
page.penaltyCompInput.value = String(xc.auth.penaltyComps)
Doc.hide(page.penaltyComps)
Doc.show(page.penaltyCompInput)
page.penaltyCompInput.focus()
const checkClick = (e: MouseEvent) => {
if (Doc.mouseInElement(e, page.penaltyCompBox)) return
hideCompInput()
Doc.unbind(document, 'click', checkClick)
}
Doc.bind(document, 'click', checkClick)
})

Doc.bind(page.penaltyCompInput, 'keyup', async (e: KeyboardEvent) => {
Doc.hide(page.penaltyCompsErr)
if (e.key === 'Escape') {
hideCompInput()
return
}
if (!(e.key === 'Enter')) return
Expand All @@ -166,13 +153,11 @@ export default class DexSettingsPage extends BasePage {
try {
await this.updateBondOptions({ penaltyComps })
loaded()
page.penaltyComps.textContent = String(penaltyComps)
} catch (e) {
loaded()
Doc.show(page.penaltyCompsErr)
page.penaltyCompsErr.textContent = intl.prep(intl.ID_API_ERROR, { msg: e.msg })
}
hideCompInput()
})

this.dexAddrForm = new forms.DEXAddressForm(page.dexAddrForm, async (xc: Exchange) => {
Expand Down
9 changes: 7 additions & 2 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ export default class MarketsPage extends BasePage {
this.updateRegistrationStatusView()

const showSection = (section: PageElement | undefined) => {
const elements = [page.registrationStatus, page.bondRequired, page.bondCreationPending, page.notRegistered]
const elements = [page.registrationStatus, page.bondRequired, page.bondCreationPending, page.notRegistered, page.penaltyCompsRequired]
for (const el of elements) {
Doc.setVis(el === section, el)
}
Expand All @@ -1000,6 +1000,11 @@ export default class MarketsPage extends BasePage {
} else if (market.dex.viewOnly) {
page.unregisteredDex.textContent = market.dex.host
showSection(page.notRegistered)
} else if (market.dex.auth.targetTier > 0 && market.dex.auth.rep.penalties > market.dex.auth.penaltyComps) {
page.acctPenalties.textContent = `${market.dex.auth.rep.penalties}`
page.acctPenaltyComps.textContent = `${market.dex.auth.penaltyComps}`
page.compsDexSettingsLink.href = `/dexsettings/${market.dex.host}`
showSection(page.penaltyCompsRequired)
} else if (this.hasPendingBonds()) {
showSection(page.registrationStatus)
} else if (market.dex.auth.targetTier > 0) {
Expand Down Expand Up @@ -1121,7 +1126,7 @@ export default class MarketsPage extends BasePage {
// Hide the balance widget
this.balanceWgt.setBalanceVisibility(false)

Doc.hide(page.notRegistered, page.bondRequired, page.noWallet)
Doc.hide(page.notRegistered, page.bondRequired, page.noWallet, page.penaltyCompsRequired)

// If we have not yet connected, there is no dex.assets or any other
// exchange data, so just put up a message and wait for the connection to be
Expand Down
Loading