mempool/frontend/src/app/components/push-transaction/push-transaction.component.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-10-19 15:37:45 +04:00
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
2022-09-21 17:23:45 +02:00
import { ApiService } from '../../services/api.service';
2021-10-19 15:37:45 +04:00
@Component({
selector: 'app-push-transaction',
templateUrl: './push-transaction.component.html',
styleUrls: ['./push-transaction.component.scss']
})
export class PushTransactionComponent implements OnInit {
pushTxForm: FormGroup;
error: string = '';
txId: string = '';
isLoading = false;
constructor(
private formBuilder: FormBuilder,
private apiService: ApiService,
) { }
ngOnInit(): void {
this.pushTxForm = this.formBuilder.group({
txHash: ['', Validators.required],
});
}
postTx() {
this.isLoading = true;
this.error = '';
this.txId = '';
this.apiService.postTransaction$(this.pushTxForm.get('txHash').value)
.subscribe((result) => {
this.isLoading = false;
this.txId = result;
this.pushTxForm.reset();
},
(error) => {
if (typeof error.error === 'string') {
const matchText = error.error.match('"message":"(.*?)"');
this.error = matchText && matchText[1] || error.error;
} else if (error.message) {
this.error = error.message;
}
this.isLoading = false;
});
}
}