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

Commit

Permalink
fix: bug fixes while updating UI
Browse files Browse the repository at this point in the history
  • Loading branch information
satello committed Apr 18, 2018
1 parent 3971422 commit f4c7d7c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
13 changes: 13 additions & 0 deletions src/contracts/ContractImplementation.js
Expand Up @@ -43,6 +43,19 @@ class ContractImplementation {
return newLoadingPromise
}

/**
* Get the web3 provider object from the initialized web3 instance
* @returns {object} web3 provider object
*/
getWeb3Provider = () => this._Web3Wrapper.getProvider()

/**
* MetaMask safe get block data by blockNumber
* @param {Int} blockNumber - Block number
* @returns {Promise} block object
*/
getBlock = async blockNumber => this._Web3Wrapper.getBlock(blockNumber)

/**
* Set a new contract instance
* @param {string} contractAddress - The address of the contract
Expand Down
3 changes: 2 additions & 1 deletion src/contracts/abstractions/Arbitrable.js
Expand Up @@ -35,14 +35,15 @@ class ArbitrableContract extends AbstractContract {
description = '',
...args
) => {
const contractInstance = await this._contractImplementation.deploy(
const contractInstance = await this._contractImplementation.constructor.deploy(
account,
value,
hashContract,
arbitratorAddress,
timeout,
partyB,
arbitratorExtraData,
this._contractImplementation.getWeb3Provider(),
...args
)

Expand Down
7 changes: 2 additions & 5 deletions src/contracts/abstractions/Arbitrator.js
Expand Up @@ -25,11 +25,7 @@ class Arbitrator extends AbstractContract {
const _getDisputesForUserFromStore = async account =>
Promise.all(
(await this._StoreProvider.getDisputesForUser(account)).map(dispute =>
this._contractImplementation.getDispute(
dispute.arbitratorAddress,
dispute.disputeId,
account
)
this._contractImplementation.getDispute(dispute.disputeId, account)
)
)

Expand All @@ -44,6 +40,7 @@ class Arbitrator extends AbstractContract {
const myDisputes = await this._contractImplementation.getDisputesForJuror(
account
)

// update user profile for each dispute
await Promise.all(
myDisputes.map(async dispute => {
Expand Down
Expand Up @@ -267,10 +267,9 @@ class ArbitrableTransaction extends ContractImplementation {

/**
* Data of the contract
* @param {string} address Address of the ArbitrableTransaction contract.
* @returns {object} Object Data of the contract.
*/
getData = async address => {
getData = async () => {
await this.loadContract()

const [
Expand Down Expand Up @@ -303,7 +302,7 @@ class ArbitrableTransaction extends ContractImplementation {
])

return {
address,
address: this.getContractAddress(),
arbitrator,
extraData,
timeout: timeout.toNumber(),
Expand Down
31 changes: 12 additions & 19 deletions src/resources/Disputes.js
Expand Up @@ -73,30 +73,32 @@ class Disputes {
/**
* Event listener handler that stores dispute in store upon creation
* @param {string} event - The event log.
* @param {string} account - Account of user to update store data for
*/
_storeNewDisputeHandler = async event => {
_storeNewDisputeHandler = async (event, account) => {
// There is no need to handle this event if we are not using the store
const disputeId = event.args._disputeID.toNumber()

const contractAddress = this._ArbitratorInstance.getContractAddress()
const existingDispute = (await this._StoreProviderInstance.getDispute(
const existingDispute = await this._StoreProviderInstance.getDispute(
contractAddress,
disputeId
)).body
)

// Add dispute to store if not there
if (_.isNull(existingDispute)) {
// arbitrator data
const disputeData = await this._ArbitratorInstance.getDispute(disputeId)
const disputeData = await this.getDataForDispute(disputeId, account)
// arbitrable contract data
await this._ArbitrableInstance.setContractInstance(
disputeData.arbitrableContractAddress
)
const arbitrableContractData = await this._ArbitrableInstance.getData()
// timestamp
const blockTimestamp = this._ArbitratorInstance._Web3Wrapper.getBlock(
const blockTimestamp = (await this._ArbitratorInstance.getBlock(
event.blockNumber
).timestamp
)).timestamp

const appealCreatedAt = disputeData.appealCreatedAt
appealCreatedAt[disputeData.numberOfAppeals] = blockTimestamp * 1000

Expand Down Expand Up @@ -177,15 +179,11 @@ class Disputes {
) {
// get ruledAt from block timestamp
const blockNumber = event.blockNumber
const blockTimestamp = this._ArbitratorInstance._Web3Wrapper.getBlock(
const blockTimestamp = (await this._ArbitratorInstance.getBlock(
blockNumber
).timestamp
)).timestamp

const disputeData = await this.getDataForDispute(
contractAddress,
disputeId,
account
)
const disputeData = await this.getDataForDispute(disputeId, account)
const appealRuledAt = disputeData.appealRuledAt
appealRuledAt[disputeData.numberOfAppeals] = blockTimestamp * 1000

Expand All @@ -211,7 +209,6 @@ class Disputes {
const newPeriod = event.args._period.toNumber()
// send appeal possible notifications
if (newPeriod === arbitratorConstants.PERIOD.VOTE) {
this._checkArbitratorWrappersSet()
const disputes = await this._StoreProviderInstance.getDisputesForUser(
account
)
Expand All @@ -229,11 +226,7 @@ class Disputes {
) >= 0
) {
const deadline = await this._ArbitratorInstance.getDeadlineForOpenDispute()
const disputeData = await this.getDataForDispute(
contractAddress,
disputeId,
account
)
const disputeData = await this.getDataForDispute(disputeId, account)
const appealDeadlines = disputeData.appealDeadlines
appealDeadlines[disputeData.numberOfAppeals] = deadline

Expand Down
9 changes: 8 additions & 1 deletion src/utils/Web3Wrapper.js
Expand Up @@ -32,7 +32,14 @@ class Web3Wrapper {

blockNumber = () => this._web3.eth.blockNumber

getBlock = blockNumber => this._web3.eth.getBlock(blockNumber)
getBlock = blockNumber =>
new Promise((resolve, reject) => {
this._web3.eth.getBlock(blockNumber, (error, result) => {
if (error) reject(error)

resolve(result)
})
})

doesContractExistAtAddressAsync = async address => {
const code = await this._web3.eth.getCode(address)
Expand Down

0 comments on commit f4c7d7c

Please sign in to comment.