2024-03-24 09:02:19 +00:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
|
|
|
import { ApiService } from '../../services/api.service';
|
|
|
|
import { StateService } from '../../services/state.service';
|
|
|
|
import { SeoService } from '../../services/seo.service';
|
|
|
|
import { OpenGraphService } from '../../services/opengraph.service';
|
|
|
|
import { TestMempoolAcceptResult } from '../../interfaces/node-api.interface';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-test-transactions',
|
|
|
|
templateUrl: './test-transactions.component.html',
|
|
|
|
styleUrls: ['./test-transactions.component.scss']
|
|
|
|
})
|
|
|
|
export class TestTransactionsComponent implements OnInit {
|
|
|
|
testTxsForm: UntypedFormGroup;
|
|
|
|
error: string = '';
|
|
|
|
results: TestMempoolAcceptResult[] = [];
|
|
|
|
isLoading = false;
|
|
|
|
invalidMaxfeerate = false;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private formBuilder: UntypedFormBuilder,
|
|
|
|
private apiService: ApiService,
|
|
|
|
public stateService: StateService,
|
|
|
|
private seoService: SeoService,
|
|
|
|
private ogService: OpenGraphService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.testTxsForm = this.formBuilder.group({
|
|
|
|
txs: ['', Validators.required],
|
|
|
|
maxfeerate: ['', Validators.min(0)]
|
|
|
|
});
|
|
|
|
|
2024-07-03 16:24:45 +09:00
|
|
|
this.seoService.setTitle($localize`:@@f74d6f23e06c5a75d95a994017c00191c162ba9f:Test Transactions`);
|
2024-03-24 09:02:19 +00:00
|
|
|
this.ogService.setManualOgImage('tx-push.jpg');
|
|
|
|
}
|
|
|
|
|
|
|
|
testTxs() {
|
2024-03-25 05:52:03 +00:00
|
|
|
let txs: string[] = [];
|
|
|
|
try {
|
|
|
|
txs = (this.testTxsForm.get('txs')?.value as string).split(',').map(hex => hex.trim());
|
|
|
|
if (!txs?.length) {
|
|
|
|
this.error = 'At least one transaction is required';
|
|
|
|
return;
|
|
|
|
} else if (txs.length > 25) {
|
|
|
|
this.error = 'Exceeded maximum of 25 transactions';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.error = e?.message;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-24 09:02:19 +00:00
|
|
|
let maxfeerate;
|
|
|
|
this.invalidMaxfeerate = false;
|
|
|
|
try {
|
|
|
|
const maxfeerateVal = this.testTxsForm.get('maxfeerate')?.value;
|
|
|
|
if (maxfeerateVal != null && maxfeerateVal !== '') {
|
|
|
|
maxfeerate = parseFloat(maxfeerateVal) / 100_000;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.invalidMaxfeerate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isLoading = true;
|
|
|
|
this.error = '';
|
|
|
|
this.results = [];
|
2024-03-25 05:52:03 +00:00
|
|
|
this.apiService.testTransactions$(txs, maxfeerate === 0.1 ? null : maxfeerate)
|
2024-03-24 09:02:19 +00:00
|
|
|
.subscribe((result) => {
|
|
|
|
this.isLoading = false;
|
|
|
|
this.results = result || [];
|
|
|
|
this.testTxsForm.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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|