-
Notifications
You must be signed in to change notification settings - Fork 78
Add vote proposal card UI #561
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3337ccb
Add Vote Proposal card layout
baomastr cc65657
Add props, mappings and translations
baomastr 5490e98
Add progressbar story for custom color
baomastr 244bf65
Add countdown
baomastr 49e1b7d
Add truncate for title
baomastr 4c16c39
Add progress calculations
baomastr 68281e7
Chore: fixes
baomastr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
import * as React from 'react'; | ||
import { SVGProps } from 'react'; | ||
|
||
const SvgDots = (props: SVGProps<SVGSVGElement>) => ( | ||
<svg | ||
width="21" | ||
height="4" | ||
viewBox="0 0 21 4" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<circle cx="10.5" cy="2" r="2" fill="currentColor" /> | ||
<circle cx="18.5" cy="2" r="2" fill="currentColor" /> | ||
<circle cx="2.5" cy="2" r="2" fill="currentColor" /> | ||
</svg> | ||
); | ||
|
||
export default SvgDots; |
This file contains hidden or 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,11 @@ | ||
import * as React from 'react'; | ||
import { SVGProps } from 'react'; | ||
|
||
const SvgExclamation = (props: SVGProps<SVGSVGElement>) => ( | ||
<svg viewBox="0 0 3 18" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}> | ||
<circle cx="1.5" cy="16.5" r="1.5" fill="currentColor" /> | ||
<rect x="0.5" width="2" height="12" rx="1" fill="currentColor" /> | ||
</svg> | ||
); | ||
|
||
export default SvgExclamation; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
117 changes: 117 additions & 0 deletions
117
src/components/v2/VoteProposalUi/ActiveVotingProgress/index.tsx
This file contains hidden or 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,117 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import React, { useMemo } from 'react'; | ||
import { BigNumber } from 'bignumber.js'; | ||
import Typography from '@mui/material/Typography'; | ||
import { useTranslation } from 'translation'; | ||
import { PALETTE } from 'theme/MuiThemeProvider/muiTheme'; | ||
import { TokenId } from 'types'; | ||
import { convertWeiToCoins } from 'utilities/common'; | ||
import { ProgressBar } from '../../ProgressBar'; | ||
import { useStyles } from '../styles'; | ||
|
||
interface IActiveVotingProgressProps { | ||
tokenId: TokenId; | ||
votedForWei?: BigNumber; | ||
votedAgainstWei?: BigNumber; | ||
abstainedWei?: BigNumber; | ||
votedTotalWei?: BigNumber; | ||
} | ||
|
||
const getValueString = (tokenId: TokenId, valueWei?: BigNumber) => { | ||
// if !valueWei the progress row will not be rendered | ||
if (!valueWei) return undefined; | ||
return convertWeiToCoins({ | ||
valueWei, | ||
tokenId, | ||
returnInReadableFormat: true, | ||
}); | ||
}; | ||
|
||
const getValueNumber = (tokenId: TokenId, valueWei?: BigNumber) => { | ||
if (!valueWei) return 0; | ||
return +convertWeiToCoins({ | ||
valueWei, | ||
tokenId, | ||
returnInReadableFormat: false, | ||
}).toFormat(); | ||
}; | ||
|
||
export const ActiveVotingProgress: React.FC<IActiveVotingProgressProps> = ({ | ||
tokenId, | ||
votedForWei, | ||
votedAgainstWei, | ||
abstainedWei, | ||
votedTotalWei, | ||
}) => { | ||
const styles = useStyles(); | ||
const { t } = useTranslation(); | ||
|
||
const votedTotalCoins = getValueNumber(tokenId, votedTotalWei); | ||
|
||
const defaultProgressbarProps = { | ||
step: 0.0001, | ||
min: 0, | ||
|
||
// || 1 is used for rendering an empty progressbar for case when votedTotalCoins is 0 | ||
max: votedTotalCoins || 1, | ||
}; | ||
|
||
const activeProposalVotingData = useMemo( | ||
() => [ | ||
{ | ||
id: 'for', | ||
label: t('voteProposalUi.statusCard.for'), | ||
value: getValueString(tokenId, votedForWei), | ||
progressBarProps: { | ||
ariaLabel: t('voteProposalUi.statusCard.ariaLabelFor'), | ||
value: getValueNumber(tokenId, votedForWei), | ||
}, | ||
}, | ||
{ | ||
id: 'against', | ||
label: t('voteProposalUi.statusCard.against'), | ||
value: getValueString(tokenId, votedAgainstWei), | ||
progressBarProps: { | ||
successColor: PALETTE.interactive.error50, | ||
ariaLabel: t('voteProposalUi.statusCard.ariaLabelAgainst'), | ||
value: getValueNumber(tokenId, votedAgainstWei), | ||
}, | ||
}, | ||
{ | ||
id: 'abstain', | ||
label: t('voteProposalUi.statusCard.abstain'), | ||
value: getValueString(tokenId, abstainedWei), | ||
progressBarProps: { | ||
successColor: PALETTE.text.secondary, | ||
ariaLabel: t('voteProposalUi.statusCard.ariaLabelAbstain'), | ||
value: getValueNumber(tokenId, abstainedWei), | ||
}, | ||
}, | ||
], | ||
[votedForWei, votedAgainstWei, abstainedWei], | ||
); | ||
|
||
return ( | ||
<div css={styles.votesWrapper}> | ||
{activeProposalVotingData.map(({ id, label, value, progressBarProps }) => { | ||
if (!value) { | ||
return null; | ||
} | ||
return ( | ||
<React.Fragment key={id}> | ||
<div css={styles.voteRow}> | ||
<Typography variant="small2" color="textPrimary"> | ||
{label} | ||
</Typography> | ||
|
||
<Typography variant="small2" color="textPrimary"> | ||
{value} | ||
</Typography> | ||
</div> | ||
<ProgressBar {...defaultProgressbarProps} {...progressBarProps} /> | ||
</React.Fragment> | ||
coreyar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
})} | ||
</div> | ||
); | ||
}; |
This file contains hidden or 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,60 @@ | ||
import React from 'react'; | ||
import { BigNumber } from 'bignumber.js'; | ||
import { withThemeProvider, withCenterStory } from 'stories/decorators'; | ||
import { VoteProposalUi } from '.'; | ||
|
||
export default { | ||
title: 'Components/VoteProposalUi', | ||
decorators: [withThemeProvider, withCenterStory({ width: 750 })], | ||
parameters: { | ||
backgrounds: { | ||
default: 'Primary', | ||
}, | ||
}, | ||
}; | ||
|
||
export const Active = () => ( | ||
<VoteProposalUi | ||
proposalNumber={58} | ||
proposalText="Buy back and burn and Tokenomic contribution finished soon" | ||
proposalStatus="active" | ||
votedForWei={new BigNumber('500000000000000000')} | ||
votedAgainstWei={new BigNumber('2000000000000000000')} | ||
abstainedWei={new BigNumber('0')} | ||
userVoteStatus="votedFor" | ||
cancelDate={new Date(Date.now() + 3650000)} | ||
tokenId="xvs" | ||
/> | ||
); | ||
export const Queued = () => ( | ||
<VoteProposalUi | ||
proposalNumber={58} | ||
proposalText="Buy back and burn and Tokenomic contribution finished soon with very very very very very very very very very very very very very very very very long text example" | ||
proposalStatus="queued" | ||
cancelDate={new Date(Date.now() + 3650000)} | ||
/> | ||
); | ||
export const ReadyToExecute = () => ( | ||
<VoteProposalUi | ||
proposalNumber={58} | ||
proposalText="Buy back and burn and Tokenomic contribution finished soon" | ||
proposalStatus="readyToExecute" | ||
cancelDate={new Date(Date.now() + 3650000)} | ||
/> | ||
); | ||
export const Executed = () => ( | ||
<VoteProposalUi | ||
proposalNumber={58} | ||
proposalText="Buy back and burn and Tokenomic contribution finished soon" | ||
proposalStatus="executed" | ||
cancelDate={new Date(Date.now() + 3650000)} | ||
/> | ||
); | ||
export const Cancelled = () => ( | ||
<VoteProposalUi | ||
proposalNumber={58} | ||
proposalText="Buy back and burn and Tokenomic contribution finished soon" | ||
proposalStatus="cancelled" | ||
cancelDate={new Date(Date.now())} | ||
/> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.