Skip to content

Commit

Permalink
Commits changes to wallet while waiting for parity to process governa…
Browse files Browse the repository at this point in the history
…nce messages
  • Loading branch information
jarrydallison committed Oct 17, 2022
1 parent 0f11c87 commit 61f1979
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/Components/Sprite/Sprite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const Svg = styled.svg<SvgProps>`
--secondaryColor: ${({ secondaryColor }) => secondaryColor};
width: ${({ size, width }) => width || size};
height: ${({ size, height }) => height || size};
transform: ${({ flipX }) => flipX && `scaleX(-1)`} ${({ flipY }) => flipY && `scaleY(-1)`};
${({ spin }) => Boolean(spin) && `rotate(${spin}deg)`};
transform: ${({ flipX }) => flipX && `scaleX(-1)`} ${({ flipY }) => flipY && `scaleY(-1)`}
${({ spin }) => Boolean(spin) && `rotate(${spin}deg)`};
transition: ${({ animate }) => animate && 'transform 150ms linear'};
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useEffect, useState } from 'react';
import { useEffect, useState } from 'react';
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 { useWalletConnect } from '@provenanceio/walletconnect-js';
import { useGovernance, useAccounts } from 'redux/hooks';
import { VotingChart, Countdown } from './Components';

Expand Down Expand Up @@ -138,6 +139,7 @@ const ManageVotingModal = ({
const hasDelegations = parseInt(accountDelegationsTotal.amount) > 0;
const [voteAnyway, setVoteAnyway] = useState(false);
const [error, setError] = useState('');
const { walletConnectService: wcs } = useWalletConnect();

useEffect(() => {
setIsOpen(isLoggedIn && modalOpen);
Expand Down Expand Up @@ -236,12 +238,14 @@ const ManageVotingModal = ({
}
// Submit proposal message
if (!voted) {
await submitVotes({
const { data } = await submitVotes({
proposalId,
voter: voterId,
votes,
}).catch((error) => {
setError(error);
});
wcs.customAction({
description: 'Submit Proposal',
message: data.base64,
});
}
// Clear the form
Expand Down
3 changes: 2 additions & 1 deletion src/Pages/Proposal/Proposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const Proposal = () => {

useEffect(() => {
if (address) {
getAccountAssets({ address });
// TODO: Need an endpoint that only returns a users hash value
getAccountAssets({ address, count: 100 });
}
}, [getAccountAssets, address]);

Expand Down
8 changes: 5 additions & 3 deletions src/Pages/Proposals/Components/ManageProposalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ContentProps,
} from 'utils';
import { PROPOSAL_TYPES } from 'consts';
import { useBlocks, useGovernance } from '../../../redux/hooks';
import { useApp, useBlocks, useGovernance } from 'redux/hooks';
import { Countdown } from '../../Proposal/Components/ManageVotingModal/Components';

const Title = styled.div`
Expand Down Expand Up @@ -103,6 +103,7 @@ const ManageProposalModal = ({
const [proposalType, setProposalType] = useState('text');
const { submitProposal } = useGovernance();
const { walletConnectService: wcs } = useWalletConnect();
const { authToken } = useApp();

useEffect(() => {
setIsOpen(isLoggedIn && modalOpen);
Expand Down Expand Up @@ -168,15 +169,16 @@ const ManageProposalModal = ({
validationSchema={proposalValidations(proposalType, blockNumber)}
onSubmit={async (values: ProposalProps, { resetForm }) => {
// Remove the file from values to send separately
const file = values.file;
delete values.file;
const file = values?.file;
if (file) delete values.file;
// Format values as needed
const { data } = await submitProposal({
// Format the type string to match the query
type: values.dropdown.toUpperCase().replace(/ /g, '_'),
// Get the proposal content as a string
data: proposalContent(values as unknown as ContentProps),
file: (file as unknown as File) || undefined,
token: authToken,
});

// Submit via walletconnect-js
Expand Down
5 changes: 3 additions & 2 deletions src/redux/features/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export const axios = _axios.create({
withCredentials: true,
});

export const xhrSetToken = (value: string) =>
(axios.defaults.headers.Authorization = `Bearer ${value}`);
export const xhrSetToken = (value: string) => {
axios.defaults.headers.Authorization = `Bearer ${value}`;
};

function errorHandling(error: any) {
if (error.response) {
Expand Down
2 changes: 2 additions & 0 deletions src/redux/features/governance/governanceSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,12 @@ export const submitProposal = ({
type,
data,
file,
token,
}: {
type: string;
data: SubmitProposalProps;
file?: File;
token: string;
}) => {
// Create a new FormData object
const formData = new FormData();
Expand Down
40 changes: 27 additions & 13 deletions src/utils/proposals/proposalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,33 @@ export const proposalContent = ({
funds,
submitter,
}: ContentProps) => ({
content: JSON.stringify({
changes,
name,
height,
info,
runAs,
accessConfig,
admin,
codeId,
label,
msg,
funds,
}),
// If there is content, stringify. Otherwise, return an empty string
content:
changes ||
name ||
height ||
info ||
runAs ||
accessConfig ||
admin ||
codeId ||
label ||
msg ||
funds
? JSON.stringify({
changes,
name,
height,
info,
runAs,
accessConfig,
admin,
codeId,
label,
msg,
funds,
})
: '',
title,
description,
initialDeposit: initialDeposit
Expand Down

0 comments on commit 61f1979

Please sign in to comment.