From ca9f40c2b00f3019ee7fe72a5ca9c674d42179dd Mon Sep 17 00:00:00 2001 From: Brian Stafford Date: Wed, 8 Nov 2023 13:27:14 -0600 Subject: [PATCH] add auto-renew toggle and penalty comps input --- client/core/bond.go | 9 +- client/core/core_test.go | 12 +- client/core/types.go | 4 +- client/rpcserver/types.go | 7 +- client/webserver/locales/en-us.go | 3 +- .../webserver/site/src/css/dex_settings.scss | 4 + client/webserver/site/src/css/forms.scss | 27 ++++ .../webserver/site/src/html/dexsettings.tmpl | 26 ++- client/webserver/site/src/html/forms.tmpl | 3 + client/webserver/site/src/js/app.ts | 4 +- client/webserver/site/src/js/dexsettings.ts | 152 +++++++++++++++--- client/webserver/site/src/js/forms.ts | 8 +- client/webserver/site/src/js/locales.ts | 5 +- client/webserver/site/src/js/registry.ts | 2 +- 14 files changed, 224 insertions(+), 42 deletions(-) diff --git a/client/core/bond.go b/client/core/bond.go index a2f719d73b..eab1e09539 100644 --- a/client/core/bond.go +++ b/client/core/bond.go @@ -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 } @@ -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 diff --git a/client/core/core_test.go b/client/core/core_test.go index 6b7c006218..a030f6531c 100644 --- a/client/core/core_test.go +++ b/client/core/core_test.go @@ -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, }, @@ -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, }, @@ -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, @@ -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, }, @@ -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, }, @@ -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, }, diff --git a/client/core/types.go b/client/core/types.go index 34eb71d927..ea21e8bc80 100644 --- a/client/core/types.go +++ b/client/core/types.go @@ -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"` } diff --git a/client/rpcserver/types.go b/client/rpcserver/types.go index 4dab0a2432..fb7a7ef109 100644 --- a/client/rpcserver/types.go +++ b/client/rpcserver/types.go @@ -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 { @@ -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, diff --git a/client/webserver/locales/en-us.go b/client/webserver/locales/en-us.go index f06714266d..6b5c06ddec 100644 --- a/client/webserver/locales/en-us.go +++ b/client/webserver/locales/en-us.go @@ -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", @@ -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.", diff --git a/client/webserver/site/src/css/dex_settings.scss b/client/webserver/site/src/css/dex_settings.scss index e114c4a09a..e930ebd150 100644 --- a/client/webserver/site/src/css/dex_settings.scss +++ b/client/webserver/site/src/css/dex_settings.scss @@ -6,3 +6,7 @@ color: green; } +#penaltyCompInput { + width: 2rem; +} + diff --git a/client/webserver/site/src/css/forms.scss b/client/webserver/site/src/css/forms.scss index d83f468db8..088d64c304 100644 --- a/client/webserver/site/src/css/forms.scss +++ b/client/webserver/site/src/css/forms.scss @@ -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; + } +} \ No newline at end of file diff --git a/client/webserver/site/src/html/dexsettings.tmpl b/client/webserver/site/src/html/dexsettings.tmpl index 360523a042..1bc2c9d83a 100644 --- a/client/webserver/site/src/html/dexsettings.tmpl +++ b/client/webserver/site/src/html/dexsettings.tmpl @@ -37,7 +37,31 @@
-
+
+
+
+ Auto Renew +
+
+
+
+
+
+
+
+
+ Penalty Comps + +
+
+ + +
+
+
+
+
+
{{template "reputationMeter"}}
diff --git a/client/webserver/site/src/html/forms.tmpl b/client/webserver/site/src/html/forms.tmpl index 9446a92281..2499f67dbe 100644 --- a/client/webserver/site/src/html/forms.tmpl +++ b/client/webserver/site/src/html/forms.tmpl @@ -228,6 +228,9 @@ {{define "regAssetForm"}}
+
+ +
[[[What is a fidelity bond]]]