Skip to content

Commit 9c47327

Browse files
authored
fix(governance): modal bugs, redable styles, show common names for contracts (#1164)
* fix modal bugs, reable styles, show common names for contracts * use theme for blue
1 parent b650b17 commit 9c47327

6 files changed

Lines changed: 52 additions & 21 deletions

File tree

src/constants/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export const UNI: { [chainId in ChainId]: Token } = {
3434
[ChainId.KOVAN]: new Token(ChainId.KOVAN, UNI_ADDRESS, 18, 'UNI', 'Uniswap')
3535
}
3636

37+
export const COMMON_CONTRACT_NAMES: { [address: string]: string } = {
38+
'0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984': 'UNI',
39+
'0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F': 'Governance Alpha',
40+
'0x1a9C8182C09F50C8318d769245beA52c32BE35BC': 'Timelock'
41+
}
42+
3743
// TODO: specify merkle distributor for mainnet
3844
export const MERKLE_DISTRIBUTOR_ADDRESS: { [chainId in ChainId]?: string } = {
3945
[ChainId.MAINNET]: '0x090D4613473dEE047c3f2706764f49E0821D256e'

src/pages/Vote/VotePage.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ import VoteModal from '../../components/vote/VoteModal'
1717
import { TokenAmount, JSBI } from '@uniswap/sdk'
1818
import { useTokenBalance } from '../../state/wallet/hooks'
1919
import { useActiveWeb3React } from '../../hooks'
20-
import { UNI, ZERO_ADDRESS, PROPOSAL_LENGTH_IN_DAYS } from '../../constants'
20+
import { UNI, ZERO_ADDRESS, PROPOSAL_LENGTH_IN_DAYS, COMMON_CONTRACT_NAMES } from '../../constants'
2121
import { isAddress, getEtherscanLink } from '../../utils'
22+
import { ApplicationModal } from '../../state/application/actions'
23+
import { useModalOpen, useToggleDelegateModal, useToggleVoteModal } from '../../state/application/hooks'
24+
import DelegateModal from '../../components/vote/DelegateModal'
2225

2326
const PageWrapper = styled(AutoColumn)`
2427
width: 100%;
@@ -108,7 +111,12 @@ export default function VotePage({
108111
const [support, setSupport] = useState<boolean>(true)
109112

110113
// modal for casting votes
111-
const [showModal, setShowModal] = useState<boolean>(false)
114+
const showVoteModal = useModalOpen(ApplicationModal.VOTE)
115+
const toggleVoteModal = useToggleVoteModal()
116+
117+
// toggle for showing delegation modal
118+
const showDelegateModal = useModalOpen(ApplicationModal.DELEGATE)
119+
const toggelDelegateModal = useToggleDelegateModal()
112120

113121
// get and format date from data
114122
const startTimestamp: number | undefined = useTimestampFromBlock(proposalData?.startBlock)
@@ -133,21 +141,19 @@ export default function VotePage({
133141
)
134142

135143
// show links in propsoal details if content is an address
144+
// if content is contract with common name, replace address with common name
136145
const linkIfAddress = (content: string) => {
137146
if (isAddress(content) && chainId) {
138-
return <ExternalLink href={getEtherscanLink(chainId, content, 'address')}>{content}</ExternalLink>
147+
const commonName = COMMON_CONTRACT_NAMES[content] ?? content
148+
return <ExternalLink href={getEtherscanLink(chainId, content, 'address')}>{commonName}</ExternalLink>
139149
}
140150
return <span>{content}</span>
141151
}
142152

143153
return (
144154
<PageWrapper gap="lg" justify="center">
145-
<VoteModal
146-
isOpen={showModal}
147-
onDismiss={() => setShowModal(false)}
148-
proposalId={proposalData?.id}
149-
support={support}
150-
/>
155+
<VoteModal isOpen={showVoteModal} onDismiss={toggleVoteModal} proposalId={proposalData?.id} support={support} />
156+
<DelegateModal isOpen={showDelegateModal} onDismiss={toggelDelegateModal} title="Unlock Votes" />
151157
<ProposalInfo gap="lg" justify="start">
152158
<RowBetween style={{ width: '100%' }}>
153159
<ArrowWrapper to="/vote">
@@ -162,15 +168,15 @@ export default function VotePage({
162168
{endDate && endDate < now
163169
? 'Voting ended ' + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL))
164170
: proposalData
165-
? 'Voting ends approximately' + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL))
171+
? 'Voting ends approximately ' + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL))
166172
: ''}
167173
</TYPE.main>
168174
{showUnlockVoting && endDate && endDate > now && (
169175
<ButtonPrimary
170176
style={{ width: 'fit-content' }}
171177
padding="8px"
172178
borderRadius="8px"
173-
onClick={() => setShowModal(true)}
179+
onClick={toggelDelegateModal}
174180
>
175181
Unlock Voting
176182
</ButtonPrimary>
@@ -188,7 +194,7 @@ export default function VotePage({
188194
borderRadius="8px"
189195
onClick={() => {
190196
setSupport(true)
191-
setShowModal(true)
197+
toggleVoteModal()
192198
}}
193199
>
194200
Vote For
@@ -198,7 +204,7 @@ export default function VotePage({
198204
borderRadius="8px"
199205
onClick={() => {
200206
setSupport(false)
201-
setShowModal(true)
207+
toggleVoteModal()
202208
}}
203209
>
204210
Vote Against
@@ -260,7 +266,7 @@ export default function VotePage({
260266
})}
261267
</AutoColumn>
262268
<AutoColumn gap="md">
263-
<TYPE.mediumHeader fontWeight={600}>Overview</TYPE.mediumHeader>
269+
<TYPE.mediumHeader fontWeight={600}>Description</TYPE.mediumHeader>
264270
<MarkDownWrapper>
265271
<ReactMarkdown source={proposalData?.description} />
266272
</MarkDownWrapper>

src/pages/Vote/index.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React from 'react'
22
import { AutoColumn } from '../../components/Column'
33
import styled from 'styled-components'
44
import { TYPE, ExternalLink } from '../../theme'
@@ -19,6 +19,8 @@ import { JSBI, TokenAmount, ChainId } from '@uniswap/sdk'
1919
import { shortenAddress, getEtherscanLink } from '../../utils'
2020
import Loader from '../../components/Loader'
2121
import FormattedCurrencyAmount from '../../components/FormattedCurrencyAmount'
22+
import { useModalOpen, useToggleDelegateModal } from '../../state/application/hooks'
23+
import { ApplicationModal } from '../../state/application/actions'
2224

2325
const PageWrapper = styled(AutoColumn)``
2426

@@ -102,7 +104,10 @@ const EmptyProposals = styled.div`
102104

103105
export default function Vote() {
104106
const { account, chainId } = useActiveWeb3React()
105-
const [showModal, setShowModal] = useState<boolean>(false)
107+
108+
// toggle for showing delegation modal
109+
const showDelegateModal = useModalOpen(ApplicationModal.DELEGATE)
110+
const toggelDelegateModal = useToggleDelegateModal()
106111

107112
// get data to list all proposals
108113
const allProposals: ProposalData[] = useAllProposalData()
@@ -120,8 +125,8 @@ export default function Vote() {
120125
return (
121126
<PageWrapper gap="lg" justify="center">
122127
<DelegateModal
123-
isOpen={showModal}
124-
onDismiss={() => setShowModal(false)}
128+
isOpen={showDelegateModal}
129+
onDismiss={toggelDelegateModal}
125130
title={showUnlockVoting ? 'Unlock Votes' : 'Update Delegation'}
126131
/>
127132
<TopSection gap="md">
@@ -161,7 +166,7 @@ export default function Vote() {
161166
style={{ width: 'fit-content' }}
162167
padding="8px"
163168
borderRadius="8px"
164-
onClick={() => setShowModal(true)}
169+
onClick={toggelDelegateModal}
165170
>
166171
Unlock Voting
167172
</ButtonPrimary>
@@ -195,7 +200,7 @@ export default function Vote() {
195200
>
196201
{userDelegatee === account ? 'Self' : shortenAddress(userDelegatee)}
197202
</StyledExternalLink>
198-
<TextButton onClick={() => setShowModal(true)} style={{ marginLeft: '4px' }}>
203+
<TextButton onClick={toggelDelegateModal} style={{ marginLeft: '4px' }}>
199204
(edit)
200205
</TextButton>
201206
</AddressButton>

src/state/application/actions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export enum ApplicationModal {
2424
SELF_CLAIM,
2525
ADDRESS_CLAIM,
2626
CLAIM_POPUP,
27-
MENU
27+
MENU,
28+
DELEGATE,
29+
VOTE
2830
}
2931

3032
export const updateBlockNumber = createAction<{ chainId: number; blockNumber: number }>('application/updateBlockNumber')

src/state/application/hooks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ export function useToggleSelfClaimModal(): () => void {
5151
return useToggleModal(ApplicationModal.SELF_CLAIM)
5252
}
5353

54+
export function useToggleDelegateModal(): () => void {
55+
return useToggleModal(ApplicationModal.DELEGATE)
56+
}
57+
58+
export function useToggleVoteModal(): () => void {
59+
return useToggleModal(ApplicationModal.VOTE)
60+
}
61+
5462
// returns a function that allows adding a popup
5563
export function useAddPopup(): (content: PopupContent, key?: string) => void {
5664
const dispatch = useDispatch()

src/theme/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ body {
192192
padding: 0;
193193
}
194194
195+
a {
196+
color: ${colors(false).blue1};
197+
}
198+
195199
* {
196200
box-sizing: border-box;
197201
}

0 commit comments

Comments
 (0)