From dff2b92d32c3ec53298892b848f56e35a030786a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 9 Oct 2024 11:36:27 +0200 Subject: [PATCH 1/2] Step down DCA frequency unit when interval multiplier is lowered --- .changeset/perfect-turtles-begin.md | 5 +++++ packages/apps/src/app/dca/Form.ts | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 .changeset/perfect-turtles-begin.md diff --git a/.changeset/perfect-turtles-begin.md b/.changeset/perfect-turtles-begin.md new file mode 100644 index 0000000000..fbd1f7ddb9 --- /dev/null +++ b/.changeset/perfect-turtles-begin.md @@ -0,0 +1,5 @@ +--- +'@galacticcouncil/apps': patch +--- + +Step down DCA frequency unit when interval multiplier is lowered diff --git a/packages/apps/src/app/dca/Form.ts b/packages/apps/src/app/dca/Form.ts index 5287f3e278..2b5c181b1b 100644 --- a/packages/apps/src/app/dca/Form.ts +++ b/packages/apps/src/app/dca/Form.ts @@ -139,8 +139,17 @@ export class DcaForm extends BaseElement { this.dispatchEvent(new CustomEvent('interval-mul-change', options)); setTimeout(() => { - if (this.frequencyRanges[this.frequencyUnit] <= 1) { - this.setFrequencyUnit(this.maxFrequency, 'min'); + if (multipliplier && this.frequencyRanges[this.frequencyUnit] <= 1) { + const units = Object.keys(this.frequencyRanges); + const unit = + (units[units.indexOf(this.frequencyUnit) - 1] as FrequencyUnit) || + 'min'; + const values = { + min: this.maxFrequency, + hour: Math.floor(this.maxFrequency / HOUR_MIN), + day: Math.floor(this.maxFrequency / DAY_MIN), + }; + this.setFrequencyUnit(values[unit], unit); } }, 0); } @@ -398,12 +407,6 @@ export class DcaForm extends BaseElement { day: Math.floor(value / DAY_MIN), }; - const frequencyRanges = { - min: range, - hour: rangeInHours, - day: rangeInDays, - }; - const units = [ 'min', this.frequencyRanges.hour > 0 && 'hour', From 9b5f9688090780240a769d40579482114a133ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Tue, 15 Oct 2024 12:21:38 +0200 Subject: [PATCH 2/2] Improve DCA interval tooltip --- packages/apps/src/app/dca/Form.ts | 27 +++++++++---------- packages/apps/src/app/dca/translation.en.json | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/apps/src/app/dca/Form.ts b/packages/apps/src/app/dca/Form.ts index 2b5c181b1b..d7dac473b4 100644 --- a/packages/apps/src/app/dca/Form.ts +++ b/packages/apps/src/app/dca/Form.ts @@ -374,21 +374,6 @@ export class DcaForm extends BaseElement { const max = this.maxFrequency; const value = this.frequency ?? max; - const valueMsec = value * 60 * 1000; - const blockTime = 12_000; - const blockCount = Math.floor(valueMsec / blockTime); - const blockHint = - blockCount > 0 - ? i18n.t('form.advanced.intervalBlocks', { - minutes: value, - blocks: blockCount, - }) - : undefined; - - const range = max - min; - const rangeInHours = Math.floor(range / HOUR_MIN); - const rangeInDays = Math.floor(range / DAY_MIN); - const minValues: Record = { min: min, hour: Math.ceil(min / HOUR_MIN), @@ -413,6 +398,18 @@ export class DcaForm extends BaseElement { this.frequencyRanges.day > 0 && 'day', ].filter((u): u is FrequencyUnit => !!u); + const valueMsec = value * 60 * 1000; + const blockTime = 12_000; + const blockCount = Math.floor(valueMsec / blockTime); + const blockHint = + blockCount > 0 + ? i18n.t('form.advanced.intervalBlocks', { + unit: i18n.t(`form.frequency.${this.frequencyUnit}`), + value: values[this.frequencyUnit], + blocks: blockCount, + }) + : undefined; + return html` {{amountIn}} {{assetIn}} for <1>{{assetOut}} every <1>~{{frequency}} with a total budget of <1>{{amountInBudget}} {{assetIn}} over the period of <1>~{{time}}",