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

feat: fr vaults #1202

Draft
wants to merge 5 commits into
base: feat/VR
Choose a base branch
from
Draft
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
10 changes: 5 additions & 5 deletions src/components/PositionAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { FiClock } from 'react-icons/fi';
import { MdAutorenew } from 'react-icons/md';
import styled from 'styled-components';
import { UserContext } from '../contexts/UserContext';
import { IVault, ISeries, IAsset, IStrategy, ActionType } from '../types';
import { IVault, ISeries, IStrategy, ActionType } from '../types';
import Logo from './logos/Logo';
import useVYTokens, { IVYToken } from '../hooks/entities/useVYTokens';
import useVaultsVR from '../hooks/entities/useVaultsVR';
import useVaults from '../hooks/entities/useVaults';

const Outer = styled(Box)`
position: relative;
Expand Down Expand Up @@ -42,11 +42,11 @@ function PositionAvatar({

/* STATE FROM CONTEXT */
const { userState } = useContext(UserContext);
const { assetMap, seriesMap, vaultMap } = userState;
const { data: vaultsVR } = useVaultsVR();
const { assetMap, seriesMap } = userState;
const { data: vaults } = useVaults();

const base = assetMap.get(position?.baseId!); // same for both series, vaults, and vyTokens
const vault = isVault ? vaultMap.get(position?.id!) || vaultsVR?.get(position?.id!) : undefined;
const vault = isVault ? vaults.get(position?.id!) : undefined;
const series = vault ? seriesMap.get(vault.seriesId!) : seriesMap.get(position?.id!);
const vyToken = vyTokens?.get(position?.id!);

Expand Down
8 changes: 4 additions & 4 deletions src/components/positionItems/VaultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { cleanValue } from '../../utils/appUtils';
import { GA_Event, GA_Properties } from '../../types/analytics';
import useAnalytics from '../../hooks/useAnalytics';
import useAssetPair from '../../hooks/viewHelperHooks/useAssetPair/useAssetPair';
import useVaultsVR from '../../hooks/entities/useVaultsVR';
import useVaults from '../../hooks/entities/useVaults';

function VaultItem({ vault, index, condensed }: { vault: IVault; index: number; condensed?: boolean }) {
const router = useRouter();
const { logAnalyticsEvent } = useAnalytics();

const {
userState: { seriesMap, vaultsLoading, selectedVault, assetMap },
userState: { seriesMap, selectedVault, assetMap },
userActions,
} = useContext(UserContext);
const { setSelectedVault } = userActions;
Expand All @@ -34,7 +34,7 @@ function VaultItem({ vault, index, condensed }: { vault: IVault; index: number;
} as GA_Properties.position_opened);
};

const { isLoading: vaultsLoadingVR } = useVaultsVR();
const { isLoadingFR: vaultsLoadingFR, isLoadingVR: vaultsLoadingVR } = useVaults();
const vaultBase = assetMap?.get(vault.baseId);
const vaultIlk = assetMap?.get(vault.ilkId);
const vaultIsVR = !vault.seriesId;
Expand Down Expand Up @@ -75,7 +75,7 @@ function VaultItem({ vault, index, condensed }: { vault: IVault; index: number;
</Text>
{!vaultIsVR && (
<Text weight={450} size="xsmall">
{(vaultsLoading && vault.id === selectedVault?.id) || !debtInBase_ ? (
{(vaultsLoadingFR && vault.id === selectedVault?.id) || !debtInBase_ ? (
<SkeletonWrap width={30} />
) : (
cleanValue(debtInBase_, 2)
Expand Down
16 changes: 7 additions & 9 deletions src/components/selectors/VaultPositionSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import VaultListItem from '../positionItems/VaultItem';
import ListWrap from '../wraps/ListWrap';
import { SettingsContext } from '../../contexts/SettingsContext';
import useAccountPlus from '../../hooks/useAccountPlus';
import useVaultsVR from '../../hooks/entities/useVaultsVR';
import useVaults from '../../hooks/entities/useVaults';

interface IVaultFilter {
base: IAsset | undefined;
Expand All @@ -21,10 +21,10 @@ function VaultPositionSelector(target: any) {
settingsState: { dashHideInactiveVaults },
} = useContext(SettingsContext);
const {
userState: { vaultMap, selectedSeries, selectedBase },
userState: { selectedSeries, selectedBase },
} = useContext(UserContext);

const { data: vaultsVR } = useVaultsVR();
const { data: vaults } = useVaults();

const { address: account } = useAccountPlus();

Expand All @@ -37,8 +37,7 @@ function VaultPositionSelector(target: any) {

const handleFilter = useCallback(
({ base, series, ilk }: IVaultFilter) => {
if (!vaultMap) return;
const _filteredVaults = Array.from(vaultMap.values())
const _filteredVaults = Array.from(vaults.values())
.filter((vault) => !dashHideInactiveVaults || vault.isActive)
.filter((vault) => (base ? vault.baseId === base.proxyId : true))
.filter((vault) => (series ? vault.seriesId === series.id : true))
Expand All @@ -49,13 +48,12 @@ function VaultPositionSelector(target: any) {
setFilteredVaults(_filteredVaults);
console.log('filteredVaults in VaultPositionSelector.tsx: ', _filteredVaults);
},
[vaultMap, dashHideInactiveVaults]
[vaults, dashHideInactiveVaults]
);

/* CHECK the list of current vaults which match the current series/ilk selection */
useEffect(() => {
if (!vaultMap) return;
const _allVaults = [...vaultMap.values(), ...(vaultsVR?.values() || [])]
const _allVaults = [...vaults.values()]
// filter out vaults that have same base and ilk (borrow and pool liquidity positions)
.filter((vault) => vault.baseId !== vault.ilkId)

Expand All @@ -73,7 +71,7 @@ function VaultPositionSelector(target: any) {
if (selectedBase && selectedSeries) {
handleFilter({ base: selectedBase, series: selectedSeries, ilk: undefined });
}
}, [vaultMap, selectedBase, selectedSeries, handleFilter, vaultsVR]);
}, [selectedBase, selectedSeries, handleFilter, vaults]);

useEffect(() => {
allVaults.length <= 5 && setShowAllVaults(true);
Expand Down
11 changes: 5 additions & 6 deletions src/components/views/Borrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ import useAccountPlus from '../../hooks/useAccountPlus';
import VariableRate from '../selectors/VariableRate';
import useBasesVR from '../../hooks/views/useBasesVR';
import useAssetPair from '../../hooks/viewHelperHooks/useAssetPair/useAssetPair';
import useVaultsVR from '../../hooks/entities/useVaultsVR';
import { ContractNames } from '../../config/contracts';
import { Cauldron, VRCauldron } from '../../contracts';
import useVaults from '../../hooks/entities/useVaults';

const Borrow = () => {
const mobile: boolean = useContext<any>(ResponsiveContext) === 'small';
Expand All @@ -62,8 +62,7 @@ const Borrow = () => {

/* STATE FROM CONTEXT */
const { userState, userActions } = useContext(UserContext);
const { assetMap, vaultMap, vaultsLoading, selectedSeries, selectedIlk, selectedBase, selectedVault, selectedVR } =
userState;
const { assetMap, selectedSeries, selectedIlk, selectedBase, selectedVault, selectedVR } = userState;
const { setSelectedIlk } = userActions;

const { address: activeAccount } = useAccountPlus();
Expand Down Expand Up @@ -91,7 +90,7 @@ const Borrow = () => {
const { apr } = useApr(borrowInput, ActionType.BORROW, selectedSeries);
const { data: assetPair } = useAssetPair(selectedBase?.id, selectedIlk?.id);
const { data: basesVR } = useBasesVR();
const { data: vaultsVR } = useVaultsVR();
const { vaultsFR, vaultsVR } = useVaults();

const {
collateralizationPercent,
Expand Down Expand Up @@ -256,7 +255,7 @@ const Borrow = () => {
/* CHECK the list of current vaults which match the current series/ilk selection */ // TODO look at moving this to helper hook?
useEffect(() => {
if (selectedBase && selectedIlk) {
const vaults = [...(selectedVR ? (vaultsVR || []).values() : (vaultMap || []).values())];
const vaults = [...(selectedVR ? (vaultsVR || []).values() : (vaultsFR || []).values())];
const matchingVaults = vaults.filter(
(v) =>
v.ilkId === selectedIlk.proxyId &&
Expand All @@ -266,7 +265,7 @@ const Borrow = () => {
);
setMatchingVaults(matchingVaults);
}
}, [vaultMap, selectedBase, selectedIlk, selectedSeries, vaultsVR, selectedVR]);
}, [selectedBase, selectedIlk, selectedSeries, vaultsVR, selectedVR, vaultsFR]);

/* handle selected vault */
useEffect(() => {
Expand Down
19 changes: 5 additions & 14 deletions src/components/views/VaultPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { WETH } from '../../config/assets';
import { Address } from '@wagmi/core';
import useAccountPlus from '../../hooks/useAccountPlus';
import useAssetPair from '../../hooks/viewHelperHooks/useAssetPair/useAssetPair';
import useVaultsVR from '../../hooks/entities/useVaultsVR';
import useVaults from '../../hooks/entities/useVaults';

const VaultPosition = () => {
const mobile: boolean = useContext<any>(ResponsiveContext) === 'small';
Expand All @@ -61,14 +61,14 @@ const VaultPosition = () => {

/* STATE FROM CONTEXT */
const { userState, userActions } = useContext(UserContext);
const { assetMap, seriesMap, vaultMap, vaultsLoading: vaultsLoadingFR, selectedVR } = userState;
const { assetMap, seriesMap, selectedVR } = userState;
const { setSelectedBase, setSelectedIlk, setSelectedSeries, setSelectedVault, setSelectedVR } = userActions;
const { data: vaultsVR, isLoading: vaultsLoadingVR } = useVaultsVR();
const { data: vaults, isLoadingVR: vaultsLoadingVR, isLoadingFR: vaultsLoadingFR } = useVaults();
const vaultsLoading = selectedVR ? vaultsLoadingVR : vaultsLoadingFR;

const { address: account } = useAccountPlus();

const _selectedVault = vaultMap?.get(idFromUrl as string) || vaultsVR?.get(idFromUrl as string);
const _selectedVault = vaults.get(idFromUrl as string);

const vaultBase = assetMap?.get(_selectedVault?.baseId!);
const vaultIlk = assetMap?.get(_selectedVault?.ilkId!);
Expand Down Expand Up @@ -377,16 +377,7 @@ const VaultPosition = () => {
_selectedVault && setSelectedBase(_base);
_selectedVault && setSelectedIlk(_ilkToUse!);
_selectedVault && setSelectedVault(_selectedVault);
}, [
vaultMap,
_selectedVault,
seriesMap,
assetMap,
setSelectedSeries,
setSelectedBase,
setSelectedIlk,
setSelectedVault,
]);
}, [_selectedVault, seriesMap, assetMap, setSelectedSeries, setSelectedBase, setSelectedIlk, setSelectedVault]);

useEffect(() => {
if (_selectedVault && account !== _selectedVault?.owner) router.push(prevLoc);
Expand Down
Loading