From 1a589f693c1e44eb37bcc3ae7211d06f7f5c0ee9 Mon Sep 17 00:00:00 2001 From: wildkif Date: Thu, 7 Feb 2019 17:36:07 +0200 Subject: [PATCH] fix error start getting aliases after syncing --- .../src/app/_helpers/models/wallet.model.ts | 4 +- .../pipes/history-type-messages.pipe.ts | 8 ++-- .../app/_helpers/services/backend.service.ts | 15 +++--- .../html_source/src/app/app.component.ts | 46 ++++++++----------- .../assign-alias/assign-alias.component.ts | 22 ++++----- .../app/open-wallet/open-wallet.component.ts | 1 + .../restore-wallet.component.ts | 1 + .../html_source/src/assets/i18n/en.json | 2 + 8 files changed, 48 insertions(+), 51 deletions(-) diff --git a/src/gui/qt-daemon/html_source/src/app/_helpers/models/wallet.model.ts b/src/gui/qt-daemon/html_source/src/app/_helpers/models/wallet.model.ts index a0ad37cc..276c9f1a 100644 --- a/src/gui/qt-daemon/html_source/src/app/_helpers/models/wallet.model.ts +++ b/src/gui/qt-daemon/html_source/src/app/_helpers/models/wallet.model.ts @@ -13,7 +13,7 @@ export class Wallet { mined_total: number; tracking_hey: string; - alias?: string; + alias?: object; staking?: boolean; new_messages?: number; new_contracts?: number; @@ -45,7 +45,7 @@ export class Wallet { this.mined_total = mined; this.tracking_hey = tracking; - this.alias = ''; + this.alias = {}; this.staking = false; this.new_messages = 0; this.new_contracts = 0; diff --git a/src/gui/qt-daemon/html_source/src/app/_helpers/pipes/history-type-messages.pipe.ts b/src/gui/qt-daemon/html_source/src/app/_helpers/pipes/history-type-messages.pipe.ts index 57023797..4ceb1000 100644 --- a/src/gui/qt-daemon/html_source/src/app/_helpers/pipes/history-type-messages.pipe.ts +++ b/src/gui/qt-daemon/html_source/src/app/_helpers/pipes/history-type-messages.pipe.ts @@ -38,10 +38,10 @@ export class HistoryTypeMessagesPipe implements PipeTransform { // return ''; // case 3: // return ''; - // case 4: - // return ''; - // case 5: - // return ''; + case 4: + return this.translate.instant('HISTORY.TYPE_MESSAGES.CREATE_ALIAS'); + case 5: + return this.translate.instant('HISTORY.TYPE_MESSAGES.UPDATE_ALIAS'); case 6: return this.translate.instant('HISTORY.TYPE_MESSAGES.MINED'); case 7: diff --git a/src/gui/qt-daemon/html_source/src/app/_helpers/services/backend.service.ts b/src/gui/qt-daemon/html_source/src/app/_helpers/services/backend.service.ts index 93b05b69..3e16060c 100644 --- a/src/gui/qt-daemon/html_source/src/app/_helpers/services/backend.service.ts +++ b/src/gui/qt-daemon/html_source/src/app/_helpers/services/backend.service.ts @@ -511,12 +511,12 @@ export class BackendService { } registerAlias (wallet_id, alias, address, fee, comment, reward, callback) { - let params = { + const params = { wallet_id: wallet_id, alias: { alias: alias, address: address, - tracking_key: "", + tracking_key: '', comment: comment }, fee: this.moneyToIntPipe.transform(fee), @@ -526,12 +526,12 @@ export class BackendService { } updateAlias (wallet_id, alias, fee, callback) { - let params = { + const params = { wallet_id: wallet_id, alias: { - alias: alias.name.replace("@", ""), + alias: alias.name.replace('@', ''), address: alias.address, - tracking_key: "", + tracking_key: '', comment: alias.comment }, fee: this.moneyToIntPipe.transform(fee) @@ -556,7 +556,7 @@ export class BackendService { } getWalletAlias(address) { - if (address != null) { + if (address != null && this.variablesService.daemon_state === 2) { if (this.variablesService.aliasesChecked[address] == null) { this.variablesService.aliasesChecked[address] = {}; if (this.variablesService.aliases.length) { @@ -580,7 +580,8 @@ export class BackendService { return this.variablesService.aliasesChecked[address]; } return {}; - }; + } + } diff --git a/src/gui/qt-daemon/html_source/src/app/app.component.ts b/src/gui/qt-daemon/html_source/src/app/app.component.ts index cd4c404c..860e4bea 100644 --- a/src/gui/qt-daemon/html_source/src/app/app.component.ts +++ b/src/gui/qt-daemon/html_source/src/app/app.component.ts @@ -397,27 +397,27 @@ export class AppComponent implements OnInit, OnDestroy { this.variablesService.aliasesChecked[data.events[i].details.address]['comment'] = data.events[i].details.comment; } if (this.variablesService.enableAliasSearch) { - let newAlias = { + const newAlias = { name: '@' + data.events[i].details.alias, address: data.events[i].details.address, comment: data.events[i].details.comment }; this.variablesService.aliases = this.variablesService.aliases.concat(newAlias); - this.variablesService.aliases = this.variablesService.aliases.sort((a, b) => { - if (a.name.length > b.name.length) return 1; - if (a.name.length < b.name.length) return -1; - if (a.name > b.name) return 1; - if (a.name < b.name) return -1; - return 0; - }); + // this.variablesService.aliases = this.variablesService.aliases.sort((a, b) => { + // if (a.name.length > b.name.length) return 1; + // if (a.name.length < b.name.length) return -1; + // if (a.name > b.name) return 1; + // if (a.name < b.name) return -1; + // return 0; + // }); this.variablesService.changeAliases(); } break; case 'CORE_EVENT_UPDATE_ALIAS': - for (let address in this.variablesService.aliasesChecked) { + for (const address in this.variablesService.aliasesChecked) { if (this.variablesService.aliasesChecked.hasOwnProperty(address)) { - if (this.variablesService.aliasesChecked[address].name === "@" + data.events[i].details.alias) { - if (this.variablesService.aliasesChecked[address].address != data.events[i].details.details.address) { + if (this.variablesService.aliasesChecked[address].name === '@' + data.events[i].details.alias) { + if (this.variablesService.aliasesChecked[address].address !== data.events[i].details.details.address) { delete this.variablesService.aliasesChecked[address]['name']; delete this.variablesService.aliasesChecked[address]['address']; delete this.variablesService.aliasesChecked[address]['comment']; @@ -434,18 +434,10 @@ export class AppComponent implements OnInit, OnDestroy { this.variablesService.aliasesChecked[data.events[i].details.details.address]['comment'] = data.events[i].details.details.comment; } if (this.variablesService.enableAliasSearch) { - let currentAlias; - for (let i = 0, length = this.variablesService.aliases.length; i < length; i++) { - if (i in this.variablesService.aliases) { - let element = this.variablesService.aliases[i]; - if ('name' in element && element['name'] === '@' + data.events[i].details.alias) { - currentAlias = this.variablesService.aliases[i]; - } - } - } - if (currentAlias) { - currentAlias.address = data.events[i].details.details.address; - currentAlias.comment = data.events[i].details.details.comment; + const CurrentAlias = this.variablesService.aliases.find((element) => element.name === '@' + data.events[i].details.alias); + if (CurrentAlias) { + CurrentAlias.address = data.events[i].details.details.address; + CurrentAlias.comment = data.events[i].details.details.comment; } } this.variablesService.changeAliases(); @@ -529,11 +521,11 @@ export class AppComponent implements OnInit, OnDestroy { getAliases() { this.backend.getAllAliases((status, data, error) => { - if (error == 'CORE_BUSY') { + if (error === 'CORE_BUSY') { window.setTimeout(() => { this.getAliases(); - },10000); - } else if (error == 'OVERFLOW') { + }, 10000); + } else if (error === 'OVERFLOW') { this.variablesService.aliases = []; this.variablesService.enableAliasSearch = false; } else { @@ -541,7 +533,7 @@ export class AppComponent implements OnInit, OnDestroy { if (data.aliases && data.aliases.length) { this.variablesService.aliases = []; data.aliases.forEach(alias => { - let newAlias = { + const newAlias = { name: '@' + alias.alias, address: alias.address, comment: alias.comment diff --git a/src/gui/qt-daemon/html_source/src/app/assign-alias/assign-alias.component.ts b/src/gui/qt-daemon/html_source/src/app/assign-alias/assign-alias.component.ts index 09ac6cec..91df7489 100644 --- a/src/gui/qt-daemon/html_source/src/app/assign-alias/assign-alias.component.ts +++ b/src/gui/qt-daemon/html_source/src/app/assign-alias/assign-alias.component.ts @@ -1,14 +1,14 @@ import {Component, OnInit, NgZone} from '@angular/core'; import {FormGroup, FormControl, Validators} from '@angular/forms'; -import {Location} from "@angular/common"; +import {Location} from '@angular/common'; import {Router} from '@angular/router'; import {BackendService} from '../_helpers/services/backend.service'; import {VariablesService} from '../_helpers/services/variables.service'; -import {ModalService} from "../_helpers/services/modal.service"; -import {Wallet} from "../_helpers/models/wallet.model"; -import {MoneyToIntPipe} from "../_helpers/pipes/money-to-int.pipe"; -import {IntToMoneyPipe} from "../_helpers/pipes/int-to-money.pipe"; -import BigNumber from "bignumber.js"; +import {ModalService} from '../_helpers/services/modal.service'; +import {Wallet} from '../_helpers/models/wallet.model'; +import {MoneyToIntPipe} from '../_helpers/pipes/money-to-int.pipe'; +import {IntToMoneyPipe} from '../_helpers/pipes/int-to-money.pipe'; +import BigNumber from 'bignumber.js'; @Component({ selector: 'app-assign-alias', @@ -51,7 +51,7 @@ export class AssignAliasComponent implements OnInit { this.assignForm.get('name').valueChanges.subscribe(value => { this.canRegister = false; this.alias.exists = false; - let newName = value.toLowerCase().replace('@', ''); + const newName = value.toLowerCase().replace('@', ''); if (!(this.assignForm.controls['name'].errors && this.assignForm.controls['name'].errors.hasOwnProperty('pattern')) && newName.length >= 6 && newName.length <= 25) { this.backend.getAliasByName(newName, status => { this.ngZone.run(() => { @@ -86,15 +86,15 @@ export class AssignAliasComponent implements OnInit { } assignAlias() { - let alias = this.backend.getWalletAlias(this.wallet.address); + const alias = this.backend.getWalletAlias(this.wallet.address); if (alias.hasOwnProperty('name')) { this.modalService.prepareModal('info', 'ASSIGN_ALIAS.ONE_ALIAS'); } else { this.alias.comment = this.assignForm.get('comment').value; - this.backend.registerAlias(this.wallet.wallet_id, this.alias.name, this.wallet.address, this.alias.fee, this.alias.comment, this.alias.rewardOriginal, (status, data) => { + this.backend.registerAlias(this.wallet.wallet_id, this.alias.name, this.wallet.address, this.alias.fee, this.alias.comment, this.alias.rewardOriginal, (status) => { if (status) { - //service.unconfirmed_aliases.push({tx_hash: data.tx_hash, name: this.alias.name}); - //wallet.wakeAlias = true; + // service.unconfirmed_aliases.push({tx_hash: data.tx_hash, name: this.alias.name}); + // wallet.wakeAlias = true; this.modalService.prepareModal('info', 'ASSIGN_ALIAS.REQUEST_ADD_REG'); this.router.navigate(['/wallet/' + this.wallet.wallet_id]); } diff --git a/src/gui/qt-daemon/html_source/src/app/open-wallet/open-wallet.component.ts b/src/gui/qt-daemon/html_source/src/app/open-wallet/open-wallet.component.ts index 0dcf2f89..2f0b3a24 100644 --- a/src/gui/qt-daemon/html_source/src/app/open-wallet/open-wallet.component.ts +++ b/src/gui/qt-daemon/html_source/src/app/open-wallet/open-wallet.component.ts @@ -98,6 +98,7 @@ export class OpenWalletComponent implements OnInit, OnDestroy { open_data['wi'].mined_total, open_data['wi'].tracking_hey ); + new_wallet.alias = this.backend.getWalletAlias(new_wallet.address); if (open_data.recent_history && open_data.recent_history.history) { new_wallet.prepareHistory(open_data.recent_history.history); } diff --git a/src/gui/qt-daemon/html_source/src/app/restore-wallet/restore-wallet.component.ts b/src/gui/qt-daemon/html_source/src/app/restore-wallet/restore-wallet.component.ts index f7518683..4ac5e156 100644 --- a/src/gui/qt-daemon/html_source/src/app/restore-wallet/restore-wallet.component.ts +++ b/src/gui/qt-daemon/html_source/src/app/restore-wallet/restore-wallet.component.ts @@ -80,6 +80,7 @@ export class RestoreWalletComponent implements OnInit { restore_data['wi'].mined_total, restore_data['wi'].tracking_hey ); + this.variablesService.opening_wallet.alias = this.backend.getWalletAlias(this.variablesService.opening_wallet.address); if (restore_data.recent_history && restore_data.recent_history.history) { this.variablesService.opening_wallet.prepareHistory(restore_data.recent_history.history); } diff --git a/src/gui/qt-daemon/html_source/src/assets/i18n/en.json b/src/gui/qt-daemon/html_source/src/assets/i18n/en.json index c8a5ace6..9abcfdca 100644 --- a/src/gui/qt-daemon/html_source/src/assets/i18n/en.json +++ b/src/gui/qt-daemon/html_source/src/assets/i18n/en.json @@ -214,6 +214,8 @@ "UNDEFINED": "Undefined", "COMPLETE_BUYER": "Successfully complete contract, return remaining pledge", "COMPLETE_SELLER": "Successfully complete contract, receive payment on contract, and return pledge", + "CREATE_ALIAS": "Fee for assigning alias", + "UPDATE_ALIAS": "Fee for editing alias", "MINED": "Mined funds", "CREATE_CONTRACT": "Send contract offer", "PLEDGE_CONTRACT": "Make pledge on offer",