-
+
-
-
{{ errorService.getFieldError(form, 'transactionId') | translate }}
+
+ {{ errorService.getFieldError(form, 'searchField') | translate }}
diff --git a/web-ui/src/app/components/finder/finder.component.ts b/web-ui/src/app/components/finder/finder.component.ts
index dd3d0cf..83872a1 100644
--- a/web-ui/src/app/components/finder/finder.component.ts
+++ b/web-ui/src/app/components/finder/finder.component.ts
@@ -2,10 +2,17 @@ import { Component, OnInit } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Observable } from 'rxjs/Observable';
+import { TranslateService } from '@ngx-translate/core';
+
import { ErrorService } from '../../services/error.service';
import { NavigatorService } from '../../services/navigator.service';
+import { AddressesService } from '../../services/addresses.service';
+import { BlocksService } from '../../services/blocks.service';
import { TransactionsService } from '../../services/transactions.service';
+const BLOCK_REGEX = '^[A-Fa-f0-9]{64}$';
+const ADDRESS_REGEX = '^[a-zA-Z0-9]{34}$';
+
@Component({
selector: 'app-finder',
templateUrl: './finder.component.html',
@@ -18,7 +25,10 @@ export class FinderComponent implements OnInit {
constructor(
private formBuilder: FormBuilder,
private navigatorService: NavigatorService,
+ private addressesService: AddressesService,
+ private blocksService: BlocksService,
private transactionsService: TransactionsService,
+ private translateService: TranslateService,
public errorService: ErrorService) {
this.createForm();
@@ -29,18 +39,40 @@ export class FinderComponent implements OnInit {
private createForm() {
this.form = this.formBuilder.group({
- transactionId: [null, [Validators.required, Validators.pattern('^[A-Fa-f0-9]{64}$')]],
+ searchField: [null, [Validators.required, Validators.pattern(`(${ADDRESS_REGEX})|(${BLOCK_REGEX})`)]],
});
}
onSubmit() {
- const txid = this.form.get('transactionId').value;
+ const searchField = this.form.get('searchField').value;
+
+ if (new RegExp(ADDRESS_REGEX).test(searchField)) {
+ // address
+ this.addressesService.get(searchField)
+ .subscribe(
+ response => this.navigatorService.addressDetails(searchField),
+ response => this.errorService.renderServerErrors(this.form, response)
+ );
+ } else {
+ // block or transaction
+ this.transactionsService.get(searchField)
+ .subscribe(
+ response => this.navigatorService.transactionDetails(searchField),
+ response => this.lookForBlock(searchField)
+ );
+ }
+ }
- // instead of redirecting, we check if the transaction is valid.
- this.transactionsService.get(txid)
+ private lookForBlock(blockhash: string) {
+ this.blocksService.get(blockhash)
.subscribe(
- response => this.navigatorService.transactionDetails(txid),
- response => this.errorService.renderServerErrors(this.form, response)
+ response => this.navigatorService.blockDetails(blockhash),
+ response => this.onNothingFound()
);
}
+
+ private onNothingFound() {
+ this.translateService.get('error.nothingFound')
+ .subscribe(msg => this.errorService.setFieldError(this.form, 'searchField', msg));
+ }
}
diff --git a/web-ui/src/app/services/error.service.ts b/web-ui/src/app/services/error.service.ts
index 3996a24..7957104 100644
--- a/web-ui/src/app/services/error.service.ts
+++ b/web-ui/src/app/services/error.service.ts
@@ -80,7 +80,7 @@ export class ErrorService {
return control != null;
}
- private setFieldError(form: FormGroup, fieldName: string, message: string) {
+ setFieldError(form: FormGroup, fieldName: string, message: string) {
const control = this.findFieldControl(form, fieldName);
const errors = { [message]: true };
control.setErrors(errors);
diff --git a/web-ui/src/app/services/navigator.service.ts b/web-ui/src/app/services/navigator.service.ts
index 1c1544a..e8dfe83 100644
--- a/web-ui/src/app/services/navigator.service.ts
+++ b/web-ui/src/app/services/navigator.service.ts
@@ -11,6 +11,14 @@ export class NavigatorService {
this.router.navigate([path]);
}
+ addressDetails(address: string) {
+ this.go('/addresses/' + address);
+ }
+
+ blockDetails(blockhash: string) {
+ this.go('/blocks/' + blockhash);
+ }
+
transactionDetails(txid: string) {
this.go('/transactions/' + txid);
}