diff --git a/src/abstractWrappers/Disputes.js b/src/abstractWrappers/Disputes.js index 29faf48..a6158f7 100644 --- a/src/abstractWrappers/Disputes.js +++ b/src/abstractWrappers/Disputes.js @@ -516,15 +516,17 @@ class Disputes extends AbstractWrapper { arbitrableContractAddress ) - let votes = [] let isJuror = false + let votes = [] let hasRuled = false + let netPNK = 0 if (account) { votes = await this.getVotesForJuror(arbitratorAddress, disputeId, account) try { const userData = await this.getUserDisputeFromStore(arbitratorAddress, disputeId, account) isJuror = userData.isJuror hasRuled = userData.hasRuled + netPNK = userData.netPNK || 0 } catch (e) { isJuror = false hasRuled = false @@ -544,31 +546,31 @@ class Disputes extends AbstractWrapper { // Arbitrable Contract Data // FIXME hash not being stored in contract atm hash: arbitrableContractAddress, - arbitrableContractAddress: arbitrableContractAddress, + arbitrableContractAddress, arbitrableContractStatus: arbitrableContractData.status, - arbitratorAddress: arbitratorAddress, + arbitratorAddress, partyA: arbitrableContractData.partyA, partyB: arbitrableContractData.partyB, // Dispute Data - disputeId: disputeId, + disputeId, session: dispute.firstSession + dispute.numberOfAppeals, numberOfAppeals: dispute.numberOfAppeals, fee: dispute.arbitrationFeePerJuror, - deadline: deadline, + deadline, disputeState: dispute.state, disputeStatus: dispute.status, voteCounters: dispute.voteCounters, - PNKRepartitions: dispute.PNKRepartitions, // Store Data description: constractStoreData ? constractStoreData.description : undefined, email: constractStoreData ? constractStoreData.email : undefined, - evidence: evidence, - isJuror: isJuror, - votes: votes, - hasRuled: hasRuled, - ruling: ruling, + evidence, + isJuror, + votes, + hasRuled, + ruling, + netPNK }) } } diff --git a/src/contractWrappers/KlerosWrapper.js b/src/contractWrappers/KlerosWrapper.js index e0029e4..4e19628 100644 --- a/src/contractWrappers/KlerosWrapper.js +++ b/src/contractWrappers/KlerosWrapper.js @@ -374,23 +374,24 @@ class KlerosWrapper extends ContractWrapper { const contractInstance = await this.load(contractAddress) try { const dispute = await contractInstance.disputes(disputeId) - const numberOfAppeals = dispute[2].toNumber() const rulingChoices = dispute[3].toNumber() - const voteCounters = [] - const PNKRepartitions = [] + let voteCounters = [] + let status for (let appeal = 0; appeal <= numberOfAppeals; appeal++) { const counter = [] - const repartition = [] - for (let choice = 0; choice <= rulingChoices; choice++) { - counter.push(contractInstance.getVoteCount(disputeId, appeal, choice)) - repartition.push(contractInstance.repartitionedPNK(disputeId, appeal, choice)) - } + for (let choice = 0; choice <= rulingChoices; choice++) + counter.push(contractInstance.getVoteCount(disputeId, appeal, choice).then(v => v.toNumber())) voteCounters.push(counter) - PNKRepartitions.push(repartition) } - + [voteCounters, status] = await Promise.all( + [ + Promise.all(voteCounters.map(counter => Promise.all(counter))), + contractInstance.disputeStatus(disputeId) + ] + ) + return { arbitratedContract: dispute[0], firstSession: dispute[1].toNumber(), @@ -400,8 +401,7 @@ class KlerosWrapper extends ContractWrapper { arbitrationFeePerJuror: this._Web3Wrapper.fromWei(dispute[5], 'ether'), state: dispute[6].toNumber(), voteCounters, - PNKRepartitions, - status: (await contractInstance.disputeStatus(disputeId)).toNumber() + status: status.toNumber() } } catch (e) { throw new Error(e) diff --git a/src/test/kleros.test.js b/src/test/kleros.test.js index 3fe9508..1827cdc 100644 --- a/src/test/kleros.test.js +++ b/src/test/kleros.test.js @@ -436,6 +436,7 @@ describe('Kleros', () => { expect(dispute.arbitratedContract).toEqual(contractArbitrableTransactionData.address) expect(dispute.firstSession).toEqual((await klerosPOCInstance.session()).toNumber()) expect(dispute.numberOfAppeals).toEqual(0) + expect(dispute.voteCounters).toEqual(Array(dispute.numberOfAppeals + 1).fill(Array(dispute.rulingChoices + 1).fill(0))) // check fetch resolution options const resolutionOptions = await KlerosInstance.disputes.getRulingOptions(klerosCourt.address, 0) @@ -498,6 +499,7 @@ describe('Kleros', () => { expect(disputesForJuror[0].deadline).toBe(1000 * (newState.lastPeriodChange + (await klerosPOCInstance.timePerPeriod(newState.period)).toNumber())) expect(disputesForJuror[0].arbitrableContractAddress).toEqual(contractArbitrableTransactionData.address) expect(disputesForJuror[0].votes).toEqual([1,2,3]) + expect(disputesForJuror[0].netPNK).toBe(0) // stateful notifications juror jurorStatefullNotifications = await KlerosInstance.notifications.getStatefulNotifications(juror, true)