Skip to content

Commit

Permalink
fix: btc withdraw all issue
Browse files Browse the repository at this point in the history
  • Loading branch information
naturexie committed Jan 21, 2025
1 parent 86f8ce5 commit 237b942
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions components/Modal/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function Action({
collateralType,
poolAsset,
isDisabled,
maxWithdrawAmount,
}) {
const [loading, setLoading] = useState(false);
const { amount, useAsCollateral, isMax } = useAppSelector(getSelectedValues);
Expand All @@ -45,6 +46,7 @@ export default function Action({
const { available, canUseAsCollateral, extraDecimals, collateral, disabled, decimals } =
getModalData({
...asset,
maxWithdrawAmount,
maxBorrowAmount,
healthFactor,
amount,
Expand Down Expand Up @@ -117,6 +119,7 @@ export default function Action({
amount,
isMax,
isMeme,
available,
});
break;
}
Expand Down
1 change: 1 addition & 0 deletions components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ const Modal = () => {
<Alerts data={alerts} />
<Action
maxBorrowAmount={maxBorrowAmount}
maxWithdrawAmount={maxWithdrawAmount}
healthFactor={healthFactor}
collateralType={selectedCollateralType}
poolAsset={assets[tokenId]}
Expand Down
13 changes: 10 additions & 3 deletions store/actions/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ interface Props {
amount: string;
isMax: boolean;
isMeme: boolean;
available: number;
}

export async function withdraw({ tokenId, extraDecimals, amount, isMax, isMeme }: Props) {
export async function withdraw({
tokenId,
extraDecimals,
amount,
isMax,
isMeme,
available,
}: Props) {
const state = store.getState();
const { oracleContract, logicContract, memeOracleContract, logicMEMEContract, selector } =
await getBurrow();
Expand Down Expand Up @@ -65,9 +73,8 @@ export async function withdraw({ tokenId, extraDecimals, amount, isMax, isMeme }
const suppliedBalance = new Decimal(account.portfolio?.supplied[tokenId]?.balance || 0);
const hasBorrow = account.portfolio?.borrows?.length > 0;
const maxAmount = computeWithdrawMaxAmount(tokenId, assets, account.portfolio!);

const expandedAmount = isMax
? maxAmount
? decimalMin(maxAmount, expandTokenDecimal(available, decimals + extraDecimals))
: decimalMin(maxAmount, expandTokenDecimal(amount, decimals + extraDecimals));

const transactions: Transaction[] = [];
Expand Down

0 comments on commit 237b942

Please sign in to comment.