Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Release] - Hide Clearinghouse V1 + BLV for users w/o positions. Cooler Extend Loan Approval Fix #3021

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions src/views/Lending/Cooler/hooks/useGetCoolerLoans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,32 @@ export const useGetCoolerLoans = ({
const { data: signer } = useSigner();

const { data, isFetched, isLoading } = useQuery(
["getCoolerLoans", networks.MAINNET, factoryAddress, collateralAddress, debtAddress],
["getCoolerLoans", networks.MAINNET, factoryAddress, collateralAddress, debtAddress, walletAddress],
async () => {
if (!walletAddress || !factoryAddress || !collateralAddress || !debtAddress || !signer) return [];
const contract = CoolerFactory__factory.connect(factoryAddress, signer);
try {
if (!walletAddress || !factoryAddress || !collateralAddress || !debtAddress || !signer) return [];
const contract = CoolerFactory__factory.connect(factoryAddress, signer);

const coolerAddress = await contract.callStatic.generateCooler(collateralAddress, debtAddress);
const coolerContract = Cooler__factory.connect(coolerAddress, Providers.getStaticProvider(networks.MAINNET));
const coolerAddress = await contract.callStatic.generateCooler(collateralAddress, debtAddress);
const coolerContract = Cooler__factory.connect(coolerAddress, Providers.getStaticProvider(networks.MAINNET));

const loans = [];
let loanId = 0;
while (true) {
try {
const loanData = await coolerContract.loans(loanId);
// const newCollateralAmount = await coolerContract.newCollateralFor(loanId);
loans.push({ ...loanData, loanId });
loanId++;
} catch (e) {
break;
const loans = [];
let loanId = 0;
while (true) {
try {
const loanData = await coolerContract.loans(loanId);
// const newCollateralAmount = await coolerContract.newCollateralFor(loanId);
loans.push({ ...loanData, loanId });
loanId++;
} catch (e) {
break;
}
}
}

return loans.filter(loan => !loan.collateral.isZero() && !loan.principal.isZero());
return loans.filter(loan => !loan.collateral.isZero() && !loan.principal.isZero());
} catch (e) {
return [];
}
},
{ enabled: !!walletAddress && !!factoryAddress && !!collateralAddress && !!debtAddress && !!signer },
);
Expand Down
2 changes: 1 addition & 1 deletion src/views/Lending/Cooler/positions/ExtendLoan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const ExtendLoan = ({
payment.
</>
}
spendAmount={new DecimalBigNumber(interestDue.toString())}
spendAmount={new DecimalBigNumber(interestDue.toString(), 18)}
>
<PrimaryButton
fullWidth
Expand Down
108 changes: 65 additions & 43 deletions src/views/Lending/Cooler/positions/Positions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,52 @@ import { useGetCoolerLoans } from "src/views/Lending/Cooler/hooks/useGetCoolerLo
import { CreateOrRepayLoan } from "src/views/Lending/Cooler/positions/CreateOrRepayLoan";
import { DelegateVoting } from "src/views/Lending/Cooler/positions/DelegateVoting";
import { ExtendLoan } from "src/views/Lending/Cooler/positions/ExtendLoan";
import { LiquidityCTA } from "src/views/Liquidity/LiquidityCTA";
import { useAccount } from "wagmi";

export const CoolerPositions = () => {
const { address } = useAccount();
const [currentClearingHouse, setCurrentClearingHouse] = useState<"clearingHouseV1" | "clearingHouseV2">(
"clearingHouseV2",
);
const { data: clearingHouse } = useGetClearingHouse({ clearingHouse: currentClearingHouse });
const { data: clearingHouseV1 } = useGetClearingHouse({ clearingHouse: "clearingHouseV1" });
const { data: clearingHouseV2 } = useGetClearingHouse({ clearingHouse: "clearingHouseV2" });

const [createLoanModalOpen, setCreateLoanModalOpen] = useState(false);
const { data: loans, isFetched: isFetchedLoans } = useGetCoolerLoans({
const { data: loansV1, isFetched: isFetchedLoansV1 } = useGetCoolerLoans({
walletAddress: address,
factoryAddress: clearingHouseV1?.factory,
collateralAddress: clearingHouseV1?.collateralAddress,
debtAddress: clearingHouseV1?.debtAddress,
});

const { data: coolerAddressV1 } = useGetCoolerForWallet({
walletAddress: address,
factoryAddress: clearingHouse?.factory,
collateralAddress: clearingHouse?.collateralAddress,
debtAddress: clearingHouse?.debtAddress,
factoryAddress: clearingHouseV1?.factory,
collateralAddress: clearingHouseV1?.collateralAddress,
debtAddress: clearingHouseV1?.debtAddress,
clearingHouseVersion: "clearingHouseV1",
});

const { data: coolerAddress } = useGetCoolerForWallet({
const { data: loansV2, isFetched: isFetchedLoansV2 } = useGetCoolerLoans({
walletAddress: address,
factoryAddress: clearingHouse?.factory,
collateralAddress: clearingHouse?.collateralAddress,
debtAddress: clearingHouse?.debtAddress,
clearingHouseVersion: currentClearingHouse,
factoryAddress: clearingHouseV2?.factory,
collateralAddress: clearingHouseV2?.collateralAddress,
debtAddress: clearingHouseV2?.debtAddress,
});

const { data: coolerAddressV2 } = useGetCoolerForWallet({
walletAddress: address,
factoryAddress: clearingHouseV2?.factory,
collateralAddress: clearingHouseV2?.collateralAddress,
debtAddress: clearingHouseV2?.debtAddress,
clearingHouseVersion: "clearingHouseV2",
});

const coolerAddress = currentClearingHouse === "clearingHouseV1" ? coolerAddressV1 : coolerAddressV2;
const clearingHouse = currentClearingHouse === "clearingHouseV1" ? clearingHouseV1 : clearingHouseV2;
const loans = currentClearingHouse === "clearingHouseV1" ? loansV1 : loansV2;
const isFetchedLoans = currentClearingHouse === "clearingHouseV1" ? isFetchedLoansV1 : isFetchedLoansV2;

const { data: delegationAddress } = useCheckDelegation({ coolerAddress });

const [extendLoan, setExtendLoan] = useState<any>(null);
Expand All @@ -69,37 +91,39 @@ export const CoolerPositions = () => {
<OutstandingPrincipal />
</Grid>
</Grid>
<Box display="flex" mt="16px" justifyContent="right">
<Select
value={currentClearingHouse}
label="ClearingHouse"
onChange={e => {
setCurrentClearingHouse(e.target.value as "clearingHouseV1" | "clearingHouseV2");
}}
sx={{
width: "200px",
height: "44px",
backgroundColor: theme.colors.gray[700],
border: "none",
".MuiOutlinedInput-notchedOutline": {
border: "none",
},
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
{clearingHouseV1 && loansV1 && loansV1.length > 0 && (
<Box display="flex" mt="16px" justifyContent="right">
<Select
value={currentClearingHouse}
label="ClearingHouse"
onChange={e => {
setCurrentClearingHouse(e.target.value as "clearingHouseV1" | "clearingHouseV2");
}}
sx={{
width: "200px",
height: "44px",
backgroundColor: theme.colors.gray[700],
border: "none",
},
"&:hover .MuiOutlinedInput-notchedOutline": {
border: "none",
},
"& .MuiSelect-select": {
display: "flex",
alignItems: "center",
},
}}
>
<MenuItem value="clearingHouseV1">ClearingHouse V1</MenuItem>
<MenuItem value="clearingHouseV2">ClearingHouse V2</MenuItem>
</Select>
</Box>
".MuiOutlinedInput-notchedOutline": {
border: "none",
},
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
border: "none",
},
"&:hover .MuiOutlinedInput-notchedOutline": {
border: "none",
},
"& .MuiSelect-select": {
display: "flex",
alignItems: "center",
},
}}
>
<MenuItem value="clearingHouseV1">ClearingHouse V1</MenuItem>
<MenuItem value="clearingHouseV2">ClearingHouse V2</MenuItem>
</Select>
</Box>
)}

<Box mb="21px" mt="66px">
<Typography variant="h1">Your Positions</Typography>
Expand Down Expand Up @@ -268,8 +292,6 @@ export const CoolerPositions = () => {
/>
</>
)}

<LiquidityCTA />
</div>
);
};
3 changes: 0 additions & 3 deletions src/views/Lending/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { formatCurrency } from "src/helpers";
import { useGetLendAndBorrowStats } from "src/hooks/useGetLendBorrowStats";
import { useOhmPrice } from "src/hooks/usePrices";
import { useCoolerSnapshotLatest } from "src/views/Lending/Cooler/hooks/useSnapshot";
import { LiquidityCTA } from "src/views/Liquidity/LiquidityCTA";

export const Lending = () => {
const theme = useTheme();
Expand Down Expand Up @@ -114,8 +113,6 @@ export const Lending = () => {
</Box>
</Box>
</Box>

<LiquidityCTA />
</Box>
</div>
);
Expand Down
24 changes: 0 additions & 24 deletions src/views/Liquidity/LiquidityCTA.tsx

This file was deleted.

155 changes: 0 additions & 155 deletions src/views/Liquidity/SingleSidedFarms.tsx

This file was deleted.

Loading
Loading