From 0491952be749726222f3d3d333e5ed94f8d0df16 Mon Sep 17 00:00:00 2001 From: RustemYuzlibaev Date: Tue, 6 Feb 2024 14:45:04 +0500 Subject: [PATCH 01/16] fix css --- src/components/pages/OrderBook/BookWidget.vue | 27 +++++++++++++------ src/components/pages/OrderBook/BuySell.vue | 7 ++--- .../pages/OrderBook/CustomiseWidget.vue | 18 +++++++++++++ .../pages/OrderBook/Dialogs/CancelOrders.vue | 8 +++--- .../pages/OrderBook/Dialogs/PlaceOrder.vue | 23 ++++++---------- .../OrderBook/Popovers/PairListPopover.vue | 4 +-- src/consts/index.ts | 4 +-- src/views/OrderBook.vue | 6 ++--- 8 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 src/components/pages/OrderBook/CustomiseWidget.vue diff --git a/src/components/pages/OrderBook/BookWidget.vue b/src/components/pages/OrderBook/BookWidget.vue index 9a193bdec..d8f81dd4a 100644 --- a/src/components/pages/OrderBook/BookWidget.vue +++ b/src/components/pages/OrderBook/BookWidget.vue @@ -317,11 +317,17 @@ export default class BookWidget extends Mixins(TranslationMixin, mixins.LoadingM } /** - * // TODO: [Rustem] add missed type, add missed docs, it's unclear how this method works + * Aggregates orders based on selected precision by user + * @param orders to be aggregated + * @returns aggregated orders */ - private calculateStepsDistribution(orders, precision = 10): OrderBookPriceVolumeAggregated[] { + private calculateStepsDistribution( + orders: OrderBookPriceVolume[], + precision = 10 + ): OrderBookPriceVolume[] | OrderBookPriceVolumeAggregated[] { if (this.isBookPrecisionEqual(precision.toString())) return orders; + // finds max price to know proper edge in orders distribution const maxPrice = FPNumber.max(...orders.map(([price]) => price)) as FPNumber; if (!maxPrice) return orders; @@ -335,16 +341,19 @@ export default class BookWidget extends Mixins(TranslationMixin, mixins.LoadingM if (!edge.isZeroMod(step)) edge = edge.sub(edge.mod(step)); + // iteratively finds a range to be placed for (let index = 0; index < orders.length; index++) { const [price, amount] = orders[index]; if (FPNumber.lte(edge, FPNumber.ZERO)) break; if (FPNumber.lt(edge, price)) break; + // checks whether eligible for this range if (FPNumber.lte(price, edge) && FPNumber.gt(price, edge.sub(step))) { accumulatedAmount = accumulatedAmount.add(amount); accumulatedTotal = price.mul(amount).add(accumulatedTotal); } else { + // if not, puts accumulated amount and total in row and starts with next one aggregatedOrders.push([edge, accumulatedAmount, accumulatedTotal]); accumulatedAmount = FPNumber.ZERO; @@ -353,11 +362,13 @@ export default class BookWidget extends Mixins(TranslationMixin, mixins.LoadingM index -= 1; } + // scenario when last [price, volume] wasn't recorded in 'else' branch; push it in last row if (index === orders.length - 1) { aggregatedOrders.push([edge, accumulatedAmount, accumulatedTotal]); } } + // filter empty records return aggregatedOrders.filter((row: OrderBookPriceVolumeAggregated) => !row[1].isZero()); } @@ -379,12 +390,12 @@ export default class BookWidget extends Mixins(TranslationMixin, mixins.LoadingM const maxAmount = FPNumber.max(...aggregated.map((order) => order[1])) as FPNumber; const result: LimitOrderForm[] = []; - aggregated.forEach((row: OrderBookPriceVolumeAggregated) => { + aggregated.forEach((row: OrderBookPriceVolume | OrderBookPriceVolumeAggregated) => { const [price, amount, acc] = row; if (amount.isZero()) return; - const total = this.isBookPrecisionEqual(this.selectedStep) ? price.mul(amount) : acc; + const total = (this.isBookPrecisionEqual(this.selectedStep) ? price.mul(amount) : acc) as FPNumber; result.push({ price: this.toBookPrecision(price), @@ -490,7 +501,7 @@ $mono-font: 'JetBrainsMono'; } .order-info.price { - color: var(--status-day-success, #34ad87); + color: var(--s-color-status-success); } } @@ -500,7 +511,7 @@ $mono-font: 'JetBrainsMono'; } .order-info.price { - color: var(--status-day-error, #f754a3); + color: var(--s-color-status-error); } } @@ -530,14 +541,14 @@ $mono-font: 'JetBrainsMono'; &--up { .mark-price, .trend-icon { - color: #34ad87; + color: var(--s-color-status-success); } } &--down { .mark-price, .trend-icon { - color: #f754a3; + color: var(--s-color-status-error); } } } diff --git a/src/components/pages/OrderBook/BuySell.vue b/src/components/pages/OrderBook/BuySell.vue index 6ef607dce..9107a31e0 100644 --- a/src/components/pages/OrderBook/BuySell.vue +++ b/src/components/pages/OrderBook/BuySell.vue @@ -312,7 +312,6 @@ export default class BuySellWidget extends Mixins(TranslationMixin, mixins.Forma }); } - // TODO: [Rustem]: Refactor this function to reduce its Cognitive Complexity from 33 to the 15 allowed. [+22 locations]sonarlint(typescript:S3776) get buttonText(): string { if (!this.isLoggedIn) return this.t('connectWalletText'); @@ -356,7 +355,6 @@ export default class BuySellWidget extends Mixins(TranslationMixin, mixins.Forma this.reading = reading; } - // TODO: [Rustem] Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed. [+14 locations]sonarlint(typescript:S3776) get buttonDisabled(): boolean { if (this.bookStopped) return true; @@ -376,14 +374,13 @@ export default class BuySellWidget extends Mixins(TranslationMixin, mixins.Forma if (this.priceExceedsSpread) return true; } } else { - if (!this.baseValue) return true; // TODO: [Rustem] check with btn text + if (!this.baseValue) return true; if (!this.marketQuotePrice) return true; } return this.isOutOfAmountBounds; } - // TODO: [Rustem] Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed. [+15 locations]sonarlint(typescript:S3776) async checkInputValidation(): Promise { this.setError({ reason: '', reading: '' }); @@ -925,7 +922,7 @@ export default class BuySellWidget extends Mixins(TranslationMixin, mixins.Forma .buy-btn { width: 100%; - background-color: #34ad87 !important; + background-color: var(--s-color-status-success) !important; } .buy-btn.is-disabled { diff --git a/src/components/pages/OrderBook/CustomiseWidget.vue b/src/components/pages/OrderBook/CustomiseWidget.vue new file mode 100644 index 000000000..36bdd32af --- /dev/null +++ b/src/components/pages/OrderBook/CustomiseWidget.vue @@ -0,0 +1,18 @@ + + + + + diff --git a/src/components/pages/OrderBook/Dialogs/CancelOrders.vue b/src/components/pages/OrderBook/Dialogs/CancelOrders.vue index 78bade98b..c46c2f6e9 100644 --- a/src/components/pages/OrderBook/Dialogs/CancelOrders.vue +++ b/src/components/pages/OrderBook/Dialogs/CancelOrders.vue @@ -6,9 +6,6 @@ {{ t('orderBook.dialog.cancelAll') }} - - {{ t('orderBook.dialog.noCancel') }} - @@ -34,7 +31,7 @@ export default class CancelOrders extends Mixins(mixins.DialogMixin, Translation } - diff --git a/src/components/pages/OrderBook/Dialogs/PlaceOrder.vue b/src/components/pages/OrderBook/Dialogs/PlaceOrder.vue index f1926436e..7917db8b0 100644 --- a/src/components/pages/OrderBook/Dialogs/PlaceOrder.vue +++ b/src/components/pages/OrderBook/Dialogs/PlaceOrder.vue @@ -1,5 +1,5 @@