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

(govern) fix: update state after voting, fix rollover pool sorting, a… #73

Merged
merged 2 commits into from
Aug 1, 2024
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
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
10 changes: 2 additions & 8 deletions apps/govern/components/Contracts/ContractsList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { CheckOutlined, InfoCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { CheckOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Card as CardAntd, Space, Table, Typography } from 'antd';
import { ColumnsType } from 'antd/es/table';
import styled from 'styled-components';
import { Allocation, StakingContract } from 'types';
import { useAccount } from 'wagmi';

import { COLOR } from 'libs/ui-theme/src';
import { CHAIN_NAMES } from 'libs/util-constants/src';

import { formatWeiBalance } from 'common-util/functions/balance';
Expand Down Expand Up @@ -65,12 +64,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
4 changes: 3 additions & 1 deletion apps/govern/components/Contracts/EditVotes/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +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 next week \(according to Unix time\)./,
),
).toBeInTheDocument();
});

Expand Down
2 changes: 1 addition & 1 deletion apps/govern/components/Contracts/EditVotes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ 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 next week (according to Unix time).
</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
7 changes: 6 additions & 1 deletion 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 @@ -17,7 +18,10 @@ export const NextWeekTooltip = ({ children }: { children: ReactNode }) => {
overlayStyle={TOOLTIP_STYLE}
title={
<Space direction="vertical">
<Text>Updated voting weights will take effect at the start of next week Unix time.</Text>
<Text>
Updated voting weights will take effect at the start of next week (according to Unix
time).
</Text>
<a
href={`https://etherscan.io/address/${
VOTE_WEIGHTING.addresses[mainnet.id]
Expand All @@ -31,6 +35,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,
Tanya-atatakai marked this conversation as resolved.
Show resolved Hide resolved
clearUserState: (state) => {
state.userVotes = initialState.userVotes;
state.isUserVotesLoading = true;
Expand Down
Loading