From 0c42bf5f045cf12a1e3a4b5ed46d455c25f33953 Mon Sep 17 00:00:00 2001 From: "nature.xie" Date: Wed, 27 Dec 2023 08:39:31 +0800 Subject: [PATCH] update --- components/Modal/CollateralTypeSelector.tsx | 2 +- components/Modal/index.tsx | 3 ++- redux/selectors/getPortfolioAssets.ts | 4 ++-- redux/selectors/getWithdrawMaxAmount.ts | 8 ++++---- store/actions/adjustCollateral.ts | 2 +- store/actions/repay.ts | 2 +- store/actions/shadow.ts | 1 - 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/Modal/CollateralTypeSelector.tsx b/components/Modal/CollateralTypeSelector.tsx index 5be5d095..100ee376 100644 --- a/components/Modal/CollateralTypeSelector.tsx +++ b/components/Modal/CollateralTypeSelector.tsx @@ -83,7 +83,7 @@ export function CollateralTypeSelectorBorrow({ {selectedCollateralType === position ? : null} - {digitalProcess(maxBorrowAmountPositions[position].maxBorrowAmount || 0, 2)} + {digitalProcess(maxBorrowAmountPositions[position]?.maxBorrowAmount || 0, 2)} ); diff --git a/components/Modal/index.tsx b/components/Modal/index.tsx index e8740b43..4753df03 100644 --- a/components/Modal/index.tsx +++ b/components/Modal/index.tsx @@ -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, diff --git a/redux/selectors/getPortfolioAssets.ts b/redux/selectors/getPortfolioAssets.ts index 960a142f..e98d8431 100644 --- a/redux/selectors/getPortfolioAssets.ts +++ b/redux/selectors/getPortfolioAssets.ts @@ -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(); diff --git a/redux/selectors/getWithdrawMaxAmount.ts b/redux/selectors/getWithdrawMaxAmount.ts index 18e9a274..7b0dab19 100644 --- a/redux/selectors/getWithdrawMaxAmount.ts +++ b/redux/selectors/getWithdrawMaxAmount.ts @@ -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; @@ -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) => { @@ -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; diff --git a/store/actions/adjustCollateral.ts b/store/actions/adjustCollateral.ts index c7528858..cb04a7e3 100644 --- a/store/actions/adjustCollateral.ts +++ b/store/actions/adjustCollateral.ts @@ -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, }, }, }; diff --git a/store/actions/repay.ts b/store/actions/repay.ts index 37ee098a..b248580c 100644 --- a/store/actions/repay.ts +++ b/store/actions/repay.ts @@ -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, diff --git a/store/actions/shadow.ts b/store/actions/shadow.ts index a3b22028..70cb69fe 100644 --- a/store/actions/shadow.ts +++ b/store/actions/shadow.ts @@ -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: [