mirror of
https://github.com/status-im/meritocracy.git
synced 2025-02-26 04:15:21 +00:00
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 Meritocracy from 'Embark/contracts/Meritocracy';
|
||||||
|
|
||||||
|
import {getContributorList} from '../services/Meritocracy';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
- list praise for contributor
|
- list praise for contributor
|
||||||
- listen to events to update UI, (initially on page load but within function calls)
|
- 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 {
|
class Home extends React.Component {
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
errorMsg: null,
|
errorMsg: null,
|
||||||
busy: false,
|
busy: true,
|
||||||
selectedContributors: [],
|
selectedContributors: [],
|
||||||
contributorList: [],
|
contributorList: [],
|
||||||
currentContributor: {
|
currentContributor: {
|
||||||
@ -45,11 +43,18 @@ class Home extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
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) {
|
handleContributorSelection(_selectedContributors) {
|
||||||
@ -85,7 +90,7 @@ class Home extends React.Component {
|
|||||||
praises.push(Meritocracy.methods.getStatus(web3.eth.defaultAccount, i).call());
|
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;
|
if(contribData) currentContributor.name = contribData.label;
|
||||||
|
|
||||||
currentContributor.praises = await Promise.all(praises);
|
currentContributor.praises = await Promise.all(praises);
|
||||||
@ -105,7 +110,7 @@ class Home extends React.Component {
|
|||||||
|
|
||||||
async getContributors() {
|
async getContributors() {
|
||||||
const registry = await Meritocracy.methods.getRegistry().call({from: web3.eth.defaultAccount});
|
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});
|
this.setState({contributorList});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +193,7 @@ class Home extends React.Component {
|
|||||||
|
|
||||||
return (<div>
|
return (<div>
|
||||||
{errorMsg && <Alert bsStyle="danger">{errorMsg}</Alert>}
|
{errorMsg && <Alert bsStyle="danger">{errorMsg}</Alert>}
|
||||||
|
{busy && <p>Working...</p>}
|
||||||
|
|
||||||
{currentContributor.name && <h2>Hello, {currentContributor.name} !</h2>}
|
{currentContributor.name && <h2>Hello, {currentContributor.name} !</h2>}
|
||||||
<span>Your Total Received Kudos: { currentContributor.totalReceived || 0} SNT</span> <br/>
|
<span>Your Total Received Kudos: { currentContributor.totalReceived || 0} SNT</span> <br/>
|
||||||
|
26
app/js/services/Meritocracy.js
Normal file
26
app/js/services/Meritocracy.js
Normal file
@ -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 = {
|
module.exports = {
|
||||||
// default applies to all environments
|
// default applies to all environments
|
||||||
default: {
|
default: {
|
||||||
enabled: false,
|
enabled: true,
|
||||||
ipfs_bin: "ipfs",
|
ipfs_bin: "ipfs",
|
||||||
provider: "ipfs",
|
provider: "ipfs",
|
||||||
available_providers: ["ipfs"],
|
available_providers: ["ipfs"],
|
||||||
@ -28,7 +28,6 @@ module.exports = {
|
|||||||
// default environment, merges with the settings in default
|
// default environment, merges with the settings in default
|
||||||
// assumed to be the intended environment by `embark run`
|
// assumed to be the intended environment by `embark run`
|
||||||
development: {
|
development: {
|
||||||
enabled: false,
|
|
||||||
provider: "ipfs",
|
provider: "ipfs",
|
||||||
upload: {
|
upload: {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
|
0
contributors.json
Normal file
0
contributors.json
Normal file
35
package-lock.json
generated
35
package-lock.json
generated
@ -152,6 +152,15 @@
|
|||||||
"lodash": "^4.17.11"
|
"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": {
|
"babel-plugin-emotion": {
|
||||||
"version": "9.2.11",
|
"version": "9.2.11",
|
||||||
"resolved": "https://registry.npmjs.org/babel-plugin-emotion/-/babel-plugin-emotion-9.2.11.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.2.tgz",
|
||||||
"integrity": "sha512-Rl7PvTae0pflc1YtxtKbiSqq20Ts6vpIYOD5WBafl4y123DyHUeLrRdQP66sQW8/6gmX8jrYJLXwNeMqYVJcow=="
|
"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": {
|
"dom-helpers": {
|
||||||
"version": "3.4.0",
|
"version": "3.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.4.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz",
|
||||||
"integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng=="
|
"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": {
|
"fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
|
||||||
"integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0="
|
"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": {
|
"is-directory": {
|
||||||
"version": "0.3.1",
|
"version": "0.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz",
|
||||||
@ -572,6 +602,11 @@
|
|||||||
"minimist": "0.0.8"
|
"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": {
|
"node-fetch": {
|
||||||
"version": "1.7.3",
|
"version": "1.7.3",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^0.18.0",
|
||||||
"bootstrap": "^4.3.1",
|
"bootstrap": "^4.3.1",
|
||||||
"embark-solc": "^4.0.1",
|
"embark-solc": "^4.0.1",
|
||||||
"embarkjs-connector-web3": "^4.0.0",
|
"embarkjs-connector-web3": "^4.0.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user