Skip to content
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

Breaking changes while updating to wcjs. Just a temp commit #397

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Features
- Switch hash stats to pull from CMC #393
- Display multiple blocks per tx hash, navigate to tx by hash and block #395
- Update governance to use new endpoints #390

## 3.2.0

Expand Down
926 changes: 812 additions & 114 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sideEffects": false,
"dependencies": {
"@provenanceio/wallet-lib": "2.4.3",
"@provenanceio/walletconnect-js": "1.2.6",
"@reduxjs/toolkit": "1.8.1",
"axios": "0.21.2",
"bech32": "2.0.0",
Expand Down
244 changes: 121 additions & 123 deletions src/Pages/Proposal/Components/ManageVotingModal/ManageVotingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import React, { useEffect, useState } from 'react';
import { Formik, FormikProps } from "formik";
import { Formik, FormikProps } from 'formik';
import styled, { useTheme } from 'styled-components';
import { Button, Modal, Forms } from 'Components';
import { isEmpty, votingData as data, votingValidations as validations } from 'utils';
import { VotingChart, Countdown } from "./Components";
import { VotingChart, Countdown } from './Components';
import { useGovernance, useAccounts } from '../../../../redux/hooks';

const ModalContainer = styled.div<{ isOpen: boolean }>`
display: ${({ isOpen }) => (isOpen ? 'inherit' : 'none')};
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
background: rgba(0, 0, 0, 0.5);
`;

const Title = styled.div`
text-align: center;
font-size: 2rem;
font-weight: ${({ theme }) => theme.FONT_WEIGHT_BOLD};
font-weight: ${({ theme }) => theme.FONT_WEIGHT_BOLD};
margin-bottom: 20px;
`;
const Description = styled.div`
Expand Down Expand Up @@ -47,8 +58,7 @@ const VoteWarning = styled.div`
display: flex;
margin: 1.6rem 0;
padding: 20px;
border: ${({ theme }) => theme.ORANGE_PRIMARY}
1px solid;
border: ${({ theme }) => theme.ORANGE_PRIMARY} 1px solid;
border-radius: 0.6rem;
color: ${({ theme }) => theme.ORANGE_PRIMARY};
flex-direction: column;
Expand All @@ -69,7 +79,7 @@ const CheckboxLabel = styled.label`
padding-top: 1.8rem;
`;
const Checkbox = styled.input`
margin-right:5px;
margin-right: 5px;
width: 2rem;
height: 2rem;
`;
Expand Down Expand Up @@ -131,9 +141,7 @@ const ManageVotingModal = ({
// Get content for voting message
const getContent = (values: VotingProps) => {
const emptyObj: VotingProps = {};
data(voteType).forEach((item) =>
emptyObj[item.field] = values[item.field]
);
data(voteType).forEach((item) => (emptyObj[item.field] = values[item.field]));
return emptyObj;
};

Expand All @@ -157,13 +165,10 @@ const ManageVotingModal = ({
const initialValues: { [key: string]: string | [{}] } = {};
data(type).map((item) => {
if (!item.subFields) {
initialValues[item.field] = item.initialValue || "";
}
else {
initialValues[item.field] = item.initialValue || '';
} else {
const subValues: { [key: string]: string | string[] } = {};
item.subFields.map(subItem =>
subValues[subItem.field] = item.initialValue || ""
);
item.subFields.map((subItem) => (subValues[subItem.field] = item.initialValue || ''));
initialValues[item.field] = [subValues];
}
return initialValues;
Expand All @@ -172,132 +177,125 @@ const ManageVotingModal = ({
};

const getVals = (formik: FormikProps<any>, colors: boolean) => {
const total = (
parseInt(formik.getFieldProps("yes").value || '0') +
parseInt(formik.getFieldProps("no").value || '0') +
parseInt(formik.getFieldProps("abstain").value || '0') +
parseInt(formik.getFieldProps("noWithVeto").value || '0'));

if (colors) {
return total !== 100 ? theme.NEGATIVE_CHANGE : theme.POSITIVE_CHANGE;
}
else {
return `${total}`
};
const total =
parseInt(formik.getFieldProps('yes').value || '0') +
parseInt(formik.getFieldProps('no').value || '0') +
parseInt(formik.getFieldProps('abstain').value || '0') +
parseInt(formik.getFieldProps('noWithVeto').value || '0');

if (colors) {
return total !== 100 ? theme.NEGATIVE_CHANGE : theme.POSITIVE_CHANGE;
} else {
return `${total}`;
}
};

const votingMessage = (
<>
Your vote has been submitted.
<br/>
<br/>
{!hasDelegations &&
<br />
<br />
{!hasDelegations && (
<>
Since you have no delegations, your vote will not count towards the vote totals,
but will be visible in the "Proposal Votes" table below.
<br/>
<br/>
Since you have no delegations, your vote will not count towards the vote totals, but will
be visible in the "Proposal Votes" table below.
<br />
<br />
</>
}
)}
Results may take up to 30 seconds to post to Explorer. Please be patient.
<br/>
<br/>
To continue, either wait for the timer to time out, at which point the page will
refresh. Otherwise, exit this popup and refresh the page to see voting results.
<br />
<br />
To continue, either wait for the timer to time out, at which point the page will refresh.
Otherwise, exit this popup and refresh the page to see voting results.
</>
);

return (
<Modal isOpen={isOpen} onClose={handleModalClose} largeModal={true}>
<Formik
enableReinitialize
initialValues={{
...getInitialValues(voteType),
}}
validationSchema={validations(voteType)}
onSubmit={(values: VotingProps, { resetForm }) => {
<ModalContainer isOpen={isOpen}>
<Modal isOpen={isOpen} onClose={handleModalClose} largeModal={true}>
<Formik
enableReinitialize
initialValues={{
...getInitialValues(voteType),
}}
validationSchema={validations(voteType)}
onSubmit={(values: VotingProps, { resetForm }) => {
// Submit proposal message
if (!voted) {
onVoting(proposalId, voterId, getContent(values), voteType === 'weighted');
}
// Clear the form
resetForm();
}}
>
{formik => (
<form onSubmit={formik.handleSubmit}>
{!hasDelegations && !voteAnyway && !voted &&
<ThisField>
<VoteWarning>
<WarningTitle>
<Label>Voting Notice</Label>
</WarningTitle>
You currently have no delegated hash in your account. While you
are still able to submit a vote, your vote will not be
counted towards the vote totals on this proposal. To have your
votes counted, you must either delegate hash or log in to an
account with delegated hash. Note that fees are assessed to any
votes that are submitted regardless of delegation status.
<WarningButton>
<Button onClick={() => setVoteAnyway(true)}>Vote Anyway</Button>
</WarningButton>
</VoteWarning>
</ThisField>
}
{(hasDelegations || voteAnyway) && !voted &&
<>
<Title>Vote on <b>{title}</b></Title>
<PairTitle>Proposal ID</PairTitle>
<Description>{proposalId}</Description>
<PairTitle>Description</PairTitle>
<Description>{description}</Description>
<PairTitle>Vote Tally</PairTitle>
{!isEmpty(tally) && <VotingChart voteData={tally} />}
<Forms config={data(voteType)} formik={formik} grid={voteType === 'weighted'}/>
{voteType === 'weighted' &&
<Total>
<Value>
Total (must be 100%):
</Value>
<Value
color={getVals(formik, true)}
>
{getVals(formik, false)}%
</Value>
</Total>
}
<MenuEnd>
<CheckboxLabel>
<Checkbox
type="checkbox"
onChange={handleWeightedVoting}
/>
Submit weighted votes
</CheckboxLabel>
<ButtonGroup>
<Button
type="submit"
disabled={voteType === 'weighted' && getVals(formik, false) !== '100'}
>
Submit
</Button>
</ButtonGroup>
</MenuEnd>
</>
}
{voted &&
<Countdown
onClick={handleModalClose}
seconds={30}
title='Vote Submitted'
message={votingMessage}
/>
}
</form>
)}
</Formik>
</Modal>
}}
>
{(formik) => (
<form onSubmit={formik.handleSubmit}>
{!hasDelegations && !voteAnyway && !voted && (
<ThisField>
<VoteWarning>
<WarningTitle>
<Label>Voting Notice</Label>
</WarningTitle>
You currently have no delegated hash in your account. While you are still able
to submit a vote, your vote will not be counted towards the vote totals on this
proposal. To have your votes counted, you must either delegate hash or log in to
an account with delegated hash. Note that fees are assessed to any votes that
are submitted regardless of delegation status.
<WarningButton>
<Button onClick={() => setVoteAnyway(true)}>Vote Anyway</Button>
</WarningButton>
</VoteWarning>
</ThisField>
)}
{(hasDelegations || voteAnyway) && !voted && (
<>
<Title>
Vote on <b>{title}</b>
</Title>
<PairTitle>Proposal ID</PairTitle>
<Description>{proposalId}</Description>
<PairTitle>Description</PairTitle>
<Description>{description}</Description>
<PairTitle>Vote Tally</PairTitle>
{!isEmpty(tally) && <VotingChart voteData={tally} />}
<Forms config={data(voteType)} formik={formik} grid={voteType === 'weighted'} />
{voteType === 'weighted' && (
<Total>
<Value>Total (must be 100%):</Value>
<Value color={getVals(formik, true)}>{getVals(formik, false)}%</Value>
</Total>
)}
<MenuEnd>
<CheckboxLabel>
<Checkbox type="checkbox" onChange={handleWeightedVoting} />
Submit weighted votes
</CheckboxLabel>
<ButtonGroup>
<Button
type="submit"
disabled={voteType === 'weighted' && getVals(formik, false) !== '100'}
>
Submit
</Button>
</ButtonGroup>
</MenuEnd>
</>
)}
{voted && (
<Countdown
onClick={handleModalClose}
seconds={30}
title="Vote Submitted"
message={votingMessage}
/>
)}
</form>
)}
</Formik>
</Modal>
</ModalContainer>
);
};

export default ManageVotingModal;
export default ManageVotingModal;
33 changes: 13 additions & 20 deletions src/Pages/Proposal/Components/ProposalVoting.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
import React from 'react';
import { useWallet } from '@provenanceio/wallet-lib';
import { Loading } from 'Components';
import { useWalletConnect } from '@provenanceio/walletconnect-js';
import { Loading } from 'Components';
import { useVoting, useGovernance, useApp } from '../../../redux/hooks';
import ManageVotingModal from "./ManageVotingModal";
import ManageVotingModal from './ManageVotingModal';

const ProposalVoting = () => {
const { handleVoting, ManageVotingBtn, modalFns, voted, setVoted } = useVoting();
const { proposal, proposalVotesLoading } = useGovernance();
const { isLoggedIn } = useApp();
const { walletService } = useWallet();
const { walletConnectState } = useWalletConnect();

const {
header: {
description,
proposalId,
title,
},
header: { description, proposalId, title },
} = proposal;

const {
state: { address },
} = walletService;
const { address } = walletConnectState;

return (
<>
{!proposalId ? <Loading /> :
<ManageVotingBtn title={`Proposal ${proposalId}`}/>}
{!proposalVotesLoading &&
<ManageVotingModal
{!proposalId ? <Loading /> : <ManageVotingBtn title={`Proposal ${proposalId}`} />}
{!proposalVotesLoading && (
<ManageVotingModal
isLoggedIn={isLoggedIn}
modalOpen={modalFns.modalOpen}
onClose={modalFns.deactivateModalOpen}
Expand All @@ -39,9 +32,9 @@ const ProposalVoting = () => {
voted={voted}
setVoted={setVoted}
/>
}
)}
</>
)
}
);
};

export default ProposalVoting;
export default ProposalVoting;
Loading