Skip to content

Commit

Permalink
toDecima Places round up added for the input during approvement
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulZhemanov committed Feb 24, 2024
1 parent 6dcd30c commit 0887a41
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropsWithChildren, useMemo } from "react";
import BigNumber from "bignumber.js";
import { ethers } from "ethers";
import _ from "lodash";
import { makeAutoObservable, reaction } from "mobx";
Expand Down Expand Up @@ -212,19 +213,21 @@ class CreateOrderSpotVM {
const quoteToken = market.quoteToken;

const activeToken = this.isSell ? baseToken : quoteToken;
const approveAmount = this.isSell ? this.inputAmount : this.inputTotal;
const approveAmount = (this.isSell ? this.inputAmount : this.inputTotal).toDecimalPlaces(0, BigNumber.ROUND_UP);

this.setLoading(true);

try {
const tokenContract = new ethers.Contract(activeToken.assetId, ERC20_ABI, accountStore.signer);
console.log(approveAmount.toString());
const approveTransaction = await tokenContract.approve(CONTRACT_ADDRESSES.spotMarket, approveAmount.toString());

await approveTransaction.wait();
await this.loadAllowance();

notificationStore.toast(`${activeToken.symbol} approved!`, { type: "success" });
} catch (error) {
console.error(error);
notificationStore.toast(`Something goes wrong with ${activeToken.symbol} approve`, { type: "error" });
}

Expand Down

0 comments on commit 0887a41

Please sign in to comment.