import { QueryResult } from '@aragon/connect-thegraph' ; import Vote from '../../models/Vote' ; import { VoteData } from '../../types' ; function buildVote ( vote , connector , provider ) { const { id , voting , voteId , creator , originalCreator , context , status , actionId , challengeId , challenger , challengeEndDate , disputeId , setting , startDate , totalPower , snapshotBlock , yeas , nays , pausedAt , pauseDuration , quietEndingExtensionDuration , quietEndingSnapshotSupport , script , settledAt , disputedAt , executedAt , isAccepted , settlementOffer , collateralRequirement , submitterArbitratorFee , challengerArbitratorFee , } = vote ; const voteData = { id , votingId : voting . id , voteId , creator , originalCreator , duration : setting . voteTime , quietEndingExtension : setting . quietEndingExtension , context , status , actionId , challengeId , challenger , challengeEndDate , disputeId , settingId : setting . id , startDate , totalPower , snapshotBlock , yeas , nays , pausedAt , pauseDuration , quietEndingExtensionDuration , quietEndingSnapshotSupport , script , settledAt , disputedAt , executedAt , isAccepted , tokenId : voting . token . id , tokenSymbol : voting . token . symbol , tokenDecimals : voting . token . decimals , settlementOffer , collateralRequirementId : collateralRequirement . id , collateralTokenId : collateralRequirement . token . id , collateralTokenSymbol : collateralRequirement . token . symbol , collateralTokenDecimals : collateralRequirement . token . decimals , submitterArbitratorFeeId : submitterArbitratorFee ? submitterArbitratorFee . id : null , challengerArbitratorFeeId : challengerArbitratorFee ? challengerArbitratorFee . id : null } ; return new Vote ( voteData , connector , provider ) ; } export function parseVote ( result , connector , provider ) { const vote = result . data . vote ; if ( ! vote ) { throw new Error ( 'Unable to parse vote.' ) ; } return buildVote ( vote , connector , provider ) ; } export function parseVotes ( result , connector , provider ) { const votes = result . data . votes ; if ( ! votes ) { throw new Error ( 'Unable to parse votes.' ) ; } return votes . map ( ( vote ) => buildVote ( vote , connector , provider ) ) ; }