Skip to content

Commit

Permalink
Merge branch 'master' into bean-ui-use-clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
uncoolzero authored Sep 12, 2023
2 parents 41560b7 + 48ad260 commit 21deb0a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
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

0 comments on commit 21deb0a

Please sign in to comment.