From cbd79baed5c418153c5a964301b87ec32bbf54e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B8b=C4=97rt=C3=B8?= <106074508+EchoDex@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:50:45 +0400 Subject: [PATCH] fix: infinity and market price logic --- .../LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx | 10 ++++++++++ spark-frontend/src/stores/SettingsStore.ts | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx index 7246e82c..dcc0910f 100644 --- a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx +++ b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx @@ -142,6 +142,11 @@ class CreateOrderSpotVM { const { tradeStore, balanceStore } = this.rootStore; this.inputAmount = amount.toDecimalPlaces(0); + if (this.inputPrice.eq(BN.ZERO)) { + this.inputTotal = BN.ZERO; + return; + } + if (!sync) return; const formattedInputPrice = BN.formatUnits(this.inputPrice, DEFAULT_DECIMALS); @@ -170,6 +175,11 @@ class CreateOrderSpotVM { const { tradeStore, balanceStore } = this.rootStore; this.inputTotal = total; + if (this.inputPrice.eq(BN.ZERO)) { + this.inputAmount = BN.ZERO; + return; + } + if (!sync) return; const formattedInputPrice = BN.formatUnits(this.inputPrice, DEFAULT_DECIMALS); diff --git a/spark-frontend/src/stores/SettingsStore.ts b/spark-frontend/src/stores/SettingsStore.ts index 87aff50c..73553b26 100644 --- a/spark-frontend/src/stores/SettingsStore.ts +++ b/spark-frontend/src/stores/SettingsStore.ts @@ -5,9 +5,9 @@ import { THEME_TYPE } from "@src/themes/ThemeProvider"; import RootStore from "@stores/RootStore"; export interface ISerializedSettingStore { - isUserAgreedWithTerms: boolean; - tradeTableSize: number; - orderType: ORDER_TYPE; + isUserAgreedWithTerms?: boolean; + tradeTableSize?: number; + orderType?: ORDER_TYPE; } export enum TRADE_TABLE_SIZE { @@ -25,9 +25,9 @@ class SettingsStore { this.rootStore = rootStore; makeAutoObservable(this); if (initState) { - this.setIsUserAgreedWithTerms(initState.isUserAgreedWithTerms); - this.setTradeTableSize(initState.tradeTableSize); - this.setOrderType(initState.orderType); + this.setIsUserAgreedWithTerms(initState.isUserAgreedWithTerms ?? false); + this.setTradeTableSize(initState.tradeTableSize ?? TRADE_TABLE_SIZE.S); + this.setOrderType(initState.orderType ?? ORDER_TYPE.Market); } }