Skip to content

Commit

Permalink
fix: correct error logic
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoDex committed Mar 4, 2024
1 parent 1f9bd0f commit 71b6952
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const CreateOrderSpot: React.FC<IProps> = 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}
Expand All @@ -157,7 +157,7 @@ const CreateOrderSpot: React.FC<IProps> = 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)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 71b6952

Please sign in to comment.