From 1077841fe7277bd95ec8ba138340a2dea0eb18c1 Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva Date: Tue, 12 Jun 2018 19:08:56 -0300 Subject: [PATCH] stability fixes --- package.json | 4 +- src/app/dashboard/send/send.component.ts | 17 +- src/app/dashboard/vote/vote.component.ts | 11 +- src/app/dashboard/vote/voting.service.ts | 232 ++++++++++++----------- src/app/eosjs.service.ts | 1 - src/index.html | 2 +- 6 files changed, 142 insertions(+), 125 deletions(-) diff --git a/package.json b/package.json index b4b928e4..691eb14c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "iconUrl": "file:///C:/simpleos/src/favicon.ico", "setupIcon": "C:/simpleos/src/favicon.ico", "noMsi": false, - "setupMsi": "simplEOS-setup" + "setupMsi": "simplEOS-setup.msi" } }, { @@ -116,6 +116,7 @@ "popper.js": "^1.14.3", "primeng": "^5.2.6", "rxjs": "^6.2.0", + "opn": "^5.3.0", "rxjs-compat": "^6.2.0", "text-encoding-shim": "latest", "text-mask-addons": "^3.7.2", @@ -151,7 +152,6 @@ "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "npm-run-all": "^4.1.3", - "opn": "^5.3.0", "protractor": "~5.3.0", "ts-node": "~5.0.1", "tslint": "~5.9.1", diff --git a/src/app/dashboard/send/send.component.ts b/src/app/dashboard/send/send.component.ts index 7e364e3d..0192a02f 100644 --- a/src/app/dashboard/send/send.component.ts +++ b/src/app/dashboard/send/send.component.ts @@ -133,6 +133,13 @@ export class SendComponent implements OnInit { this.sendForm.controls['amount'].setErrors(null); this.amounterror = ''; } + if (parseFloat(this.sendForm.value.amount) === 0 || this.sendForm.value.amount === '') { + this.sendForm.controls['amount'].setErrors({'incorrect': true}); + this.amounterror = 'invalid amount'; + } else { + this.sendForm.controls['amount'].setErrors(null); + this.amounterror = ''; + } } checkAccountName() { @@ -302,7 +309,7 @@ export class SendComponent implements OnInit { } openSendModal() { - // this.confirmForm.reset(); + this.confirmForm.reset(); this.fromAccount = this.aService.selected.getValue().name; this.sendModal = true; } @@ -315,12 +322,11 @@ export class SendComponent implements OnInit { const amount = this.sendForm.get('amount').value; const memo = this.sendForm.get('memo').value; const publicKey = selAcc.details['permissions'][0]['required_auth'].keys[0].key; - console.log(publicKey); if (amount > 0 && this.sendForm.valid) { - console.log(this.confirmForm.get('pass').value, publicKey); this.eos.authenticate(this.confirmForm.get('pass').value, publicKey).then((res) => { + console.log('AuthResult', res); if (res === true) { - this.eos.transfer(from, to, amount.toFixed(4) + ' EOS', memo).then((result) => { + this.eos.transfer(from, to, parseFloat(amount).toFixed(4) + ' EOS', memo).then((result) => { this.aService.refreshFromChain(); if (result === true) { this.wrongpass = ''; @@ -348,6 +354,9 @@ export class SendComponent implements OnInit { this.busy = false; this.wrongpass = 'Wrong password!'; } + }).catch(() => { + this.busy = false; + this.wrongpass = 'Error: Wrong password!'; }); } } diff --git a/src/app/dashboard/vote/vote.component.ts b/src/app/dashboard/vote/vote.component.ts index 25bc763b..cb3a3593 100644 --- a/src/app/dashboard/vote/vote.component.ts +++ b/src/app/dashboard/vote/vote.component.ts @@ -31,7 +31,6 @@ export class VoteComponent implements OnInit, AfterViewInit { private fb: FormBuilder, private toaster: ToasterService) { this.max = 100; this.min = 0; - this.nVotes = 0; this.valuetoStake = 0; this.percenttoStake = 0; this.stakeModal = false; @@ -56,6 +55,11 @@ export class VoteComponent implements OnInit, AfterViewInit { this.stakedBalance = selected.staked; this.loadPlacedVotes(selected); }); + this.voteService.listReady.asObservable().subscribe((state) => { + if (state) { + this.updateCounter(); + } + }); this.aService.accounts.forEach((a) => { if (a.name === selectedAcc.name) { const currentVotes = a.details['voter_info']['producers']; @@ -67,8 +71,8 @@ export class VoteComponent implements OnInit, AfterViewInit { } ngAfterViewInit() { + console.log('ngAfterViewInit'); this.voteService.listProducers(); - this.updateCounter(); } processVotes() { @@ -85,10 +89,12 @@ export class VoteComponent implements OnInit, AfterViewInit { updateCounter() { let val = 0; this.voteService.bps.forEach((bp) => { + console.log(bp.checked); if (bp.checked) { val++; } }); + console.log('Count votes:' + val); this.nVotes = val; } @@ -134,6 +140,7 @@ export class VoteComponent implements OnInit, AfterViewInit { this.voteService.bps.forEach((elem) => { elem.checked = currentVotes.indexOf(elem.account) !== -1; }); + this.updateCounter(); } private showToast(type: string, title: string, body: string) { diff --git a/src/app/dashboard/vote/voting.service.ts b/src/app/dashboard/vote/voting.service.ts index 1d40cbdf..d0a01ce5 100644 --- a/src/app/dashboard/vote/voting.service.ts +++ b/src/app/dashboard/vote/voting.service.ts @@ -5,134 +5,136 @@ import {Subject} from 'rxjs'; import {AccountsService} from '../../accounts.service'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class VotingService { - public bps: any[]; - public listReady = new Subject(); - public counter = new Subject(); - selectedAccount: any; - initList: boolean; - totalActivatedStake: number; - totalProducerVoteWeight: number; - chainActive: boolean; - stakePercent: number; + public bps: any[]; + public listReady = new Subject(); + public counter = new Subject(); + selectedAccount: any; + initList: boolean; + totalActivatedStake: number; + totalProducerVoteWeight: number; + chainActive: boolean; + stakePercent: number; - constructor(private eos: EOSJSService, private http: HttpClient, private aService: AccountsService) { - this.bps = []; - this.initList = false; - this.chainActive = false; - this.totalActivatedStake = 0; - this.totalProducerVoteWeight = 0; - this.stakePercent = 0; - this.startUpdateGlobalStake(); - this.aService.selected.asObservable().subscribe((sA) => { - this.selectedAccount = sA; - if (this.bps.length === 0 && !this.initList) { - this.listProducers(); - } - }); - } + constructor(private eos: EOSJSService, private http: HttpClient, private aService: AccountsService) { + this.bps = []; + this.initList = false; + this.chainActive = false; + this.totalActivatedStake = 0; + this.totalProducerVoteWeight = 0; + this.stakePercent = 0; + this.startUpdateGlobalStake(); + this.aService.selected.asObservable().subscribe((sA) => { + this.selectedAccount = sA; + if (this.bps.length === 0 && !this.initList) { + this.listProducers(); + } + }); + } - shuffle(array) { - let currentIndex = array.length, temporaryValue, randomIndex; - while (0 !== currentIndex) { - randomIndex = Math.floor(Math.random() * currentIndex); - currentIndex -= 1; - temporaryValue = array[currentIndex]; - array[currentIndex] = array[randomIndex]; - array[randomIndex] = temporaryValue; - } - return array; + shuffle(array) { + let currentIndex = array.length, temporaryValue, randomIndex; + while (0 !== currentIndex) { + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + temporaryValue = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temporaryValue; } + return array; + } - randomizeList() { - this.bps = this.shuffle(this.bps); - } + randomizeList() { + this.bps = this.shuffle(this.bps); + } - updateGlobalStake() { - this.eos.getChainInfo().then((global) => { - this.totalActivatedStake = parseInt(global.rows[0]['total_activated_stake'], 10) / 10000; - this.stakePercent = (Math.round((100 * this.totalActivatedStake / 150000000.0) * 1000) / 1000); - }); - } + updateGlobalStake() { + this.eos.getChainInfo().then((global) => { + this.totalActivatedStake = parseInt(global.rows[0]['total_activated_stake'], 10) / 10000; + this.stakePercent = (Math.round((100 * this.totalActivatedStake / 150000000.0) * 1000) / 1000); + }); + } - startUpdateGlobalStake() { - this.updateGlobalStake(); - setInterval(() => { - this.updateGlobalStake(); - }, 10000); - } + startUpdateGlobalStake() { + this.updateGlobalStake(); + setInterval(() => { + this.updateGlobalStake(); + }, 10000); + } - listProducers() { - if (this.initList === false) { - this.initList = true; - this.aService.initFirst(); - this.eos.listProducers().then((producers) => { - this.eos.getChainInfo().then((global) => { - this.totalActivatedStake = parseInt(global.rows[0]['total_activated_stake'], 10) / 10000; - this.totalProducerVoteWeight = parseFloat(global.rows[0]['total_producer_vote_weight']); - this.chainActive = this.totalActivatedStake > 150000000.0; - const total_votes = this.totalProducerVoteWeight; - // Pass 1 - Add accounts - producers.rows.forEach((prod: any, idx) => { - const vote_pct: any = Math.round((100 * prod['total_votes'] / total_votes) * 1000) / 1000; - const voted = this.selectedAccount.details['voter_info']['producers'].indexOf(prod['owner']) !== -1; - const producerMetadata = { - name: prod['owner'], - account: prod['owner'], - key: prod['producer_key'], - location: '', - status: (idx < 21 && this.chainActive) ? 'producing' : 'standby', - total_votes: vote_pct + '%', - social: '', - email: '', - website: prod.url, - logo_256: '', - code: '', - checked: voted - }; - this.bps.push(producerMetadata); - }); - this.listReady.next(true); - // Pass 2 - Enhance metadata - setTimeout(() => { - producers.rows.forEach((prod: any, idx) => { - this.improveMeta(prod, idx); - }); - }, 500); - }); + listProducers() { + if (this.initList === false) { + this.initList = true; + this.aService.initFirst(); + this.eos.listProducers().then((producers) => { + this.eos.getChainInfo().then((global) => { + this.totalActivatedStake = parseInt(global.rows[0]['total_activated_stake'], 10) / 10000; + this.totalProducerVoteWeight = parseFloat(global.rows[0]['total_producer_vote_weight']); + this.chainActive = this.totalActivatedStake > 150000000.0; + const total_votes = this.totalProducerVoteWeight; + // Pass 1 - Add accounts + const myAccount = this.aService.selected.getValue(); + console.log('MyAccount', myAccount, this.selectedAccount); + producers.rows.forEach((prod: any, idx) => { + const vote_pct: any = Math.round((100 * prod['total_votes'] / total_votes) * 1000) / 1000; + const voted = myAccount.details['voter_info']['producers'].indexOf(prod['owner']) !== -1; + const producerMetadata = { + name: prod['owner'], + account: prod['owner'], + key: prod['producer_key'], + location: '', + status: (idx < 21 && this.chainActive) ? 'producing' : 'standby', + total_votes: vote_pct + '%', + social: '', + email: '', + website: prod.url, + logo_256: '', + code: '', + checked: voted + }; + this.bps.push(producerMetadata); + }); + this.listReady.next(true); + // Pass 2 - Enhance metadata + setTimeout(() => { + producers.rows.forEach((prod: any, idx) => { + this.improveMeta(prod, idx); }); - } + }, 500); + }); + }); } + } - improveMeta(prod, idx) { - const url = prod.url.endsWith('.json') ? prod.url : prod.url + '/bp.json'; - if (url !== '') { - this.http.post('http://proxy.eosrio.io:4200', { - url: url - }).subscribe((data) => { - if (data) { - if (data['org']) { - const org = data['org']; - const loc = (org.location.name) ? (org.location.name + ', ' + org.location.country) : (org.location.country); - const logo_256 = (org['branding']) ? org['branding']['logo_256'] : ''; - if (data['producer_account_name'] === prod['owner']) { - this.bps[idx].name = org['candidate_name']; - this.bps[idx].account = data['producer_account_name']; - this.bps[idx].location = loc; - this.bps[idx].social = org['social'] || {}; - this.bps[idx].email = org['email']; - this.bps[idx].website = org['website']; - this.bps[idx].logo_256 = logo_256; - this.bps[idx].code = org['code_of_conduct']; - } - } - } - }, () => { - // console.log(url, err); - }); + improveMeta(prod, idx) { + const url = prod.url.endsWith('.json') ? prod.url : prod.url + '/bp.json'; + if (url !== '') { + this.http.post('http://proxy.eosrio.io:4200', { + url: url + }).subscribe((data) => { + if (data) { + if (data['org']) { + const org = data['org']; + const loc = (org.location.name) ? (org.location.name + ', ' + org.location.country) : (org.location.country); + const logo_256 = (org['branding']) ? org['branding']['logo_256'] : ''; + if (data['producer_account_name'] === prod['owner']) { + this.bps[idx].name = org['candidate_name']; + this.bps[idx].account = data['producer_account_name']; + this.bps[idx].location = loc; + this.bps[idx].social = org['social'] || {}; + this.bps[idx].email = org['email']; + this.bps[idx].website = org['website']; + this.bps[idx].logo_256 = logo_256; + this.bps[idx].code = org['code_of_conduct']; + } + } } + }, () => { + // console.log(url, err); + }); } + } } diff --git a/src/app/eosjs.service.ts b/src/app/eosjs.service.ts index 1e2930a8..55ea4397 100644 --- a/src/app/eosjs.service.ts +++ b/src/app/eosjs.service.ts @@ -376,7 +376,6 @@ export class EOSJSService { } async authenticate(pass, publickey): Promise { - console.log(pass, publickey); this.auth = false; await this.initKeys(publickey, pass); return await this.decryptKeys(publickey); diff --git a/src/index.html b/src/index.html index 5edd16fd..5e69fb03 100644 --- a/src/index.html +++ b/src/index.html @@ -5,7 +5,7 @@ SimplEOS Wallet - +