Skip to content

Commit

Permalink
Fix todos
Browse files Browse the repository at this point in the history
Also update vocdoni react components
  • Loading branch information
selankon committed Oct 31, 2023
1 parent 33b9c8e commit 467b951
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 66 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions src/containers/transactionModals/gaslessVotingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}
Expand Down
46 changes: 10 additions & 36 deletions src/context/createGaslessProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Census,
Census3Census,
Election,
ErrAccountNotFound,
ICensus3Token,
IElectionParameters,
TokenCensus,
Expand All @@ -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',
Expand Down Expand Up @@ -74,8 +72,6 @@ const proposalToElection = ({
};
};

// todo(kon): end to move this block somewhere else

const useCreateGaslessProposal = ({daoToken}: ICreateGaslessProposal) => {
const [electionId, setElectionId] = useState('');

Expand All @@ -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;
Expand Down Expand Up @@ -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<TokenCensus> => {
async function getCensus3Token(): Promise<ICensus3Token> {
Expand Down Expand Up @@ -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');

Expand All @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions src/context/createProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ const CreateProposalWrapper: React.FC<Props> = ({
const disableActionButton =
!proposalCreationData && creationProcessState !== TransactionState.SUCCESS;

// todo(kon): this code have to be placed somewhere else?
const {
steps: gaslessProposalSteps,
globalState: gaslessGlobalState,
Expand Down Expand Up @@ -703,7 +702,6 @@ const CreateProposalWrapper: React.FC<Props> = ({
}, [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');
Expand All @@ -724,15 +722,14 @@ const CreateProposalWrapper: React.FC<Props> = ({
total_usd_cost: averageFee ? tokenPrice * Number(averageFee) : 0,
});

// todo(kon): fix this if needed
let proposalIterator: AsyncGenerator<ProposalCreationStepValue>;
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
Expand Down
1 change: 0 additions & 1 deletion src/context/proposalTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ const ProposalTransactionProvider: React.FC<Props> = ({children}) => {
/*************************************************
* Render *
*************************************************/
// todo(kon): handle this properly
return (
<ProposalTransactionContext.Provider value={value}>
{children}
Expand Down
3 changes: 1 addition & 2 deletions src/context/stepperModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ const StepperModal = <X extends GenericKeyEnum>({
<IconChevronRight />
) : undefined
}
// todo(kon): implement disabled button when is loading gas fees but not when gasEstimationError??
// disabled={gasEstimationError !== undefined}
disabled={gasEstimationError !== undefined}
onClick={callback}
/>
</ButtonContainer>
Expand Down
24 changes: 10 additions & 14 deletions src/context/useGaslessVoting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ 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',
}

export type GaslessVotingSteps = StepsMap<GaslessVotingStepId>;

// todo(kon): end to move this block somewhere else

const useGaslessVoting = () => {
const {client: vocdoniClient} = useVocdoniClient();
const pluginClient = usePluginClient(
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 467b951

Please sign in to comment.