Skip to content

Commit

Permalink
feat: create a constant for the default index of undefined voting mode
Browse files Browse the repository at this point in the history
  • Loading branch information
clauBv23 committed Apr 11, 2024
1 parent 99ea005 commit 7b64a78
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
11 changes: 8 additions & 3 deletions packages/subgraph/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
MembershipContractAnnounced,
TokenVoting,
} from '../../generated/templates/TokenVoting/TokenVoting';
import {RATIO_BASE, VOTER_OPTIONS, VOTING_MODES} from '../utils/constants';
import {
RATIO_BASE,
VOTER_OPTIONS,
VOTING_MODES,
VOTING_MODE_UNDEFINED_INDEX,
} from '../utils/constants';
import {identifyAndFetchOrCreateERC20TokenEntity} from '../utils/erc20';
import {generateMemberEntityId, generateVoteEntityId} from '../utils/ids';
import {
Expand Down Expand Up @@ -73,7 +78,7 @@ export function _handleProposalCreated(
let votingModeIndex = parameters.votingMode;
if (!VOTING_MODES.has(votingModeIndex)) {
// if the voting mode is not defined, set it to 'Undefined'
votingModeIndex = 10;
votingModeIndex = VOTING_MODE_UNDEFINED_INDEX;
}

const votingMode = VOTING_MODES.get(votingModeIndex);
Expand Down Expand Up @@ -273,7 +278,7 @@ export function handleVotingSettingsUpdated(
let votingModeIndex = event.params.votingMode;
if (!VOTING_MODES.has(votingModeIndex)) {
// if the voting mode is not defined, set it to 'Undefined'
votingModeIndex = 10;
votingModeIndex = VOTING_MODE_UNDEFINED_INDEX;
}

const votingMode = VOTING_MODES.get(votingModeIndex);
Expand Down
4 changes: 3 additions & 1 deletion packages/subgraph/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export enum TransferType {
Deposit,
}

export const VOTING_MODE_UNDEFINED_INDEX = 10;

export const DECODE_OFFSET =
'0x0000000000000000000000000000000000000000000000000000000000000020';

Expand All @@ -40,7 +42,7 @@ export const VOTING_MODES = new Map<number, string>()
.set(0, 'Standard')
.set(1, 'EarlyExecution')
.set(2, 'VoteReplacement')
.set(10, 'Undefined');
.set(VOTING_MODE_UNDEFINED_INDEX, 'Undefined');

export const TOKEN_VOTING_INTERFACE_ID = '0x50eb001e';
export const ADDRESSLIST_VOTING_INTERFACE_ID = '0x5f21eb8b';
Expand Down
7 changes: 4 additions & 3 deletions packages/subgraph/tests/helpers/method-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
VOTER_OPTIONS,
VOTE_OPTIONS,
VOTING_MODES,
VOTING_MODE_UNDEFINED_INDEX,
} from '../../src/utils/constants';
import {generateMemberEntityId} from '../../src/utils/ids';
import {
Expand Down Expand Up @@ -205,7 +206,7 @@ class TokenVotingProposalMethods extends TokenVotingProposal {
this.votingModeIndex = votingModeIndex;
this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex))
? (VOTING_MODES.get(parseInt(votingModeIndex)) as string)
: (VOTING_MODES.get(10) as string);
: (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string);

this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD);
this.minVotingPower = BigInt.fromString(MIN_VOTING_POWER);
Expand Down Expand Up @@ -384,7 +385,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin {
this.votingModeIndex = votingModeIndex; // for event we need the index of the mapping to simulate the contract event
this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex))
? (VOTING_MODES.get(parseInt(votingModeIndex)) as string)
: (VOTING_MODES.get(10) as string);
: (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string);

this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD);
this.minParticipation = BigInt.fromString(MIN_PARTICIPATION);
Expand Down Expand Up @@ -440,7 +441,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin {
this.votingModeIndex = votingModeIndex;
this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex))
? (VOTING_MODES.get(parseInt(votingModeIndex)) as string)
: (VOTING_MODES.get(10) as string);
: (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string);
this.supportThreshold = newSupportThreshold;
this.minParticipation = newMinParticipation;
this.minDuration = newMinDuration;
Expand Down

0 comments on commit 7b64a78

Please sign in to comment.