Skip to content

Commit

Permalink
fix(governance): modal bugs, redable styles, show common names for co…
Browse files Browse the repository at this point in the history
…ntracts (#1164)

* fix modal bugs, reable styles, show common names for contracts

* use theme for blue
  • Loading branch information
ianlapham authored Oct 12, 2020
1 parent b650b17 commit 9c47327
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export const UNI: { [chainId in ChainId]: Token } = {
[ChainId.KOVAN]: new Token(ChainId.KOVAN, UNI_ADDRESS, 18, 'UNI', 'Uniswap')
}

export const COMMON_CONTRACT_NAMES: { [address: string]: string } = {
'0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984': 'UNI',

This comment has been minimized.

Copy link
@NoahZinsmeister

NoahZinsmeister Oct 12, 2020

Contributor

can we use the hardcoded constants for these addresses instead?

'0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F': 'Governance Alpha',
'0x1a9C8182C09F50C8318d769245beA52c32BE35BC': 'Timelock'

This comment has been minimized.

Copy link
@NoahZinsmeister

NoahZinsmeister Oct 12, 2020

Contributor

i think the values here should read Governance and Timelock

}

// TODO: specify merkle distributor for mainnet
export const MERKLE_DISTRIBUTOR_ADDRESS: { [chainId in ChainId]?: string } = {
[ChainId.MAINNET]: '0x090D4613473dEE047c3f2706764f49E0821D256e'
Expand Down
34 changes: 20 additions & 14 deletions src/pages/Vote/VotePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import VoteModal from '../../components/vote/VoteModal'
import { TokenAmount, JSBI } from '@uniswap/sdk'
import { useTokenBalance } from '../../state/wallet/hooks'
import { useActiveWeb3React } from '../../hooks'
import { UNI, ZERO_ADDRESS, PROPOSAL_LENGTH_IN_DAYS } from '../../constants'
import { UNI, ZERO_ADDRESS, PROPOSAL_LENGTH_IN_DAYS, COMMON_CONTRACT_NAMES } from '../../constants'
import { isAddress, getEtherscanLink } from '../../utils'
import { ApplicationModal } from '../../state/application/actions'
import { useModalOpen, useToggleDelegateModal, useToggleVoteModal } from '../../state/application/hooks'
import DelegateModal from '../../components/vote/DelegateModal'

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

// modal for casting votes
const [showModal, setShowModal] = useState<boolean>(false)
const showVoteModal = useModalOpen(ApplicationModal.VOTE)
const toggleVoteModal = useToggleVoteModal()

// toggle for showing delegation modal
const showDelegateModal = useModalOpen(ApplicationModal.DELEGATE)
const toggelDelegateModal = useToggleDelegateModal()

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

// show links in propsoal details if content is an address
// if content is contract with common name, replace address with common name
const linkIfAddress = (content: string) => {
if (isAddress(content) && chainId) {
return <ExternalLink href={getEtherscanLink(chainId, content, 'address')}>{content}</ExternalLink>
const commonName = COMMON_CONTRACT_NAMES[content] ?? content
return <ExternalLink href={getEtherscanLink(chainId, content, 'address')}>{commonName}</ExternalLink>
}
return <span>{content}</span>
}

return (
<PageWrapper gap="lg" justify="center">
<VoteModal
isOpen={showModal}
onDismiss={() => setShowModal(false)}
proposalId={proposalData?.id}
support={support}
/>
<VoteModal isOpen={showVoteModal} onDismiss={toggleVoteModal} proposalId={proposalData?.id} support={support} />
<DelegateModal isOpen={showDelegateModal} onDismiss={toggelDelegateModal} title="Unlock Votes" />
<ProposalInfo gap="lg" justify="start">
<RowBetween style={{ width: '100%' }}>
<ArrowWrapper to="/vote">
Expand All @@ -162,15 +168,15 @@ export default function VotePage({
{endDate && endDate < now
? 'Voting ended ' + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL))
: proposalData
? 'Voting ends approximately' + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL))
? 'Voting ends approximately ' + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL))
: ''}
</TYPE.main>
{showUnlockVoting && endDate && endDate > now && (
<ButtonPrimary
style={{ width: 'fit-content' }}
padding="8px"
borderRadius="8px"
onClick={() => setShowModal(true)}
onClick={toggelDelegateModal}
>
Unlock Voting
</ButtonPrimary>
Expand All @@ -188,7 +194,7 @@ export default function VotePage({
borderRadius="8px"
onClick={() => {
setSupport(true)
setShowModal(true)
toggleVoteModal()
}}
>
Vote For
Expand All @@ -198,7 +204,7 @@ export default function VotePage({
borderRadius="8px"
onClick={() => {
setSupport(false)
setShowModal(true)
toggleVoteModal()
}}
>
Vote Against
Expand Down Expand Up @@ -260,7 +266,7 @@ export default function VotePage({
})}
</AutoColumn>
<AutoColumn gap="md">
<TYPE.mediumHeader fontWeight={600}>Overview</TYPE.mediumHeader>
<TYPE.mediumHeader fontWeight={600}>Description</TYPE.mediumHeader>
<MarkDownWrapper>
<ReactMarkdown source={proposalData?.description} />
</MarkDownWrapper>
Expand Down
17 changes: 11 additions & 6 deletions src/pages/Vote/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React from 'react'
import { AutoColumn } from '../../components/Column'
import styled from 'styled-components'
import { TYPE, ExternalLink } from '../../theme'
Expand All @@ -19,6 +19,8 @@ import { JSBI, TokenAmount, ChainId } from '@uniswap/sdk'
import { shortenAddress, getEtherscanLink } from '../../utils'
import Loader from '../../components/Loader'
import FormattedCurrencyAmount from '../../components/FormattedCurrencyAmount'
import { useModalOpen, useToggleDelegateModal } from '../../state/application/hooks'
import { ApplicationModal } from '../../state/application/actions'

const PageWrapper = styled(AutoColumn)``

Expand Down Expand Up @@ -102,7 +104,10 @@ const EmptyProposals = styled.div`

export default function Vote() {
const { account, chainId } = useActiveWeb3React()
const [showModal, setShowModal] = useState<boolean>(false)

// toggle for showing delegation modal
const showDelegateModal = useModalOpen(ApplicationModal.DELEGATE)
const toggelDelegateModal = useToggleDelegateModal()

// get data to list all proposals
const allProposals: ProposalData[] = useAllProposalData()
Expand All @@ -120,8 +125,8 @@ export default function Vote() {
return (
<PageWrapper gap="lg" justify="center">
<DelegateModal
isOpen={showModal}
onDismiss={() => setShowModal(false)}
isOpen={showDelegateModal}
onDismiss={toggelDelegateModal}
title={showUnlockVoting ? 'Unlock Votes' : 'Update Delegation'}
/>
<TopSection gap="md">
Expand Down Expand Up @@ -161,7 +166,7 @@ export default function Vote() {
style={{ width: 'fit-content' }}
padding="8px"
borderRadius="8px"
onClick={() => setShowModal(true)}
onClick={toggelDelegateModal}
>
Unlock Voting
</ButtonPrimary>
Expand Down Expand Up @@ -195,7 +200,7 @@ export default function Vote() {
>
{userDelegatee === account ? 'Self' : shortenAddress(userDelegatee)}
</StyledExternalLink>
<TextButton onClick={() => setShowModal(true)} style={{ marginLeft: '4px' }}>
<TextButton onClick={toggelDelegateModal} style={{ marginLeft: '4px' }}>
(edit)
</TextButton>
</AddressButton>
Expand Down
4 changes: 3 additions & 1 deletion src/state/application/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export enum ApplicationModal {
SELF_CLAIM,
ADDRESS_CLAIM,
CLAIM_POPUP,
MENU
MENU,
DELEGATE,
VOTE
}

export const updateBlockNumber = createAction<{ chainId: number; blockNumber: number }>('application/updateBlockNumber')
Expand Down
8 changes: 8 additions & 0 deletions src/state/application/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export function useToggleSelfClaimModal(): () => void {
return useToggleModal(ApplicationModal.SELF_CLAIM)
}

export function useToggleDelegateModal(): () => void {
return useToggleModal(ApplicationModal.DELEGATE)
}

export function useToggleVoteModal(): () => void {
return useToggleModal(ApplicationModal.VOTE)
}

// returns a function that allows adding a popup
export function useAddPopup(): (content: PopupContent, key?: string) => void {
const dispatch = useDispatch()
Expand Down
4 changes: 4 additions & 0 deletions src/theme/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ body {
padding: 0;
}
a {
color: ${colors(false).blue1};
}
* {
box-sizing: border-box;
}
Expand Down

1 comment on commit 9c47327

@vercel
Copy link

@vercel vercel bot commented on 9c47327 Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.