feat: obtain arbitrator list

This commit is contained in:
Richard Ramos 2019-04-30 11:47:05 -04:00
parent 5f45b1c894
commit e4dd499835
8 changed files with 49 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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