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

60 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-10-19 15:37:45 +04:00
import { Component, OnInit } from '@angular/core';
2022-11-28 11:55:23 +09:00
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
2022-09-21 17:23:45 +02:00
import { ApiService } from '../../services/api.service';
import { StateService } from '../../services/state.service';
import { SeoService } from '../../services/seo.service';
2024-03-10 10:21:11 +09:00
import { OpenGraphService } from '../../services/opengraph.service';
import { seoDescriptionNetwork } from '../../shared/common.utils';
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 {
2022-11-28 11:55:23 +09:00
pushTxForm: UntypedFormGroup;
2021-10-19 15:37:45 +04:00
error: string = '';
txId: string = '';
isLoading = false;
constructor(
2022-11-28 11:55:23 +09:00
private formBuilder: UntypedFormBuilder,
2021-10-19 15:37:45 +04:00
private apiService: ApiService,
public stateService: StateService,
private seoService: SeoService,
2024-03-10 10:21:11 +09:00
private ogService: OpenGraphService,
2021-10-19 15:37:45 +04:00
) { }
ngOnInit(): void {
this.pushTxForm = this.formBuilder.group({
txHash: ['', Validators.required],
});
this.seoService.setTitle($localize`:@@meta.title.push-tx:Broadcast Transaction`);
this.seoService.setDescription($localize`:@@meta.description.push-tx:Broadcast a transaction to the ${this.stateService.network==='liquid'||this.stateService.network==='liquidtestnet'?'Liquid':'Bitcoin'}${seoDescriptionNetwork(this.stateService.network)} network using the transaction's hash.`);
2024-03-15 09:35:08 +00:00
this.ogService.setManualOgImage('tx-push.jpg');
2021-10-19 15:37:45 +04:00
}
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;
});
}
}