Skip to content

Commit

Permalink
feat: update morning components
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Sep 27, 2024
1 parent 1f423ca commit 5d1beb1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 18 deletions.
59 changes: 43 additions & 16 deletions projects/ui/src/components/Field/FieldOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { IS_DEV } from '~/util';

import useTemperature from '~/hooks/beanstalk/useTemperature';
import { useAppSelector } from '~/state';
import Row from '../Common/Row';

const Split = ({ children }: { children: React.ReactNode }) => (
<Row justifyContent="space-between" gap={1}>
{children}
</Row>
);

const minimize = false;
/**
Expand Down Expand Up @@ -38,22 +45,42 @@ const FieldOverlay: React.FC<{}> = () => {
<Box>
<Box sx={{ width: '400px' }}>
<Stack gap={0.5} p={2}>
<Typography>
Current Block: {morning.blockNumber.toString()}
</Typography>
<Typography>
Sunrise Block: {sunrise.sunriseBlock.toString()}
</Typography>
<Typography>Delta Blocks: {deltaBlocks.toString()}</Typography>
<Typography>SunriseTime: {seasonTime.toString()}</Typography>
<Typography>
Interval: {morning.index.plus(1).toString()}
</Typography>
<Typography>temp from storage: {temp.scaled.toString()}</Typography>
<Typography>
calculated temp: {calculatedTempData?.toString()}
</Typography>
<Typography>max temp: {temp.max.toString()}</Typography>
<Split>
<Typography>SeasonTime:</Typography>
<Typography>{seasonTime.toString()}</Typography>
</Split>
<Split>
<Typography>Morning Block:</Typography>
<Typography>{morning.blockNumber.toString()}</Typography>
</Split>
<Split>
<Typography>Sunrise Block:</Typography>
<Typography>{sunrise.sunriseBlock.toString()}</Typography>
</Split>
<Split>
<Typography>Delta Blocks:</Typography>
<Typography>{deltaBlocks.toString()}</Typography>
</Split>
<Split>
<Typography>Morning index:</Typography>
<Typography>{morning.index.toString()}</Typography>
</Split>
<Split>
<Typography>Interval:</Typography>
<Typography>{morning.index.plus(1).toString()}</Typography>
</Split>
<Split>
<Typography>Scaled Temperature:</Typography>
<Typography>{temp.scaled.toString()}</Typography>
</Split>
<Split>
<Typography>Calculated temp:</Typography>
<Typography>{calculatedTempData?.toString()}</Typography>
</Split>
<Split>
<Typography>Max Temperature:</Typography>
<Typography>{temp.max.toString()}</Typography>
</Split>
</Stack>
</Box>
</Box>
Expand Down
34 changes: 32 additions & 2 deletions projects/ui/src/components/Nav/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ import Row from '~/components/Common/Row';
import { SGEnvironments, SUBGRAPH_ENVIRONMENTS } from '~/graph/endpoints';
import useSetting from '~/hooks/app/useSetting';
import useFarmerSiloBalances from '~/hooks/farmer/useFarmerSiloBalances';
import { save } from '~/state';
import { setNextSunrise } from '~/state/beanstalk/sun/actions';
import { save, useAppSelector } from '~/state';
import {
setMorning,
setNextSunrise,
updateSeasonResult,
} from '~/state/beanstalk/sun/actions';
import { clearApolloCache, trimAddress } from '~/util';
import useChainId from '~/hooks/chain/useChainId';
import { CHAIN_INFO } from '~/constants';
import { useAccount } from 'wagmi';
import { useSetRemainingUntilSunrise } from '~/state/beanstalk/sun/updater';
import { getMorningResult } from '~/state/beanstalk/sun';
import OutputField from '../Common/Form/OutputField';

const Split: FC<{}> = ({ children }) => (
Expand Down Expand Up @@ -91,6 +96,7 @@ const SettingsDialog: FC<{ open: boolean; onClose?: () => void }> = ({
const siloBalances = useFarmerSiloBalances();
const account = useAccount();
const setRemainingUntilSunrise = useSetRemainingUntilSunrise();
const seasonStruct = useAppSelector((s) => s._beanstalk.sun.season);

const checkAddress = useCallback(
(address: string) => {
Expand Down Expand Up @@ -138,6 +144,22 @@ const SettingsDialog: FC<{ open: boolean; onClose?: () => void }> = ({
dispatch(setNextSunrise(_next));
setRemainingUntilSunrise(_next.diffNow());
}, [dispatch, setRemainingUntilSunrise]);

const simulateMorning = useCallback(() => {
const _seasonStruct = {
...seasonStruct,
timestamp: DateTime.now(),
};

const morningResult = getMorningResult({
timestamp: _seasonStruct.timestamp,
blockNumber: _seasonStruct.sunriseBlock,
});

dispatch(updateSeasonResult(_seasonStruct));
dispatch(setMorning(morningResult));
}, [dispatch, seasonStruct]);

const exportDepositsCSV = useCallback(() => {
const rows = Object.keys(siloBalances).reduce(
(prev, curr) => {
Expand Down Expand Up @@ -352,6 +374,14 @@ const SettingsDialog: FC<{ open: boolean; onClose?: () => void }> = ({
Export
</Button>
</Split>
<Split>
<Typography color="text.secondary">
Simulate Morning
</Typography>
<Button {...buttonStyle} onClick={simulateMorning}>
Simulate
</Button>
</Split>
</Stack>
</>
) : null}
Expand Down

0 comments on commit 5d1beb1

Please sign in to comment.