-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display the votes on the network proposal details page
- Loading branch information
Showing
13 changed files
with
696 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Display the votes on the network proposal details page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { FC } from 'react' | ||
import { TFunction } from 'i18next' | ||
import { useTranslation } from 'react-i18next' | ||
import Box from '@mui/material/Box' | ||
import CheckCircleIcon from '@mui/icons-material/CheckCircle' | ||
import CancelIcon from '@mui/icons-material/Cancel' | ||
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle' | ||
import { styled } from '@mui/material/styles' | ||
import { COLORS } from '../../../styles/theme/colors' | ||
import { ProposalVoteValue } from '../../../types/vote' | ||
|
||
const StyledBox = styled(Box)(({ theme }) => ({ | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
gap: 3, | ||
flex: 1, | ||
borderRadius: 10, | ||
padding: theme.spacing(2, 2, 2, '10px'), | ||
fontSize: '12px', | ||
minWidth: '85px', | ||
})) | ||
|
||
const StyledIcon = styled(Box)({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
fontSize: '18px', | ||
}) | ||
|
||
const getStatuses = (t: TFunction) => ({ | ||
[ProposalVoteValue.abstain]: { | ||
backgroundColor: COLORS.lightSilver, | ||
icon: RemoveCircleIcon, | ||
iconColor: COLORS.grayMedium, | ||
label: t('networkProposal.vote.abstain'), | ||
textColor: COLORS.grayExtraDark, | ||
}, | ||
[ProposalVoteValue.yes]: { | ||
backgroundColor: COLORS.honeydew, | ||
icon: CheckCircleIcon, | ||
iconColor: COLORS.eucalyptus, | ||
label: t('networkProposal.vote.yes'), | ||
textColor: COLORS.grayExtraDark, | ||
}, | ||
[ProposalVoteValue.no]: { | ||
backgroundColor: COLORS.linen, | ||
icon: CancelIcon, | ||
iconColor: COLORS.errorIndicatorBackground, | ||
label: t('networkProposal.vote.no'), | ||
textColor: COLORS.grayExtraDark, | ||
}, | ||
}) | ||
|
||
type ProposalVoteIndicatorProps = { | ||
vote: ProposalVoteValue | ||
} | ||
|
||
export const ProposalVoteIndicator: FC<ProposalVoteIndicatorProps> = ({ vote }) => { | ||
const { t } = useTranslation() | ||
|
||
if (!ProposalVoteValue[vote]) { | ||
return null | ||
} | ||
|
||
const statusConfig = getStatuses(t)[vote] | ||
const IconComponent = statusConfig.icon | ||
|
||
return ( | ||
<StyledBox sx={{ backgroundColor: statusConfig.backgroundColor, color: statusConfig.textColor }}> | ||
{statusConfig.label} | ||
<StyledIcon sx={{ color: statusConfig.iconColor }}> | ||
<IconComponent color="inherit" fontSize="inherit" /> | ||
</StyledIcon> | ||
</StyledBox> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { FC } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import Box from '@mui/material/Box' | ||
import Chip from '@mui/material/Chip' | ||
import Typography from '@mui/material/Typography' | ||
import { COLORS } from '../../../styles/theme/colors' | ||
import { ProposalVoteValue, VoteType } from '../../../types/vote' | ||
|
||
type VoteTypePillsProps = { | ||
handleChange: (voteType: VoteType) => void | ||
value?: VoteType | ||
} | ||
|
||
export const VoteTypePills: FC<VoteTypePillsProps> = ({ handleChange, value }) => { | ||
const { t } = useTranslation() | ||
const options: { label: string; value: VoteType }[] = [ | ||
{ | ||
label: t('networkProposal.vote.all'), | ||
value: 'any', | ||
}, | ||
{ | ||
label: t('networkProposal.vote.yes'), | ||
value: ProposalVoteValue.yes, | ||
}, | ||
{ | ||
label: t('networkProposal.vote.abstain'), | ||
value: ProposalVoteValue.abstain, | ||
}, | ||
{ | ||
label: t('networkProposal.vote.no'), | ||
value: ProposalVoteValue.no, | ||
}, | ||
] | ||
|
||
return ( | ||
<> | ||
{options.map(option => { | ||
const selected = option.value === value | ||
return ( | ||
<Chip | ||
key={option.value} | ||
onClick={() => handleChange(option.value)} | ||
clickable | ||
color="secondary" | ||
label={ | ||
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}> | ||
<Typography component="span" sx={{ fontSize: 16 }}> | ||
{option.label} | ||
</Typography> | ||
</Box> | ||
} | ||
sx={{ | ||
mr: 3, | ||
borderColor: COLORS.brandMedium, | ||
backgroundColor: selected ? COLORS.brandMedium : COLORS.brandMedium15, | ||
color: selected ? COLORS.white : COLORS.grayExtraDark, | ||
}} | ||
variant={selected ? 'outlined-selected' : 'outlined'} | ||
/> | ||
) | ||
})} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { FC } from 'react' | ||
import TextField from '@mui/material/TextField' | ||
import SearchIcon from '@mui/icons-material/Search' | ||
import HighlightOffIcon from '@mui/icons-material/HighlightOff' | ||
import InputAdornment from '@mui/material/InputAdornment' | ||
import { COLORS } from '../../../styles/theme/colors' | ||
import { SearchVariant } from '../Search' | ||
import { useTranslation } from 'react-i18next' | ||
import IconButton from '@mui/material/IconButton' | ||
|
||
export interface SearchBarProps { | ||
variant: SearchVariant | ||
value: string | ||
onChange: (value: string) => void | ||
} | ||
|
||
export const VoterSearchBar: FC<SearchBarProps> = ({ variant, value, onChange }) => { | ||
const { t } = useTranslation() | ||
const startAdornment = variant === 'button' && ( | ||
<InputAdornment | ||
position="start" | ||
disablePointerEvents // Pass clicks through, so it focuses the input | ||
> | ||
<SearchIcon sx={{ color: COLORS.grayDark }} /> | ||
</InputAdornment> | ||
) | ||
|
||
const onClearValue = () => onChange('') | ||
|
||
const endAdornment = ( | ||
<InputAdornment position="end"> | ||
<> | ||
{value && ( | ||
<IconButton color="inherit" onClick={onClearValue}> | ||
<HighlightOffIcon /> | ||
</IconButton> | ||
)} | ||
</> | ||
</InputAdornment> | ||
) | ||
|
||
return ( | ||
<> | ||
<TextField | ||
value={value} | ||
onChange={e => onChange(e.target.value)} | ||
InputProps={{ | ||
inputProps: { | ||
sx: { | ||
p: 0, | ||
marginRight: 2, | ||
}, | ||
}, | ||
startAdornment, | ||
endAdornment, | ||
}} | ||
placeholder={t('networkProposal.searchForVoters')} | ||
// FormHelperTextProps={{ | ||
// component: 'div', // replace p with div tag | ||
// sx: { | ||
// marginTop: 0, | ||
// marginBottom: 0, | ||
// marginLeft: variant === 'button' ? '48px' : '17px', | ||
// marginRight: variant === 'button' ? '48px' : '17px', | ||
// }, | ||
// }} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { FC } from 'react' | ||
import { Network } from '../../../types/network' | ||
import { Layer, Validator } from '../../../oasis-nexus/api' | ||
import { SearchScope } from '../../../types/searchScope' | ||
import { ValidatorLink } from './ValidatorLink' | ||
|
||
export const DeferredValidatorLink: FC<{ | ||
network: Network | ||
address: string | ||
validator: Validator | undefined | ||
isError: boolean | ||
highlightedPart?: string | undefined | ||
}> = ({ network, address, validator, isError, highlightedPart }) => { | ||
const scope: SearchScope = { network, layer: Layer.consensus } | ||
|
||
if (isError) { | ||
console.log('Warning: failed to look up validators!') | ||
} | ||
|
||
return ( | ||
<ValidatorLink | ||
address={address} | ||
network={scope.network} | ||
name={validator?.media?.name} | ||
highlightedPart={highlightedPart} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.