Skip to content
Permalink
Browse files

fix: bug fixes while updating UI

  • Loading branch information...
satello committed Apr 18, 2018
1 parent 3971422 commit f4c7d7ccd4396de29db08799544296fef9acd4e1
@@ -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
@@ -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
)

@@ -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)
)
)

@@ -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 => {
@@ -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 [
@@ -303,7 +302,7 @@ class ArbitrableTransaction extends ContractImplementation {
])

return {
address,
address: this.getContractAddress(),
arbitrator,
extraData,
timeout: timeout.toNumber(),
@@ -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

@@ -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

@@ -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
)
@@ -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

@@ -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)

0 comments on commit f4c7d7c

Please sign in to comment.
You can’t perform that action at this time.