Skip to content

Commit

Permalink
feat: update token deposits context
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Sep 24, 2024
1 parent fa3166a commit 52c2d2e
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions projects/ui/src/components/Silo/Token/TokenDepositsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import React, {
useContext,
useMemo,
useState,
useEffect,
} from 'react';
import useBDV from '~/hooks/beanstalk/useBDV';
import useTabs from '~/hooks/display/useTabs';
import useFarmerSiloBalanceSdk from '~/hooks/farmer/useFarmerSiloBalanceSdk';
import { exists } from '~/util/UI';
Expand Down Expand Up @@ -42,7 +40,6 @@ export type TokenDepositsContextType = {
slug: SiloTokenSlug;
balances: TokenSiloBalance<TokenValue> | undefined;
depositsById: Record<string, Deposit<TokenValue>>;
updateableDepositsById: Record<string, UpdateableDeposit<TokenValue>>;
setSelected: (
depositId: string,
selectType: TokenDepositsSelectType,
Expand All @@ -69,20 +66,13 @@ const TokenDepositsContext = createContext<TokenDepositsContextType | null>(
null
);

const emptyObj = {};

// This could probably be refactored for less duplicated code
export const TokenDepositsProvider = (props: {
children: React.ReactNode;
token: ERC20Token;
}) => {
const [selected, setSelected] = useState<Set<string>>(new Set());
const [slugIndex, setSlugIndex] = useTabs(SLUGS, 'content', 0);
const [updateableDepositsById, setUpdateableDepositsById] =
useState<TokenDepositsContextType['updateableDepositsById']>(emptyObj);
const getBDV = useBDV();

const tokenBDV = getBDV(props.token);

const siloBalances = useFarmerSiloBalanceSdk(props.token);

Expand All @@ -95,28 +85,6 @@ export const TokenDepositsProvider = (props: {
return map;
}, [siloBalances?.deposits]);

useEffect(() => {
if (!siloBalances?.convertibleDeposits?.length) {
setUpdateableDepositsById(emptyObj);
return;
}

const map = siloBalances.convertibleDeposits.reduce(
(prev, deposit) => {
const newBDV = deposit.amount.mul(tokenBDV.toNumber());
if (!deposit.bdv.lt(newBDV.toNumber())) return prev;
prev[deposit.id.toString()] = {
...deposit,
newBDV,
};
return prev;
},
{} as typeof updateableDepositsById
);

setUpdateableDepositsById(map);
}, [siloBalances, tokenBDV]);

const handleSetSelected = useCallback(
(
depositId: string,
Expand Down Expand Up @@ -169,7 +137,6 @@ export const TokenDepositsProvider = (props: {
token: props.token,
balances: siloBalances,
depositsById: depositMap,
updateableDepositsById,
slug: slugIndexMap[slugIndex] || 'token',
setSlug,
setSelected: handleSetSelected,
Expand Down

0 comments on commit 52c2d2e

Please sign in to comment.