Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes regarding competitions #375

Merged
merged 16 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ script:
- docker-compose logs graph-node
- echo -en 'travis_fold:end:script.3\\r'


# sleep a long time to wait fo rthe graph-node to finish indexing
# until https://github.com/daostack/subgraph/issues/241 is resolved
- sleep 60
# sleep a bit to make sure the subgraph is ready
- sleep 5
- echo -en 'travis_fold:end:script.2\\r'
- npm run lint
- npm run test
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/client",
"version": "0.2.43",
"version": "0.2.44",
"description": "",
"keywords": [],
"main": "dist/lib/index.js",
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ export { Reward, IRewardState, IRewardStaticState, IRewardQueryOptions } from '.
export { Scheme, ISchemeState, ISchemeStaticState, ISchemeQueryOptions } from './scheme'
export { ReputationFromTokenScheme } from './schemes/reputationFromToken'
export { IContributionReward} from './schemes/contributionReward'
export { hasCompetitionContract, IProposalCreateOptionsCompetition, Competition, CompetitionScheme,
export { hasCompetitionContract, isCompetitionScheme,
IProposalCreateOptionsCompetition,
ICompetitionSuggestionQueryOptions,
ICompetitionVoteQueryOptions,
Competition,
CompetitionScheme,
CompetitionSuggestion, CompetitionVote,
ICompetitionProposal, ICompetitionVote, ICompetitionSuggestion } from './schemes/competition'
ICompetitionProposalState, ICompetitionVoteState, ICompetitionSuggestionState } from './schemes/competition'
export { IContributionRewardExt, IProposalCreateOptionsContributionRewardExt } from './schemes/contributionRewardExt'
export { IGenericScheme } from './schemes/genericScheme'
export { IUGenericScheme } from './schemes/uGenericScheme'
Expand Down
6 changes: 3 additions & 3 deletions src/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Operation, toIOperationObservable } from './operation'
import { IQueueState } from './queue'
import { IRewardQueryOptions, Reward } from './reward'
import { ISchemeState, Scheme } from './scheme'
import { ICompetitionProposal, IProposalCreateOptionsCompetition } from './schemes/competition'
import { ICompetitionProposalState, IProposalCreateOptionsCompetition } from './schemes/competition'
import * as ContributionReward from './schemes/contributionReward'
import * as ContributionRewardExt from './schemes/contributionRewardExt'
import * as GenericScheme from './schemes/genericScheme'
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface IProposalState extends IProposalStaticState {
accountsWithUnclaimedRewards: Address[],
boostedAt: Date
contributionReward: ContributionReward.IContributionReward|null
competition: ICompetitionProposal|null
competition: ICompetitionProposalState|null
confidenceThreshold: number
closingAt: Date
createdAt: Date
Expand Down Expand Up @@ -391,7 +391,7 @@ export class Proposal implements IStateful<IProposalState> {
}

let contributionReward: ContributionReward.IContributionReward|null = null
let competition: ICompetitionProposal|null = null
let competition: ICompetitionProposalState|null = null
let type: IProposalType
let genericScheme: GenericScheme.IGenericScheme|null = null
let schemeRegistrar: SchemeRegistrar.ISchemeRegistrar|null = null
Expand Down
43 changes: 25 additions & 18 deletions src/schemes/competition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ISchemeState, SchemeBase } from './base'

const Web3 = require('web3')

