Skip to content

Commit

Permalink
add auto-renew toggle and penalty comps input
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Nov 8, 2023
1 parent afefe4b commit ca9f40c
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 42 deletions.
9 changes: 6 additions & 3 deletions client/core/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,12 +986,12 @@ func (c *Core) nextBondKey(assetID uint32) (*secp256k1.PrivateKey, uint32, error
// the target trading tier, the preferred asset to use for bonds, and the
// maximum amount allowable to be locked in bonds.
func (c *Core) UpdateBondOptions(form *BondOptionsForm) error {
dc, _, err := c.dex(form.Addr)
dc, _, err := c.dex(form.Host)
if err != nil {
return err
}
// TODO: exclude unregistered and/or watch-only
dbAcct, err := c.db.Account(form.Addr)
dbAcct, err := c.db.Account(form.Host)
if err != nil {
return err
}
Expand Down Expand Up @@ -1063,7 +1063,10 @@ func (c *Core) UpdateBondOptions(form *BondOptionsForm) error {
dbAcct.TargetTier = targetTier
}

penaltyComps := form.PenaltyComps
var penaltyComps = penaltyComps0
if form.PenaltyComps != nil {
penaltyComps = *form.PenaltyComps
}
dc.acct.penaltyComps = penaltyComps
dbAcct.PenaltyComps = penaltyComps

Expand Down
12 changes: 6 additions & 6 deletions client/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10576,7 +10576,7 @@ func TestUpdateBondOptions(t *testing.T) {
name: "set target tier to 1",
bal: singlyBondedReserves,
form: BondOptionsForm{
Addr: acct.host,
Host: acct.host,
TargetTier: &targetTier,
BondAssetID: &bondAsset.ID,
},
Expand All @@ -10590,7 +10590,7 @@ func TestUpdateBondOptions(t *testing.T) {
name: "low balance",
bal: singlyBondedReserves - 1,
form: BondOptionsForm{
Addr: acct.host,
Host: acct.host,
TargetTier: &targetTier,
BondAssetID: &bondAsset.ID,
},
Expand All @@ -10600,7 +10600,7 @@ func TestUpdateBondOptions(t *testing.T) {
name: "max-bonded too low",
bal: singlyBondedReserves,
form: BondOptionsForm{
Addr: acct.host,
Host: acct.host,
TargetTier: &targetTier,
BondAssetID: &bondAsset.ID,
MaxBondedAmt: &tooLowMaxBonded,
Expand All @@ -10610,7 +10610,7 @@ func TestUpdateBondOptions(t *testing.T) {
{
name: "unsupported bond asset",
form: BondOptionsForm{
Addr: acct.host,
Host: acct.host,
TargetTier: &targetTier,
BondAssetID: &wrongBondAssetID,
},
Expand All @@ -10620,7 +10620,7 @@ func TestUpdateBondOptions(t *testing.T) {
name: "lower target tier with zero balance OK",
bal: 0,
form: BondOptionsForm{
Addr: acct.host,
Host: acct.host,
TargetTier: &targetTierZero,
BondAssetID: &bondAsset.ID,
},
Expand All @@ -10635,7 +10635,7 @@ func TestUpdateBondOptions(t *testing.T) {
name: "lower target tier to zero with other exchanges still keeps reserves",
bal: 0,
form: BondOptionsForm{
Addr: acct.host,
Host: acct.host,
TargetTier: &targetTierZero,
BondAssetID: &bondAsset.ID,
},
Expand Down
4 changes: 2 additions & 2 deletions client/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ type SupportedAsset struct {
// BondOptionsForm is used from the settings page to change the auto-bond
// maintenance setting for a DEX.
type BondOptionsForm struct {
Addr string `json:"host"`
Host string `json:"host"`
TargetTier *uint64 `json:"targetTier,omitempty"`
MaxBondedAmt *uint64 `json:"maxBondedAmt,omitempty"`
PenaltyComps uint16 `json:"penaltyComps"`
PenaltyComps *uint16 `json:"penaltyComps,omitempty"`
BondAssetID *uint32 `json:"bondAssetID,omitempty"`
}

Expand Down
7 changes: 4 additions & 3 deletions client/rpcserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func parseBondOptsArgs(params *RawParams) (*core.BondOptionsForm, error) {
}
}

var penaltyComps uint16
var penaltyComps *uint16
if len(params.Args) > 4 {
pc, err := checkIntArg(params.Args[4], "penaltyComps", 16)
if err != nil {
Expand All @@ -517,12 +517,13 @@ func parseBondOptsArgs(params *RawParams) (*core.BondOptionsForm, error) {
return nil, fmt.Errorf("penaltyComps out of range (0, %d)", math.MaxUint16)
}
if pc > 0 {
penaltyComps = uint16(pc)
pc16 := uint16(pc)
penaltyComps = &pc16
}
}

req := &core.BondOptionsForm{
Addr: params.Args[0],
Host: params.Args[0],
TargetTier: targetTierP,
MaxBondedAmt: maxBondedP,
BondAssetID: bondAssetP,
Expand Down
3 changes: 2 additions & 1 deletion client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var EnUS = map[string]string{
"bond_strength": "Bond Strength",
"target_tier": "Target Tier",
"target_tier_tooltip": "This is the target account tier you wish to maintain. Set to zero if you wish to disable tier maintenance (do not post new bonds).",
"compensation_tooltip": "Enable posting additional bonds to offset penalized tiers.",
"Actual Tier": "Actual Tier",
"Penalties": "Penalties",
"Change Tier": "Change Tier",
Expand Down Expand Up @@ -205,7 +206,7 @@ var EnUS = map[string]string{
"Progress": "Progress",
"remaining": "remaining",
"2 Fund your Wallet": "2: Fund your Wallet",
"bond_definition": "A fidelity bond is funds temporarily locked in an on-chain contract. After the contract expires, your wallet will reclaim the funds.",
"bond_definition": "A fidelity bond is funds temporarily locked in an on-chain contract. After the contract expires, your wallet will reclaim the funds. On mainnet, funds are locked for up to 2 months.",
"bonds_can_be_revoked": "Bonds can be revoked if an account engages in continued disruptive behavior, such as backing out on a swap. Revoked bonds can be re-activated with continued normal trading activity.",
"bigger_bonds_higher_limit": "You can create larger bonds to increase your trading tier, enabling trading of larger quantities at a time. Larger bonds also increase your capacity for violations before trading privileges are suspended.",
"limits_reputation": "Trading limits are also increased as you establish reputation by engaging in normal trading activity and successfully completing matches.",
Expand Down
4 changes: 4 additions & 0 deletions client/webserver/site/src/css/dex_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
color: green;
}

#penaltyCompInput {
width: 2rem;
}

27 changes: 27 additions & 0 deletions client/webserver/site/src/css/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,30 @@ div[data-handler=init] {
height: 25px;
}
}

.anitoggle {
width: 1.5rem;
height: 0.9rem;
border-radius: 0.45rem;
background-color: #777a;
cursor: pointer;

&.on {
background-color: $buycolor_dark;
}

& > div {
position: relative;
top: 0.1rem;
left: 0.1rem;
width: 0.7rem;
height: 0.7rem;
border-radius: 0.35rem;
transition: left 0.5s;
background-color: $dark_body_bg;
}

&.on > div {
left: 0.7rem;
}
}
26 changes: 25 additions & 1 deletion client/webserver/site/src/html/dexsettings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,31 @@
</div>
</div>
<hr class="mb-1">
<div id="repMeter">
<div id="otherBondSettings" class="d-flex align-items-stretch brdrbottom pb-1">
<div class="col-12 pe-2">
<div id="autoRenewBox" class="d-flex justify-content-between align-items-center hoverbg pointer">
<span>Auto Renew</span>
<div>
<div id="toggleAutoRenew" class="anitoggle"></div>
</div>
</div>
<div id="renewErr" class="d-hide flex-center errcolor fs15"></div>
</div>
<div class="col-12 ps-2 brdrleft">
<div id="penaltyCompBox" class="d-flex justify-content-between align-items-center hoverbg pointer">
<div>
<span>Penalty Comps</span>
<span class="ico-info fs14" data-tooltip="[[[compensation_tooltip]]]"></span>
</div>
<div>
<span id="penaltyComps"></span>
<input id="penaltyCompInput" type="number" step="1" class="d-hide fs14 text-center">
</div>
</div>
<div id="penaltyCompsErr" class="d-hide flex-center errcolor fs15"></div>
</div>
</div>
<div id="repMeter" class="w-100">
{{template "reputationMeter"}}
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions client/webserver/site/src/html/forms.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@

{{define "regAssetForm"}}
<div data-tmpl="whatsABondPanel" class="d-hide">
<div data-tmpl="whatsABondBack" class="w-100 py-2 pointer hoverbg">
<span class="ico-wide-headed-left-arrow fs24"></span>
</div>
<div class="flex-center fs22 mb-2">[[[What is a fidelity bond]]]</div>
<ul class="fs16">
<li>
Expand Down
4 changes: 1 addition & 3 deletions client/webserver/site/src/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ export default class Application {
}

if (process.env.NODE_ENV === 'development') {
window.user = () => {
console.log(this.user)
}
window.user = () => this.user
}

// use user current locale set by backend
Expand Down
Loading

0 comments on commit ca9f40c

Please sign in to comment.