Allow searching for and viewing assets not in the asset registry.

fixes #111
This commit is contained in:
softsimon 2020-11-22 16:03:23 +07:00
parent 30fb0bad78
commit 11d67cf756
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
5 changed files with 30 additions and 15 deletions

View File

@ -24,7 +24,7 @@
<td>Precision</td> <td>Precision</td>
<td>{{ assetContract[3] }}</td> <td>{{ assetContract[3] }}</td>
</tr> </tr>
<tr *ngIf="!isNativeAsset"> <tr *ngIf="!isNativeAsset && assetContract[0]">
<td>Issuer</td> <td>Issuer</td>
<td><a target="_blank" href="{{ 'http://' + assetContract[0] }}">{{ assetContract[0] }}</a></td> <td><a target="_blank" href="{{ 'http://' + assetContract[0] }}">{{ assetContract[0] }}</a></td>
</tr> </tr>

View File

@ -98,6 +98,9 @@ export class AssetComponent implements OnInit, OnDestroy {
switchMap(([asset, assetsData]) => { switchMap(([asset, assetsData]) => {
this.asset = asset; this.asset = asset;
this.assetContract = assetsData[this.asset.asset_id]; this.assetContract = assetsData[this.asset.asset_id];
if (!this.assetContract) {
this.assetContract = [null, '?', 'Unknown', 0];
}
this.isNativeAsset = asset.asset_id === this.nativeAssetId; this.isNativeAsset = asset.asset_id === this.nativeAssetId;
this.updateChainStats(); this.updateChainStats();
this.websocketService.startTrackAsset(asset.asset_id); this.websocketService.startTrackAsset(asset.asset_id);

View File

@ -4,7 +4,7 @@
<input #instance="ngbTypeahead" [ngbTypeahead]="typeaheadSearch" (selectItem)="itemSelected()" (focus)="focus$.next($any($event).target.value)" (click)="click$.next($any($event).target.value)" formControlName="searchText" type="text" class="form-control" placeholder="TXID, block height, hash or address"> <input #instance="ngbTypeahead" [ngbTypeahead]="typeaheadSearch" (selectItem)="itemSelected()" (focus)="focus$.next($any($event).target.value)" (click)="click$.next($any($event).target.value)" formControlName="searchText" type="text" class="form-control" placeholder="TXID, block height, hash or address">
</div> </div>
<div> <div>
<button type="submit" class="btn btn-block btn-primary"><fa-icon [icon]="['fas', 'search']" [fixedWidth]="true" title="Search"></fa-icon></button> <button [disabled]="isSearching" type="submit" class="btn btn-block btn-primary"><fa-icon [icon]="['fas', 'search']" [fixedWidth]="true" title="Search"></fa-icon></button>
</div> </div>
</div> </div>
</form> </form>

View File

@ -17,6 +17,7 @@ import { NgbTypeahead } from '@ng-bootstrap/ng-bootstrap';
export class SearchFormComponent implements OnInit { export class SearchFormComponent implements OnInit {
network = ''; network = '';
assets: object = {}; assets: object = {};
isSearching = false;
searchForm: FormGroup; searchForm: FormGroup;
@Output() searchTriggered = new EventEmitter(); @Output() searchTriggered = new EventEmitter();
@ -74,25 +75,36 @@ export class SearchFormComponent implements OnInit {
search() { search() {
const searchText = this.searchForm.value.searchText.trim(); const searchText = this.searchForm.value.searchText.trim();
if (searchText) { if (searchText) {
this.isSearching = true;
if (this.regexAddress.test(searchText)) { if (this.regexAddress.test(searchText)) {
this.router.navigate([(this.network ? '/' + this.network : '') + '/address/', searchText]); this.navigate('/address/', searchText);
this.searchTriggered.emit();
} else if (this.regexBlockhash.test(searchText) || this.regexBlockheight.test(searchText)) { } else if (this.regexBlockhash.test(searchText) || this.regexBlockheight.test(searchText)) {
this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', searchText]); this.navigate('/block/', searchText);
this.searchTriggered.emit();
} else if (this.regexTransaction.test(searchText)) { } else if (this.regexTransaction.test(searchText)) {
if (this.network === 'liquid' && this.assets[searchText]) { if (this.network === 'liquid') {
this.router.navigate([(this.network ? '/' + this.network : '') + '/asset/', searchText]); if (this.assets[searchText]) {
this.navigate('/asset/', searchText);
}
this.electrsApiService.getAsset$(searchText)
.subscribe(
() => { this.navigate('/asset/', searchText); },
() => { this.navigate('/tx/', searchText); }
);
} else { } else {
this.router.navigate([(this.network ? '/' + this.network : '') + '/tx/', searchText]); this.navigate('/tx/', searchText);
} }
this.searchTriggered.emit();
} else { } else {
return; this.isSearching = false;
} }
this.searchForm.setValue({
searchText: '',
});
} }
} }
navigate(url: string, searchText: string) {
this.router.navigate([(this.network ? '/' + this.network : '') + url, searchText]);
this.searchTriggered.emit();
this.searchForm.setValue({
searchText: '',
});
this.isSearching = false;
}
} }

View File

@ -129,7 +129,7 @@
</ng-template> </ng-template>
<ng-template #defaultscriptpubkey_type> <ng-template #defaultscriptpubkey_type>
<ng-template [ngIf]="vout.scriptpubkey_type === 'op_return'" [ngIfElse]="otherPubkeyType"> <ng-template [ngIf]="vout.scriptpubkey_type === 'op_return'" [ngIfElse]="otherPubkeyType">
<a placement="bottom" [ngbTooltip]="vout.scriptpubkey | hex2ascii">OP_RETURN</a>&nbsp;<span class="badge badge-secondary scriptmessage">{{ vout.scriptpubkey_asm | hex2ascii }}</span> <a placement="bottom" [ngbTooltip]="vout.scriptpubkey | hex2ascii">OP_RETURN</a>&nbsp;<span *ngIf="vout.scriptpubkey_asm !== 'OP_RETURN'" class="badge badge-secondary scriptmessage">{{ vout.scriptpubkey_asm | hex2ascii }}</span>
</ng-template> </ng-template>
<ng-template #otherPubkeyType>{{ vout.scriptpubkey_type | scriptpubkeyType }}</ng-template> <ng-template #otherPubkeyType>{{ vout.scriptpubkey_type | scriptpubkeyType }}</ng-template>
</ng-template> </ng-template>