Skip to content

Commit

Permalink
stability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
igorls committed Jun 12, 2018
1 parent 2edb2df commit 1077841
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 125 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 13 additions & 4 deletions src/app/dashboard/send/send.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 = '';
Expand Down Expand Up @@ -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!';
});
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/app/dashboard/vote/vote.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'];
Expand All @@ -67,8 +71,8 @@ export class VoteComponent implements OnInit, AfterViewInit {
}

ngAfterViewInit() {
console.log('ngAfterViewInit');
this.voteService.listProducers();
this.updateCounter();
}

processVotes() {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
232 changes: 117 additions & 115 deletions src/app/dashboard/vote/voting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean>();
public counter = new Subject<Number>();
selectedAccount: any;
initList: boolean;
totalActivatedStake: number;
totalProducerVoteWeight: number;
chainActive: boolean;
stakePercent: number;
public bps: any[];
public listReady = new Subject<Boolean>();
public counter = new Subject<Number>();
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);
});
}
}
}
1 change: 0 additions & 1 deletion src/app/eosjs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ export class EOSJSService {
}

async authenticate(pass, publickey): Promise<boolean> {
console.log(pass, publickey);
this.auth = false;
await this.initKeys(publickey, pass);
return await this.decryptKeys(publickey);
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
<meta charset="utf-8">
<title>SimplEOS Wallet</title>
<base href="./">
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script>document.write('<base href="' + document.location + '" />');</script>
Expand Down

0 comments on commit 1077841

Please sign in to comment.