Skip to content

Commit

Permalink
(govern) fix: update state after voting, fix rollover pool sorting, a…
Browse files Browse the repository at this point in the history
…dd next week explanation
  • Loading branch information
Atatakai authored and Atatakai committed Aug 1, 2024
1 parent 23eb9e9 commit 13879ae
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
2 changes: 2 additions & 0 deletions apps/govern/common-util/constants/scopeKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ export const VOTE_USER_POWER_KEY = 'voteUserPower';
export const NEXT_USERS_SLOPES_KEY = 'nextUserSlopes';
export const NEXT_RELATIVE_WEIGHTS_KEY = 'nextRelativeWeights';
export const LATEST_BLOCK_KEY = 'latestBlock';
export const TIME_SUM_KEY = 'timeSum';

export const INVALIDATE_AFTER_UPDATE_KEYS = [
LAST_USER_VOTE_KEY,
VOTE_USER_POWER_KEY,
NEXT_USERS_SLOPES_KEY,
NEXT_RELATIVE_WEIGHTS_KEY,
LATEST_BLOCK_KEY,
TIME_SUM_KEY,
];

export const INVALIDATE_AFTER_ACCOUNT_CHANGE = [
Expand Down
7 changes: 1 addition & 6 deletions apps/govern/components/Contracts/ContractsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ const getColumns = ({
),
},
{
title: (
<NextWeekTooltip>
Next week&apos;s weight
<InfoCircleOutlined className="ml-8" style={{ color: COLOR.GREY_2 }} />
</NextWeekTooltip>
),
title: <NextWeekTooltip>Next week&apos;s weight</NextWeekTooltip>,
key: 'nextWeight',
dataIndex: 'nextWeight',
render: (nextWeight) => (
Expand Down
3 changes: 2 additions & 1 deletion apps/govern/components/Contracts/EditVotes/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ describe('<EditVotes />', () => {
expect(screen.getByText('My voting weight')).toBeInTheDocument();

expect(
screen.getByText(/New voting weight will take effect at the beginning of the next week./),
screen.getByText(/Updated voting weights will take effect at the start of/),
).toBeInTheDocument();
expect(screen.getByText(/next Unix time week./)).toBeInTheDocument();
});

describe('Voting contract row', () => {
Expand Down
4 changes: 3 additions & 1 deletion apps/govern/components/Contracts/EditVotes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RETAINER_ADDRESS } from 'common-util/constants/addresses';
import { INVALIDATE_AFTER_UPDATE_KEYS } from 'common-util/constants/scopeKeys';
import { getBytes32FromAddress } from 'common-util/functions/addresses';
import { voteForNomineeWeights } from 'common-util/functions/requests';
import { NextWeekTooltip } from 'components/NextWeekTooltip';
import { queryClient } from 'context/Web3ModalProvider';
import { clearState } from 'store/govern';
import { useAppDispatch, useAppSelector } from 'store/index';
Expand Down Expand Up @@ -218,7 +219,8 @@ export const EditVotes = ({ allocations, setAllocations, setIsUpdating }: EditVo
/>

<Paragraph type="secondary" className="text-end">
New voting weight will take effect at the beginning of the next week.
Updated voting weights will take effect at the start of&nbsp;
<NextWeekTooltip hideDescription>next Unix time week.</NextWeekTooltip>
</Paragraph>
<Flex gap={12} justify="flex-end">
<Button size="large" onClick={onCancel}>
Expand Down
10 changes: 3 additions & 7 deletions apps/govern/components/Contracts/MyVotingWeight/Votes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ const columns: ColumnsType<MyVote> = [
render: (currentWeight) => <Text>{`${currentWeight}%`}</Text>,
},
{
title: (
<NextWeekTooltip>
My updated weight <InfoCircleOutlined className="ml-8" style={{ color: COLOR.GREY_2 }} />
</NextWeekTooltip>
),
title: <NextWeekTooltip>My updated weight</NextWeekTooltip>,
key: 'nextWeight',
dataIndex: 'nextWeight',
render: (nextWeight) => <Text>{`${nextWeight}%`}</Text>,
Expand Down Expand Up @@ -155,8 +151,8 @@ export const Votes = ({ setIsUpdating, setAllocations }: VotesProps) => {
});
}
return res.sort((item) =>
// put Rollover address at the end
item.address === getBytes32FromAddress(RETAINER_ADDRESS) ? 1 : -1,
// put Rollover pool at the end
item.isRetainer ? 1 : -1,
);
}, []);
}, [userVotes, stakingContracts]);
Expand Down
16 changes: 14 additions & 2 deletions apps/govern/components/NextWeekTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InfoCircleOutlined } from '@ant-design/icons';
import { Space, Tooltip, Typography } from 'antd';
import { ReactNode } from 'react';
import { mainnet } from 'viem/chains';
Expand All @@ -10,14 +11,24 @@ const { Text } = Typography;

const TOOLTIP_STYLE = { maxWidth: '350px' };

export const NextWeekTooltip = ({ children }: { children: ReactNode }) => {
export const NextWeekTooltip = ({
children,
hideDescription = false,
}: {
children: ReactNode;
hideDescription?: boolean;
}) => {
return (
<Tooltip
color={COLOR.WHITE}
overlayStyle={TOOLTIP_STYLE}
title={
<Space direction="vertical">
<Text>Updated voting weights will take effect at the start of next week Unix time.</Text>
{!hideDescription && (
<Text>
Updated voting weights will take effect at the start of next Unix time week.
</Text>
)}
<a
href={`https://etherscan.io/address/${
VOTE_WEIGHTING.addresses[mainnet.id]
Expand All @@ -31,6 +42,7 @@ export const NextWeekTooltip = ({ children }: { children: ReactNode }) => {
}
>
{children}
<InfoCircleOutlined className="ml-8" style={{ color: COLOR.GREY_2 }} />
</Tooltip>
);
};
3 changes: 2 additions & 1 deletion apps/govern/hooks/useFetchStakingContractsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useReadContract } from 'wagmi';
import { VOTE_WEIGHTING } from 'libs/util-contracts/src/lib/abiAndAddresses';

import { RETAINER_ADDRESS } from 'common-util/constants/addresses';
import { NEXT_RELATIVE_WEIGHTS_KEY } from 'common-util/constants/scopeKeys';
import { NEXT_RELATIVE_WEIGHTS_KEY, TIME_SUM_KEY } from 'common-util/constants/scopeKeys';
import { getBytes32FromAddress } from 'common-util/functions';
import { setStakingContracts } from 'store/govern';
import { useAppDispatch, useAppSelector } from 'store/index';
Expand Down Expand Up @@ -39,6 +39,7 @@ export const useFetchStakingContractsList = () => {
abi: VOTE_WEIGHTING.abi,
chainId: mainnet.id,
functionName: 'timeSum',
scopeKey: TIME_SUM_KEY,
query: {
select: (data) => Number(data),
},
Expand Down
4 changes: 1 addition & 3 deletions apps/govern/store/govern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export const governSlice = createSlice({
setLastUserVote: (state, action: PayloadAction<GovernState['lastUserVote']>) => {
state.lastUserVote = action.payload;
},
clearState: (state) => {
state = { ...initialState };
},
clearState: () => initialState,
clearUserState: (state) => {
state.userVotes = initialState.userVotes;
state.isUserVotesLoading = true;
Expand Down

0 comments on commit 13879ae

Please sign in to comment.