import { Component, OnInit, ViewEncapsulation, AfterViewInit, Injectable } from '@angular/core'; import { Router } from '@angular/router'; import Web3 from 'web3'; import { DetailsService } from '../details.service'; import { GovBlocksMaster } from 'govblocksjs'; @Component({ selector: 'app-globals', template: `

globals works!

`, styles: [] }) @Injectable() export class GlobalsComponent implements OnInit { // public data; router: any; public static masterAbi: Array; public static governanceDataAbi: Array; public static memberRolesAbi: Array; public static proposalCategoryAbi: Array; public static simpleVotingAbi: Array; public static rankBasedVotingAbi: Array; public static featureWeightedAbi: Array; public static standardVotingTypeAbi: Array; public static governanceAbi: Array; public static poolAbi: Array; public static GBTControllerAbi: Array; public static GBTStandardTokenAbi: Array; public static votingTypeAbi = [ { constant: false, inputs: [ { name: '_proposalId', type: 'uint256' }, { name: '_solutionStake', type: 'uint256' }, { name: '_solutionHash', type: 'string' }, { name: '_validityUpto', type: 'uint256' }, { name: '_v', type: 'uint8' }, { name: '_r', type: 'bytes32' }, { name: '_s', type: 'bytes32' }, { name: '_lockTokenTxHash', type: 'bytes32' } ], name: 'initiateAddSolution', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: false, inputs: [{ name: '_proposalId', type: 'uint256' }], name: 'giveReward_afterFinalDecision', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: false, inputs: [ { name: '_proposalId', type: 'uint256' }, { name: '_memberAddress', type: 'address' }, { name: '_solutionStake', type: 'uint256' }, { name: '_solutionHash', type: 'string' }, { name: '_dateAdd', type: 'uint256' }, { name: '_validityUpto', type: 'uint256' }, { name: '_v', type: 'uint8' }, { name: '_r', type: 'bytes32' }, { name: '_s', type: 'bytes32' }, { name: '_lockTokenTxHash', type: 'bytes32' } ], name: 'addSolution', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: false, inputs: [ { name: '_proposalId', type: 'uint256' }, { name: '_solutionChosen', type: 'uint256[]' }, { name: '_voteStake', type: 'uint256' }, { name: '_validityUpto', type: 'uint256' }, { name: '_v', type: 'uint8' }, { name: '_r', type: 'bytes32' }, { name: '_s', type: 'bytes32' }, { name: '_lockTokenTxHash', type: 'bytes32' } ], name: 'proposalVoting', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: false, inputs: [{ name: '_proposalId', type: 'uint256' }], name: 'closeProposalVote', outputs: [], payable: false, stateMutability: 'nonpayable', type: 'function' }, { constant: true, inputs: [], name: 'votingTypeName', outputs: [{ name: '', type: 'string' }], payable: false, stateMutability: 'view', type: 'function' } ]; public static gbMasterAbi; public static gbMasterAddress; public static masterAddress; public static governanceDataAddress; public static memberRolesAddress; public static proposalCategoryAddress; public static simpleVotingAddress; public static rankBasedVotingAddress; public static featureWeightedAddress; public static standardVotingTypeAddress; public static governanceAddress; public static poolAddress; public static GBTControllerAddress; public static GBTStandardTokenAddress; public static result; public static network; public static apiObj = {}; public static apiInstance; public static gbmaster; public static governance = {}; public static proposalData = {}; public static memberData = {}; public static categoryData = {}; // public static gbApiObj = GBapi; public startIndex; public lengthOfProposal; public categoryName; public proposalCount; public proposalIndex; public stakes; public userObj; public abiArray = []; public web3; public proposals = []; public allAbis = []; public versionContract = [ 'Master', 'GovernanceData', 'MemberRoles', 'ProposalCategory', 'SimpleVoting', 'RankBasedVoting', 'FeatureWeighted', 'StandardVotingType', 'Governance', 'Pool', 'GBTController', 'GBTStandardToken' ]; constructor() { let user = localStorage.getItem('currentUser'); this.userObj = JSON.parse(user); this.web3 = new Web3(window['web3'].currentProvider); this.web3.eth.defaultAccount = this.web3.eth.coinbase; GlobalsComponent.gbmaster = new GovBlocksMaster(this.web3); // this.web3.version.getNetwork((err, netId) => // { // GlobalsComponent.gbMasterAddress="0xbc7e609bc10b22c206b4fd2dc90b5637697cad0d"; // GlobalsComponent.gbMasterAbi=[{"constant":true,"inputs":[],"name":"getGBTCAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_GDAddress","type":"address"},{"name":"_SVAddress","type":"address"},{"name":"_GOVAddress","type":"address"}],"name":"changeAllAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getAllDappLength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_memberAddress","type":"address"}],"name":"changeAuthorizedGB","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_gbUserName","type":"bytes32"}],"name":"getGovBlocksUserDetails","outputs":[{"name":"GbUserName","type":"bytes32"},{"name":"masterContractAddress","type":"address"},{"name":"allContractsbyteCodeHash","type":"string"},{"name":"allCcontractsAbiHash","type":"string"},{"name":"versionNo","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getGOVAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_memberAddress","type":"address"},{"name":"_memberRoleId","type":"uint256"},{"name":"_typeOf","type":"uint8"}],"name":"updateMemberRoleGB","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_gbUserName","type":"bytes32"}],"name":"getDappDescHash","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_gbUserName","type":"bytes32"}],"name":"getDappMasterAddress","outputs":[{"name":"masterAddress","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_memberAddress","type":"address"}],"name":"isAuthorizedGBOwner","outputs":[{"name":"auth","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_GBTControllerAddress","type":"address"},{"name":"_GBTAddress","type":"address"}],"name":"GovBlocksMasterInit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_Address","type":"address"}],"name":"getGovBlocksUserDetails2","outputs":[{"name":"dappName","type":"bytes32"},{"name":"masterContractAddress","type":"address"},{"name":"dappTokenAddress","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getDappUser","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_gbUserName","type":"bytes32"}],"name":"getDappTokenAddress","outputs":[{"name":"tokenAddres","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_GBTConrollerAddress","type":"address"}],"name":"updateGBTControllerAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_categoryId","type":"uint256"},{"name":"_categoryData","type":"string"}],"name":"updateCategoryGB","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_dappDescriptionHash","type":"string"}],"name":"changeDappDescHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getGBTandGBTC","outputs":[{"name":"_GBTController","type":"address"},{"name":"_GBToken","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_gbUserName","type":"bytes32"}],"name":"getGovBlocksUserDetails1","outputs":[{"name":"GbUserName","type":"bytes32"},{"name":"masterContractAddress","type":"address"},{"name":"dappTokenAddress","type":"address"},{"name":"allContractsbyteCodeHash","type":"string"},{"name":"allCcontractsAbiHash","type":"string"},{"name":"versionNo","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getSVAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAllDappArray","outputs":[{"name":"","type":"bytes32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_descHash","type":"string"}],"name":"addNewCategoryGB","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"authGBOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_GBTControllerAddress","type":"address"},{"name":"_GBTokenAddress","type":"address"}],"name":"changeAllAddress1","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_index","type":"uint256"}],"name":"getGovBlocksUserDetailsByIndex","outputs":[{"name":"index","type":"uint256"},{"name":"GbUserName","type":"bytes32"},{"name":"MasterContractAddress","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getGDAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_typeOf","type":"bytes16"},{"name":"_value","type":"uint256"}],"name":"configureGlobalParameters","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_hash","type":"string"}],"name":"setDappUser","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_byteCodeHash","type":"string"},{"name":"_abiHash","type":"string"}],"name":"setByteCodeAndAbi","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_newMasterAddress","type":"address"}],"name":"changeDappMasterAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getGBTAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_dappTokenAddress","type":"address"}],"name":"changeDappTokenAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_dappTokenAddress","type":"address"},{"name":"_dappDescriptionHash","type":"string"}],"name":"addGovBlocksUser","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getByteCodeAndAbi","outputs":[{"name":"byteCode","type":"string"},{"name":"abiHash","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_gbUserName","type":"bytes32"},{"name":"_newRoleName","type":"bytes32"},{"name":"_newDescHash","type":"string"}],"name":"addNewMemberRoleGB","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_contractAddress","type":"address"}],"name":"getDappNameByAddress","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_gbIndex","type":"uint256"}],"name":"getAllDappById","outputs":[{"name":"_gbUserName","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_GBTContractAddress","type":"address"}],"name":"updateGBTAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]; this.generateAllAbis(); // }); this.web3.version.getNetwork((err, netId) => { switch (netId) { case '1': GlobalsComponent.network = 'main-net'; break; case '2': GlobalsComponent.network = 'ropsten'; break; case '42': GlobalsComponent.network = 'kovan'; break; case '4': GlobalsComponent.network = 'rinkeby'; break; default: GlobalsComponent.network = 'unknown'; } }); // console.log(GBapi); // console.log(GlobalsComponent.gbmaster); // GlobalsComponent.gbmaster.getdAppInstance("GOVBLOCKS",function(error,result){ // console.log(result); // }.bind(this)); var instance; if ( this.userObj.companyName != '' && this.userObj.companyName != null && GlobalsComponent.governance[this.userObj.companyName] == null ) { let i = GlobalsComponent.gbmaster.getdAppInstance( this.userObj.companyName, function(error, result1) { instance = result1; // GlobalsComponent.apiObj[instance.dAppName] = instance.main; GlobalsComponent.governance[instance.dAppName] = instance.governance; GlobalsComponent.proposalData[instance.dAppName] = instance.proposalData; (window).proposalData = GlobalsComponent.proposalData; GlobalsComponent.memberData[instance.dAppName] = instance.memberData; GlobalsComponent.categoryData[instance.dAppName] = instance.categoryData; }.bind(this) ); } } generateAllAbis() { GlobalsComponent.gbmaster.getABIarray( function(errHash, resHash) { if (!errHash) { this.abiArray = resHash; this.setAllAbi(); } }.bind(this) ); } setAllAbi() { GlobalsComponent.masterAbi = this.abiArray['Master']; GlobalsComponent.governanceDataAbi = this.abiArray['GovernanceData']; GlobalsComponent.memberRolesAbi = this.abiArray['MemberRoles']; GlobalsComponent.proposalCategoryAbi = this.abiArray['ProposalCategory']; GlobalsComponent.simpleVotingAbi = this.abiArray['SimpleVoting']; GlobalsComponent.rankBasedVotingAbi = this.abiArray['RankBasedVoting']; GlobalsComponent.featureWeightedAbi = this.abiArray[ 'FeatureWeightedVoting' ]; GlobalsComponent.standardVotingTypeAbi = this.abiArray[ 'StandardVotingType' ]; GlobalsComponent.governanceAbi = this.abiArray['Governance']; GlobalsComponent.poolAbi = this.abiArray['Pool']; GlobalsComponent.GBTStandardTokenAbi = this.abiArray['GBTStandardToken']; this.setAllAddress(); } public poolBalance; public tokenPrice; setAllAddress() { let user = localStorage.getItem('currentUser'); this.userObj = JSON.parse(user); if (this.userObj.masterAddress != '') { GlobalsComponent.gbmaster.getdAppContractAddresses( this.userObj.companyName, function(error2, result2) { if (!error2) { GlobalsComponent.result = result2; GlobalsComponent.masterAddress = this.userObj.masterAddress; GlobalsComponent.governanceDataAddress = result2['G0vernanceData']; GlobalsComponent.memberRolesAddress = result2['MemberRoles']; GlobalsComponent.proposalCategoryAddress = result2['ProposalCategory']; GlobalsComponent.simpleVotingAddress = result2['SimpleVoting']; GlobalsComponent.rankBasedVotingAddress = result2['RankBasedVoting']; GlobalsComponent.featureWeightedAddress = result2['FeatureWeighted']; GlobalsComponent.standardVotingTypeAddress = result2['StandardVotingType']; GlobalsComponent.governanceAddress = result2['Governance']; GlobalsComponent.poolAddress = result2['Pool']; GlobalsComponent.GBTStandardTokenAddress = result2['GBTStandardToken']; GlobalsComponent.gbmaster.getPoolBalanceinETH( this.userObj.companyName, function(errorPoolBal, resPoolBal) { this.poolBalance = (resPoolBal.toNumber() / 1e18).toFixed(2); }.bind(this) ); GlobalsComponent.gbmaster.getGBTokenPrice( function(error1, result1) { if (!error1) { this.actualTokenPrice = result1; this.tokenPrice = this.actualTokenPrice / 1e18; } }.bind(this) ); } }.bind(this) ); } } getAbiFromArray(contractname) { for (var i = 0; i < this.allAbis.length; i++) { if (this.allAbis[i].smartcontractcode == contractname) { return JSON.parse(this.allAbis[i].contractAbi); } } } ngOnInit() {} } export function generator() { var web3 = new Web3(window['web3'].currentProvider); // console.log(this.web3); web3.eth.defaultAccount = web3.eth.coinbase; let user = localStorage.getItem('currentUser'); this.userObj = JSON.parse(user); var instance; if (GlobalsComponent.gbmaster == undefined) { GlobalsComponent.gbmaster = new GovBlocksMaster(web3); } if ( this.userObj.companyName != '' && this.userObj.companyName != null && GlobalsComponent.governance[this.userObj.companyName] == null ) { let i = GlobalsComponent.gbmaster.getdAppInstance( this.userObj.companyName, function(error, result1) { instance = result1; // GlobalsComponent.apiObj[instance.dAppName] = instance.main; GlobalsComponent.governance[instance.dAppName] = instance.governance; GlobalsComponent.proposalData[instance.dAppName] = instance.proposalData; (window).proposalData = GlobalsComponent.proposalData; GlobalsComponent.memberData[instance.dAppName] = instance.memberData; GlobalsComponent.categoryData[instance.dAppName] = instance.categoryData; }.bind(this) ); } if (this.userObj.masterAddress != '') { GlobalsComponent.gbmaster.getdAppContractAddresses( this.userObj.companyName, function(error2, result2) { if (!error2) { GlobalsComponent.result = result2; GlobalsComponent.masterAddress = this.userObj.masterAddress; GlobalsComponent.governanceDataAddress = result2['GvernanceData']; GlobalsComponent.memberRolesAddress = result2['MemberRoles']; GlobalsComponent.proposalCategoryAddress = result2['ProposalCategory']; GlobalsComponent.simpleVotingAddress = result2['SimpleVoting']; GlobalsComponent.rankBasedVotingAddress = result2['RankBasedVoting']; GlobalsComponent.featureWeightedAddress = result2['FeatureWeighted']; GlobalsComponent.standardVotingTypeAddress = result2['StandardVotingType']; GlobalsComponent.governanceAddress = result2['Governance']; GlobalsComponent.poolAddress = result2['Pool']; GlobalsComponent.GBTStandardTokenAddress = result2['GBTStandardToken']; } }.bind(this) ); } } export function setDappInstance(companyName) { var instance; let i = GlobalsComponent.gbmaster.getdAppInstance( companyName, function(error, result1) { instance = result1; // GlobalsComponent.apiObj[instance.dAppName] = instance.main; GlobalsComponent.governance[instance.dAppName] = instance.governance; GlobalsComponent.proposalData[instance.dAppName] = instance.proposalData; (window).proposalData = GlobalsComponent.proposalData; GlobalsComponent.memberData[instance.dAppName] = instance.memberData; GlobalsComponent.categoryData[instance.dAppName] = instance.categoryData; }.bind(this) ); } export function iframe_resize() { // var body = document.body, // html = document.documentElement, // height = Math.max(body.scrollHeight, body.offsetHeight, // html.clientHeight, html.scrollHeight, html.offsetHeight); var iframe; if (window.location.href.includes('iframe')) { $('body.m-content--skin-light2').css('background-color', 'transparent'); $('.iframe>.m-wrapper').css('height', '100%'); iframe = document.getElementsByClassName('iframe'); var height = Math.max(iframe[0].scrollHeight, iframe[0].offsetHeight, 500); if (parent.postMessage) { parent.postMessage(height, '*'); } } }