From 467b95190599085458dca22ca6697871e5f6a9ca Mon Sep 17 00:00:00 2001 From: selankon Date: Tue, 31 Oct 2023 12:21:59 +0100 Subject: [PATCH] Fix todos Also update vocdoni react components --- package.json | 2 +- .../transactionModals/gaslessVotingModal.tsx | 4 -- src/context/createGaslessProposal.tsx | 46 ++++--------------- src/context/createProposal.tsx | 11 ++--- src/context/proposalTransaction.tsx | 1 - src/context/stepperModal.tsx | 3 +- src/context/useGaslessVoting.tsx | 24 ++++------ yarn.lock | 2 +- 8 files changed, 27 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 71a2d6c96..6da0abe0a 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@tiptap/starter-kit": "^2.0.3", "@vocdoni/gasless-voting": "./vocdoni-gasless-voting-v0.0.1-rc4.tgz", "@vocdoni/gasless-voting-ethers": "./vocdoni-gasless-voting-ethers-v0.0.1-rc1.tgz", - "@vocdoni/react-providers": "^0.1.10", + "@vocdoni/react-providers": "^0.1.13", "@vocdoni/sdk": "^0.3.1", "@walletconnect/core": "^2.8.3", "@walletconnect/utils": "^2.8.3", diff --git a/src/containers/transactionModals/gaslessVotingModal.tsx b/src/containers/transactionModals/gaslessVotingModal.tsx index 3fe407163..57bd2c2b0 100644 --- a/src/containers/transactionModals/gaslessVotingModal.tsx +++ b/src/containers/transactionModals/gaslessVotingModal.tsx @@ -82,9 +82,6 @@ JSX.Element => { // clear up previous submission state setVoteSubmitted(false); - // todo(kon): simple way of voting, use providers better - // It retrieves from local storage the vocdoni election id. Won't be this on the final implementation - // Not showing errors neither await submitGaslessVote(vote); await onVoteSubmitted( @@ -114,7 +111,6 @@ JSX.Element => { onClose={handleCloseVoteModal} callback={handleVoteExecution} closeOnDrag={gaslessGlobalState !== StepStatus.LOADING} - // todo(kon): implementent free cost gas component maxFee={BigInt(0)} averageFee={BigInt(0)} gasEstimationError={undefined} diff --git a/src/context/createGaslessProposal.tsx b/src/context/createGaslessProposal.tsx index a1a490f30..803322a7d 100644 --- a/src/context/createGaslessProposal.tsx +++ b/src/context/createGaslessProposal.tsx @@ -11,7 +11,6 @@ import { Census, Census3Census, Election, - ErrAccountNotFound, ICensus3Token, IElectionParameters, TokenCensus, @@ -25,7 +24,6 @@ import { useFunctionStepper, } from '../hooks/useFunctionStepper'; -// todo(kon): move this block somewhere else export enum GaslessProposalStepId { REGISTER_VOCDONI_ACCOUNT = 'REGISTER_VOCDONI_ACCOUNT', CREATE_VOCDONI_ELECTION = 'CREATE_VOCDONI_ELECTION', @@ -74,8 +72,6 @@ const proposalToElection = ({ }; }; -// todo(kon): end to move this block somewhere else - const useCreateGaslessProposal = ({daoToken}: ICreateGaslessProposal) => { const [electionId, setElectionId] = useState(''); @@ -97,9 +93,9 @@ const useCreateGaslessProposal = ({daoToken}: ICreateGaslessProposal) => { } as GaslessProposalSteps, }); - const {client: vocdoniClient, census3} = useClient(); + const {client: vocdoniClient, census3, account, createAccount} = useClient(); - // todo(kon): move this somewhere? + // todo(kon): check if this is needed somewhere else const collectFaucet = useCallback( async (cost: number, account: AccountData) => { let balance = account.balance; @@ -132,46 +128,25 @@ const useCreateGaslessProposal = ({daoToken}: ICreateGaslessProposal) => { value: i, })) ); - // todo(kon): handle how collect faucet have to work + const cost = await vocdoniClient.calculateElectionCost(election); - const accountInfo = await vocdoniClient.fetchAccountInfo(); - console.log( - 'DEBUG', - 'Estimated cost', - cost, - 'balance', - accountInfo.balance - ); + console.log('DEBUG', 'Estimated cost', cost, 'balance', account!.balance); - await collectFaucet(cost, accountInfo); + await collectFaucet(cost, account!); console.log('DEBUG', 'Creating election:', election); return await vocdoniClient.createElection(election); }, - [collectFaucet, vocdoniClient] + [account, collectFaucet, vocdoniClient] ); - const createAccount = useCallback(async () => { + const checkAccountCreation = useCallback(async () => { // Check if the account is already created, if not, create it - let account: AccountData | null = null; - try { - console.log('DEBUG', 'get account info'); - account = await vocdoniClient.fetchAccountInfo(); - } catch (e) { - // todo(kon): replace error handling when the api return code error is fixed. Now is a generic 500 - if (e instanceof ErrAccountNotFound) { - console.log('DEBUG', 'Account not found, creating it'); - account = await vocdoniClient.createAccount(); - } else throw e; - } - - if (!account) { - throw Error('Error creating a Vocdoni account'); - } + await createAccount(); return account; - }, [vocdoniClient]); + }, [account, createAccount]); const createCensus = useCallback(async (): Promise => { async function getCensus3Token(): Promise { @@ -238,7 +213,7 @@ const useCreateGaslessProposal = ({daoToken}: ICreateGaslessProposal) => { // 1. Create an account if not exists await doStep( GaslessProposalStepId.REGISTER_VOCDONI_ACCOUNT, - createAccount + checkAccountCreation ); console.log('DEBUG', 'Account created start creating gasless proposal'); @@ -261,7 +236,6 @@ const useCreateGaslessProposal = ({daoToken}: ICreateGaslessProposal) => { console.log('DEBUG', 'Election created', electionId); // 3. Register the proposal onchain - // todo(kon): Register election to the DAO await doStep( GaslessProposalStepId.CREATE_ONCHAIN_PROPOSAL, async () => await handleOnchainProposal(electionId) diff --git a/src/context/createProposal.tsx b/src/context/createProposal.tsx index 35a264fef..2fff6b1f4 100644 --- a/src/context/createProposal.tsx +++ b/src/context/createProposal.tsx @@ -149,7 +149,6 @@ const CreateProposalWrapper: React.FC = ({ const disableActionButton = !proposalCreationData && creationProcessState !== TransactionState.SUCCESS; - // todo(kon): this code have to be placed somewhere else? const { steps: gaslessProposalSteps, globalState: gaslessGlobalState, @@ -703,7 +702,6 @@ const CreateProposalWrapper: React.FC = ({ }, [queryClient]); const handlePublishProposal = useCallback( - // todo(kon): this is a quickfix to update the internal cache with updated data. Delete this attribute when minSDK is ready async (vochainProposalId?: string) => { if (!pluginClient) { return new Error('ERC20 SDK client is not initialized correctly'); @@ -724,15 +722,14 @@ const CreateProposalWrapper: React.FC = ({ total_usd_cost: averageFee ? tokenPrice * Number(averageFee) : 0, }); - // todo(kon): fix this if needed let proposalIterator: AsyncGenerator; if (gasless && vochainProposalId) { - const proposalParams = - proposalCreationData as CreateGasslessProposalParams; - proposalParams.vochainProposalId = vochainProposalId; proposalIterator = ( pluginClient as GaslessVotingClient - ).methods.createProposal(proposalParams); + ).methods.createProposal({ + ...(proposalCreationData as CreateGasslessProposalParams), + vochainProposalId, + }); } else { proposalIterator = ( pluginClient as MultisigClient | TokenVotingClient diff --git a/src/context/proposalTransaction.tsx b/src/context/proposalTransaction.tsx index 414762b05..acc739ca5 100644 --- a/src/context/proposalTransaction.tsx +++ b/src/context/proposalTransaction.tsx @@ -587,7 +587,6 @@ const ProposalTransactionProvider: React.FC = ({children}) => { /************************************************* * Render * *************************************************/ - // todo(kon): handle this properly return ( {children} diff --git a/src/context/stepperModal.tsx b/src/context/stepperModal.tsx index c35ad6a68..2f7920c28 100644 --- a/src/context/stepperModal.tsx +++ b/src/context/stepperModal.tsx @@ -173,8 +173,7 @@ const StepperModal = ({ ) : undefined } - // todo(kon): implement disabled button when is loading gas fees but not when gasEstimationError?? - // disabled={gasEstimationError !== undefined} + disabled={gasEstimationError !== undefined} onClick={callback} /> diff --git a/src/context/useGaslessVoting.tsx b/src/context/useGaslessVoting.tsx index 93b1e6100..42adcfa3f 100644 --- a/src/context/useGaslessVoting.tsx +++ b/src/context/useGaslessVoting.tsx @@ -21,7 +21,6 @@ import {useWallet} from '../hooks/useWallet'; import {useDaoDetailsQuery} from '../hooks/useDaoDetails'; import {ProposalStatus} from '@aragon/sdk-client-common'; -// todo(kon): move this block somewhere else export enum GaslessVotingStepId { CREATE_VOTE_ID = 'CREATE_VOTE_ID', PUBLISH_VOTE = 'PUBLISH_VOTE', @@ -29,8 +28,6 @@ export enum GaslessVotingStepId { export type GaslessVotingSteps = StepsMap; -// todo(kon): end to move this block somewhere else - const useGaslessVoting = () => { const {client: vocdoniClient} = useVocdoniClient(); const pluginClient = usePluginClient( @@ -53,17 +50,16 @@ const useGaslessVoting = () => { [daoDetails, pluginClient] ); - const {steps, updateStepStatus, doStep, globalState, resetStates} = - useFunctionStepper({ - initialSteps: { - CREATE_VOTE_ID: { - status: StepStatus.WAITING, - }, - PUBLISH_VOTE: { - status: StepStatus.WAITING, - }, - } as GaslessVotingSteps, - }); + const {steps, doStep, globalState, resetStates} = useFunctionStepper({ + initialSteps: { + CREATE_VOTE_ID: { + status: StepStatus.WAITING, + }, + PUBLISH_VOTE: { + status: StepStatus.WAITING, + }, + } as GaslessVotingSteps, + }); const submitVote = useCallback( async (vote: VoteProposalParams, electionId: string) => { diff --git a/yarn.lock b/yarn.lock index ea3ffce2c..632514d19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4621,7 +4621,7 @@ long "^5.2.1" protobufjs "^7.1.2" -"@vocdoni/react-providers@^0.1.10": +"@vocdoni/react-providers@^0.1.13": version "0.1.13" resolved "https://registry.yarnpkg.com/@vocdoni/react-providers/-/react-providers-0.1.13.tgz#d6789272107af76f1481745a98c23bebb45f4122" integrity sha512-UsKuspv5ZF9MX6cNIEGzOVUMzV6Yk+6z52yqj6qvXwXAQ9XYi6pehP53d/VSK/NWr7jBRZvgEVtFhSRX83F8HA==