add Meritocracy service and get contributors from IPFS
This commit is contained in:
parent
f6b500b33a
commit
610c1b2542
|
@ -6,21 +6,19 @@ import Select from 'react-select';
|
|||
|
||||
import Meritocracy from 'Embark/contracts/Meritocracy';
|
||||
|
||||
import {getContributorList} from '../services/Meritocracy';
|
||||
|
||||
/*
|
||||
TODO:
|
||||
- list praise for contributor
|
||||
- listen to events to update UI, (initially on page load but within function calls)
|
||||
*/
|
||||
|
||||
// Todo Resolve ENS entries
|
||||
import contributors from "../contributors";
|
||||
let options = contributors;
|
||||
|
||||
class Home extends React.Component {
|
||||
|
||||
state = {
|
||||
errorMsg: null,
|
||||
busy: false,
|
||||
busy: true,
|
||||
selectedContributors: [],
|
||||
contributorList: [],
|
||||
currentContributor: {
|
||||
|
@ -45,11 +43,18 @@ class Home extends React.Component {
|
|||
}
|
||||
|
||||
async componentDidMount() {
|
||||
options = options.map(prepareOptions);
|
||||
try {
|
||||
this.contibutorList = await getContributorList();
|
||||
this.contibutorList = this.contibutorList.map(prepareOptions);
|
||||
|
||||
await this.getContributors();
|
||||
await this.getContributors();
|
||||
|
||||
this.getCurrentContributorData();
|
||||
this.getCurrentContributorData();
|
||||
|
||||
this.setState({busy: false});
|
||||
} catch (e) {
|
||||
this.setState({errorMessage: e.message || e});
|
||||
}
|
||||
}
|
||||
|
||||
handleContributorSelection(_selectedContributors) {
|
||||
|
@ -85,7 +90,7 @@ class Home extends React.Component {
|
|||
praises.push(Meritocracy.methods.getStatus(web3.eth.defaultAccount, i).call());
|
||||
}
|
||||
|
||||
const contribData = options.find(x => x.value === web3.eth.defaultAccount);
|
||||
const contribData = this.contibutorList.find(x => x.value === web3.eth.defaultAccount);
|
||||
if(contribData) currentContributor.name = contribData.label;
|
||||
|
||||
currentContributor.praises = await Promise.all(praises);
|
||||
|
@ -105,7 +110,7 @@ class Home extends React.Component {
|
|||
|
||||
async getContributors() {
|
||||
const registry = await Meritocracy.methods.getRegistry().call({from: web3.eth.defaultAccount});
|
||||
const contributorList = options.filter(x => registry.includes(x.value) && x.value !== web3.eth.defaultAccount);
|
||||
const contributorList = this.contibutorList.filter(x => registry.includes(x.value) && x.value !== web3.eth.defaultAccount);
|
||||
this.setState({contributorList});
|
||||
}
|
||||
|
||||
|
@ -188,6 +193,7 @@ class Home extends React.Component {
|
|||
|
||||
return (<div>
|
||||
{errorMsg && <Alert bsStyle="danger">{errorMsg}</Alert>}
|
||||
{busy && <p>Working...</p>}
|
||||
|
||||
{currentContributor.name && <h2>Hello, {currentContributor.name} !</h2>}
|
||||
<span>Your Total Received Kudos: { currentContributor.totalReceived || 0} SNT</span> <br/>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import Meritocracy from 'Embark/contracts/Meritocracy';
|
||||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import axios from 'axios';
|
||||
|
||||
const IPFS_HASH = 'QmfWJJYFBJReu2rzTDzkBKXHazE52GVWrTcVNKdcupnxNH';
|
||||
|
||||
export function addContributor(name, address) {
|
||||
Meritocracy.methods.addContributor(address)
|
||||
}
|
||||
|
||||
export function getContributorList() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const url = EmbarkJS.Storage.getUrl(IPFS_HASH);
|
||||
console.log('Url', url);
|
||||
const response = await axios.get(url);
|
||||
console.log(response.data);
|
||||
resolve(response.data.contributors);
|
||||
} catch (e) {
|
||||
const message = 'Error getting contributor file on IPFS';
|
||||
console.error(message);
|
||||
console.error(e);
|
||||
reject(message);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = {
|
||||
// default applies to all environments
|
||||
default: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
ipfs_bin: "ipfs",
|
||||
provider: "ipfs",
|
||||
available_providers: ["ipfs"],
|
||||
|
@ -28,7 +28,6 @@ module.exports = {
|
|||
// default environment, merges with the settings in default
|
||||
// assumed to be the intended environment by `embark run`
|
||||
development: {
|
||||
enabled: false,
|
||||
provider: "ipfs",
|
||||
upload: {
|
||||
host: "localhost",
|
||||
|
|
|
@ -152,6 +152,15 @@
|
|||
"lodash": "^4.17.11"
|
||||
}
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.18.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
|
||||
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.3.0",
|
||||
"is-buffer": "^1.1.5"
|
||||
}
|
||||
},
|
||||
"babel-plugin-emotion": {
|
||||
"version": "9.2.11",
|
||||
"resolved": "https://registry.npmjs.org/babel-plugin-emotion/-/babel-plugin-emotion-9.2.11.tgz",
|
||||
|
@ -303,6 +312,14 @@
|
|||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.2.tgz",
|
||||
"integrity": "sha512-Rl7PvTae0pflc1YtxtKbiSqq20Ts6vpIYOD5WBafl4y123DyHUeLrRdQP66sQW8/6gmX8jrYJLXwNeMqYVJcow=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.2.6",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"dom-helpers": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz",
|
||||
|
@ -387,6 +404,14 @@
|
|||
"resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz",
|
||||
"integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng=="
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
|
||||
"integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==",
|
||||
"requires": {
|
||||
"debug": "^3.2.6"
|
||||
}
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
|
@ -480,6 +505,11 @@
|
|||
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
|
||||
"integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0="
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||
},
|
||||
"is-directory": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz",
|
||||
|
@ -572,6 +602,11 @@
|
|||
"minimist": "0.0.8"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"license": "ISC",
|
||||
"homepage": "",
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"bootstrap": "^4.3.1",
|
||||
"embark-solc": "^4.0.1",
|
||||
"embarkjs-connector-web3": "^4.0.0",
|
||||
|
|
Loading…
Reference in New Issue