Skip to content

Commit

Permalink
handle usn decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
xieqiancaosissi committed Jan 3, 2024
1 parent a3fe963 commit 1cc6365
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
22 changes: 13 additions & 9 deletions components/Modal/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ export default function Action({ maxBorrowAmount, healthFactor, poolAsset }) {
let usnMinRepay = "0";
const isUsn = tokenId === "usn";
if (isUsn && poolAsset?.supplied?.shares) {
usnMinRepay = new Decimal(
expandToken(
new Decimal(poolAsset?.supplied?.balance)
.div(poolAsset?.supplied?.shares)
.mul(2)
.toFixed(),
decimals,
),
).toFixed(0);
// usnMinRepay = new Decimal(
// expandToken(
// new Decimal(poolAsset?.supplied?.balance)
// .div(poolAsset?.supplied?.shares)
// .mul(2)
// .toFixed(0, 2),
// decimals,
// ),
// ).toFixed(0);
usnMinRepay = new Decimal(poolAsset?.supplied?.balance)
.div(poolAsset?.supplied?.shares)
.mul(2)
.toFixed(0, 2);
}
await repay({
tokenId,
Expand Down
21 changes: 14 additions & 7 deletions components/Modal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Decimal from "decimal.js";
import { USD_FORMAT, TOKEN_FORMAT, PERCENT_DIGITS, NEAR_STORAGE_DEPOSIT } from "../../store";
import type { UIAsset } from "../../interfaces";
import { formatWithCommas_number, toDecimal } from "../../utils/uiNumber";
import { expandToken } from "../../store/helper";
import { expandToken, shrinkToken } from "../../store/helper";
import { decimalMax } from "../../utils";

interface Alert {
Expand Down Expand Up @@ -120,13 +120,20 @@ export const getModalData = (asset): UIAsset & Props & { disabled: boolean } =>
data.rates = [];
break;
case "Repay": {
let minRepay = 0;
let minRepay = "0";
const isUsn = tokenId === "usn";
if (isUsn && poolAsset?.supplied?.shares) {
minRepay = new Decimal(poolAsset?.supplied?.balance)
.div(poolAsset?.supplied?.shares)
.mul(2)
.toNumber();
// minRepay = new Decimal(poolAsset?.supplied?.balance)
// .div(poolAsset?.supplied?.shares)
// .mul(2)
// .toNumber();
minRepay = shrinkToken(
new Decimal(poolAsset?.supplied?.balance)
.div(poolAsset?.supplied?.shares)
.mul(2)
.toFixed(0, 2),
18,
);
}
data.totalTitle = `Repay Borrow Amount`;
data.available = toDecimal(
Expand All @@ -136,7 +143,7 @@ export const getModalData = (asset): UIAsset & Props & { disabled: boolean } =>
isWrappedNear
? Number(Math.max(0, available + availableNEAR - NEAR_STORAGE_DEPOSIT))
: available,
isUsn ? Math.max(borrowed, minRepay) : borrowed,
isUsn ? Math.max(borrowed, +minRepay) : borrowed,
),
);
data.alerts = {};
Expand Down

0 comments on commit 1cc6365

Please sign in to comment.