Commit 1344ee0e authored by Paul Herbert's avatar Paul Herbert

2100 - Breeze Updates for ICO: Generate Addresses complete.

parent ee131b80
......@@ -15,14 +15,23 @@
<div style="margin-top:20px">
<label style="font-size:14px;margin-bottom:1px">Generate Addresses</label>
<div class="input-group" style="width:240px; height:35px">
<input formControlName="addressCountControl" type="text" class="form-control" placeholder="Number to generate..." style="border-radius: 0px">
<span class="input-group-btn">
<div>
<button *ngIf="!addressCountControl.invalid" style="outline: none" class="btn btn-default" type="button">Go</button>
<button *ngIf="addressCountControl.invalid" style="outline:none; color: gray" class="btn btn-default" type="button">Go</button>
</div>
</span>
<div style="display:flex; flex-direction:row">
<div class="input-group" style="height:35px; margin-bottom:1px; width:240px">
<input formControlName="addressCountControl" type="text" class="form-control" placeholder="Number to generate..." style="border-radius: 0px">
<span class="input-group-btn">
<div>
<button *ngIf="!addressCountControl.invalid && addressCount" (click)="generateAddresses()"
class="btn btn-default" type="button">Go</button>
<button *ngIf="addressCountControl.invalid || !addressCount" style="color: gray; outline:none" class="btn btn-default" type="button">Go</button>
</div>
</span>
</div>
<img style="width:16px; height:16px; margin-left:6px"
*ngIf="showTick" src="../../../../assets/images/Tick_Mark-16.png"/>
<app-feedback *ngIf="!generateAddressesLoadingState.success" style="margin-left:5px; width:115px"
[loading]="generateAddressesLoadingState.loading"
[errored]="generateAddressesLoadingState.errored"
[erroredText]="'Failed to generate'"></app-feedback>
</div>
</div>
......
import { Component, OnInit, OnDestroy, Input } from '@angular/core';
import { Subscription } from 'rxJs/Subscription';
import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
import 'rxjs/add/operator/filter';
import { timer } from 'rxjs/observable/timer';
import { AdvancedService } from './../advanced.service';
import { LoadingState } from './loadingState';
......@@ -13,45 +13,68 @@ import { LoadingState } from './loadingState';
styleUrls: ['./advanced-ico.component.css']
})
export class AdvancedIcoComponent implements OnInit, OnDestroy {
public icoFormGroup: FormGroup;
private _extPubKey = '';
private addressCount: string;
private extPubKeySubs: Subscription;
private _extPubKeyLoadingState: LoadingState = new LoadingState();
private generateAddressesSubs: Subscription;
private addresses = new Array<string>();
constructor(private advancedService: AdvancedService, private formBuilder: FormBuilder) {
this.loadExtPubKey();
}
constructor(private advancedService: AdvancedService, private formBuilder: FormBuilder) { }
ngOnInit() {
this.registerFormControls();
this.loadExtPubKey();
}
public get extPubKey(): string { return this._extPubKey; }
public get extPubKeyLoadingState(): LoadingState { return this._extPubKeyLoadingState; }
public icoFormGroup: FormGroup;
public extPubKey = "";
public extPubKeyLoadingState = new LoadingState();
public generateAddressesLoadingState = new LoadingState();
public get addressCountControl() { return this.icoFormGroup.get('addressCountControl'); }
public get showTick() {
return this.generateAddressesLoadingState.success && this.addresses.length && (Number(this.addressCount)===this.addresses.length)
}
public generateAddresses() {
this.internalGenerateAddresses();
}
private loadExtPubKey() {
this.extPubKeyLoadingState.loading = true;
this.extPubKeySubs = this.advancedService.getExtPubKey()
.subscribe(x => this.onExtPubKey(x), e => this.extPubKeyLoadingState.errored = true);
.subscribe(x => this.onExtPubKey(x),
_ => this.extPubKeyLoadingState.errored = true);
}
private internalGenerateAddresses() {
this.addresses = new Array<string>();
this.generateAddressesLoadingState.loading = true;
if (this.generateAddressesSubs) {
this.generateAddressesSubs.unsubscribe();
}
this.generateAddressesSubs = this.advancedService.generateAddresses(Number(this.addressCount))
.subscribe(x => this.onGenerateAddresses(x),
_ => this.generateAddressesLoadingState.errored = true);
}
private onExtPubKey(key: string) {
this._extPubKey = key;
this.extPubKey = key;
this.extPubKeyLoadingState.loading = false;
}
private onGenerateAddresses(addresses: string[]) {
this.generateAddressesLoadingState.loading = false;
this.addresses = addresses;
}
private registerFormControls() {
this.icoFormGroup = this.formBuilder.group({
addressCountControl: ["", [Validators.required, Validators.pattern('^[1-9][0-9]*$')]]
addressCountControl: ['', [Validators.pattern('^[1-9][0-9]*$')]]
});
let ignore = false;
this.addressCountControl.valueChanges.filter(_ => !ignore).subscribe(_ => {
if (this.addressCountControl.invalid && this.addressCountControl.value) {
ignore = true;
this.addressCountControl.setValue(this.addressCount);
ignore = false;
this.addressCountControl.valueChanges.subscribe(_ => {
if (this.addressCountControl.invalid) {
this.addressCountControl.setValue(this.addressCount);
} else {
this.addressCount = this.addressCountControl.value;
}
......@@ -59,6 +82,11 @@ export class AdvancedIcoComponent implements OnInit, OnDestroy {
}
ngOnDestroy() {
this.extPubKeySubs.unsubscribe();
if (this.extPubKeySubs) {
this.extPubKeySubs.unsubscribe();
}
if (this.generateAddressesSubs) {
this.generateAddressesSubs.unsubscribe();
}
}
}
export class LoadingState {
private _loading = false;
private _errored = false;
......@@ -7,6 +6,9 @@ export class LoadingState {
public get erroredText(): string {
return this._erroredText;
}
public set erroredText(value: string) {
this._erroredText = value;
}
public get loading(): boolean {
return this._loading;
......
......@@ -7,13 +7,28 @@ import { GlobalService } from '../../shared/services/global.service';
@Injectable()
export class AdvancedService {
private readonly accountName = 'account 0';
private readonly walletName;
private readonly urlPrefix = 'http://localhost:37221/api/Wallet/';
constructor(private httpClient: HttpClient, private globalService: GlobalService) { }
constructor(private httpClient: HttpClient, private globalService: GlobalService) {
this.walletName = this.globalService.getWalletName();
}
public getExtPubKey(): Observable<string> {
const walletName = this.globalService.getWalletName();
const url = `${this.urlPrefix}extpubkey?WalletName=${walletName}&AccountName=${this.accountName}`;
const url = `${this.urlPrefix}extpubkey?WalletName=${this.walletName}&AccountName=${this.accountName}`;
return this.httpClient.get(url).map(x => x.toString());
}
public generateAddresses(count: number): Observable<string[]> {
const url = `${this.urlPrefix}unusedaddresses?WalletName=${this.walletName}&AccountName=${this.accountName}&Count=${count}`;
return this.httpClient.get(url).map(x => this.processAddresses(x));
}
private processAddresses(response: any): string[] {
let addresses = new Array<string>();
for (const address of response) {
addresses.push(address);
}
return addresses;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment