Skip to content

Commit

Permalink
feat: remove any types + follow interface specification
Browse files Browse the repository at this point in the history
  • Loading branch information
yum0e committed Sep 15, 2023
1 parent 1660e08 commit 5426dd1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion group-generators/generators/tally/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const generator: GroupGenerator = {
const TallyProvider = new dataProviders.TallyProvider();

const input = {
name: "Aave",
governance: "Aave",
// proposalId: 315,
};
const tallyGetGovernanceProposers = await TallyProvider.getGovernanceProposers(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "DAO",
"argName": "governance",
"type": "string",
"example": "aave",
"example": "Aave",
"description": "A specific DAO"
},
{
Expand All @@ -35,7 +35,7 @@
"name": "DAO",
"argName": "governance",
"type": "string",
"example": "aave",
"example": "Aave",
"description": "A specific DAO"
}
]
Expand All @@ -50,7 +50,7 @@
"name": "DAO",
"argName": "governance",
"type": "string",
"example": "aave",
"example": "Aave",
"description": "A specific DAO"
}
]
Expand Down
37 changes: 22 additions & 15 deletions group-generators/helpers/data-providers/tally/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class TallyProvider extends GraphQLProvider implements ITallyProv
}

public async getProposalVoters({
name,
governance,
proposalId,
}: inputGetProposalVoters): Promise<FetchedData> {
const data = await this._queryNameToGovernorAddress();
Expand All @@ -60,17 +60,16 @@ export default class TallyProvider extends GraphQLProvider implements ITallyProv

if (data && Array.isArray(data.governors)) {
const matchingGovernors = data.governors.filter(
(governor: { name: string }) => governor.name === name
(governor: { name: string }) => governor.name === governance
);

for (const governor of matchingGovernors) {
for (const proposals of governor.proposals) {
const propId = proposals.id;

if (parseInt(propId) === proposalId) {
if (propId === proposalId.toString()) {
const allVotes = proposals.votes;

allVotes.forEach((voteItem: { id: string; voter: any }) => {
allVotes.forEach((voteItem: { id: string; voter: { address: string } }) => {
const { voter } = voteItem;
const { address } = voter;
if (fetchedData[address]) {
Expand All @@ -90,22 +89,24 @@ export default class TallyProvider extends GraphQLProvider implements ITallyProv
}

public async getProposalVotersCount({
name,
governance,
proposalId,
}: inputGetProposalVoters): Promise<number> {
const ProposalVoterData = await this.getProposalVoters({ name, proposalId });
const ProposalVoterData = await this.getProposalVoters({ governance, proposalId });

const ProposalVoterCount = Object.keys(ProposalVoterData).length;
return ProposalVoterCount;
}

public async getGovernanceVoters({ name }: inputGetGovernanceProposers): Promise<FetchedData> {
public async getGovernanceVoters({
governance,
}: inputGetGovernanceProposers): Promise<FetchedData> {
const data: queryData = await this._queryNameToGovernorAddress();
const fetchedData: { [address: string]: number } = {};

if (data && Array.isArray(data.governors)) {
const matchingGovernors = data.governors.filter(
(governor: { name: string }) => governor.name === name
(governor: { name: string }) => governor.name === governance
);

for (const governor of matchingGovernors) {
Expand All @@ -130,20 +131,24 @@ export default class TallyProvider extends GraphQLProvider implements ITallyProv
return fetchedData;
}

public async getGovernanceVotersCount({ name }: inputGetGovernanceProposers): Promise<number> {
const VoterData = await this.getGovernanceVoters({ name });
public async getGovernanceVotersCount({
governance,
}: inputGetGovernanceProposers): Promise<number> {
const VoterData = await this.getGovernanceVoters({ governance });

const VoterCount = Object.keys(VoterData).length;
return VoterCount;
}

public async getGovernanceProposers({ name }: inputGetGovernanceProposers): Promise<FetchedData> {
public async getGovernanceProposers({
governance,
}: inputGetGovernanceProposers): Promise<FetchedData> {
const data: queryData = await this._queryNameToGovernorAddress();
const fetchedData: { [address: string]: number } = {};

if (data && Array.isArray(data.governors)) {
const matchingGovernors = data.governors.filter(
(governor: { name: string }) => governor.name === name
(governor: { name: string }) => governor.name === governance
);

for (const governor of matchingGovernors) {
Expand All @@ -163,8 +168,10 @@ export default class TallyProvider extends GraphQLProvider implements ITallyProv
return fetchedData;
}

public async getGovernanceProposersCount({ name }: inputGetGovernanceProposers): Promise<number> {
const proposersData = await this.getGovernanceProposers({ name });
public async getGovernanceProposersCount({
governance,
}: inputGetGovernanceProposers): Promise<number> {
const proposersData = await this.getGovernanceProposers({ governance });

const proposerCount = Object.keys(proposersData).length;
return proposerCount;
Expand Down
10 changes: 7 additions & 3 deletions group-generators/helpers/data-providers/tally/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { IGraphQLProvider } from "@group-generators/helpers/data-providers/graph
export type ITallyProvider = IGraphQLProvider;

export interface inputGetGovernanceProposers {
name: string;
governance: string;
}

export interface inputGetProposalVoters {
name: string;
governance: string;
proposalId: number;
}

Expand All @@ -23,7 +23,11 @@ export interface govArray {
id: string;
type: string;
name: string;
proposals: any[];
proposals: {
id: string;
votes: { id: string; voter: { address: string } }[];
proposer: { address: string };
}[];
delegates: Delegate[];
}

Expand Down

0 comments on commit 5426dd1

Please sign in to comment.