Skip to content

Commit

Permalink
feat: fix eth value not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Oct 10, 2024
1 parent 132e059 commit 2987925
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
8 changes: 6 additions & 2 deletions projects/ui/src/components/Nav/Buttons/SunButton.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ query SunButton($season_lte: Int!) {
fields: fieldHourlySnapshots(
first: 25
where: {
field: "0xc1e088fc1323b20bcbee9bd1b9fc9546db5624c5"
field: "0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70"
season_lte: $season_lte
caseId_not: null
}
Expand All @@ -38,7 +38,11 @@ query SunButton($season_lte: Int!) {
first: 25
orderBy: season
orderDirection: desc
where: { season_lte: $season_lte, beanToMaxLpGpPerBdvRatio_gt: 0 }
where: {
silo: "0xd1a0060ba708bc4bcd3da6c37efa8dedf015fb70"
season_lte: $season_lte
beanToMaxLpGpPerBdvRatio_gt: 0
}
) {
id
season
Expand Down
30 changes: 17 additions & 13 deletions projects/ui/src/hooks/farmer/useFarmerBalancesWithFiatValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { useCallback, useMemo } from 'react';

import { TokenMap, ZERO_BN } from '~/constants';
import { ERC20Token, NativeToken } from '@beanstalk/sdk';
import { getTokenIndex } from '~/util';
import {
TokenInstance,
useSupportedBalanceTokens,
} from '../beanstalk/useTokens';
import useDataFeedTokenPrices from '../beanstalk/useDataFeedTokenPrices';
import useFarmerBalances from './useFarmerBalances';
import useFarmerBalancesBreakdown from './useFarmerBalancesBreakdown';
import { useSupportedBalanceTokens } from '../beanstalk/useTokens';

const sortMap = {
BEAN: 0,
Expand Down Expand Up @@ -58,9 +62,9 @@ export default function useFarmerBalancesWithFiatValue(includeZero?: boolean) {

// helpers
const getBalances = useCallback(
(addr: string) => ({
farm: farmerBalances?.[addr]?.internal ?? ZERO_BN,
circulating: farmerBalances?.[addr]?.external ?? ZERO_BN,
(token: TokenInstance) => ({
farm: farmerBalances?.[getTokenIndex(token)]?.internal ?? ZERO_BN,
circulating: farmerBalances?.[getTokenIndex(token)]?.external ?? ZERO_BN,
}),
[farmerBalances]
);
Expand All @@ -70,17 +74,17 @@ export default function useFarmerBalancesWithFiatValue(includeZero?: boolean) {
const external: TokenMap<TokenBalanceWithFiatValue> = {};

tokens.forEach((token) => {
const balance = getBalances(token.address);
const value = tokenPrices[token.address] ?? ZERO_BN;
const balance = getBalances(token);
const value = tokenPrices[getTokenIndex(token)] ?? ZERO_BN;
if (balance.farm?.gt(0) || includeZero) {
internal[token.address] = {
internal[getTokenIndex(token)] = {
token,
amount: balance.farm,
value: balance.farm.multipliedBy(value),
};
}
if (balance.circulating?.gt(0) || includeZero) {
external[token.address] = {
external[getTokenIndex(token)] = {
token,
amount: balance.circulating,
value: balance.circulating.multipliedBy(value),
Expand All @@ -95,17 +99,17 @@ export default function useFarmerBalancesWithFiatValue(includeZero?: boolean) {
const token = tokenMap[addr];
if (!token) return;
if (amount?.gt(0) || includeZero) {
internal[addr] = {
internal[getTokenIndex(token)] = {
token,
amount,
value,
};
}
if (circulating[addr]?.amount?.gt(0) || includeZero) {
external[addr] = {
if (circulating[getTokenIndex(token)]?.amount?.gt(0) || includeZero) {
external[getTokenIndex(token)] = {
token,
amount: circulating[addr]?.amount ?? ZERO_BN,
value: circulating[addr]?.value ?? ZERO_BN,
amount: circulating[getTokenIndex(token)]?.amount ?? ZERO_BN,
value: circulating[getTokenIndex(token)]?.value ?? ZERO_BN,
};
}
});
Expand Down
5 changes: 3 additions & 2 deletions projects/ui/src/state/farmer/balances/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createReducer } from '@reduxjs/toolkit';
import { getTokenIndex } from '~/util';
import { FarmerBalances } from '.';
import { clearBalances, updateBalance, updateBalances } from './actions';

Expand All @@ -7,11 +8,11 @@ export const initialState: FarmerBalances = {};
export default createReducer(initialState, (builder) =>
builder
.addCase(updateBalance, (state, { payload }) => {
state[payload.token.address] = payload.balance;
state[getTokenIndex(payload.token)] = payload.balance;
})
.addCase(updateBalances, (state, { payload }) => {
payload.forEach((elem) => {
state[elem.token.address] = elem.balance;
state[getTokenIndex(elem.token)] = elem.balance;
});
})
.addCase(clearBalances, () => initialState)
Expand Down
6 changes: 4 additions & 2 deletions projects/ui/src/state/farmer/balances/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import flatMap from 'lodash/flatMap';
import { ZERO_BN } from '~/constants';
import { tokenResult } from '~/util';
import { tokenResult, getTokenIndex } from '~/util';
import useAccount from '~/hooks/ledger/useAccount';
import { useTokens } from '~/hooks/beanstalk/useTokens';
import { useBeanstalkContract } from '~/hooks/ledger/useContract';
Expand Down Expand Up @@ -72,11 +72,13 @@ export const useFetchFarmerBalances = () => {
);
const balances = await promises;

console.log('balances: ', balances);

console.debug('[farmer/updater/useFetchBalances] RESULT: ', balances);

const localBalances = balances.reduce(
(obj, elem) =>
Object.assign(obj, { [elem.token.address]: elem.balance }),
Object.assign(obj, { [getTokenIndex(elem.token)]: elem.balance }),
{}
);
localStorage.setItem('farmerBalances', JSON.stringify(localBalances));
Expand Down

0 comments on commit 2987925

Please sign in to comment.