From ec99b9148e3caf4088104e6c17aff577ebbd2e73 Mon Sep 17 00:00:00 2001 From: Anil Kumar Rai Date: Tue, 25 Jul 2023 20:01:19 +0530 Subject: [PATCH 1/2] fix: console warning after network switch --- src/mobx/stores/WalletStore.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/mobx/stores/WalletStore.ts b/src/mobx/stores/WalletStore.ts index 5ffb59e11..173e612fa 100644 --- a/src/mobx/stores/WalletStore.ts +++ b/src/mobx/stores/WalletStore.ts @@ -72,14 +72,7 @@ export class WalletStore { /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ private getLibrary(provider: any): Web3Provider { - const library = new Web3Provider( - provider, - typeof provider.chainId === 'number' - ? provider.chainId - : typeof provider.chainId === 'string' - ? parseInt(provider.chainId) - : 'any', - ); + const library = new Web3Provider(provider, 'any'); library.pollingInterval = 15000; return library; } From c058dc9c9ba2cb530000f9bcda54d25d8c56da96 Mon Sep 17 00:00:00 2001 From: Anil Rai Date: Tue, 12 Sep 2023 21:22:38 +0530 Subject: [PATCH 2/2] Removed governance related code. (#2568) * removed governance related code. * changes as per review comment * regenerated contract * added lokijs for failing test cases --- .env | 4 +- .env.example | 2 - package.json | 1 + .../navbar/NavbarSocialContact.tsx | 18 -- src/components-v2/navbar/NavbarTabs.tsx | 9 - src/components-v2/sidebar/index.tsx | 4 - src/components/Governance/AddressInfoCard.tsx | 47 --- src/components/Governance/EventsTable.tsx | 154 --------- src/components/Governance/EventsTableItem.tsx | 32 -- src/components/Governance/ProposalAction.tsx | 140 --------- .../Governance/ProposalDetailModal.tsx | 291 ------------------ src/components/Governance/ProposalModal.tsx | 245 --------------- src/components/Governance/index.tsx | 95 ------ src/config/environment.ts | 2 - .../interfaces/navbar-config.interface.ts | 1 - src/config/navbar.config.ts | 8 - src/config/routes.tsx | 11 - src/contracts/common.ts | 8 + .../factories/AuraLocker__factory.ts | 2 +- .../factories/BadgerPeakSwap__factory.ts | 2 +- .../factories/CurveFactoryPool__factory.ts | 2 +- .../factories/GovernanceTimelock__factory.ts | 2 +- .../factories/IbbtcVaultZap__factory.ts | 2 +- .../factories/VoteLockedDeposit__factory.ts | 2 +- src/hooks/useGovRoles.ts | 37 --- src/mobx/stores/GovernancePortalStore.ts | 73 ----- src/mobx/stores/RootStore.ts | 3 - src/mobx/stores/UserStore.ts | 31 -- src/tests/__snapshots__/Navbar.test.tsx.snap | 206 ++++++------- yarn.lock | 5 + 30 files changed, 116 insertions(+), 1323 deletions(-) delete mode 100644 src/components/Governance/AddressInfoCard.tsx delete mode 100644 src/components/Governance/EventsTable.tsx delete mode 100644 src/components/Governance/EventsTableItem.tsx delete mode 100644 src/components/Governance/ProposalAction.tsx delete mode 100644 src/components/Governance/ProposalDetailModal.tsx delete mode 100644 src/components/Governance/ProposalModal.tsx delete mode 100644 src/components/Governance/index.tsx delete mode 100644 src/hooks/useGovRoles.ts delete mode 100644 src/mobx/stores/GovernancePortalStore.ts diff --git a/.env b/.env index 0dd74c920..0d9278223 100644 --- a/.env +++ b/.env @@ -1,5 +1,3 @@ ESLINT_NO_DEV_ERRORS=true EXTEND_ESLINT=true -REACT_APP_GOVERNANCE_TIMELOCK=false -REACT_APP_GRAVIAURA_CHART=true -REACT_APP_GOVERNANCE_TAB=false \ No newline at end of file +REACT_APP_GRAVIAURA_CHART=true \ No newline at end of file diff --git a/.env.example b/.env.example index 5a4f0aaf8..b24184d38 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,4 @@ ESLINT_NO_DEV_ERRORS=true EXTEND_ESLINT=true -REACT_APP_GOVERNANCE_TIMELOCK=false REACT_APP_GRAVIAURA_CHART=true -REACT_APP_GOVERNANCE_TAB=false REACT_APP_WALLET_CONNECT_PROJECT_ID=dcdb98454f70814fa8bf6983dca8b5a9 \ No newline at end of file diff --git a/package.json b/package.json index 16a2e87a0..df07bce73 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "devDependencies": { "axios": "^1.2.4", "glob": "^8.0.3", + "lokijs": "^1.5.12", "source-map-explorer": "^2.5.3" }, "jest": { diff --git a/src/components-v2/navbar/NavbarSocialContact.tsx b/src/components-v2/navbar/NavbarSocialContact.tsx index 9f3f8f80e..da04e8620 100644 --- a/src/components-v2/navbar/NavbarSocialContact.tsx +++ b/src/components-v2/navbar/NavbarSocialContact.tsx @@ -1,10 +1,7 @@ import { Grid, Link, makeStyles } from '@material-ui/core'; import clsx from 'clsx'; -import React from 'react'; import { Typography } from 'ui-library/Typography'; -import { FLAGS } from '../../config/environment'; - const useStyles = makeStyles(() => ({ socialIcon: { height: '14px', @@ -17,9 +14,6 @@ const useStyles = makeStyles(() => ({ twitter: { margin: '0px 16px 0px 8px', }, - governance: { - margin: '0px 18px', - }, })); export const NavbarSocialContact = (): JSX.Element => { @@ -49,18 +43,6 @@ export const NavbarSocialContact = (): JSX.Element => { - - - - GOVERNANCE - - - diff --git a/src/components-v2/navbar/NavbarTabs.tsx b/src/components-v2/navbar/NavbarTabs.tsx index 41771fa57..be0b67cce 100644 --- a/src/components-v2/navbar/NavbarTabs.tsx +++ b/src/components-v2/navbar/NavbarTabs.tsx @@ -1,5 +1,4 @@ import { makeStyles, Tab, Tabs, useMediaQuery, useTheme } from '@material-ui/core'; -import { FLAGS } from 'config/environment'; import { StoreContext } from 'mobx/stores/store-context'; import { observer } from 'mobx-react-lite'; import { QueryParams, Route } from 'mobx-router'; @@ -70,14 +69,6 @@ export const NavbarTabs = observer((): JSX.Element => { value={routes.IbBTC.path} /> )} - {FLAGS.GOVERNANCE_TAB && config.governance && ( - goToTab(routes.governance)} - value={routes.governance.path} - /> - )} ); }); diff --git a/src/components-v2/sidebar/index.tsx b/src/components-v2/sidebar/index.tsx index 086234169..1ddcd783f 100644 --- a/src/components-v2/sidebar/index.tsx +++ b/src/components-v2/sidebar/index.tsx @@ -2,7 +2,6 @@ import { Drawer, IconButton, useTheme } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import CloseIcon from '@material-ui/icons/Close'; import { SITE_VERSION } from 'config/constants'; -import routes from 'config/routes'; import { StoreContext } from 'mobx/stores/store-context'; import { observer } from 'mobx-react-lite'; import React, { useContext } from 'react'; @@ -88,9 +87,6 @@ const Sidebar = observer(() => { window.open('https://docs.badger.com/')}> Wiki - store.router.goTo(routes.governance)}> - Governance - window.open('https://forum.badger.finance')}> Forum diff --git a/src/components/Governance/AddressInfoCard.tsx b/src/components/Governance/AddressInfoCard.tsx deleted file mode 100644 index 3e4c8e446..000000000 --- a/src/components/Governance/AddressInfoCard.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import { Grid, Link, makeStyles, Typography } from '@material-ui/core'; -import ArrowUpward from '@material-ui/icons/ArrowUpward'; -import { observer } from 'mobx-react-lite'; -import React from 'react'; - -export interface AddressInfoCardProps { - title: string; - address?: string; - linkAddress: string; -} - -const useStyles = makeStyles(() => ({ - linkIcon: { - display: 'inline-block', - transform: 'rotate(45deg)', - color: 'white', - }, - address: { - maxWidth: '100px', - paddingRight: '1px', - }, -})); - -const AddressInfoCard: React.FC = observer((props: AddressInfoCardProps) => { - const classes = useStyles(); - const { title, address, linkAddress } = props; - return ( -
- - {title} - - - - - {address} - - - - - - - -
- ); -}); - -export default AddressInfoCard; diff --git a/src/components/Governance/EventsTable.tsx b/src/components/Governance/EventsTable.tsx deleted file mode 100644 index 957a401f1..000000000 --- a/src/components/Governance/EventsTable.tsx +++ /dev/null @@ -1,154 +0,0 @@ -import { GovernanceProposal } from '@badger-dao/sdk'; -import { - Paper, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TablePagination, - TableRow, -} from '@material-ui/core'; -import { Skeleton } from '@material-ui/lab'; -import routes from 'config/routes'; -import { GovernancePortalStore } from 'mobx/stores/GovernancePortalStore'; -import { StoreContext } from 'mobx/stores/store-context'; -import { observer } from 'mobx-react-lite'; -import { QueryParams } from 'mobx-router'; -import { useContext, useEffect, useLayoutEffect, useState } from 'react'; - -import EventsTableItem from './EventsTableItem'; -import ProposalDetailModal from './ProposalDetailModal'; - -export interface EventTableProps { - governancePortal: GovernancePortalStore; - nextPage: (val: number) => void; - loadingProposals: boolean; - setPerPage: (val: number) => void; -} - -const EventsTable = observer( - ({ governancePortal, nextPage, loadingProposals, setPerPage }: EventTableProps): JSX.Element => { - const [showProposalDetailModal, setShowProposalDetailModal] = useState(false); - const [selectedProposal, setSelectedProposal] = useState(null); - const { governanceProposals } = governancePortal; - const store = useContext(StoreContext); - - useEffect(() => { - const { proposalId }: QueryParams = { ...store.router.queryParams }; - if (proposalId) { - const proposal = governanceProposals?.items.find((proposal) => proposal.proposalId === proposalId); - - if (proposal) { - setSelectedProposal(proposal); - setShowProposalDetailModal(true); - } - } - }, [governanceProposals?.items.length]); - - const handleChangePage = (event: unknown, newPage: number) => { - nextPage(newPage + 1); - }; - - const handleChangeRowsPerPage = (event: React.ChangeEvent) => { - setPerPage(+event.target.value); - }; - - const handleProposalClick = (proposal: GovernanceProposal) => { - // add proposal id to route - store.router.goTo(routes.governance, {}, { ...store.router.queryParams, proposalId: proposal.proposalId }); - }; - - const handleProposalClose = () => { - // eslint-disable-next-line unused-imports/no-unused-vars - const { proposalId, ...rest }: QueryParams = { ...store.router.queryParams }; - // remove proposal id from route - store.router.goTo(routes.governance, {}, { ...rest }); - }; - - useLayoutEffect(() => { - const { proposalId }: QueryParams = { ...store.router.queryParams }; - if (proposalId) { - const proposal = governanceProposals?.items.find((proposal) => proposal.proposalId === proposalId); - if (proposal) { - setShowProposalDetailModal(true); - setSelectedProposal(proposal); - } - } else if (showProposalDetailModal) { - setShowProposalDetailModal(false); - } - }, [store.router.currentPath]); - - const handleVeto = async () => { - // if (selectedProposal?.proposalId) { - // store.governancePortal.veto(selectedProposal?.proposalId, (res, status) => { - // if (status === 'success') { - // toast.success('Vetoed successfully!'); - // } else { - // toast.error(res?.message || 'Something went wrong!'); - // } - // }); - // } - }; - - const handleUnVeto = () => { - console.log('HandleUnVeto'); - }; - - return ( - <> - - - - - Proposal Id - Status - Created At - Ready At - - - - {!loadingProposals && - governanceProposals?.items.map((proposal) => ( - - ))} - {loadingProposals && ( - - - {new Array(5).fill('').map((_, index) => ( - - ))} - - - )} - -
-
- - - - - ); - }, -); - -export default EventsTable; diff --git a/src/components/Governance/EventsTableItem.tsx b/src/components/Governance/EventsTableItem.tsx deleted file mode 100644 index 1abb2b131..000000000 --- a/src/components/Governance/EventsTableItem.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { GovernanceProposal } from '@badger-dao/sdk'; -import { makeStyles, TableCell, TableRow } from '@material-ui/core'; -import { shortenAddress } from 'utils/componentHelpers'; -import { getFormatedDateTime } from 'utils/date'; - -export interface EventTableProps { - proposal: GovernanceProposal; - onProposalClick: (data: GovernanceProposal) => void; -} - -const useStyles = makeStyles({ - root: { - cursor: 'pointer', - '&:hover': { - backgroundColor: 'rgba(255, 255, 255, 0.08)', - }, - }, -}); - -const EventsTableItem = ({ proposal, onProposalClick }: EventTableProps): JSX.Element => { - const classes = useStyles(); - return ( - onProposalClick(proposal)}> - {proposal?.proposalId && shortenAddress(proposal?.proposalId, 10)} - {proposal.currentStatus} - {getFormatedDateTime(new Date(Number(proposal.createdAt) * 1000))} - {getFormatedDateTime(new Date(Number(proposal.readyTime) * 1000))} - - ); -}; - -export default EventsTableItem; diff --git a/src/components/Governance/ProposalAction.tsx b/src/components/Governance/ProposalAction.tsx deleted file mode 100644 index 4c879b3dd..000000000 --- a/src/components/Governance/ProposalAction.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import { GovernanceProposalAction, GovernanceProposalsDispute, GovernanceProposalsStatus } from '@badger-dao/sdk'; -import { - Box, - Collapse, - Divider, - List, - ListItem, - ListItemText, - makeStyles, - Table, - TableBody, - TableCell, - TableContainer, - TableRow, - Typography, -} from '@material-ui/core'; -import { ExpandLess, ExpandMore } from '@material-ui/icons'; -import React, { useState } from 'react'; -import { decamelize, isObject } from 'utils/componentHelpers'; - -const useStyles = makeStyles(() => ({ - table: { - borderTop: '1px solid rgba(81, 81, 81, 1)', - '& td': { - padding: 8, - wordBreak: 'break-all', - borderBottom: 0, - '&:first-child': { - borderLeft: '1px solid rgba(81, 81, 81, 1)', - }, - '&:last-child': { - borderRight: '1px solid rgba(81, 81, 81, 1)', - }, - }, - '& tr': { - '&:last-child': { - borderBottom: '1px solid rgba(81, 81, 81, 1)', - }, - }, - }, - listItem: { - borderLeft: '1px solid rgba(81, 81, 81, 1)', - borderRight: '1px solid rgba(81, 81, 81, 1)', - }, -})); - -interface ProposalActionType { - actions: Array; - label: string; - open?: boolean; -} - -const ProposalAction = ({ actions, label, open = false }: ProposalActionType) => { - const classes = useStyles(); - - const [openAccord, setOpenAccord] = useState<{ [key: string]: boolean }>(() => - new Array(actions.length) - .fill('') - .reduce( - (acc: { [key: string]: boolean }, _, index) => ({ ...acc, [index]: open && index === 0 ? true : false }), - {}, - ), - ); - - const handleClick = (index: number) => { - setOpenAccord({ - ...openAccord, - [index]: !openAccord[index], - }); - }; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const renderValue = (key: string, value: any) => { - if (typeof value !== 'object' && value) { - return value; - } else if (isObject(value)) { - // eslint-disable-next-line unused-imports/no-unused-vars - const { inputTypes, ...rest } = value; - return ( - - {renderAction(rest)} -
- ); - } else if (Array.isArray(value)) { - return ( - - {value.map((data, index) => ( - - - {typeof data !== 'object' ? JSON.stringify(data) : data?.hex} - - {value.length > 1 && } - - ))} - - ); - } - }; - - const renderAction = (obj: GovernanceProposalsDispute | GovernanceProposalsStatus | GovernanceProposalAction) => { - return (Object.keys(obj) as Array).map((key) => ( - - - - {decamelize(key, ' ')} - - - {renderValue(key, obj[key])} - - )); - }; - - return ( - <> - {actions.map((action, index: number) => ( - - - - handleClick(index)}> - - {openAccord[index] ? : } - - - - - - - {renderAction(action)} -
-
-
-
-
-
- ))} - - ); -}; - -export default ProposalAction; diff --git a/src/components/Governance/ProposalDetailModal.tsx b/src/components/Governance/ProposalDetailModal.tsx deleted file mode 100644 index 1d044068f..000000000 --- a/src/components/Governance/ProposalDetailModal.tsx +++ /dev/null @@ -1,291 +0,0 @@ -import { GovernanceProposal, GovernanceProposalsDispute, GovernanceProposalsStatus } from '@badger-dao/sdk'; -import { - Box, - Button, - Card, - CardContent, - CardHeader, - Dialog, - DialogActions, - DialogContent, - DialogTitle, - Grid, - IconButton, - makeStyles, - Table, - TableBody, - TableCell, - TableContainer, - TableRow, - Theme, - Typography, -} from '@material-ui/core'; -import CloseIcon from '@material-ui/icons/Close'; -import { Loader } from 'components/Loader'; -import useGovRoles from 'hooks/useGovRoles'; -import React from 'react'; -import { decamelize, shortenAddress } from 'utils/componentHelpers'; -import { getFormatedDateTime } from 'utils/date'; - -import ProposalAction from './ProposalAction'; - -const useStyles = makeStyles((theme: Theme) => ({ - root: { - color: 'rgba(255,255,255,0.6)', - paddingTop: 0, - paddingBottom: 30, - }, - title: { - padding: 20, - borderBottom: '1px solid rgba(81, 81, 81, 1)', - }, - titleText: { - display: 'flex', - alignItems: 'center', - '& img': { - marginRight: 10, - }, - }, - closeButton: { - position: 'absolute', - right: theme.spacing(1), - top: theme.spacing(1), - }, - formField: { - marginBottom: 10, - }, - proposalId: { - paddingLeft: 5, - }, - linkIcon: { - display: 'inline-block', - transform: 'rotate(45deg)', - color: 'white', - '& svg': { - fontSize: 16, - }, - }, - nested: { - paddingLeft: theme.spacing(1), - }, - detailtable: { - '& td': { - border: '0px !important', - '&:first-child': { - paddingLeft: '0px !important', - }, - }, - }, - table: { - '& td': { - padding: 8, - wordBreak: 'break-all', - '&:first-child': { - borderLeft: '1px solid rgba(81, 81, 81, 1)', - }, - '&:last-child': { - borderRight: '1px solid rgba(81, 81, 81, 1)', - }, - }, - }, - card: { - border: '1px solid rgba(81, 81, 81, 1)', - padding: theme.spacing(0, 1), - margin: theme.spacing(2, 0), - }, - cardHeader: { - padding: theme.spacing(1, 0, 0, 0), - '& span': { - fontSize: '16px', - }, - }, - cardContent: { - '&:last-child': { - padding: theme.spacing(1, 0), - }, - }, -})); - -export type BodyAsChildrenType = Omit; - -interface ProposalDetailModalTypes { - open: boolean; - onModalClose: () => void; - proposal: GovernanceProposal | null; - onVeto: () => void; - onUnVeto: () => void; - vetoing: boolean; -} - -export type ProposalBodyType = Omit; - -export default function ProposalDetailModal({ - open, - onModalClose, - proposal, - onVeto, - onUnVeto, - vetoing, -}: ProposalDetailModalTypes) { - const classes = useStyles(); - const { hasVetoRole, hasUnVetoRole } = useGovRoles(); - - if (!proposal) return null; - - const { disputes, statuses, actions, ...rest } = proposal; - const { proposalId, createdAt, contractAddr, readyTime, currentStatus, creationBlock, updateBlock } = rest; - - const events: Array = [...disputes, ...statuses]; - - const actionRow = (label: string, value: string | undefined) => ( - - - - {label} - - - {value} - - ); - - return ( - - - - - - - - Proposal Id : - - - {proposal?.proposalId && shortenAddress(proposal?.proposalId, 6)} - - - - - - - Status : - - - {proposal?.currentStatus} - - - - - - - - - - - - {/* - - - - - Ethscan - - - - - - - - - - */} - - - - - {actionRow(decamelize('proposalId', ' '), proposalId)} - {actionRow(decamelize('createdAt', ' '), getFormatedDateTime(new Date(Number(createdAt) * 1000)))} - {actionRow(decamelize('contractAddr', ' '), contractAddr)} - {actionRow(decamelize('readyTime', ' '), getFormatedDateTime(new Date(Number(readyTime) * 1000)))} - {actionRow(decamelize('contractAddr', ' '), contractAddr)} - {actionRow(decamelize('currentStatus', ' '), currentStatus)} - {actionRow(decamelize('creationBlock', ' '), creationBlock.toString())} - {actionRow(decamelize('updateBlock', ' '), updateBlock.toString())} - -
-
- - {actions.length > 0 && ( - - - - {actions.length > 0 && } - {events.length > 0 && } - - - )} - - {/* {events.length > 0 && ( - - - - {events.length > 0 && } - - - )} */} - - - - - - Created At : - - - {proposal?.createdAt && getFormatedDateTime(new Date(Number(proposal.createdAt) * 1000))} - - - - - - - Ready At : - - - {proposal?.readyTime && getFormatedDateTime(new Date(Number(proposal.readyTime) * 1000))} - - - - -
- - - {hasVetoRole && ( - - )} - - {hasUnVetoRole && ( - - )} - -
- ); -} diff --git a/src/components/Governance/ProposalModal.tsx b/src/components/Governance/ProposalModal.tsx deleted file mode 100644 index 92c7286c0..000000000 --- a/src/components/Governance/ProposalModal.tsx +++ /dev/null @@ -1,245 +0,0 @@ -import { - Accordion, - AccordionActions, - AccordionDetails, - AccordionSummary, - Box, - Button, - Dialog, - DialogContent, - DialogTitle, - Divider, - Grid, - IconButton, - makeStyles, - TextField, - Theme, - Typography, -} from '@material-ui/core'; -import AddIcon from '@material-ui/icons/Add'; -import CloseIcon from '@material-ui/icons/Close'; -import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; -import React, { useState } from 'react'; - -const salt = '0xc1059ed2dc130227aa1d1d539ac94c641306905c020436c636e19e3fab56fc7f'; - -const useStyles = makeStyles((theme: Theme) => ({ - root: { - color: 'rgba(255,255,255,0.6)', - paddingTop: 0, - paddingBottom: 30, - }, - title: { - padding: 20, - }, - titleText: { - display: 'flex', - alignItems: 'center', - '& img': { - marginRight: 10, - }, - }, - closeButton: { - position: 'absolute', - right: theme.spacing(1), - top: theme.spacing(1), - }, - formField: { - marginBottom: 10, - }, -})); - -interface ProposalModalTypes { - open: boolean; - onModalClose: () => void; -} - -interface ProposalTypes { - id: number; - fields: { - [key: string]: { - label: string; - value: string; - hasError: boolean; - defaultValue?: string; - }; - }; -} - -const ProposalModal = ({ open, onModalClose }: ProposalModalTypes) => { - const classes = useStyles(); - - const [proposals, setProposals] = useState([ - { - id: 1, - fields: { - target: { - label: 'target (address)', - value: '', - hasError: false, - }, - value: { - label: 'value (uint256)', - value: '', - hasError: false, - }, - data: { - label: 'data (bytes)', - value: '', - hasError: false, - }, - predecessor: { - label: 'predecessor (bytes32)', - value: '0x', - hasError: false, - defaultValue: '0x', - }, - salt: { - label: 'salt (bytes32)', - value: salt, - hasError: false, - defaultValue: salt, - }, - delay: { - label: 'delay (uint256)', - value: '', - hasError: false, - }, - }, - }, - ]); - - const handleFieldValueChange = (value: string, formIndex: number, fieldName: string) => { - const prevProposals = [...proposals]; - const field = prevProposals[formIndex].fields[fieldName]; - field['value'] = value; - field['hasError'] = field['value'] ? false : true; - setProposals(prevProposals); - }; - - const handleAddNewProposal = () => { - const firstProposal = [...proposals][0]; - setProposals([ - ...proposals, - { - id: firstProposal.id + 1, - fields: Object.fromEntries( - Object.entries(firstProposal.fields).map((value) => [ - value[0], - { ...value[1], value: value[1].defaultValue ? value[1].defaultValue : '', hasError: false }, - ]), - ), - }, - ]); - }; - - const handleSubmitProposal = () => { - let hasError = false; - const prevProposals = [...proposals]; - prevProposals.map((proposal) => - Object.keys(proposal.fields).forEach((key) => { - if (!proposal.fields[key].value) { - proposal.fields[key].hasError = true; - hasError = true; - } else { - proposal.fields[key].hasError = false; - } - }), - ); - setProposals(prevProposals); - if (hasError) return; - }; - - const handleFormDelete = (formIndex: number) => { - const prevProposals = [...proposals]; - prevProposals.splice(formIndex, 1); - setProposals(prevProposals); - }; - - const handleFormClear = (formIndex: number) => { - const prevProposals = [...proposals]; - prevProposals[formIndex].fields = Object.fromEntries( - Object.entries(prevProposals[formIndex].fields).map((value) => [ - value[0], - { ...value[1], value: value[1].defaultValue ? value[1].defaultValue : '', hasError: false }, - ]), - ); - setProposals(prevProposals); - }; - - return ( - - - - - Create Proposal - - - - - - - - {proposals.map((proposal, index) => ( - - - } aria-controls="panel1a-content" id="panel1a-header"> - Proposal {index + 1} - - - - {Object.keys(proposal.fields).map((key) => ( - handleFieldValueChange(e.target.value, index, key)} - className={classes.formField} - error={proposal.fields[key].hasError} - /> - ))} - - - - - - - {proposals.length > 1 && ( - - )} - - - - ))} - - - - - - - - - - - - ); -}; - -export default ProposalModal; diff --git a/src/components/Governance/index.tsx b/src/components/Governance/index.tsx deleted file mode 100644 index de7853881..000000000 --- a/src/components/Governance/index.tsx +++ /dev/null @@ -1,95 +0,0 @@ -import { Network } from '@badger-dao/sdk'; -import { Button, Grid, IconButton } from '@material-ui/core'; -import useGovRoles from 'hooks/useGovRoles'; -import { StoreContext } from 'mobx/stores/store-context'; -import { observer } from 'mobx-react-lite'; -import { useContext, useEffect, useState } from 'react'; - -import { LayoutContainer, PageHeaderContainer } from '../../components-v2/common/Containers'; -import PageHeader from '../../components-v2/common/PageHeader'; -import AddressInfoCard from './AddressInfoCard'; -import EventsTable from './EventsTable'; -import ProposalModal from './ProposalModal'; - -const GovernancePortal = observer(() => { - const store = useContext(StoreContext); - const { governancePortal, chain } = store; - const [showGovernanceFilters, setShowGovernanceFilters] = useState(false); - const [showProposalModal, setShowProposalModal] = useState(false); - - const { hasProposalRole } = useGovRoles(); - - useEffect(() => { - if (chain.network === Network.Arbitrum) { - governancePortal.loadData(); - } - }, [governancePortal, chain.network]); - - const toggleShowDialog = () => { - setShowGovernanceFilters(!showGovernanceFilters); - }; - - const handleNextPage = (nextPage: number) => { - governancePortal.updatePage(chain.network, nextPage); - }; - - const handleSetPerPage = (perPage: number) => { - governancePortal.updatePerPage(chain.network, perPage); - }; - - return ( - - - - - - - - - - - - - - - - - - vault filters - - - - - - {hasProposalRole && ( - - - - )} - - { - setShowProposalModal(!showProposalModal); - }} - /> - - ); -}); - -export default GovernancePortal; diff --git a/src/config/environment.ts b/src/config/environment.ts index 84313346d..d915650dc 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -59,9 +59,7 @@ export const BADGER_API = getApi(); const toBool = (val: string | undefined): boolean => (val ? val.toLowerCase() === 'true' : false); export const FLAGS = { - GOVERNANCE_TIMELOCK: toBool(process.env.REACT_APP_GOVERNANCE_TIMELOCK), GRAVIAURA_CHART: toBool(process.env.REACT_APP_GRAVIAURA_CHART), - GOVERNANCE_TAB: toBool(process.env.REACT_APP_GOVERNANCE_TAB), }; export const projectId = process.env.REACT_APP_WALLET_CONNECT_PROJECT_ID; diff --git a/src/config/interfaces/navbar-config.interface.ts b/src/config/interfaces/navbar-config.interface.ts index 4f89c135d..99d6d0802 100644 --- a/src/config/interfaces/navbar-config.interface.ts +++ b/src/config/interfaces/navbar-config.interface.ts @@ -3,5 +3,4 @@ export interface NavbarConfig { ibBTC: boolean; bridge: boolean; boost: boolean; - governance: boolean; } diff --git a/src/config/navbar.config.ts b/src/config/navbar.config.ts index 842cc810c..cc3e7101a 100644 --- a/src/config/navbar.config.ts +++ b/src/config/navbar.config.ts @@ -9,56 +9,48 @@ const navbarConfig: Record = { ibBTC: true, bridge: false, boost: true, - governance: false, }, [Network.Ethereum]: { cycle: true, ibBTC: true, bridge: false, boost: true, - governance: false, }, [Network.Arbitrum]: { cycle: true, ibBTC: false, bridge: false, boost: true, - governance: true, }, [Network.Avalanche]: { cycle: false, ibBTC: false, bridge: false, boost: false, - governance: false, }, [Network.BinanceSmartChain]: { cycle: false, ibBTC: false, bridge: false, boost: false, - governance: false, }, [Network.Polygon]: { cycle: true, ibBTC: false, bridge: false, boost: false, - governance: false, }, [Network.Fantom]: { cycle: false, ibBTC: false, bridge: false, boost: false, - governance: false, }, [Network.Optimism]: { cycle: false, ibBTC: false, bridge: false, boost: false, - governance: false, }, }; diff --git a/src/config/routes.tsx b/src/config/routes.tsx index 960359fd5..eae3caf8d 100644 --- a/src/config/routes.tsx +++ b/src/config/routes.tsx @@ -6,14 +6,12 @@ import React from 'react'; import { VaultSortOrder } from '../mobx/model/ui/vaults-filters'; import store, { RootStore } from '../mobx/stores/RootStore'; import { parseQueryMultipleParams } from '../mobx/utils/helpers'; -import { FLAGS } from './environment'; const Landing = React.lazy(() => import('../pages/Landing')); const NotFound = React.lazy(() => import('../components-v2/common/NotFound')); const BoostOptimizer = React.lazy(() => import('../components/Boost')); const IbBTC = React.lazy(() => import('components/IbBTC')); const VaultDetailWrapper = React.lazy(() => import('components-v2/vault-detail/VaultDetailWrapper')); -const Governance = React.lazy(() => import('components/Governance')); const Bridge = React.lazy(() => import('components/Bridge')); const withSuspense = (Component: React.FunctionComponent) => ( @@ -75,15 +73,6 @@ const routes = { store.vaultDetail.reset(); }, }), - governance: FLAGS.GOVERNANCE_TIMELOCK - ? new Route({ - path: '/governance', - component: withSuspense(Governance), - }) - : new Route({ - path: '/governance', - component: withSuspense(NotFound), - }), bridge: new Route({ path: '/bridge', component: withSuspense(Bridge), diff --git a/src/contracts/common.ts b/src/contracts/common.ts index 325a68bbd..35f31be99 100644 --- a/src/contracts/common.ts +++ b/src/contracts/common.ts @@ -21,4 +21,12 @@ export interface OnEvent { (eventName: string, listener: Listener): TRes; } +export type MinEthersFactory = { + deploy(...a: ARGS[]): Promise; +}; + +export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; + +export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; + export type PromiseOrValue = T | Promise; diff --git a/src/contracts/factories/AuraLocker__factory.ts b/src/contracts/factories/AuraLocker__factory.ts index b7872c137..c8e29e2c5 100644 --- a/src/contracts/factories/AuraLocker__factory.ts +++ b/src/contracts/factories/AuraLocker__factory.ts @@ -1342,7 +1342,7 @@ const _abi = [ stateMutability: 'view', type: 'function', }, -]; +] as const; export class AuraLocker__factory { static readonly abi = _abi; diff --git a/src/contracts/factories/BadgerPeakSwap__factory.ts b/src/contracts/factories/BadgerPeakSwap__factory.ts index 15392581b..43b7c7bde 100644 --- a/src/contracts/factories/BadgerPeakSwap__factory.ts +++ b/src/contracts/factories/BadgerPeakSwap__factory.ts @@ -820,7 +820,7 @@ const _abi = [ payable: false, type: 'function', }, -]; +] as const; export class BadgerPeakSwap__factory { static readonly abi = _abi; diff --git a/src/contracts/factories/CurveFactoryPool__factory.ts b/src/contracts/factories/CurveFactoryPool__factory.ts index ddc2166df..5892eccb8 100644 --- a/src/contracts/factories/CurveFactoryPool__factory.ts +++ b/src/contracts/factories/CurveFactoryPool__factory.ts @@ -958,7 +958,7 @@ const _abi = [ }, ], }, -]; +] as const; export class CurveFactoryPool__factory { static readonly abi = _abi; diff --git a/src/contracts/factories/GovernanceTimelock__factory.ts b/src/contracts/factories/GovernanceTimelock__factory.ts index e3bfeb324..55f7faca9 100644 --- a/src/contracts/factories/GovernanceTimelock__factory.ts +++ b/src/contracts/factories/GovernanceTimelock__factory.ts @@ -973,7 +973,7 @@ const _abi = [ stateMutability: 'payable', type: 'receive', }, -]; +] as const; export class GovernanceTimelock__factory { static readonly abi = _abi; diff --git a/src/contracts/factories/IbbtcVaultZap__factory.ts b/src/contracts/factories/IbbtcVaultZap__factory.ts index 14234b8c5..3b35f99d4 100644 --- a/src/contracts/factories/IbbtcVaultZap__factory.ts +++ b/src/contracts/factories/IbbtcVaultZap__factory.ts @@ -384,7 +384,7 @@ const _abi = [ stateMutability: 'nonpayable', type: 'function', }, -]; +] as const; export class IbbtcVaultZap__factory { static readonly abi = _abi; diff --git a/src/contracts/factories/VoteLockedDeposit__factory.ts b/src/contracts/factories/VoteLockedDeposit__factory.ts index 57e19cfdf..96ca612fa 100644 --- a/src/contracts/factories/VoteLockedDeposit__factory.ts +++ b/src/contracts/factories/VoteLockedDeposit__factory.ts @@ -109,7 +109,7 @@ const _abi = [ stateMutability: 'view', type: 'function', }, -]; +] as const; export class VoteLockedDeposit__factory { static readonly abi = _abi; diff --git a/src/hooks/useGovRoles.ts b/src/hooks/useGovRoles.ts deleted file mode 100644 index 80d5bbafa..000000000 --- a/src/hooks/useGovRoles.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Network } from '@badger-dao/sdk'; -import { StoreContext } from 'mobx/stores/store-context'; -import { useContext, useEffect, useState } from 'react'; - -export default function useGovRoles() { - const [hasProposalRole, setHasProposalRole] = useState(false); - const [hasVetoRole, setHasVetoRole] = useState(false); - const [hasUnVetoRole, setHasUnVetoRole] = useState(false); - - const store = useContext(StoreContext); - - useEffect(() => { - async function getProposeRole() { - const hasRole = await store.user.hasProposalRole(); - setHasProposalRole(hasRole); - } - async function getVetoRole() { - const hasRole = await store.user.hasVetoRole(); - setHasVetoRole(hasRole); - } - async function getUnVetoRole() { - const hasRole = await store.user.hasUnVetoRole(); - setHasUnVetoRole(hasRole); - } - if (store.chain.network === Network.Arbitrum && store.user.accountDetails?.address) { - getProposeRole(); - getVetoRole(); - getUnVetoRole(); - } else { - setHasProposalRole(false); - setHasVetoRole(false); - setHasUnVetoRole(false); - } - }, [store.chain.network, store.user.accountDetails?.address]); - - return { hasProposalRole, hasVetoRole, hasUnVetoRole }; -} diff --git a/src/mobx/stores/GovernancePortalStore.ts b/src/mobx/stores/GovernancePortalStore.ts deleted file mode 100644 index 7fe176bb5..000000000 --- a/src/mobx/stores/GovernancePortalStore.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { GovernanceProposalsList, Network } from '@badger-dao/sdk'; -import { ContractTransaction } from 'ethers'; -import { action, makeAutoObservable } from 'mobx'; - -import { RootStore } from './RootStore'; - -export class GovernancePortalStore { - public contractAddress: string; - public governanceProposals?: GovernanceProposalsList; - public loadingProposals = false; - public vetoing = false; - public page = 1; - public perPage = 5; - constructor(private store: RootStore) { - this.contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'; - - makeAutoObservable(this, { - loadData: action, - }); - } - - async loadData(network = Network.Arbitrum, page = this.page, perPage = this.perPage): Promise { - const { api } = this.store; - this.loadingProposals = true; - try { - this.governanceProposals = await api.loadGovernanceProposals(network, page, perPage); - this.page = page; - } catch (error) { - console.log({ - error, - message: 'Unable to get proposal list', - }); - } finally { - this.loadingProposals = false; - } - } - - async veto(id: string, callback?: (res: ContractTransaction | unknown, status: string) => void) { - const { sdk } = this.store; - this.vetoing = true; - try { - const res = await sdk.governance.timelockController.callDispute(id); - if (callback) callback(res, 'success'); - } catch (error: unknown) { - if (callback) callback(error, 'error'); - console.log({ - error, - message: 'Unable to veto', - }); - } finally { - this.vetoing = false; - } - } - - // async unVeto() { - // const { sdk } = this.store; - // try { - // await sdk.governance.timelockController.callDisputeResolve(); - // } catch (error) { - - // } - // } - - updatePage = (network: Network, page: number) => { - this.page = page; - this.loadData(network, page); - }; - - updatePerPage = (network: Network, perPage: number) => { - this.perPage = perPage; - this.loadData(network, this.page, perPage); - }; -} diff --git a/src/mobx/stores/RootStore.ts b/src/mobx/stores/RootStore.ts index 4409e3da1..7820f22cd 100644 --- a/src/mobx/stores/RootStore.ts +++ b/src/mobx/stores/RootStore.ts @@ -6,7 +6,6 @@ import { RouterStore } from 'mobx-router'; import { BADGER_API } from '../../config/environment'; import rpc from '../../config/rpc.config'; import GasPricesStore from './GasPricesStore'; -import { GovernancePortalStore } from './GovernancePortalStore'; import IbBTCStore from './ibBTCStore'; import InfluenceVaultStore from './InfluenceVaultStore'; import LockedDepositsStore from './LockedDepositsStore'; @@ -42,7 +41,6 @@ export class RootStore { public vaultDetail: VaultDetailStore; public vaultCharts: VaultChartsStore; public gasPrices: GasPricesStore; - public governancePortal: GovernancePortalStore; public lockedDeposits: LockedDepositsStore; public transactions: TransactionsStore; public influenceVaultStore: InfluenceVaultStore; @@ -74,7 +72,6 @@ export class RootStore { this.vaultCharts = new VaultChartsStore(this); this.gasPrices = new GasPricesStore(this); this.ibBTCStore = new IbBTCStore(this); - this.governancePortal = new GovernancePortalStore(this); this.lockedDeposits = new LockedDepositsStore(this); this.influenceVaultStore = new InfluenceVaultStore(this); diff --git a/src/mobx/stores/UserStore.ts b/src/mobx/stores/UserStore.ts index a0b597c3e..54db4d03f 100644 --- a/src/mobx/stores/UserStore.ts +++ b/src/mobx/stores/UserStore.ts @@ -165,35 +165,4 @@ export default class UserStore { }); } }); - - async hasRole(role: ethers.utils.BytesLike, address: string): Promise { - return this.store.sdk.governance.timelockController.hasRole(role, address); - } - - async hasProposalRole(): Promise { - if (this.accountDetails?.address) { - const proposeRole = await this.store.sdk.governance.timelockController.PROPOSER_ROLE(); - return this.hasRole(proposeRole, this.accountDetails.address); - } else { - return false; - } - } - - async hasVetoRole(): Promise { - if (this.accountDetails?.address) { - const role = await this.store.sdk.governance.timelockController.VETO_ROLE(); - return this.hasRole(role, this.accountDetails.address); - } else { - return false; - } - } - - async hasUnVetoRole(): Promise { - if (this.accountDetails?.address) { - const role = await this.store.sdk.governance.timelockController.SUPREMECOURT_ROLE(); - return this.hasRole(role, this.accountDetails.address); - } else { - return false; - } - } } diff --git a/src/tests/__snapshots__/Navbar.test.tsx.snap b/src/tests/__snapshots__/Navbar.test.tsx.snap index 07825c075..1ff786f74 100644 --- a/src/tests/__snapshots__/Navbar.test.tsx.snap +++ b/src/tests/__snapshots__/Navbar.test.tsx.snap @@ -151,7 +151,7 @@ exports[`Navbar Renders correctly 1`] = ` class="MuiTypography-root-125 makeStyles-helperText-124" > -

@@ -654,12 +638,12 @@ exports[`Navbar Renders tablet version correctly 1`] = ` class="MuiGrid-root-17 MuiGrid-container-18 MuiGrid-item-19 MuiGrid-align-items-xs-center-26 MuiGrid-grid-xs-true-51" > Badger Logo
@@ -714,17 +698,17 @@ exports[`Navbar Renders tablet version correctly 1`] = ` class="MuiGrid-root-17 MuiGrid-item-19" >
@@ -732,7 +716,7 @@ exports[`Navbar Renders tablet version correctly 1`] = `


diff --git a/yarn.lock b/yarn.lock index 5ded05513..66e18e4e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13563,6 +13563,11 @@ lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.16, lodash@^4.17 resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== +lokijs@^1.5.12: + version "1.5.12" + resolved "https://registry.yarnpkg.com/lokijs/-/lokijs-1.5.12.tgz#cb55b37009bdf09ee7952a6adddd555b893653a0" + integrity sha512-Q5ALD6JiS6xAUWCwX3taQmgwxyveCtIIuL08+ml0nHwT3k0S/GIFJN+Hd38b1qYIMaE5X++iqsqWVksz7SYW+Q== + loose-envify@^1.1.0, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"