Skip to content

Commit dfaeeaf

Browse files
Merge pull request #414 from daostack/addTotalVotesSuggestions
add totalVotes and totalSuggestions fields
2 parents 6d2a9bf + 1342ae4 commit dfaeeaf

File tree

5 files changed

+94
-79
lines changed

5 files changed

+94
-79
lines changed

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ services:
2626
GRAPH_GRAPHQL_MAX_FIRST: '1000'
2727

2828
ipfs:
29-
image: daostack/test-env-ipfs:3.0.30
29+
image: daostack/test-env-ipfs:3.0.31
3030
ports:
3131
- 5001:5001
3232

3333
postgres:
34-
image: daostack/test-env-postgres:3.0.30
34+
image: daostack/test-env-postgres:3.0.31
3535
ports:
3636
- 9432:5432
3737
environment:
3838
POSTGRES_PASSWORD: 'letmein'
3939

4040
ganache:
41-
image: daostack/test-env-ganache:3.0.30
41+
image: daostack/test-env-ganache:3.0.31
4242
ports:
4343
- 8545:8545

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/client",
3-
"version": "0.2.60",
3+
"version": "0.2.64",
44
"description": "",
55
"keywords": [],
66
"main": "dist/lib/index.js",
@@ -66,7 +66,7 @@
6666
]
6767
},
6868
"devDependencies": {
69-
"@daostack/migration": "0.0.1-rc.40-v1",
69+
"@daostack/migration": "0.0.1-rc.41-v1",
7070
"@types/graphql": "^14.2.2",
7171
"@types/isomorphic-fetch": "^0.0.34",
7272
"@types/jest": "^24.0.15",

src/proposal.ts

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import * as SchemeRegistrar from './schemes/schemeRegistrar'
1818
import { CONTRIBUTION_REWARD_DUMMY_VERSION, REDEEMER_CONTRACT_VERSIONS } from './settings'
1919
import { IStakeQueryOptions, Stake } from './stake'
2020
import { Address, Date, ICommonQueryOptions, IStateful } from './types'
21-
import { createGraphQlQuery, isAddress, NULL_ADDRESS, realMathToNumber,
22-
secondSinceEpochToDate } from './utils'
21+
import {
22+
createGraphQlQuery, isAddress, NULL_ADDRESS, realMathToNumber,
23+
secondSinceEpochToDate
24+
} from './utils'
2325
import { IVoteQueryOptions, Vote } from './vote'
2426

2527
export const IProposalType = {
@@ -68,8 +70,8 @@ export interface IProposalStaticState {
6870
export interface IProposalState extends IProposalStaticState {
6971
accountsWithUnclaimedRewards: Address[],
7072
boostedAt: Date
71-
contributionReward: ContributionReward.IContributionReward|null
72-
competition: ICompetitionProposalState|null
73+
contributionReward: ContributionReward.IContributionReward | null
74+
competition: ICompetitionProposalState | null
7375
confidenceThreshold: number
7476
closingAt: Date
7577
createdAt: Date
@@ -79,7 +81,7 @@ export interface IProposalState extends IProposalStaticState {
7981
executedAt: Date
8082
executionState: IExecutionState
8183
expiresInQueueAt: Date
82-
genericScheme: GenericScheme.IGenericScheme|null
84+
genericScheme: GenericScheme.IGenericScheme | null
8385
genesisProtocolParams: IGenesisProtocolParams
8486
organizationId: string
8587
paramsHash: string
@@ -88,7 +90,7 @@ export interface IProposalState extends IProposalStaticState {
8890
proposer: Address
8991
queue: IQueueState
9092
quietEndingPeriodBeganAt: Date
91-
schemeRegistrar: SchemeRegistrar.ISchemeRegistrar|null
93+
schemeRegistrar: SchemeRegistrar.ISchemeRegistrar | null
9294
resolvedAt: Date
9395
stage: IProposalStage
9496
stakesFor: BN
@@ -117,15 +119,19 @@ export class Proposal implements IStateful<IProposalState> {
117119
confidenceThreshold
118120
competition {
119121
id
122+
admin
120123
endTime
121124
contract
122125
suggestionsEndTime
123126
createdAt
127+
numberOfWinningSuggestions
124128
numberOfVotesPerVoters
125129
numberOfWinners
126130
rewardSplit
127131
snapshotBlock
128132
startTime
133+
totalSuggestions
134+
totalVotes
129135
votingStartTime
130136
131137
}
@@ -328,9 +334,9 @@ export class Proposal implements IStateful<IProposalState> {
328334

329335
public context: Arc
330336
public id: string
331-
public staticState: IProposalStaticState|undefined
337+
public staticState: IProposalStaticState | undefined
332338
constructor(
333-
idOrOpts: string|IProposalStaticState,
339+
idOrOpts: string | IProposalStaticState,
334340
context: Arc
335341
) {
336342
if (typeof idOrOpts === 'string') {
@@ -350,7 +356,7 @@ export class Proposal implements IStateful<IProposalState> {
350356
if (!!this.staticState) {
351357
return this.staticState
352358
} else {
353-
const state = await this.state({subscribe: false}).pipe(first()).toPromise()
359+
const state = await this.state({ subscribe: false }).pipe(first()).toPromise()
354360
if (state === null) {
355361
throw Error(`No proposal with id ${this.id} was found in the subgraph`)
356362
}
@@ -386,41 +392,41 @@ export class Proposal implements IStateful<IProposalState> {
386392
387393
`
388394

389-
const itemMap = (item: any): IProposalState|null => {
395+
const itemMap = (item: any): IProposalState | null => {
390396
if (item === null || item === undefined) {
391397
// no proposal was found - we return null
392398
// throw Error(`No proposal with id ${this.id} could be found`)
393399
return null
394400
}
395401

396-
let contributionReward: ContributionReward.IContributionReward|null = null
397-
let competition: ICompetitionProposalState|null = null
402+
let contributionReward: ContributionReward.IContributionReward | null = null
403+
let competition: ICompetitionProposalState | null = null
398404
let type: IProposalType
399-
let genericScheme: GenericScheme.IGenericScheme|null = null
400-
let schemeRegistrar: SchemeRegistrar.ISchemeRegistrar|null = null
405+
let genericScheme: GenericScheme.IGenericScheme | null = null
406+
let schemeRegistrar: SchemeRegistrar.ISchemeRegistrar | null = null
401407
if (!!item.competition && !item.contributionReward) {
402408
throw Error(`Unexpected proposal state: competition is set, but contributionReward is not`)
403409
}
404410
if (!!item.contributionReward) {
405411
const ethRewardLeft = (
406412
item.contributionReward.ethRewardLeft !== null &&
407-
new BN(item.contributionReward.ethRewardLeft) ||
408-
null
413+
new BN(item.contributionReward.ethRewardLeft) ||
414+
null
409415
)
410416
const externalTokenRewardLeft = (
411417
item.contributionReward.externalTokenRewardLeft !== null &&
412-
new BN(item.contributionReward.externalTokenRewardLeft) ||
413-
null
418+
new BN(item.contributionReward.externalTokenRewardLeft) ||
419+
null
414420
)
415421
const nativeTokenRewardLeft = (
416422
item.contributionReward.nativeTokenRewardLeft !== null &&
417-
new BN(item.contributionReward.nativeTokenRewardLeft) ||
418-
null
423+
new BN(item.contributionReward.nativeTokenRewardLeft) ||
424+
null
419425
)
420426
const reputationChangeLeft = (
421427
item.contributionReward.reputationChangeLeft !== null &&
422-
new BN(item.contributionReward.reputationChangeLeft) ||
423-
null
428+
new BN(item.contributionReward.reputationChangeLeft) ||
429+
null
424430
)
425431

426432
type = IProposalType.ContributionReward
@@ -444,16 +450,20 @@ export class Proposal implements IStateful<IProposalState> {
444450
}
445451
if (!!item.competition) {
446452
competition = {
453+
admin: item.competition.admin,
447454
contract: item.competition.contract,
448455
createdAt: secondSinceEpochToDate(item.competition.createdAt),
449456
endTime: secondSinceEpochToDate(item.competition.endTime),
450457
id: item.competition.id,
451458
numberOfVotesPerVoter: Number(item.competition.numberOfVotesPerVoters),
452459
numberOfWinners: Number(item.competition.numberOfWinners),
460+
numberOfWinningSuggestions: Number(item.competition.numberOfWinningSuggestions),
453461
rewardSplit: item.competition.rewardSplit.map((perc: string) => Number(perc)),
454462
snapshotBlock: item.competition.snapshotBlock,
455463
startTime: secondSinceEpochToDate(item.competition.startTime),
456464
suggestionsEndTime: secondSinceEpochToDate(item.competition.suggestionsEndTime),
465+
totalSuggestions: Number(item.competition.totalSuggestions),
466+
totalVotes: Number(item.competition.totalVotes),
457467
votingStartTime: secondSinceEpochToDate(item.competition.votingStartTime)
458468
}
459469

@@ -481,7 +491,7 @@ export class Proposal implements IStateful<IProposalState> {
481491
} else {
482492
throw Error(`Unknown proposal type: schemeRegistrar without a scheme to register or to remove`)
483493
}
484-
schemeRegistrar = {
494+
schemeRegistrar = {
485495
decision: item.schemeRegistrar.decision,
486496
id: item.schemeRegistrar.id,
487497
schemeRegistered: item.schemeRegistrar.schemeRegistered,
@@ -623,7 +633,7 @@ export class Proposal implements IStateful<IProposalState> {
623633
}
624634

625635
public votes(options: IVoteQueryOptions = {}, apolloQueryOptions: IApolloQueryOptions = {}): Observable<Vote[]> {
626-
if (!options.where) { options.where = {}}
636+
if (!options.where) { options.where = {} }
627637
options.where.proposal = this.id
628638
return Vote.search(this.context, options, apolloQueryOptions)
629639
}
@@ -635,7 +645,7 @@ export class Proposal implements IStateful<IProposalState> {
635645
* all the sender's rep will be used
636646
* @return an observable Operation<Vote>
637647
*/
638-
public vote(outcome: IProposalOutcome, amount: number = 0): Operation<Vote|null> {
648+
public vote(outcome: IProposalOutcome, amount: number = 0): Operation<Vote | null> {
639649

640650
const mapReceipt = (receipt: any) => {
641651
const event = receipt.events.VoteProposal
@@ -656,17 +666,17 @@ export class Proposal implements IStateful<IProposalState> {
656666

657667
const observable = from(this.votingMachine()).pipe(
658668
concatMap((votingMachine) => {
659-
const voteMethod = votingMachine.methods.vote(
669+
const voteMethod = votingMachine.methods.vote(
660670
this.id, // proposalId
661671
outcome, // a value between 0 to and the proposal number of choices.
662672
amount.toString(), // amount of reputation to vote with . if _amount == 0 it will use all voter reputation.
663673
NULL_ADDRESS
664674
)
665675

666-
const errorHandler = async (error: Error) => {
676+
const errorHandler = async (error: Error) => {
667677
const proposal = this
668678
const proposalDataFromVotingMachine = await votingMachine.methods.proposals(proposal.id).call()
669-
if (proposalDataFromVotingMachine.proposer === NULL_ADDRESS ) {
679+
if (proposalDataFromVotingMachine.proposer === NULL_ADDRESS) {
670680
return Error(`Error in vote(): unknown proposal with id ${proposal.id}`)
671681
}
672682

@@ -680,7 +690,7 @@ export class Proposal implements IStateful<IProposalState> {
680690
return error
681691
}
682692

683-
return this.context.sendTransaction(voteMethod, mapReceipt, errorHandler)
693+
return this.context.sendTransaction(voteMethod, mapReceipt, errorHandler)
684694
})
685695
)
686696

@@ -692,7 +702,7 @@ export class Proposal implements IStateful<IProposalState> {
692702
}
693703

694704
public stakes(options: IStakeQueryOptions = {}, apolloQueryOptions: IApolloQueryOptions = {}): Observable<Stake[]> {
695-
if (!options.where) { options.where = {}}
705+
if (!options.where) { options.where = {} }
696706
options.where.proposal = this.id
697707
return Stake.search(this.context, options, apolloQueryOptions)
698708
}
@@ -709,26 +719,26 @@ export class Proposal implements IStateful<IProposalState> {
709719

710720
const map = (receipt: any) => { // map extracts Stake instance from receipt
711721

712-
const event = receipt.events.Stake
713-
if (!event) {
714-
// for some reason, a transaction was mined but no error was raised before
715-
throw new Error(`Error staking: no "Stake" event was found - ${Object.keys(receipt.events)}`)
716-
}
717-
return new Stake({
718-
amount: event.returnValues._reputation, // amount
719-
// createdAt is "about now", but we cannot calculate the data that will be indexed by the subgraph
720-
createdAt: undefined,
721-
outcome,
722-
proposal: this.id, // proposalID
723-
staker: event.returnValues._staker
724-
}, this.context)
722+
const event = receipt.events.Stake
723+
if (!event) {
724+
// for some reason, a transaction was mined but no error was raised before
725+
throw new Error(`Error staking: no "Stake" event was found - ${Object.keys(receipt.events)}`)
726+
}
727+
return new Stake({
728+
amount: event.returnValues._reputation, // amount
729+
// createdAt is "about now", but we cannot calculate the data that will be indexed by the subgraph
730+
createdAt: undefined,
731+
outcome,
732+
proposal: this.id, // proposalID
733+
staker: event.returnValues._staker
734+
}, this.context)
725735
}
726736

727-
const errorHandler = async (error: Error) => {
737+
const errorHandler = async (error: Error) => {
728738
const proposal = this
729739
const proposalState = await (await this.votingMachine()).methods.proposals(proposal.id).call()
730740
const stakingToken = this.stakingToken()
731-
if (proposalState.proposer === NULL_ADDRESS ) {
741+
if (proposalState.proposer === NULL_ADDRESS) {
732742
return new Error(`Unknown proposal with id ${proposal.id}`)
733743
}
734744
// staker has sufficient balance
@@ -781,7 +791,7 @@ export class Proposal implements IStateful<IProposalState> {
781791
options: IRewardQueryOptions = {},
782792
apolloQueryOptions: IApolloQueryOptions = {}
783793
): Observable<Reward[]> {
784-
if (!options.where) { options.where = {}}
794+
if (!options.where) { options.where = {} }
785795
options.where.proposal = this.id
786796
return Reward.search(this.context, options, apolloQueryOptions)
787797
}
@@ -802,7 +812,7 @@ export class Proposal implements IStateful<IProposalState> {
802812
const observable = this.state().pipe(
803813
first(),
804814
concatMap((state) => {
805-
let schemeAddress: Address|null
815+
let schemeAddress: Address | null
806816
if (state.contributionReward) {
807817
schemeAddress = state.scheme.address
808818
} else {
@@ -846,7 +856,7 @@ export class Proposal implements IStateful<IProposalState> {
846856
concatMap((votingMachine) => {
847857
const transaction = votingMachine.methods.execute(this.id)
848858
const map = (receipt: any) => {
849-
if (Object.keys(receipt.events).length === 0) {
859+
if (Object.keys(receipt.events).length === 0) {
850860
// this does not mean that anything failed
851861
return receipt
852862
} else {
@@ -878,7 +888,7 @@ export class Proposal implements IStateful<IProposalState> {
878888
const transaction = votingMachine.methods.executeBoosted(this.id)
879889
console.log(votingMachine.options.address)
880890
const map = (receipt: any) => {
881-
if (Object.keys(receipt.events).length === 0) {
891+
if (Object.keys(receipt.events).length === 0) {
882892
// this does not mean that anything failed
883893
return receipt
884894
} else {
@@ -929,7 +939,7 @@ export interface IProposalQueryOptions extends ICommonQueryOptions {
929939
scheme?: Address
930940
orderBy?: ProposalQuerySortOptions
931941
type?: IProposalType
932-
[key: string]: any|undefined
942+
[key: string]: any | undefined
933943
}
934944
}
935945

@@ -946,7 +956,7 @@ export interface IProposalBaseCreateOptions {
946956
}
947957

948958
export type IProposalCreateOptions = (
949-
(IProposalBaseCreateOptions & GenericScheme.IProposalCreateOptionsGS ) |
959+
(IProposalBaseCreateOptions & GenericScheme.IProposalCreateOptionsGS) |
950960
(IProposalBaseCreateOptions & SchemeRegistrar.IProposalCreateOptionsSR) |
951961
(IProposalBaseCreateOptions & ContributionReward.IProposalCreateOptionsCR) |
952962
(ContributionRewardExt.IProposalCreateOptionsContributionRewardExt) |

0 commit comments

Comments
 (0)