Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
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
2 changes: 2 additions & 0 deletions src/constants/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const MISSING_PARAMETERS = name => `Missing required parameter: ${name}`
export const PROFILE_NOT_FOUND = user => `No profile found for user: ${user}.`
export const NOTIFICATION_NOT_FOUND = txHash =>
`No notification with txHash ${txHash} exists.`
export const REQUEST_FAILED = error =>
`Request returned an error response: ${error}`

// Contracts
export const UNABLE_TO_DEPLOY_CONTRACT =
Expand Down
5 changes: 2 additions & 3 deletions src/contracts/abstractions/Arbitrable.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ArbitrableContract extends AbstractContract {
...args
)

await this._StoreProvider.updateContract(
const newContract = await this._StoreProvider.updateContract(
account,
contractInstance.address,
{
Expand All @@ -62,8 +62,7 @@ class ArbitrableContract extends AbstractContract {
}
)

// return contract data
return this.getData(contractInstance.address, account)
return newContract
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/contracts/implementations/arbitrator/KlerosPOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class KlerosPOC extends ContractImplementation {
/**
* Call contract to move on to the next period.
* @param {string} account - address of user.
* @returns {Promise} - resulting object.
*/
passPeriod = async (account = this._Web3Wrapper.getAccount(0)) => {
await this.loadContract()
Expand All @@ -171,6 +172,7 @@ class KlerosPOC extends ContractImplementation {
from: account,
gas: ethConstants.TRANSACTION.GAS
})
return this.getData()
} catch (err) {
console.error(err)
throw new Error(errorConstants.UNABLE_TO_PASS_PERIOD)
Expand Down
21 changes: 17 additions & 4 deletions src/resources/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class Disputes {
* @param {string} account - The users eth account.
*/
_storeDisputeRuledAtTimestamp = async (event, account) => {
const newPeriod = event.args._period.toNumber()
// we fetch the current period in case we are consuming old events from previous sessions
const newPeriod = await this._ArbitratorInstance.getPeriod()
// send appeal possible notifications
if (newPeriod === arbitratorConstants.PERIOD.APPEAL) {
const disputes = await this._StoreProviderInstance.getDisputesForUser(
Expand Down Expand Up @@ -202,11 +203,12 @@ class Disputes {

/**
* Event listener handler that sets the deadline for an appeal
* @param {object} event - The event log.
* @param {object} _ - The event log. Unused in function.
* @param {string} account - The users eth account.
*/
_storeAppealDeadline = async (event, account) => {
const newPeriod = event.args._period.toNumber()
_storeAppealDeadline = async (_, account) => {
// we fetch the current period in case we are consuming old events from previous sessions
const newPeriod = await this._ArbitratorInstance.getPeriod()
// send appeal possible notifications
if (newPeriod === arbitratorConstants.PERIOD.VOTE) {
const disputes = await this._StoreProviderInstance.getDisputesForUser(
Expand Down Expand Up @@ -246,6 +248,17 @@ class Disputes {
// **************************** //
// * Public * //
// **************************** //
/**
* Fetch the shared dispute data from the store.
* @param {string} disputeId - The index of the dispute.
* @returns {Promise} The dispute data in the store.
*/
getDisputeFromStore = disputeId => {
const arbitratorAddress = this._ArbitratorInstance.getContractAddress()

return this._StoreProviderInstance.getDispute(arbitratorAddress, disputeId)
}

/**
* Get data for a dispute. This method provides data from the store as well as both
* arbitrator and arbitrable contracts. Used to get all relevant data on a dispute.
Expand Down
25 changes: 16 additions & 9 deletions src/resources/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,14 @@ class Notifications {
this._requireStoreProvider()

const profile = await this._StoreProviderInstance.getUserProfile(account)
return _.filter(profile.notifications, notification => !notification.read)
const currentArbitrator = this._ArbitratorInstance.getContractAddress()
// return notifications that are for current arbitrator and are unread
return _.filter(
profile.notifications,
notification =>
notification.data.arbitratorAddress === currentArbitrator &&
!notification.read
)
}

/**
Expand All @@ -246,15 +253,15 @@ class Notifications {
* @param {number} logIndex index of the log. used to differentiate logs if multiple logs per tx
* @returns {promise} promise that can be waited on for syncronousity
*/
markStoredNotificationAsRead = (account, txHash, logIndex) => {
markStoredNotificationAsRead = async (account, txHash, logIndex) => {
this._requireStoreProvider()

return this._StoreProviderInstance.markNotificationAsRead(
const result = await this._StoreProviderInstance.markNotificationAsRead(
account,
txHash,
logIndex,
true
)
return result
}

/**
Expand Down Expand Up @@ -286,7 +293,7 @@ class Notifications {
if (newPeriod === arbitratorConstants.PERIOD.APPEAL) {
const disputes = await this._getDisputes(account) // get users disputes
const openDisputes = await this._ArbitratorInstance.getOpenDisputesForSession() // get all disputes for session
const contractAddress = this._ArbitratorInstance.getContractAddress()
const arbitratorAddress = this._ArbitratorInstance.getContractAddress()

await Promise.all(
openDisputes.map(async disputeId => {
Expand All @@ -295,7 +302,7 @@ class Notifications {
disputes,
dispute =>
dispute.disputeId === disputeId &&
dispute.arbitratorAddress === contractAddress
dispute.arbitratorAddress === arbitratorAddress
) >= 0
) {
const dispute = await this._ArbitratorInstance.getDispute(disputeId)
Expand All @@ -311,8 +318,8 @@ class Notifications {
notificationConstants.TYPE.APPEAL_POSSIBLE,
'A ruling has been made. Appeal is possible',
{
disputeId,
contractAddress,
disputeId: disputeId,
arbitratorAddress,
ruling
}
)
Expand Down Expand Up @@ -619,7 +626,7 @@ class Notifications {

// If we have store provider fetch contracts and disputes from the store.
if (this._StoreProviderInstance) {
await this._StoreProviderInstance.getDisputesForUser(account)
disputes = await this._StoreProviderInstance.getDisputesForUser(account)
} else if (isJuror) {
// We have no way to get contracts. Get disputes from current session
// TODO make a function to get open disputes for parites
Expand Down
31 changes: 21 additions & 10 deletions src/utils/StoreProviderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class StoreProviderWrapper {
* @param {object} params - Params we want to update.
* @returns {Promise} - The resulting contract data.
*/
updateContract = (userAddress, contractAddress, params) => {
updateContract = async (userAddress, contractAddress, params) => {
const getBodyFn = async () => {
let currentContractData = await this.getContractByAddress(
userAddress,
Expand All @@ -259,11 +259,20 @@ class StoreProviderWrapper {
return JSON.stringify({ ...currentContractData, ...params })
}

return this.queueWriteRequest(
const httpResponse = await this.queueWriteRequest(
getBodyFn,
'POST',
`${this._storeUri}/${userAddress}/contracts/${contractAddress}`
)

if (httpResponse.status !== 200) {
throw new Error(errorConstants.REQUEST_FAILED(httpResponse.error))
}

return _.filter(
httpResponse.body[0].contracts,
contract => contract.address === contractAddress
)[0]
}

/**
Expand Down Expand Up @@ -322,14 +331,14 @@ class StoreProviderWrapper {
const getBodyFn = async () => {
const userProfile = await this.getUserProfile(userAddress)

const disputeIndex = _.filter(
userProfile.disputes,
dispute =>
dispute.arbitratorAddress === arbitratorAddress &&
dispute.disputeId === disputeId
)
const currentDisputeProfile =
_.filter(
userProfile.disputes,
dispute =>
dispute.arbitratorAddress === arbitratorAddress &&
dispute.disputeId === disputeId
)[0] || {}

const currentDisputeProfile = userProfile.disputes[disputeIndex] || {}
delete currentDisputeProfile._id
// set these so if it is a new dispute they are included
params.disputeId = disputeId
Expand Down Expand Up @@ -446,11 +455,13 @@ class StoreProviderWrapper {
return JSON.stringify(userProfile)
}

return this.queueWriteRequest(
const result = await this.queueWriteRequest(
getBodyFn,
'POST',
`${this._storeUri}/${userAddress}`
)

return result.body.notifications
}
}

Expand Down