Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
fix(arbitrable): return new contract from deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
satello committed May 8, 2018
1 parent b581186 commit 26ea105
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
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
27 changes: 18 additions & 9 deletions src/utils/StoreProviderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,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 @@ -256,11 +256,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 !== 201) {
throw new Error(errorConstants.REQUEST_FAILED(httpResponse.error))
}

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

/**
Expand Down Expand Up @@ -319,14 +328,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

0 comments on commit 26ea105

Please sign in to comment.