import {
Component,
OnInit,
ViewEncapsulation,
AfterViewInit,
Directive,
ElementRef,
Input,
Output,
EventEmitter
} from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ScriptLoaderService } from '../../../../../_services/script-loader.service';
import { DetailsService } from '../../details.service';
import Web3 from 'web3';
import { ToastrService } from 'ngx-toastr';
import { GlobalsComponent } from '../../globals/globals.component';
declare var $: any;
@Component({
selector: '.m-grid__item.m-grid__item--fluid.m-wrapper',
templateUrl: './proposals.component.html',
styleUrls: ['./proposals.component.css'],
encapsulation: ViewEncapsulation.None
})
export class ProposalsComponent implements OnInit, AfterViewInit {
router: any;
public SummerNoteText;
public description: string;
public title: string;
loading = false;
loadingAccept = false;
loadingReject = false;
loadingVote = false;
public web3;
// public startIndex;
// public lengthOfProposal;
public proposalId;
public pTitle;
public pDescription;
public pTotalVotes;
public pStatus;
public pDateAdded;
public pTotalOptions;
public pIncentives;
public finalClosingTime;
public proposalStatusIndex;
public answerDescriptions = [];
startPage: number;
public paginationLimit = [];
public automaticAction;
public optionDateAdded;
public proposalDateAdded;
public conditionCheck = null;
public loadingRejected = false;
public memberAddress;
public showSubmitAnswer = false;
public optionNumberGiven;
public checkSummernote = 0;
public userObj;
public totalOptions;
public gBTBalance;
public optionDetails: any = {};
public message;
public statusColour = {
0: 'metal',
1: 'orange',
2: 'warning',
3: 'success',
4: 'danger',
5: 'success',
6: 'danger',
7: 'success'
};
public networkIDObj = {
'main-net': '1',
ropsten: '2',
kovan: '42',
rinkeby: '4',
unknown: 'NA'
};
public checked = 0;
public checkVoteId = 0;
public proposalOwnerAddress;
public dispVar = true;
public optionCheck1 = false;
public voteOptionId;
public proposalAnswer;
public stringProposalParameters = [];
public alreadyVotedWithDiffRole = -1;
public votingLayer = -1;
public authRole;
public memberRoleId;
public roleIdName;
public categoryId;
public currentVotingId;
public authMember = false;
public minimumStake;
public maximumStake;
public memberRoleIdname;
public checkOwner = false;
public mrSeqName = [];
public proposalTruncateAddress;
public statusOfVoting = 0;
public GBTBalance;
public checkCategorize = false;
public pCategoryId;
public answerArray = [];
public incenTransFails = false;
public optionDetailsArray = [];
public mrSequenceLength;
public totalSolutions;
public pClosingTimeArr = [];
public parentCategoryId;
public index;
public proposalDataFromHash;
public parametersName = [];
public configParamDesc;
public configParamName;
public answer;
public optionNumber = 0;
public textAreaData;
public loadingSubmit = false;
public metamaskLogin = true;
public iframeURl = '';
constructor(
private _script: ScriptLoaderService,
private router1: Router,
private route: ActivatedRoute,
private toastr: ToastrService,
private details: DetailsService,
private globals: GlobalsComponent
) {
this.startPage = 0;
this.proposalId = +this.route.snapshot.paramMap.get('id');
if (window.location.href.indexOf('iframe') >= 0) {
this.iframeURl = '/iframe';
}
}
showMoreItems(i) {
this.paginationLimit[i] = Number(this.paginationLimit[i]) + 2;
}
showLessItems(i) {
this.paginationLimit[i] = Number(this.paginationLimit[i]) - 2;
}
ngOnInit() {
this.details.setTitle('Proposals');
let user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
this.web3 = new Web3(window['web3'].currentProvider);
if (this.web3.eth.accounts[0] == undefined) {
this.memberAddress = '0x0000000000000000000000000000000000000000';
this.metamaskLogin = false;
} else {
this.memberAddress = this.web3.eth.accounts[0];
}
// this.web3.eth.defaultAccount=this.web3.eth.coinbase;
this.indexInitiate();
}
indexInitiate() {
var urlPath = window.location.href;
for (var arr = [], i = urlPath.length; i--; ) {
if (urlPath[i] == '/') {
arr.push(i);
}
}
var index = arr[1];
var urlCompanyName = urlPath.substring(index + 1, arr[0]);
if (this.userObj.companyName != urlCompanyName) {
var data = {
masterAddress: '',
userName: this.userObj.userName,
companyName: urlCompanyName,
GBMasterAddress: this.userObj.GBMasterAddress,
allAbis: this.userObj.allAbis,
email: this.userObj.email,
token: 'token',
authorized: true
};
localStorage.setItem('currentUser', JSON.stringify(data));
import('../../globals/globals.component').then(module => {
module.generator();
});
let user1 = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user1);
GlobalsComponent.gbmaster.getdAppDetails(
this.userObj.companyName,
function(error, result) {
this.versionNum = result[5].toNumber();
// if(this.versionNum > 0)
// {
this.companyMasterAddress = result[1];
this.userObj.masterAddress = this.companyMasterAddress;
GlobalsComponent.gbmaster.getdAppContractAddresses(
this.userObj.companyName,
function(error2, result2) {
if (!error2) {
var timeoutVar1 = setInterval(
function() {
let user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
if (
this.userObj.companyName in GlobalsComponent.governance
) {
GlobalsComponent.memberData[
this.userObj.companyName
].getMemberRoleIdByAddress(
this.memberAddress,
function(errorMR1, resultMR1) {
var authorized = resultMR1;
this.userObj.authorized = authorized;
var user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
var data = {
masterAddress: this.companyMasterAddress,
userName: this.userObj.userName,
companyName: urlCompanyName,
GBMasterAddress: this.userObj.GBMasterAddress,
allAbis: this.userObj.allAbis,
email: this.userObj.email,
token: 'token',
authorized: authorized
};
localStorage.setItem(
'currentUser',
JSON.stringify(data)
);
var user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
// this.web3.eth.defaultAccount=this.web3.eth.coinbase;
this.memberAddress = this.memberAddress;
this.getProposalLength();
}.bind(this)
);
clearInterval(timeoutVar1);
}
}.bind(this),
500
);
}
}.bind(this)
);
}.bind(this)
);
} else {
this.memberAddress = this.memberAddress;
import('../../globals/globals.component').then(module => {
module.generator();
});
var timeoutVar1 = setInterval(
function() {
let user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
if (this.userObj.companyName in GlobalsComponent.governance) {
this.getProposalLength();
clearInterval(timeoutVar1);
}
}.bind(this),
500
);
}
}
ngAfterViewInit() {
this.iframeResize();
this.upVoteForm();
this.submitReject();
this.acceptReject();
this.submitSolution();
this._script.load('.m-grid__item.m-grid__item--fluid.m-wrapper');
}
switchIt() {
if (this.checked == 0) {
this.checked = 1;
this.getProposalStatus(this.proposalId);
} else {
this.checked = 0;
this.iframeResize();
}
}
getOptionNumber(optionNum) {
this.optionNumber = optionNum;
}
truncate(fullStr, strLen, separator) {
if (fullStr.length <= strLen) return fullStr;
separator = separator || '...';
var sepLen = separator.length,
charsToShow = strLen - sepLen,
frontChars = Math.ceil(charsToShow / 2),
backChars = Math.floor(charsToShow / 2);
return (
fullStr.substr(0, frontChars) +
separator +
fullStr.substr(fullStr.length - backChars)
);
}
checkAutomaticAction() {
if (this.automaticAction == 'Yes') {
this.dispVar = false;
return true;
} else return false;
}
public showproposal = -1;
getProposalLength() {
this.details.setdAppName(this.userObj.companyName);
$('#loader').hide();
GlobalsComponent.proposalData[this.userObj.companyName].getProposalLength(
function(error2, resultlength) {
if (!error2) {
if (this.proposalId < resultlength) {
this.showproposal = 1;
$('#loaderProposal').hide();
this.initialCalls();
} else {
this.showproposal = 0;
$('#loaderProposal').hide();
}
}
}.bind(this)
);
}
closeProposal() {
GlobalsComponent.governance[this.userObj.companyName].closeProposalVote(
this.proposalId,
function(error, result) {
if (!error) {
this.timeoutCloseProposal(result);
this.toastr.info(
'Request submitted to ethereum(' +
GlobalsComponent.network +
'). Awaiting confirmation!'
);
} else {
this.toastr.error('Transaction Errored');
}
}.bind(this)
);
}
timeoutCloseProposal(hash) {
setTimeout(() => {
var boundFunction = this.web3.eth.getTransactionReceipt(
hash,
function(error, result) {
if (result != null) {
setTimeout(() => {
this.toastr.success('Transaction successful!');
window.location.reload();
}, 4000);
} else this.timeout(hash);
}.bind(this)
);
}, 1000);
}
public canCreateProposal = {};
public decimals = {};
public reason = {};
public tokensToLock = {};
public proposalPaused = false;
initialCalls() {
this.getProposalStatus(this.proposalId);
this.checkForDateAdd();
this.checkForVoted();
this.getGBTBalance();
this.getAllMemberNames();
this.answerDescriptions.push('Empty');
GlobalsComponent.proposalData[this.userObj.companyName].isProposalPaused(
this.proposalId,
function(errPause, resPause) {
this.proposalPaused = resPause;
}.bind(this)
);
GlobalsComponent.gbmaster.getdAppTokenDecimals(
'GOVBLOCKS',
function(errGBTdecimals, resGBTdecimals) {
this.decimals['GOVBLOCKS'] = resGBTdecimals;
}.bind(this)
);
GlobalsComponent.gbmaster.getdAppTokenDecimals(
this.userObj.companyName,
function(errTokendecimals, resTokendecimals) {
this.decimals[this.userObj.companyName] = resTokendecimals;
}.bind(this)
);
GlobalsComponent.governance[this.userObj.companyName].canCreateProposal(
this.memberAddress,
18,
function(reason, resCanCreate) {
this.canCreateProposal['Pause'] = resCanCreate;
this.reason['Pause'] = reason[0];
this.tokensToLock['Pause'] = reason[1];
}.bind(this)
);
GlobalsComponent.governance[this.userObj.companyName].canCreateProposal(
this.memberAddress,
17,
function(reason, resCanCreate) {
this.canCreateProposal['Resume'] = resCanCreate;
this.reason['Resume'] = reason[0];
this.tokensToLock['Resume'] = reason[1];
}.bind(this)
);
GlobalsComponent.memberData[
this.userObj.companyName
].getProposalAnsByAddress(
this.memberAddress,
function(errByAddress, resByAddress) {
if (!errByAddress) {
for (var i = 0; i < resByAddress.length; i++) {
if (this.proposalId == resByAddress[i].toNumber()) {
this.showSubmitAnswer = true;
this.iframeResize();
}
}
this.getProposalDetailsById3(this.proposalId);
} else {
console.log('Error in proposalAnsByAddress');
}
}.bind(this)
);
}
public boardMember = false;
checkMemberInBoard() {
GlobalsComponent.memberData[
this.userObj.companyName
].getMemberRoleIdByAddress(
this.memberAddress,
function(errCount, resCount) {
if (!errCount) {
for (let i = 0; i < resCount.length; i++) {
if (resCount[i].toNumber() == this.authRole) {
this.boardMember = true;
break;
}
}
}
}.bind(this)
);
}
public allmemberRoleNames = {};
public contractNames = [
'GovernanceData',
'MemberRoles',
'ProposalCategory',
'SimpleVoting',
'Governance',
'Pool'
];
getAllMemberNames() {
GlobalsComponent.memberData[this.userObj.companyName].getRoles_MemberCount(
function(errCount, resCount) {
if (!errCount) {
for (let c = 1; c < resCount[0].length; c++) {
this.allmemberRoleNames[c] = GlobalsComponent.gbmaster.hex_to_ascii(
resCount[0][c]
);
}
}
}.bind(this)
);
}
public ownerInterVerdict = false;
checkForOption() {
let getOptionIndex = GlobalsComponent.proposalData[
this.userObj.companyName
].getOptionDetailsByAddress(
this.proposalId,
this.memberAddress,
function(errGetOptionIndex, resGetOptionIndex) {
if (!errGetOptionIndex) {
this.optionNumber = resGetOptionIndex.solutionId; //resGetOptionIndex.solutionId + 1;
if (this.optionNumber != 0) {
this.optionNumberGiven = resGetOptionIndex.solutionId;
if (this.interVerdict == this.optionNumberGiven - 1) {
this.ownerInterVerdict = true;
}
let getOptionIndex1 = GlobalsComponent.proposalData[
this.userObj.companyName
].getOptionAddressByProposalId(
this.proposalId,
this.optionNumberGiven,
function(errGetOptionIndex1, resGetOptionIndex1) {
if (!errGetOptionIndex1) {
this.addressOfOptionOwner = resGetOptionIndex1;
this.iframeResize();
if (this.addressOfOptionOwner == this.memberAddress) {
this.optionCheck1 = true;
// voting for other option open, you have already submitted solution
} else {
this.optionCheck1 = false;
}
} else {
console.log('Error in getOptionIndex.. ');
}
}.bind(this)
);
} else {
this.optionCheck = 0;
// VOTE OPEN AND OPTION OPEN
}
} else {
console.log('Error in getOptionIndex.. ');
}
}.bind(this)
);
}
predicateBy(prop) {
return function(a, b) {
if (a[prop] > b[prop]) {
return 1;
} else if (a[prop] < b[prop]) {
return -1;
}
return 0;
};
}
checkDesc() {
if (this.pDescription.description != '') {
return true;
} else {
return false;
}
}
isStringDesc(description) {
if (typeof description === 'string') {
return true;
} else return false;
}
checkForVoted() {
GlobalsComponent.memberData[
this.userObj.companyName
].getVoteId_againstMember(
this.memberAddress,
this.proposalId,
function(errGetVotAddress, resGetVotAddress) {
if (!errGetVotAddress) {
this.voteIdExist = resGetVotAddress;
if (this.voteIdExist != 0) {
this.checkVoteId = 1;
GlobalsComponent.proposalData[
this.userObj.companyName
].getOptionByVoteId(
this.voteIdExist,
function(errGetVotOptionId, resGetVotOptionId) {
if (!errGetVotOptionId) {
this.voteOptionId = resGetVotOptionId.toNumber();
this.checkForOption();
} else {
console.log('Error in getOptionById');
}
}.bind(this)
);
} else {
this.checkForOption();
}
} else {
console.log(errGetVotAddress);
}
}.bind(this)
);
}
public dateAddTimeStamp;
checkForDateAdd() {
console.log('CheckForDateAdd()');
GlobalsComponent.proposalData[this.userObj.companyName].getOptionDateAdded(
this.proposalId,
1,
function(errOptionDate, resOptionDate) {
this.optionDateAdded = resOptionDate;
GlobalsComponent.proposalData[
this.userObj.companyName
].getProposalDateAdd(
this.proposalId,
function(errProposalDate, resProposalDate) {
if (resProposalDate != '') {
this.checkAuthorize();
this.proposalDateAdded = resProposalDate.toNumber();
if (this.optionDateAdded == this.proposalDateAdded) {
this.conditionCheck = 1;
} else {
this.conditionCheck = 0;
}
if (
((this.conditionCheck == 0 && this.proposalStatusIndex == 2) ||
(this.checked == 1 && this.proposalStatusIndex <= 1)) &&
this.showSubmitAnswer == false
) {
$('.summernote').summernote();
this.checkSummernote = 1;
this._script.load(
'assets/demo/default/custom/components/forms/widgets/summernote.js'
);
}
}
}.bind(this)
);
}.bind(this)
);
}
public proposalSolutionParams = [];
public proposalSolutionApiParams = [];
getOptionDescHash() {
if (this.conditionCheck) {
GlobalsComponent.proposalData[
this.userObj.companyName
].getOptionDetailsByProposalId(
this.proposalId,
1,
function(errGetOptData, resGetOptData) {
if (!errGetOptData) {
if (resGetOptData != '') {
if (this.pCategoryId == 2) {
var d = new Date(resGetOptData.paramValues[3] * 1000);
var options = {
year: 'numeric',
month: 'short',
day: 'numeric'
};
if (resGetOptData.paramValues[3] == 0) {
resGetOptData.paramValues[3] = 'Not limited';
} else {
resGetOptData.paramValues[3] = d.toLocaleDateString(
'en',
options
);
}
}
if (this.pCategoryId == 9)
resGetOptData.paramValues[1] =
resGetOptData.paramValues[1] / 1e18;
if (this.pCategoryId == 10)
resGetOptData.paramValues[2] =
resGetOptData.paramValues[2] / 1e18;
this.proposalSolutionParams = resGetOptData.paramValues;
if (this.pCategoryId == 11) {
this.proposalSolutionParams = JSON.parse(
resGetOptData.paramValues[0]
);
}
this.proposalSolutionApiParams = resGetOptData.apiParamValues;
}
}
}.bind(this)
);
}
}
getMemberRoleName() {
GlobalsComponent.memberData[
this.userObj.companyName
].getMemberRoleIdByAddress(
this.memberAddress,
function(errMRRoleId, resMRRoleId) {
if (!errMRRoleId) {
for (var i = 0; i < resMRRoleId.length; i++) {
if (resMRRoleId[i] == this.authRole) {
this.memberRoleId = resMRRoleId[i].toNumber();
GlobalsComponent.memberData[
this.userObj.companyName
].getMemberRoleNameById(
this.memberRoleId,
function(errRoleIdName, resRoleIdName) {
if (!errRoleIdName) {
this.memberRoleIdname = resRoleIdName;
if (this.memberRoleId != 2 && this.memberRoleId > 0) {
this.alreadyVotedWithDiffRole = 1;
} else {
this.alreadyVotedWithDiffRole = 0;
}
if (this.memberRoleId != this.authRole) {
this.votingLayer = 1;
} else {
this.votingLayer = 0;
}
} else {
console.log('Error in getMemberRoleNameById ');
}
}.bind(this)
);
}
}
} else {
console.log('Error in getMemberRoleIdByAddress');
}
}.bind(this)
);
}
public maximumStakeInf;
public interVerdict = 0;
public maxStakeInf = false;
public canSubmitSol;
public reasonSubmitSol;
public currentClosingTime = 0;
canSubmitSolution() {
GlobalsComponent.governance[this.userObj.companyName].canCreateProposal(
this.memberAddress,
this.categoryId,
function(reason, result) {
this.canSubmitSol = result;
this.reasonSubmitSol = reason;
}.bind(this)
);
}
checkAuthorize() {
GlobalsComponent.governance[this.userObj.companyName].getTokensLocked(
'GOVBLOCKS',
this.memberAddress,
'GOV',
function(errLockedTokens, resLockedTokens) {
var lockedTokens = resLockedTokens;
GlobalsComponent.proposalData[
this.userObj.companyName
].getProposalDetailsById2(
this.proposalId,
function(errPropDetails, resPropDetails) {
this.currentVotingId = resPropDetails[2].toNumber();
this.categoryId = resPropDetails[1].toNumber();
this.canSubmitSolution();
this.interVerdict = resPropDetails[3].toNumber();
GlobalsComponent.categoryData[
this.userObj.companyName
].getCategoryDataBySubCategoryId(
this.categoryId,
function(errCategoryData, resCategoryData) {
var categoryData = resCategoryData;
this.authRole = categoryData.mrSequence[
this.currentVotingId
].toNumber();
this.checkMemberInBoard();
this.finalClosingTime =
categoryData.closingTime[this.currentVotingId];
this.remainingTime =
this.proposalDateAdded * 1 +
this.finalClosingTime * 1 -
Math.round(Date.now() / 1000) * 1;
this.currentClosingTime = this.remainingTime;
if (this.remainingTime < 7200) {
this.remainingTime = Math.round(this.remainingTime / 60);
this.remainingTime += ' minutes';
} else if (this.remainingTime * -1 < 172800) {
this.remainingTime = Math.round(this.remainingTime / 3600);
this.remainingTime += ' Hours';
} else {
this.remainingTime = Math.round(this.remainingTime / 86400);
this.remainingTime += ' Days';
}
this.minimumStake = categoryData.minStake;
// if (this.minimumStake > lockedTokens) {
// this.canSubmitSol = false;
// } else {
// this.canSubmitSol = true;
// }
this.majVote = categoryData.majorityVote[this.currentVotingId];
GlobalsComponent.memberData[
this.userObj.companyName
].getMemberRoleNameById(
this.authRole,
function(errRoleIdName, resRoleIdName) {
if (!errRoleIdName) {
this.roleIdName = resRoleIdName;
GlobalsComponent.memberData[
this.userObj.companyName
].getMemberRoleIdByAddress(
this.memberAddress,
function(errMRRoleId, resMRRoleId) {
if (!errMRRoleId) {
for (var i = 0; i < resMRRoleId.length; i++) {
if (resMRRoleId[i] == this.authRole) {
this.memberRoleId = resMRRoleId[i].toNumber();
}
}
// this.memberRoleId = resMRRoleId.toNumber();
this.getMemberRoleName();
this.checkProposalClosing();
if (this.memberRoleId == this.authRole) {
this.authMember = true;
}
} else {
console.log('Error in getMemberRoleIdByAddress');
}
}.bind(this)
);
} else {
console.log('Error in getMemberRoleNameById ');
}
}.bind(this)
);
}.bind(this)
);
}.bind(this)
);
}.bind(this)
);
}
checkProposalOwner() {
let ans1 = GlobalsComponent.proposalData[
this.userObj.companyName
].getProposalOwner(
this.proposalId,
function(errProOwner, resProOwner) {
if (!errProOwner) {
this.proposalOwnerAddress = resProOwner;
this.proposalTruncateAddress = this.truncate(
this.proposalOwnerAddress,
14,
'...'
);
if (
this.proposalStatusIndex <= 2 &&
this.proposalOwnerAddress == this.memberAddress
) {
this.checkOwner = true;
}
} else {
console.log('Error in getProposalOwner');
}
}.bind(this)
);
}
checkProposalClosing() {
GlobalsComponent.governance[
this.userObj.companyName
].checkProposalVoteClosing(
this.proposalId,
function(errCheckVoteClose, resCheckVoteClose) {
if (!errCheckVoteClose) {
this.statusOfVoting = resCheckVoteClose.toNumber();
if (this.statusOfVoting == 1 && this.proposalStatusIndex == 2) {
this.iframeResize();
// let ans1 = GlobalsComponent.governance[this.userObj.companyName].getMyIndexByProposalId(this.proposalId, this.networkIDObj[GlobalsComponent.network], this.userObj.companyName, function(err, res) {
// if (res == "1") {
this.getProposalStatus(this.proposalId);
// }
// }.bind(this));
}
} else {
console.log('Error in checkProposalVoteClosing');
}
}.bind(this)
);
}
getGBTBalance() {
GlobalsComponent.gbmaster.getGBTBalance_user(
this.memberAddress,
function(errBal, resBal) {
if (resBal.e < 10) {
this.gBTBalance = Math.round(resBal * 100) / 100;
} else {
this.gBTBalance = Math.round((resBal / 1e18) * 100) / 100;
}
}.bind(this)
);
}
getMRSequenceName(j, i) {
try {
i = i.toNumber();
} catch (err) {}
GlobalsComponent.memberData[this.userObj.companyName].getMemberRoleNameById(
i,
function(errRoleIdName, resRoleIdName) {
if (!errRoleIdName) {
this.mrSeqName[j] = resRoleIdName;
} else {
console.log('Error in getMemberRoleNameById');
}
}.bind(this)
);
}
// public mrSequenceViewData = [];
getMRSequenceName1(j, i) {
GlobalsComponent.memberData[this.userObj.companyName].getMemberRoleNameById(
i,
function(errRoleIdName, resRoleIdName) {
if (!errRoleIdName) {
this.viewData.mrSeq.push(resRoleIdName);
// this.mrSequenceViewData[j] = resRoleIdName;
} else {
console.log('Error in getMemberRoleNameById');
}
}.bind(this)
);
}
getProposalStatus(proposalId) {
$('#loaderProposal').hide();
GlobalsComponent.proposalData[this.userObj.companyName].getProposalStatus(
this.proposalId,
function(errProStatusId, resultGetProStatusId) {
if (!errProStatusId) {
this.iframeResize();
if (this.conditionCheck == 1) {
this.proposalStatusIndex = resultGetProStatusId.statusId.toNumber();
} else {
this.proposalStatusIndex = resultGetProStatusId.statusId;
}
this.iframeResize();
} else {
console.log(errProStatusId);
}
}.bind(this)
);
}
checkForCategorize(pCategoryId) {
this.iframeResize();
if (pCategoryId == 0 && this.proposalStatusIndex <= 1) {
this.checkCategorize = true;
}
}
removeCondition() {
this.incenTransFails = false;
}
refresh(): void {
window.location.reload();
}
submitReject() {
$('#submitRejectForm').validate({
rules: {}
});
}
acceptReject() {
$('#acceptRejectForm').validate({
rules: {}
});
}
upVoteForm() {
$('#upVoteForm').validate({
rules: {}
});
}
submitSolution() {
$('#formSubmitSolution').validate({
rules: {
textAreaD: {
required: true
},
intParaDesc: {
required: true
},
byteParaDesc: {
required: true
},
addressParaDesc: {
required: true
},
stringParaDesc: {
required: true
}
}
});
}
// For getting all available Answers
getOptionDescByProposalId(optionIndex, all) {
GlobalsComponent.proposalData[
this.userObj.companyName
].getSolutionDataByProposalId(
this.proposalId,
optionIndex,
function(errOptData, resultGetOptionData) {
if (!errOptData) {
this.answer = resultGetOptionData;
if (this.parentCategoryId == 3) {
this.getAllParametersName(this.answer);
}
if (this.answer.length != 0) {
this.answerArray.push(this.answer);
this.answerDescriptions.push(
this.answer.description.ansDescription
);
this.paginationLimit.push(2);
var interval = setInterval(() => {
if (this.totalOptions != undefined) {
clearInterval(interval);
if (all == 1 && optionIndex < this.totalOptions) {
this.getOptionDescByProposalId(optionIndex + 1, all);
} else {
this.getProposalOptions(this.answerArray);
// $('#loaderVote').hide();
}
}
}, 200);
}
}
}.bind(this)
);
}
public forAnsAllParameterArray: number[][];
public forAnsAllApiParameterArray: number[][];
// For Getting All Parameter Details
getProposalOptions(answer) {
var i,
j = 0;
var k = 0;
var m = 0;
var n = 0;
this.forAnsAllParameterArray = [];
this.forAnsAllApiParameterArray = [];
for (i = 0; i < this.totalOptions; i++) {
this.forAnsAllParameterArray[i] = [];
this.forAnsAllApiParameterArray[i] = [];
}
for (var l = 0; l < answer.length; l++) {
var optionDetails = {};
var d = new Date(answer[l].dateAdd * 1000);
var options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
optionDetails['dateAdded'] = d.toLocaleDateString('en', options);
optionDetails['optionAddress'] = answer[l].solutionOwner;
this.optionDetailsArray[l] = optionDetails;
while (
m < answer[l].description.paramValues.length ||
n < answer[l].description.apiParamValues.length
) {
if (m < answer[l].description.paramValues.length) {
this.forAnsAllParameterArray[k][m] =
answer[l].description.paramValues[m];
}
if (n < answer[l].description.apiParamValues.length) {
this.forAnsAllApiParameterArray[k][n] =
answer[l].description.apiParamValues[n];
}
++m;
++n;
}
++k;
m = 0;
n = 0;
}
$('#loaderVote').hide();
}
gotoProposal() {
this.router = Router;
this.router.navigate(['/proposals/' + this.userObj.companyName]);
}
public pCategoryName;
public txHash = '';
public txUrllink = '';
public pStatusId;
public viewData = {
closingTime: [],
majorityVote: [],
mrAllowed: [],
minStake: '',
maxStake: '',
incentives: '',
mrSeq: []
};
public tokenHoldingTime;
public minStake;
public subCategoryExternal;
public tokenName;
getProposalDetailsById3(i) {
this.index = i;
GlobalsComponent.proposalData[this.userObj.companyName].getProposalDetails(
this.index,
function(errorId3, resultOfgetProposal) {
if (!errorId3) {
this.totalSolutions = resultOfgetProposal.totalSolutions;
this.pCategoryId = resultOfgetProposal[2].toNumber();
GlobalsComponent.categoryData[
this.userObj.companyName
].isSubCategoryExternal(
this.pCategoryId,
function(errExt, resExt) {
this.subCategoryExternal = resExt;
}.bind(this)
);
GlobalsComponent.categoryData[
this.userObj.companyName
].getSubCategoryData1(
this.pCategoryId,
function(errPCatId, resPCatId) {
this.tokenHoldingTime = resPCatId.tokenHoldingTime;
this.minStake = resPCatId.minStake;
this.parentCategoryId = resPCatId.categoryId;
GlobalsComponent.proposalData[
this.userObj.companyName
].getProposalEventData(
this.proposalId,
function(errorProposalData, resultProposalData) {
this.pIndex = this.proposalId;
this.pStatus = resultProposalData.status;
this.pStatusId = resultProposalData.statusId;
try {
if (
this.proposalStatusIndex.toNumber() !=
this.pStatusId.toNumber()
) {
window.location.reload();
}
} catch {
if (this.proposalStatusIndex != this.pStatusId) {
window.location.reload();
}
}
var transactionHash = resultProposalData.transactionHash;
this.txHash = this.truncate(
resultProposalData.transactionHash,
16,
'...'
);
if (GlobalsComponent.network == 'kovan') {
this.txUrllink =
'https://kovan.etherscan.io/tx/' + transactionHash;
} else if (GlobalsComponent.network == 'rinkeby') {
this.txUrllink =
'http://rinkeby.etherscan.io/tx/' + transactionHash;
}
if (resultProposalData == '') {
this.pTitle = '';
this.pDescription = '';
} else if (
this.parentCategoryId == 2 &&
resultProposalData.proposalDescHash != ''
) {
this.pTitle = resultProposalData.proposalTitle;
this.proposalDataFromHash = GlobalsComponent.governance[
this.userObj.companyName
].getDataFromHash(resultProposalData.proposalDescHash);
this.pDescription = this.proposalDataFromHash[0].description;
if (this.pCategoryId == 3 || this.pCategoryId == 4) {
this.pDescription['function'] = '';
this.pDescription['contractAt'] = '';
for (
var closeIndex = 0;
closeIndex < this.pDescription.mrSequence.length;
closeIndex++
) {
this.viewData.closingTime.push(
(this.pDescription.closingTime[closeIndex] / 3600)
.toFixed(2)
.replace(/\.0+$/, '')
);
this.viewData.majorityVote.push(
this.pDescription.majorityVote[closeIndex]
);
}
for (
var i = 0;
i < this.pDescription.mrSequence.length;
i++
) {
this.viewData.mrSeq.push(
this.allmemberRoleNames[
this.pDescription.mrSequence[i]
]
);
}
if (this.pDescription.mrAllowed[0] == 0) {
this.viewData.mrAllowed.push('Any one');
} else
for (
var i = 0;
i < this.pDescription.mrAllowed.length;
i++
) {
this.viewData.mrAllowed.push(
this.allmemberRoleNames[
this.pDescription.mrAllowed[i]
]
);
}
this.viewData.minStake =
this.pDescription.minStake / 1e18;
this.viewData.maxStake =
this.pDescription.maxStake / 1e18;
this.viewData.incentives =
this.pDescription.incentives / 1e18;
}
} else {
this.pTitle = resultProposalData.proposalTitle;
this.pDescription = this.getDataFromHash(
resultProposalData.proposalDescHash
);
this.pDescription = this.pDescription[0].description;
}
GlobalsComponent.proposalData[
this.userObj.companyName
].getProposalIncentive(
this.index,
function(errGetInc, resGetInc) {
if (!errGetInc) {
GlobalsComponent.proposalData[
this.userObj.companyName
].getAllVoteIdsLength_byProposal(
this.proposalId,
function(errorTotalVotes, resultTotalVotes) {
if (!errorTotalVotes) {
this.iframeResize();
this.pTotalVotes = resultTotalVotes;
this.pTotalOptions = resultOfgetProposal[5];
if (this.pTotalOptions - 1 == -1) {
this.totalOptions = 0;
} else {
this.totalOptions = this.pTotalOptions - 1;
}
var d = new Date(
resultProposalData.dateAdd * 1000
);
var options = {
// weekday: "short",
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
this.pDateAdded = d.toLocaleDateString(
'en',
options
);
this.checkForCategorize(this.pCategoryId);
this.checkProposalOwner();
}
}.bind(this)
);
GlobalsComponent.categoryData[
this.userObj.companyName
].getCategoryDataBySubCategoryId(
this.pCategoryId,
function(errorCategory, resultCategory) {
if (!errorCategory) {
GlobalsComponent.categoryData[
this.userObj.companyName
].isSubCategoryExternal(
this.pCategoryId,
function(errExt, resExt) {
if (resExt) {
this.tokenName = 'GBT';
this.pIncentives =
resGetInc /
Math.pow(10, this.decimals['GOVBLOCKS']);
} else {
this.getdAppTokenName();
this.pIncentives =
resGetInc /
Math.pow(
10,
this.decimals[this.userObj.companyName]
);
}
var categoryDetails = resultCategory;
if (
'function' in categoryDetails ||
'apiUrlLink' in categoryDetails
) {
this.automaticAction =
categoryDetails.function == '' &&
categoryDetails.apiUrlLink == ''
? 'No'
: 'Yes';
} else {
GlobalsComponent.categoryData[
this.userObj.companyName
].getSubCategoryName(
this.pCategoryId,
function(errCatName, resCatName) {
this.pCategoryName = resCatName;
this.automaticAction = 'No';
}.bind(this)
);
}
if (
this.parentCategoryId == 2 &&
typeof this.pDescription != 'string'
) {
this.pDescription.mrSequence =
categoryDetails.mrSequence;
this.pDescription.majorityVote =
categoryDetails.majorityVote;
}
this.mrSequenceLength =
categoryDetails.mrSequence.length;
for (
var closeIndex = 0;
closeIndex < this.mrSequenceLength;
closeIndex++
) {
this.pClosingTimeArr[closeIndex] = (
categoryDetails.closingTime[closeIndex] /
3600
).toFixed(2);
}
for (
var i = 0;
i < this.mrSequenceLength;
i++
) {
this.getMRSequenceName(
i,
categoryDetails.mrSequence[i]
);
}
if ('function' in categoryDetails) {
this.getCatgoryData2(this.pCategoryId);
this.pCategoryName = categoryDetails.name;
} else {
$('#loader').hide();
}
if (
this.interVerdict > 0 &&
this.conditionCheck == 0
) {
this.getOptionDescByProposalId(
this.interVerdict,
0
);
} else if (this.conditionCheck == 0) {
this.getOptionDescByProposalId(1, 1);
}
}.bind(this)
);
} else {
console.log(
'Error of getCategoryName function: ' +
errorCategory
);
}
}.bind(this)
);
} else {
console.log('Error in getProposalIncentive');
}
}.bind(this)
);
}.bind(this)
);
}.bind(this)
);
} else {
console.log('Here in error of getProposalDetailsById3');
console.log(errorId3);
}
}.bind(this)
);
}
getdAppTokenName() {
GlobalsComponent.gbmaster.getdAppTokenName(
this.userObj.companyName,
function(error, resName) {
this.tokenName = resName;
}.bind(this)
);
}
getAllParametersName(answer) {
this.parametersName = [
{
id: 'APO',
name: 'Add Proposal Owner',
desc:
'Reputation awarded to proposal initiator in case proposal is accepted'
},
{
id: 'AOO',
name: 'Add Option Owner',
desc:
'Reputation awarded to solution initiator in case proposal is accepted'
},
{
id: 'AVM',
name: 'Add Member',
desc:
' Reputation awarded to voter in case vote is in favour of accepted solution'
},
{
id: 'SPO',
name: 'Sub Proposal Owner',
desc:
'Reputation revoked fromproposal initiator in case proposal is rejected'
},
{
id: 'SOO',
name: 'Sub Option Owner',
desc:
'Reputation revoked from solution initiator in case solution is rejected'
},
{
id: 'SVM',
name: 'Sub Member',
desc:
'Reputation revoled from member in case vote against accepted solution'
},
{
id: 'GBTS',
name: 'GBTStakeValue',
desc:
'Minimum stake in GBT required to create a proposal. This ensures unnecessary proposal creation.'
},
{
id: 'RF',
name: 'Global Risk Factor',
desc:
'weightage given to proposal and solution initiator. More weightage factor means more incentive distribution to contributors.'
},
{
id: 'MSF',
name: 'Membership Scaling Factor',
desc: 'Minimum ownership % to be given greater weightage.'
},
{
id: 'SW',
name: 'Scaling Weight',
desc: 'Weightage of vote of member without staking.'
},
{
id: 'QP',
name: 'Quorum Percentage',
desc:
'It allows people to ensure that financial and legal decisions are always voted on by a good percentage of the members'
}
];
for (var i = 0; i < this.parametersName.length; i++) {
if (this.answer.description[0] == this.parametersName[i].id) {
this.configParamDesc = this.parametersName[i].desc;
this.configParamName = this.parametersName[i].name;
}
}
}
// Get Data from Hash
getDataFromHash(hash) {
if (hash == '') {
return hash;
} else {
console.log(hash);
var XMLHttp = new XMLHttpRequest();
XMLHttp.open('GET', 'https://ipfs.govblocks.io/ipfs/' + hash, false);
XMLHttp.send(null);
// // // this gives the json containing the details - title, description, voting type
var hashDetails = JSON.parse(XMLHttp.responseText);
// console.log(hashDetails);
return hashDetails;
}
}
public allParamsLength = 0;
public apiAllParamsLength = 0;
public allParameters = [];
public allApiParameters = [];
public allParameter: any = {};
public allApiParameter: any = {};
public allParameterName = [];
public allParameterDesc = [];
public allParameterType = [];
public allParaDescValue = [];
public allParameterFields = [];
public keepHtmlClass = false;
public allApiParameterName = [];
public allApiParameterDesc = [];
public allApiParaDescValue = [];
getCatgoryData2(catId) {
this.allParameterName = [];
this.allParameterDesc = [];
this.allParameterType = [];
this.allParameterFields = [];
this.allApiParameterName = [];
this.allApiParameterDesc = [];
GlobalsComponent.categoryData[
this.userObj.companyName
].getCategoryDataBySubCategoryId(
this.pCategoryId,
function(errorCategory, resultCategory) {
if (!errorCategory) {
var i: number;
var categoryDetails = resultCategory;
if ('parameterNames' in categoryDetails) {
this.allParamsLength = categoryDetails.parameterTypes.length;
}
if ('apiParameterNames' in categoryDetails) {
this.apiAllParamsLength = categoryDetails.apiParameterNames.length;
}
for (i = 0; i < this.allParamsLength; i++) {
this.keepHtmlClass = true;
this.allParameterName.push(categoryDetails.parameterNames[i]);
this.allParameterDesc.push(
categoryDetails.parameterDescriptions[i]
);
this.allParameterType.push(categoryDetails.parameterTypes[i]);
if (categoryDetails.parameterTypes[i].startsWith('uint')) {
this.allParameterFields[i] = 'number';
} else if (categoryDetails.parameterTypes[i].startsWith('bool')) {
this.allParameterFields[i] = 'text';
} else {
this.allParameterFields[i] = 'text';
}
}
for (var j = 0; j < this.apiAllParamsLength; j++) {
this.keepHtmlClass = true;
if (categoryDetails.apiParameterNames[j].includes('record')) {
this.recordIndex = j;
}
this.allApiParameterName.push(categoryDetails.apiParameterNames[j]);
this.allApiParameterDesc.push(
categoryDetails.apiParameterDescriptions[j]
);
}
$('#loader').hide();
this.getOptionDescHash();
} else {
console.log('Error of getCatgoryData2 function: ' + errorCategory);
}
}.bind(this)
);
}
public recordIndex;
public recordData = '';
getLandRecord(index) {
var recordHash = this.proposalSolutionApiParams[index];
var XMLHttp = new XMLHttpRequest();
XMLHttp.open('GET', 'https://ipfs.govblocks.io/ipfs/' + recordHash, false);
XMLHttp.send(null);
this.recordData = JSON.parse(XMLHttp.responseText);
$('#recordModal').modal('show');
}
timeout(hash) {
setTimeout(() => {
console.log('Test');
var boundFunction = this.web3.eth.getTransactionReceipt(
hash,
function(error, result) {
if (result != null) {
setTimeout(() => {
if (this.proposalStatusIndex <= 1) {
this.toastr.success(
'Open proposal for voting created along with answer!'
);
this.loadingSubmit = false;
this.refresh();
} else {
this.toastr.success('Stake in GBT Successfully Submitted!');
this.loading = false;
this.refresh();
}
}, 4000);
} else this.timeout(hash);
}.bind(this)
);
}, 10 * 1000);
}
timeoutReject(hash) {
setTimeout(() => {
console.log('Test');
var boundFunction = this.web3.eth.getTransactionReceipt(
hash,
function(error, result) {
if (result != null) {
setTimeout(() => {
this.toastr.success('Rejected Proposal Successfull');
this.loadingRejected = false;
this.refresh();
}, 4000);
} else this.timeoutReject(hash);
}.bind(this)
);
}, 10 * 1000);
}
timeoutUpVote(hash) {
setTimeout(() => {
console.log('Test');
var boundFunction = this.web3.eth.getTransactionReceipt(
hash,
function(error, result) {
if (result != null) {
setTimeout(() => {
this.toastr.success('UpVote Successfull!');
this.loadingAccept = false;
this.loadingVote = false;
this.refresh();
}, 4000);
} else {
this.timeoutUpVote(hash);
}
}.bind(this)
);
}, 10 * 1000);
}
timeoutAnswer(hash) {
setTimeout(() => {
console.log('Test');
var boundFunction = this.web3.eth.getTransactionReceipt(
hash,
function(error, result) {
if (result != null) {
setTimeout(() => {
this.toastr.success('Submitted Answer Successfull!');
this.loadingSubmit = false;
this.refresh();
}, 4000);
} else this.timeoutAnswer(hash);
}.bind(this)
);
}, 10 * 1000);
}
submitStake(pIndex): void {
var user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
if (this.userObj.email == 'govblocks@govblocks.io') {
this.message =
'Please login to your google account in order to create proposal
';
$('#loginModal').modal('show');
} else {
this.loading = true;
let nans = GlobalsComponent.governance[
this.userObj.companyName
].openProposalForVoting(
pIndex,
function(error1, resultStart) {
if (!error1) {
console.log('here is the result categorizeProposal' + resultStart);
this.toastr.info(
'Request submitted to ethereum(' +
GlobalsComponent.network +
'). Awaiting confirmation!'
);
this.timeout(resultStart);
} else {
this.loading = false;
console.log('Error in openProposalForVoting');
console.log(error1);
}
}.bind(this)
);
}
}
rejectStake(pIndex): void {
var user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
if (this.userObj.email == 'govblocks@govblocks.io') {
this.message =
'Please login to your google account in order to create proposal
';
$('#loginModal').modal('show');
} else {
var dAppName;
if (this.subCategoryExternal) {
dAppName = 'GOVBLOCKS';
} else {
dAppName = this.userObj.companyName;
}
GlobalsComponent.governance[
this.userObj.companyName
].getTokensLockedAtTime(
dAppName,
this.memberAddress,
'GOV',
Math.floor(Date.now() / 1000) + this.tokenHoldingTime * 1,
function(error, result) {
if (result >= this.minStake) {
this.loadingRejected = true;
var categoryId;
var currentVotingId;
$('#onAccept').attr('disabled', true);
var _optionChosen = [0];
let proVot = GlobalsComponent.governance[
this.userObj.companyName
].proposalVoting(
pIndex,
_optionChosen,
function(error1, _result1) {
if (!error1) {
this.toastr.info(
'Submitted the rejection to ethereum(' +
GlobalsComponent.network +
'). Awaiting confirmation!'
);
this.timeoutReject(_result1);
} else {
this.loadingRejected = false;
$('#onAccept').removeAttr('disabled');
console.log('Error in Rejection Process.');
console.log(error1);
}
}.bind(this)
);
} else {
this.toastr.warning(
'Lock more tokens inorder to vote for this proposal'
);
}
}.bind(this)
);
}
}
upVote(): void {
var pIndex = this.proposalId;
var user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
if (this.userObj.email == 'govblocks@govblocks.io') {
this.message =
'Please login to your google account in order to create proposal
';
$('#loginModal').modal('show');
} else {
var dAppName;
if (this.subCategoryExternal) {
dAppName = 'GOVBLOCKS';
} else {
dAppName = this.userObj.companyName;
}
GlobalsComponent.governance[
this.userObj.companyName
].getTokensLockedAtTime(
dAppName,
this.memberAddress,
'GOV',
Math.floor(Date.now() / 1000) + this.tokenHoldingTime * 1,
function(error, result) {
if (result >= this.minStake) {
var categoryId;
var currentVotingId;
this.loadingAccept = true;
this.loadingVote = true;
$('#onReject').attr('disabled', true);
var _optionChosen = [];
if (this.conditionCheck == 1) {
_optionChosen = [1];
} else {
_optionChosen = [this.optionNumber];
}
let proVot = GlobalsComponent.governance[
this.userObj.companyName
].proposalVoting(
pIndex,
_optionChosen,
function(error1, __result1) {
if (!error1) {
this.toastr.info(
'Submitted the UpVote to ethereum(' +
GlobalsComponent.network +
'). Awaiting confirmation!'
);
this.timeoutUpVote(__result1);
} else {
this.loadingAccept = false;
this.loadingVote = false;
$('#onReject').removeAttr('disabled');
console.log('Error in UpVoting.');
console.log(error1);
}
}.bind(this)
);
} else {
this.toastr.warning(
'Lock more tokens inorder to vote for this proposal'
);
}
}.bind(this)
);
}
}
saveText() {
if (this.canSubmitSol) {
var user = localStorage.getItem('currentUser');
this.userObj = JSON.parse(user);
if (this.userObj.email == 'govblocks@govblocks.io') {
this.message =
'Please login to your google account in order to create proposal
';
$('#loginModal').modal('show');
} else {
this.loadingSubmit = true;
this.SummerNoteText = this.textAreaData;
GlobalsComponent.proposalData[
this.userObj.companyName
].getProposalDetailsById2(
this.proposalId,
function(err, res) {
var categoryId = res[1];
GlobalsComponent.categoryData[
this.userObj.companyName
].getCategoryDataBySubCategoryId(
categoryId,
function(errCategoryData, resCategoryData) {
var categoryData = resCategoryData;
if (!('function' in categoryData)) {
this.allParaDescValue.length = 0;
categoryData['parameterDescriptions'] = [];
categoryData['parameterTypes'] = [];
}
if (
categoryData.parameterDescriptions.length ==
this.allParaDescValue.length
) {
for (var i = 0; i < categoryData.parameterTypes.length; i++) {
if (categoryData.parameterTypes[i].startsWith('bool')) {
this.allParaDescValue[i] = JSON.parse(
this.allParaDescValue[i]
);
}
}
var data = {
proposalData: '',
optionData: {
ansDescription: this.SummerNoteText,
paramValues: this.allParaDescValue,
apiParamValues: this.allApiParaDescValue
}
};
if (!this.checked) {
let initiate = GlobalsComponent.governance[
this.userObj.companyName
].initiateAddSolution(
data,
this.proposalId,
this.memberAddress,
function(errInitiate, resultInitiate) {
if (!errInitiate) {
this.toastr.info(
'Answer Submitted to ethereum(' +
GlobalsComponent.network +
'). Awaiting confirmation!'
);
this.timeoutAnswer(resultInitiate);
} else {
this.loadingSubmit = false;
console.log(
'Here in error of Initiate Verdict Option..'
);
console.log(errInitiate);
}
}.bind(this)
);
} else {
this.submitProposalWithSolution(data);
}
}
}.bind(this)
);
}.bind(this)
);
}
} else {
// this.toastr.warning('Please Lock more tokens to submit solution');
if (this.reasonSubmitSol[0] == 'Not Allowed')
this.toastr.warning(
'You are not authorized to create proposal under this category'
);
else if (this.reasonSubmitSol[0] == 'Less Tokens')
this.toastr.warning(
'Lock ' +
this.tokensToLock['Pause'] +
' token(s) to create a proposal under this category'
);
}
}
submitProposalWithSolution(data) {
GlobalsComponent.governance[
this.userObj.companyName
].submitProposalWithSolution(
data,
this.proposalId,
function(error1, result1) {
if (!error1) {
this.toastr.info(
'Proposal submitted to ethereum(' +
GlobalsComponent.network +
'). Awaiting confirmation!'
);
this.timeout(result1);
} else {
this.loadingSubmit = false;
this.toastr.error('Error executing the operation');
this.loading = false;
}
}.bind(this)
);
}
public reasonPauseProposal = null;
public loaderPauseProposal = false;
pauseProposal() {
this.loaderPauseProposal = true;
if (this.canCreateProposal['Pause']) {
var proposalData = [
{
title: 'Pause Proposal ' + this.pTitle,
shortDescription: this.reasonPauseProposal,
description: this.reasonPauseProposal
}
];
var optionData = {
paramValues: [this.proposalId],
apiParamValues: []
};
var data = {
proposalData: proposalData,
optionData: optionData,
cId: 18,
votingType: 0
};
GlobalsComponent.governance[
this.userObj.companyName
].createProposalwithOption(
data,
function(error, result) {
if (!error) {
this.timeoutPauseProposal(result);
} else {
this.loaderPauseProposal = false;
this.toastr.error('Error in creating proposal');
}
}.bind(this)
);
} else {
this.loaderPauseProposal = false;
if (this.reason['Pause'] == 'Not Allowed')
this.toastr.warning(
'You are not authorized to create proposal under this category'
);
else if (this.reason['Pause'] == 'Less Tokens')
this.toastr.warning(
'Lock ' +
this.tokensToLock['Pause'] +
' token(s) to create a proposal under this category'
);
}
}
resumeProposal() {
this.loaderPauseProposal = true;
if (this.canCreateProposal['Resume']) {
var proposalData = [
{
title: 'Resume Proposal ' + this.pTitle,
shortDescription: this.reasonPauseProposal,
description: this.reasonPauseProposal
}
];
var optionData = {
paramValues: [this.proposalId],
apiParamValues: []
};
var data = {
proposalData: proposalData,
optionData: optionData,
cId: 17,
votingType: 0
};
GlobalsComponent.governance[
this.userObj.companyName
].createProposalwithOption(
data,
function(error, result) {
if (!error) {
this.timeoutPauseProposal(result);
} else {
this.loaderPauseProposal = false;
this.toastr.error('Error in creating proposal');
}
}.bind(this)
);
} else {
this.loaderPauseProposal = false;
if (this.reason['Resume'] == 'Not Allowed')
this.toastr.warning(
'You are not authorized to create proposal under this category'
);
else if (this.reason['Resume'] == 'Less Tokens')
this.toastr.warning(
'Lock ' +
this.tokensToLock['Resume'] +
' token(s) to create a proposal under this category'
);
}
}
timeoutPauseProposal(hash) {
setTimeout(() => {
var boundFunction = this.web3.eth.getTransactionReceipt(
hash,
function(error, result) {
if (result != null) {
var proposalId = result.logs[0].topics[2];
proposalId = this.web3.toDecimal(proposalId);
this.proposalId = proposalId;
this.toastr.success('Proposal created succesfully!');
this.loaderPauseProposal = false;
this.router1.navigate([
this.iframeURl +
'/components/proposals/' +
this.userObj.companyName +
'/' +
proposalId
]);
setTimeout(() => {
window.location.reload();
}, 3000);
} else this.timeoutPauseProposal(hash);
}.bind(this)
);
}, 1000);
}
public modalTitle;
resetDescription(val) {
if (val == 1) {
this.modalTitle = 'Pause Proposal';
} else {
this.modalTitle = 'Resume Proposal';
}
this.reasonPauseProposal = null;
}
iframeResize() {
import('../../globals/globals.component').then(module => {
module.iframe_resize();
});
}
openSlide(event) {
var data_target = event.target.getAttribute('data-target');
$('.sidebar-overlay').each(function() {
$(this).removeClass('open');
if ($(this).attr('id') == data_target) {
$(this).addClass('open');
}
});
}
closeSlide(event) {
// var data_dismiss = event.target.getAttribute('data-dismiss');
$('.sidebar-overlay').each(function() {
$(this).removeClass('open');
});
}
}
export class ProposalsIframeComponent extends ProposalsComponent {}