export interface ICompetitionProposal {
export interface ICompetitionProposalState {
id: string
contract: Address
endTime: Date
Expand Down Expand Up @@ -49,7 +49,7 @@ export interface IProposalCreateOptionsCompetition extends IProposalBaseCreateOp
votingStartTime: Date,
}

export interface ICompetitionSuggestion {
export interface ICompetitionSuggestionState {
id: string
suggestionId: number
proposal: string
Expand All @@ -66,9 +66,10 @@ export interface ICompetitionSuggestion {
redeemedAt: Date|null
rewardPercentage: number
positionInWinnerList: number|null // 0 is the first, null means it is not winning
isWinner: boolean
}

export interface ICompetitionVote {
export interface ICompetitionVoteState {
id?: string
// proposal: CompetitionProposal!
// suggestion: CompetitionSuggestion!
Expand Down Expand Up @@ -552,7 +553,9 @@ export class CompetitionSuggestion {
apolloQueryOptions: IApolloQueryOptions = {}
): Observable<CompetitionSuggestion[]> {

const itemMap = (item: any) => this.mapItemToObject(item, context)
const itemMap = (item: any) => {
return new CompetitionSuggestion(this.mapItemToObject(item, context) as ICompetitionSuggestionState, context)
}

const query = gql`query CompetitionSuggestionSearch
{
Expand All @@ -570,7 +573,7 @@ export class CompetitionSuggestion {
) as Observable<CompetitionSuggestion[]>
}

private static mapItemToObject(item: any, context: Arc): ICompetitionSuggestion|null {
private static mapItemToObject(item: any, context: Arc): ICompetitionSuggestionState|null {
if (item === null) {
return null
}
Expand All @@ -583,11 +586,12 @@ export class CompetitionSuggestion {
if (item.positionInWinnerList !== null) {
positionInWinnerList = Number(item.positionInWinnerList)
}
return {
return {
createdAt: secondSinceEpochToDate(item.createdAt),
description: item.description,
descriptionHash: item.descriptionHash,
id: item.id,
isWinner: positionInWinnerList !== null,
positionInWinnerList,
proposal: item.proposal.id,
redeemedAt,
Expand All @@ -604,9 +608,12 @@ export class CompetitionSuggestion {

public id: string
public suggestionId?: number
public staticState?: ICompetitionSuggestion
public staticState?: ICompetitionSuggestionState

constructor(idOrOpts: string|{ suggestionId: number, scheme: string}|ICompetitionSuggestion, public context: Arc) {
constructor(
idOrOpts: string|{ suggestionId: number, scheme: string}|ICompetitionSuggestionState,
public context: Arc
) {
if (typeof idOrOpts === 'string') {
this.id = idOrOpts
} else {
Expand All @@ -617,22 +624,22 @@ export class CompetitionSuggestion {
this.id = CompetitionSuggestion.calculateId(idOrOpts as { suggestionId: number, scheme: string})
this.suggestionId = idOrOpts.suggestionId
} else {
const opts = idOrOpts as ICompetitionSuggestion
const opts = idOrOpts as ICompetitionSuggestionState
this.id = opts.id
this.setStaticState(opts)
}
}
}

public setStaticState(opts: ICompetitionSuggestion) {
public setStaticState(opts: ICompetitionSuggestionState) {
this.staticState = opts
}

public async fetchStaticState(): Promise<ICompetitionSuggestion> {
public async fetchStaticState(): Promise<ICompetitionSuggestionState> {
return this.state({ fetchPolicy: 'cache-first'}).pipe(first()).toPromise()
}

public state(apolloQueryOptions: IApolloQueryOptions = {}): Observable<ICompetitionSuggestion> {
public state(apolloQueryOptions: IApolloQueryOptions = {}): Observable<ICompetitionSuggestionState> {
const query = gql`query SchemeState
{
competitionSuggestion (id: "${this.id}") {
Expand Down Expand Up @@ -674,8 +681,8 @@ export class CompetitionSuggestion {

public async isWinner() {
console.warn(`This method is deprecated - please use the positionInWinnerList !== from the proposal state`)
const position = await this.getPosition()
return position !== null
const suggestionState = await this.state().pipe(first()).toPromise()
return suggestionState.isWinner
}

public redeem(beneficiary: Address = NULL_ADDRESS): Operation<boolean> {
Expand Down Expand Up @@ -742,19 +749,19 @@ export class CompetitionVote {
) as Observable<CompetitionVote[]>
}
public id?: string
public staticState?: ICompetitionVote
public staticState?: ICompetitionVoteState

constructor(idOrOpts: string|ICompetitionVote, public context: Arc) {
constructor(idOrOpts: string|ICompetitionVoteState, public context: Arc) {
if (typeof idOrOpts === 'string') {
this.id = idOrOpts
} else {
const opts = idOrOpts as ICompetitionVote
const opts = idOrOpts as ICompetitionVoteState
// this.id = opts.id
this.setStaticState(opts)
}
}

public setStaticState(opts: ICompetitionVote) {
public setStaticState(opts: ICompetitionVoteState) {
this.staticState = opts
}
}
Expand Down
Loading