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

ui: fix silo loaders #638

Merged
merged 1 commit into from
Sep 12, 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
41 changes: 24 additions & 17 deletions projects/ui/src/components/Silo/Whitelist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -676,28 +676,35 @@ const Whitelist: FC<{
>
<Typography color="text.primary">
<Row gap={0.3}>
{/* <Fiat token={token} amount={deposited?.amount} /> */}
{deposited?.amount ? (
<>
<Fiat
token={token}
amount={deposited?.amount}
/>
{isUnripe ? (
<Typography
display="inline"
color={BeanstalkPalette.theme.winter.red}
>
*
</Typography>
) : null}
</>
) : (
{farmerSilo.loading ? (
<BeanProgressIcon
size={10}
enabled
variant="indeterminate"
/>
) : (
<>
{deposited?.amount ? (
<>
<Fiat
token={token}
amount={deposited?.amount}
/>
{isUnripe ? (
<Typography
display="inline"
color={
BeanstalkPalette.theme.winter.red
}
>
*
</Typography>
) : null}
</>
) : (
<div>?</div>
)}
</>
)}
</Row>
</Typography>
Expand Down
4 changes: 4 additions & 0 deletions projects/ui/src/state/farmer/silo/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ export const updateLegacyFarmerSiloBalances =
export const updateFarmerSiloBalanceSdk = createAction<
Map<Token, TokenSiloBalance>
>('farmer/silo/updateFarmerSiloBalancesSdk');

export const updateFarmerSiloLoading = createAction<boolean>(
'farmer/silo/loading'
);
1 change: 1 addition & 0 deletions projects/ui/src/state/farmer/silo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ export type FarmerSilo = FarmerSiloBalances &
FarmerSiloRewards & {
migrationNeeded: boolean | undefined;
balancesSdk: Map<Token, TokenSiloBalance>;
loading?: boolean;
};
6 changes: 5 additions & 1 deletion projects/ui/src/state/farmer/silo/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
updateFarmerSiloBalanceSdk,
updateLegacyFarmerSiloBalances,
updateLegacyFarmerSiloRewards,
updateFarmerSiloLoading,
} from './actions';

const NEG1 = new BigNumber(-1);
Expand All @@ -32,8 +33,8 @@ export const initialFarmerSilo: FarmerSilo = {
total: NEG1,
},
migrationNeeded: undefined,

balancesSdk: new Map(),
loading: false,
};

export default createReducer(initialFarmerSilo, (builder) =>
Expand Down Expand Up @@ -61,4 +62,7 @@ export default createReducer(initialFarmerSilo, (builder) =>
.addCase(updateFarmerSiloBalanceSdk, (state, { payload }) => {
state.balancesSdk = payload;
})
.addCase(updateFarmerSiloLoading, (state, { payload }) => {
state.loading = payload;
})
);
11 changes: 10 additions & 1 deletion projects/ui/src/state/farmer/silo/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
updateFarmerMigrationStatus,
updateLegacyFarmerSiloRewards,
updateFarmerSiloBalanceSdk,
updateFarmerSiloLoading,
} from './actions';
import useSdk from '~/hooks/sdk';
import { LegacyDepositCrate } from '~/state/farmer/silo';
Expand Down Expand Up @@ -67,6 +68,7 @@ export const useFetchFarmerSilo = () => {
/// Handlers
const fetch = useCallback(async () => {
if (initialized) {
dispatch(updateFarmerSiloLoading(true));
console.debug('[farmer/silo/useFarmerSilo] FETCH');

// FIXME: multicall this section
Expand Down Expand Up @@ -309,6 +311,7 @@ export const useFetchFarmerSilo = () => {
// HEADS UP: this has to be called after updateLegacyFarmerSiloRewards
// to prevent some rendering errors. Refactor later.
dispatch(updateLegacyFarmerSiloBalances(payload));
dispatch(updateFarmerSiloLoading(false));
}
}, [initialized, sdk, account, dispatch, season]);

Expand All @@ -329,14 +332,20 @@ const FarmerSiloUpdater = () => {
const [fetch, initialized, clear] = useFetchFarmerSilo();
const account = useAccount();
const chainId = useChainId();
const dispatch = useDispatch();

useEffect(() => {
clear(account);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [account]);

useEffect(() => {
if (account && initialized) fetch();
try {
if (account && initialized) fetch();
} catch (err) {
console.log('Error during farmer.silo fetch', err);
dispatch(updateFarmerSiloLoading(false));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [account, chainId, initialized]);

Expand Down