From 71b6952678cfe0fbd199a4d5a26c4d43112a8c9e 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: Mon, 4 Mar 2024 16:11:23 +0400 Subject: [PATCH] fix: correct error logic --- .../LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx | 4 ++-- .../LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx index 57a35b44..dc16f94d 100644 --- a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx +++ b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpot.tsx @@ -141,7 +141,7 @@ const CreateOrderSpot: React.FC = observer(({ ...rest }) => { amount={vm.inputAmount} assetId={baseToken.assetId} decimals={baseToken.decimals} - error={vm.isSell ? vm.inputTotalError : undefined} + error={vm.isSell ? vm.isInputError : undefined} label="Order size" setAmount={(v) => vm.setInputAmount(v, true)} onBlur={vm.setActiveInput} @@ -157,7 +157,7 @@ const CreateOrderSpot: React.FC = observer(({ ...rest }) => { amount={vm.inputTotal} assetId={quoteToken.assetId} decimals={quoteToken.decimals} - error={vm.isSell ? undefined : vm.inputTotalError} + error={vm.isSell ? undefined : vm.isInputError} setAmount={(v) => vm.setInputTotal(v, true)} onBlur={vm.setActiveInput} onFocus={() => vm.setActiveInput(ACTIVE_INPUT.Total)} diff --git a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx index 3aba3178..9e51231b 100644 --- a/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx +++ b/spark-frontend/src/screens/TradeScreen/LeftBlock/CreateOrderSpot/CreateOrderSpotVM.tsx @@ -84,7 +84,6 @@ class CreateOrderSpotVM { this.inputPrice.eq(BN.ZERO) && this.activeInput !== ACTIVE_INPUT.Price ) { - console.log(orderType === ORDER_TYPE.Limit, this.inputPrice.eq(BN.ZERO), this.activeInput); this.setInputPriceDebounce(price); } }, @@ -96,13 +95,15 @@ class CreateOrderSpotVM { } get canProceed() { - return this.inputAmount.gt(0) && this.inputPrice.gt(0) && this.inputTotal.gt(0) && !this.inputTotalError; + return this.inputAmount.gt(0) && this.inputPrice.gt(0) && this.inputTotal.gt(0) && !this.isInputError; } - get inputTotalError(): boolean { + get isInputError(): boolean { const { tradeStore, balanceStore } = this.rootStore; + const { market } = tradeStore; const amount = this.isSell ? this.inputAmount : this.inputTotal; - const balance = balanceStore.getBalance(tradeStore.market!.quoteToken.assetId); + const token = this.isSell ? market!.baseToken.assetId : market!.quoteToken.assetId; + const balance = balanceStore.getBalance(token); return balance ? amount.gt(balance) : false; } @@ -151,7 +152,6 @@ class CreateOrderSpotVM { const formattedAmount = BN.formatUnits(this.inputAmount, tradeStore.market!.baseToken.decimals); const formattedTotal = BN.formatUnits(this.inputTotal, tradeStore.market!.quoteToken.decimals); - console.log(this.activeInput === ACTIVE_INPUT.Price); if (this.activeInput === ACTIVE_INPUT.Amount || this.activeInput === ACTIVE_INPUT.Price) { const total = BN.parseUnits(formattedAmount.times(formattedPrice), tradeStore.market!.quoteToken.decimals); this.setInputTotal(total);