diff --git a/contracts/teller-network/Arbitration.sol b/contracts/teller-network/Arbitration.sol index 18ee62af..e768cc78 100644 --- a/contracts/teller-network/Arbitration.sol +++ b/contracts/teller-network/Arbitration.sol @@ -21,8 +21,6 @@ contract Arbitration is Ownable, License { event ArbitrationResolved(uint escrowId, ArbitrationResult result, address arbitrator, uint date); enum ArbitrationResult {UNSOLVED, BUYER, SELLER} - - address public arbitrator; Arbitrable public escrow; diff --git a/src/js/features/arbitration/actions.js b/src/js/features/arbitration/actions.js index 711ebd4a..e0a38480 100644 --- a/src/js/features/arbitration/actions.js +++ b/src/js/features/arbitration/actions.js @@ -1,4 +1,4 @@ -import {ARBITRATION_UNSOLVED, GET_DISPUTED_ESCROWS, RESOLVE_DISPUTE, RESOLVE_DISPUTE_FAILED, LOAD_ARBITRATION} from './constants'; +import {ARBITRATION_UNSOLVED, GET_DISPUTED_ESCROWS, RESOLVE_DISPUTE, RESOLVE_DISPUTE_FAILED, LOAD_ARBITRATION, GET_ARBITRATORS} from './constants'; import Escrow from '../../../embarkArtifacts/contracts/Escrow'; export const getDisputedEscrows = () => ({type: GET_DISPUTED_ESCROWS}); @@ -20,3 +20,5 @@ export const resolveDispute = (escrowId, result) => { export const loadArbitration = (escrowId) => { return {type: LOAD_ARBITRATION, escrowId}; }; + +export const getArbitrators = () => ({type: GET_ARBITRATORS}); diff --git a/src/js/features/arbitration/constants.js b/src/js/features/arbitration/constants.js index e84c6272..491e9605 100644 --- a/src/js/features/arbitration/constants.js +++ b/src/js/features/arbitration/constants.js @@ -15,3 +15,6 @@ export const LOAD_ARBITRATION = 'LOAD_ARBITRATION'; export const LOAD_ARBITRATION_SUCCEEDED = 'LOAD_ARBITRATION_SUCCEEDED'; export const LOAD_ARBITRATION_FAILED = 'LOAD_ARBITRATION_FAILED'; +export const GET_ARBITRATORS = 'GET_ARBITRATORS'; +export const GET_ARBITRATORS_SUCCEEDED = 'GET_ARBITRATORS_SUCCEEDED'; +export const GET_ARBITRATORS_FAILED = 'GET_ARBITRATORS_FAILED'; diff --git a/src/js/features/arbitration/reducer.js b/src/js/features/arbitration/reducer.js index df4b326c..4b1efe4a 100644 --- a/src/js/features/arbitration/reducer.js +++ b/src/js/features/arbitration/reducer.js @@ -6,10 +6,12 @@ import { RESOLVE_DISPUTE_PRE_SUCCESS, RESOLVE_DISPUTE_SUCCEEDED, RESOLVE_DISPUTE_FAILED, - LOAD_ARBITRATION_SUCCEEDED + LOAD_ARBITRATION_SUCCEEDED, + GET_ARBITRATORS_FAILED, + GET_ARBITRATORS_SUCCEEDED } from './constants'; -const DEFAULT_STATE = {escrows: [], arbitration: null}; +const DEFAULT_STATE = {escrows: [], arbitration: null, arbitrators: []}; function reducer(state = DEFAULT_STATE, action) { let escrows = state.escrows; @@ -35,6 +37,7 @@ function reducer(state = DEFAULT_STATE, action) { }; case GET_DISPUTED_ESCROWS_FAILED: case RESOLVE_DISPUTE_FAILED: + case GET_ARBITRATORS_FAILED: return { ...state, ...{ errorGet: action.error, @@ -60,6 +63,11 @@ function reducer(state = DEFAULT_STATE, action) { ...state, arbitration: action.escrow }; + case GET_ARBITRATORS_SUCCEEDED: + return { + ...state, + arbitrators: action.arbitrators + }; default: return state; } diff --git a/src/js/features/arbitration/saga.js b/src/js/features/arbitration/saga.js index cdd45784..37669bc0 100644 --- a/src/js/features/arbitration/saga.js +++ b/src/js/features/arbitration/saga.js @@ -1,21 +1,38 @@ import Escrow from '../../../embarkArtifacts/contracts/Escrow'; import Arbitration from '../../../embarkArtifacts/contracts/Arbitration'; import MetadataStore from '../../../embarkArtifacts/contracts/MetadataStore'; - import moment from 'moment'; import {fork, takeEvery, call, put} from 'redux-saga/effects'; import { GET_DISPUTED_ESCROWS, GET_DISPUTED_ESCROWS_FAILED, GET_DISPUTED_ESCROWS_SUCCEEDED, RESOLVE_DISPUTE, RESOLVE_DISPUTE_FAILED, RESOLVE_DISPUTE_SUCCEEDED, - RESOLVE_DISPUTE_PRE_SUCCESS, LOAD_ARBITRATION, LOAD_ARBITRATION_FAILED, LOAD_ARBITRATION_SUCCEEDED + RESOLVE_DISPUTE_PRE_SUCCESS, LOAD_ARBITRATION, LOAD_ARBITRATION_FAILED, LOAD_ARBITRATION_SUCCEEDED, GET_ARBITRATORS, + GET_ARBITRATORS_SUCCEEDED, GET_ARBITRATORS_FAILED } from './constants'; import {doTransaction} from "../../utils/saga"; +window.Arbitration = Arbitration; + + export function *onResolveDispute() { yield takeEvery(RESOLVE_DISPUTE, doTransaction.bind(null, RESOLVE_DISPUTE_PRE_SUCCESS, RESOLVE_DISPUTE_SUCCEEDED, RESOLVE_DISPUTE_FAILED)); } +export function *doGetArbitrators() { + try { + const cnt = yield call(Arbitration.methods.getNumLicenseOwners().call); + const arbitrators = []; + for(let i = 0; i < cnt; i++){ + arbitrators.push(yield call(Arbitration.methods.licenseOwners(i).call)); + } + yield put({type: GET_ARBITRATORS_SUCCEEDED, arbitrators}); + } catch (error) { + console.error(error); + yield put({type: GET_ARBITRATORS_FAILED, error: error.message}); + } +} + export function *doGetEscrows() { try { const events = yield Arbitration.getPastEvents('ArbitrationRequired', {fromBlock: 1}); @@ -48,6 +65,10 @@ export function *doGetEscrows() { } } +export function *onGetArbitrators() { + yield takeEvery(GET_ARBITRATORS, doGetArbitrators); +} + export function *onGetEscrows() { yield takeEvery(GET_DISPUTED_ESCROWS, doGetEscrows); } @@ -82,4 +103,4 @@ export function *onLoadArbitration() { yield takeEvery(LOAD_ARBITRATION, doLoadArbitration); } -export default [fork(onGetEscrows), fork(onResolveDispute), fork(onLoadArbitration)]; +export default [fork(onGetEscrows), fork(onResolveDispute), fork(onLoadArbitration), fork(onGetArbitrators)]; diff --git a/src/js/features/arbitration/selectors.js b/src/js/features/arbitration/selectors.js index 5dd1c32a..fb157fe0 100644 --- a/src/js/features/arbitration/selectors.js +++ b/src/js/features/arbitration/selectors.js @@ -6,6 +6,7 @@ export const escrows = state => state.arbitration.escrows; export const errorGet = state => state.arbitration.errorGet; export const loading = state => state.arbitration.loading; export const txHash = state => state.arbitration.txHash; +export const arbitrators = state => state.arbitration.arbitrators; export const getArbitration = (state) => { const arbitration = state.arbitration.arbitration; diff --git a/src/js/pages/MyProfile/index.jsx b/src/js/pages/MyProfile/index.jsx index 7c03ffb1..b31b6d74 100644 --- a/src/js/pages/MyProfile/index.jsx +++ b/src/js/pages/MyProfile/index.jsx @@ -27,6 +27,7 @@ class MyProfile extends Component { componentDidMount() { this.props.loadProfile(this.props.address); this.props.getDisputedEscrows(); + this.props.getArbitrators(); } render() { @@ -56,7 +57,9 @@ MyProfile.propTypes = { trades: PropTypes.array, disputes: PropTypes.array, loadProfile: PropTypes.func, - getDisputedEscrows: PropTypes.func + getDisputedEscrows: PropTypes.func, + getArbitrators: PropTypes.func, + arbitrators: PropTypes.array }; const mapStateToProps = state => { @@ -66,7 +69,8 @@ const mapStateToProps = state => { address, profile, trades: escrow.selectors.getTrades(state, address, profile.offers.map(offer => offer.id)), - disputes: arbitration.selectors.escrows(state) + disputes: arbitration.selectors.escrows(state), + arbitrators: arbitration.selectors.arbitrators(state) }; }; @@ -75,5 +79,6 @@ export default connect( mapStateToProps, { loadProfile: metadata.actions.load, - getDisputedEscrows: arbitration.actions.getDisputedEscrows + getDisputedEscrows: arbitration.actions.getDisputedEscrows, + getArbitrators: arbitration.actions.getArbitrators })(MyProfile); diff --git a/test/metadata_store_spec.js b/test/metadata_store_spec.js index f9b4f956..8577951b 100644 --- a/test/metadata_store_spec.js +++ b/test/metadata_store_spec.js @@ -1,7 +1,5 @@ /*global contract, config, it, assert, before*/ -const TestUtils = require("../utils/testUtils"); - const License = require('Embark/contracts/License'); const SNT = require('Embark/contracts/SNT'); const MetadataStore = require('Embark/contracts/MetadataStore');