mirror of
https://github.com/status-im/meritocracy.git
synced 2025-01-22 11:39:32 +00:00
do remove contributor
This commit is contained in:
parent
7c308ef261
commit
8963427f64
@ -7,7 +7,7 @@ import {required, isAddress} from '../validators';
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {faTrash} from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
import {addContributor, getFormattedContributorList} from '../services/Meritocracy';
|
||||
import {addContributor, getFormattedContributorList, removeContributor} from '../services/Meritocracy';
|
||||
|
||||
import './admin.scss';
|
||||
|
||||
@ -42,6 +42,10 @@ class Admin extends React.Component {
|
||||
this.setState({busy: true, successMsg: ''});
|
||||
try {
|
||||
await addContributor(this.state.contributorName, this.state.contributorAddress);
|
||||
|
||||
const contributorList = this.state.contributorList;
|
||||
contributorList.push({label: this.state.contributorName, value: this.state.contributorAddress});
|
||||
|
||||
this.setState({busy: false, successMsg: 'Contributor added!'});
|
||||
} catch (e) {
|
||||
this.setState({error: e.message || e, busy: false});
|
||||
@ -53,8 +57,19 @@ class Admin extends React.Component {
|
||||
this.setState({focusedContributorIndex: contributorIndex, showDeleteModal: true});
|
||||
};
|
||||
|
||||
doRemove = () => {
|
||||
this.setState({focusedContributorIndex: -1, showDeleteModal: false});
|
||||
doRemove = async () => {
|
||||
const idx = this.state.focusedContributorIndex;
|
||||
this.setState({focusedContributorIndex: -1, showDeleteModal: false, busy: true});
|
||||
try {
|
||||
await removeContributor(this.state.contributorList[idx].value);
|
||||
|
||||
const contributorList = this.state.contributorList;
|
||||
contributorList.splice(idx, 1);
|
||||
|
||||
this.setState({contributorList, busy: false, successMsg: 'Contributor removed!'});
|
||||
} catch (e) {
|
||||
this.setState({error: e.message || e, busy: false});
|
||||
}
|
||||
};
|
||||
|
||||
handleClose = () => {
|
||||
|
@ -28,6 +28,33 @@ export function addContributor(name, address) {
|
||||
});
|
||||
}
|
||||
|
||||
export function removeContributor(address) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const mainAccount = web3.eth.defaultAccount;
|
||||
try {
|
||||
const registry = await Meritocracy.methods.getRegistry().call({from: mainAccount});
|
||||
let index = registry.indexOf(address);
|
||||
|
||||
const list = await getContributorList();
|
||||
const idx = list.findIndex(contributor => contributor.value === address);
|
||||
list.splice(idx, 1);
|
||||
|
||||
const newHash = await saveContributorList(list);
|
||||
|
||||
const removeContributor = Meritocracy.methods.removeContributor(index, newHash);
|
||||
let gas = await removeContributor.estimateGas({from: mainAccount});
|
||||
const receipt = await removeContributor.send({from: mainAccount, gas: gas + 1000});
|
||||
|
||||
resolve(receipt);
|
||||
} catch (e) {
|
||||
const message = 'Error removing contributor';
|
||||
console.error(message);
|
||||
console.error(e);
|
||||
reject(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function getContributorList(hash) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
@ -113,6 +140,7 @@ export async function getContributor(_address) {
|
||||
export function saveContributorList(list) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
contributorList = list;
|
||||
const newHash = await EmbarkJS.Storage.saveText(JSON.stringify(list));
|
||||
resolve(newHash);
|
||||
} catch (e) {
|
||||
|
@ -230,7 +230,7 @@ contract Meritocracy {
|
||||
// Locals
|
||||
uint256 registryLength = registry.length - 1;
|
||||
// Requirements
|
||||
require(idx < registryLength); // idx needs to be smaller than registry.length - 1 OR maxContributors
|
||||
require(idx <= registryLength); // idx needs to be smaller than registry.length - 1 OR maxContributors
|
||||
// Body
|
||||
address c = registry[idx];
|
||||
// Swap & Pop!
|
||||
|
Loading…
x
Reference in New Issue
Block a user