Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xieqiancaosissi committed Dec 27, 2023
1 parent 43b1a02 commit 0c42bf5
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/Modal/CollateralTypeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function CollateralTypeSelectorBorrow({
{selectedCollateralType === position ? <CheckedIcon /> : null}
</div>
<span>
{digitalProcess(maxBorrowAmountPositions[position].maxBorrowAmount || 0, 2)}
{digitalProcess(maxBorrowAmountPositions[position]?.maxBorrowAmount || 0, 2)}
</span>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const Modal = () => {
const maxBorrowAmountPositions = useAppSelector(getBorrowMaxAmount(tokenId));
const maxWithdrawAmount = useAppSelector(getWithdrawMaxAmount(tokenId));
const repayPositions = useAppSelector(getRepayPositions(tokenId));
const { maxBorrowAmount, maxBorrowValue } = maxBorrowAmountPositions[selectedCollateralType];
const { maxBorrowAmount = 0, maxBorrowValue = 0 } =
maxBorrowAmountPositions[selectedCollateralType] || {};
const repayAmount = repayPositions[selectedCollateralType];
const {
symbol,
Expand Down
4 changes: 2 additions & 2 deletions redux/selectors/getPortfolioAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ export const getPortfolioAssets = createSelector(
const { isLpToken } = asset;
const collateral = shrinkToken(
(isLpToken
? account.portfolio.positions[tokenId].collateral[tokenId]?.balance
? account.portfolio.positions[tokenId]?.collateral?.[tokenId]?.balance || 0
: account.portfolio.collateral[tokenId]?.balance) || 0,
asset.metadata.decimals + asset.config.extra_decimals,
);
const suppliedBalance = account.portfolio.supplied[tokenId]?.balance || 0;
const suppliedBalance = account.portfolio.supplied?.[tokenId]?.balance || 0;
const totalSupplyD = new Decimal(asset.supplied.balance)
.plus(new Decimal(asset.reserved))
.toFixed();
Expand Down
8 changes: 4 additions & 4 deletions redux/selectors/getWithdrawMaxAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getAdjustedSum = (
position?: string,
) => {
const positionId = position || DEFAULT_POSITION;
const result = Object.keys(portfolio.positions[positionId][type]).map((id) => {
const result = Object.keys(portfolio.positions[positionId]?.[type] || {}).map((id) => {
const asset = assets[id];
const positionData = portfolio.positions[positionId][type][id];
let pricedBalance;
Expand Down Expand Up @@ -64,8 +64,8 @@ export const getAdjustedSum = (
: pricedBalance.mul(asset.config.volatility_ratio).div(MAX_RATIO);
});

const sumResult = result.reduce(sumReducerDecimal, new Decimal(0));
return sumResult;
const sumResult = result?.reduce(sumReducerDecimal, new Decimal(0));
return sumResult || new Decimal(0);
};

export const computeWithdrawMaxAmount = (tokenId: string, assets: Assets, portfolio: Portfolio) => {
Expand All @@ -77,7 +77,7 @@ export const computeWithdrawMaxAmount = (tokenId: string, assets: Assets, portfo
const assetPrice = asset.price ? new Decimal(asset.price.usd) : new Decimal(0);
const suppliedBalance = new Decimal(portfolio.supplied[tokenId]?.balance || 0);
const collateralBalance = new Decimal(
portfolio.positions[position].collateral[tokenId]?.balance || 0,
portfolio.positions[position]?.collateral?.[tokenId]?.balance || 0,
);

let maxAmount = suppliedBalance;
Expand Down
2 changes: 1 addition & 1 deletion store/actions/adjustCollateral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function adjustCollateral({
token_id: tokenId,
amount: expandedAmount.gt(0)
? collateralBalance.sub(expandedAmount).toFixed(0)
: undefined, // TODO is can undefined?
: undefined,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion store/actions/repay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function repay({
asset_amount: {
amount: !isMax
? expandedAmountToken.mul(extraDecimalMultiplier).toFixed(0)
: undefined, // TODO can undefined ?
: undefined,
token_id: tokenId,
},
position,
Expand Down
1 change: 0 additions & 1 deletion store/actions/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export async function shadow_action_withdraw({
const expandAmount = expandTokenDecimal(amount, decimals).toFixed(0);
const pool_id = +tokenId.split("-")[1];
if (decreaseCollateralAmount.gt(0)) {
// TODO 待验证
transactions.push({
receiverId: oracleContract.contractId,
functionCalls: [
Expand Down

0 comments on commit 0c42bf5

Please sign in to comment.