Skip to content

Commit

Permalink
your borrowed list
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhochu committed Dec 23, 2023
1 parent 3ec73b7 commit aa6d48c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions const/constCommon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const CONST_COLLATERAL_TYPE = {
LP_TOKEN: "LP Token",
SINGLE_TOKEN: "Single Token",
};
2 changes: 1 addition & 1 deletion redux/selectors/getHealthFactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getLPHealthFactor = createSelector(
LPToken[key] = {
...value,
metadata: asset?.metadata,
healthFactor,
healthFactor: Math.trunc(healthFactor),
healthStatus,
};
}
Expand Down
12 changes: 10 additions & 2 deletions redux/selectors/getPortfolioAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Asset, Assets } from "../assetState";
import { Farm } from "../accountState";
import { standardizeAsset } from "../../utils";
import { DEFAULT_POSITION } from "../../utils/config";
import { CONST_COLLATERAL_TYPE } from "../../const/constCommon";

export const getPortfolioRewards = (
type: "supplied" | "borrowed",
Expand Down Expand Up @@ -127,6 +128,7 @@ export const getPortfolioAssets = createSelector(
totalBorrowedUSD += borrowedUSD;
return standardizeAsset({
tokenId,
collateralType: CONST_COLLATERAL_TYPE.SINGLE_TOKEN,
metadata: asset.metadata,
symbol: asset.metadata.symbol,
icon: asset.metadata.icon,
Expand All @@ -153,21 +155,23 @@ export const getPortfolioAssets = createSelector(
const b = Object.keys(lpPositions[shadow_id].borrowed)
.map((tokenId) => {
const asset = assets.data[tokenId];
const lpAsset = assets.data[shadow_id];
const borrowedBalance = lpPositions[shadow_id].borrowed[tokenId].balance;
const brrrUnclaimedAmount =
account.portfolio.farms.borrowed[tokenId]?.[brrrTokenId]?.unclaimed_amount || "0";
const totalSupplyD = new Decimal(asset.supplied.balance)
.plus(new Decimal(asset.reserved))
.toFixed();

const borrowedToken = Number(
shrinkToken(borrowedBalance, asset.metadata.decimals + asset.config.extra_decimals),
);
const borrowedUSD = borrowedToken * (asset.price?.usd || 0);
totalBorrowedUSD += borrowedUSD;
return standardizeAsset({
tokenId,
collateralType: CONST_COLLATERAL_TYPE.LP_TOKEN,
metadata: asset.metadata,
metadataLP: lpAsset.metadata,
symbol: asset.metadata.symbol,
icon: asset.metadata.icon,
price: asset.price?.usd ?? 0,
Expand All @@ -191,6 +195,10 @@ export const getPortfolioAssets = createSelector(
return { ...acc, [shadow_id]: b };
}, {});

return [supplied, borrowed, totalSuppliedUSD, totalBorrowedUSD, borrowed_LP];
const borrowedAll = borrowed;
Object.entries(borrowed_LP).forEach(([positionId, value]: [string, any]) => {
borrowedAll.push(...value);
});
return [supplied, borrowed, totalSuppliedUSD, totalBorrowedUSD, borrowed_LP, borrowedAll];
},
);
24 changes: 21 additions & 3 deletions screens/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { hiddenAssets } from "../../utils/config";

const Index = () => {
const accountId = useAccountId();
const [suppliedRows, borrowedRows, totalSuppliedUSD, totalBorrowedUSD] = usePortfolioAssets();
const [suppliedRows, borrowedRows, totalSuppliedUSD, totalBorrowedUSD, borrowed_LP, borrowedAll] =
usePortfolioAssets();
const isMobile = isMobileDevice();

let overviewNode;
Expand Down Expand Up @@ -55,15 +56,15 @@ const Index = () => {
supplyBorrowNode = (
<SupplyBorrowListMobile
suppliedRows={suppliedRows}
borrowedRows={borrowedRows}
borrowedRows={borrowedAll}
accountId={accountId}
/>
);
} else {
supplyBorrowNode = (
<StyledSupplyBorrow className="gap-6 lg:flex mb-10">
<YourSupplied suppliedRows={suppliedRows} accountId={accountId} total={totalSuppliedUSD} />
<YourBorrowed borrowedRows={borrowedRows} accountId={accountId} total={totalBorrowedUSD} />
<YourBorrowed borrowedRows={borrowedAll} accountId={accountId} total={totalBorrowedUSD} />
</StyledSupplyBorrow>
);
}
Expand Down Expand Up @@ -288,6 +289,23 @@ const yourBorrowedColumns = [
);
},
},
{
header: "Collateral Type",
cell: ({ originalData }) => {
const { collateralType, metadataLP } = originalData || {};
let tokenNames = "";
metadataLP?.tokens?.forEach((d, i) => {
const isLast = i === metadataLP.tokens.length - 1;
tokenNames += `${d.metadata.symbol}${!isLast ? "-" : ""}`;
});
return (
<div>
<div>{collateralType}</div>
<div className="h6 text-gray-300">{tokenNames}</div>
</div>
);
},
},
{
header: "Your APY",
cell: ({ originalData }) => {
Expand Down

0 comments on commit aa6d48c

Please sign in to comment.