Skip to content

Commit

Permalink
feat(cli): add initial voice credits from signup event
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmad committed Mar 14, 2024
1 parent e98881c commit 0900e69
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cli/ts/commands/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,28 @@ export const signup = async ({
/**
* Checks if user is registered with public key
* @param IRegisteredArgs - The arguments for the register check command
* @returns user registered or not and state index
* @returns user registered or not and state index, voice credit balance
*/
export const isRegisteredUser = async ({
maciAddress,
maciPubKey,
signer,
quiet = true,
}: IRegisteredUserArgs): Promise<{ isRegistered: boolean; stateIndex?: string }> => {
}: IRegisteredUserArgs): Promise<{ isRegistered: boolean; stateIndex?: string; voiceCredits?: string }> => {
banner(quiet);

const maciContract = MACIFactory.connect(maciAddress, signer);
const publicKey = PubKey.deserialize(maciPubKey).asContractParam();

const events = await maciContract.queryFilter(maciContract.filters.SignUp(undefined, publicKey.x, publicKey.y));
const stateIndex = events[0]?.args[0].toString() as string | undefined;
const voiceCredits = events[0]?.args[3].toString() as string | undefined;

logGreen(quiet, success(`State index: ${stateIndex?.toString()}, registered: ${stateIndex !== undefined}`));

return {
isRegistered: stateIndex !== undefined,
stateIndex,
voiceCredits,
};
};

0 comments on commit 0900e69

Please sign in to comment.