diff --git a/frontend/src/app/bitcoin.utils.ts b/frontend/src/app/bitcoin.utils.ts index 25432565c..5419464a9 100644 --- a/frontend/src/app/bitcoin.utils.ts +++ b/frontend/src/app/bitcoin.utils.ts @@ -254,3 +254,30 @@ export function selectPowerOfTen(val: number): { divider: number, unit: string } return selectedPowerOfTen; } + +const featureActivation = { + mainnet: { + rbf: 399701, + segwit: 477120, + taproot: 709632, + }, + testnet: { + rbf: 720255, + segwit: 872730, + taproot: 2032291, + }, + signet: { + rbf: 0, + segwit: 0, + taproot: 0, + }, +}; + +export function isFeatureActive(network: string, height: number, feature: 'rbf' | 'segwit' | 'taproot'): boolean { + const activationHeight = featureActivation[network || 'mainnet']?.[feature]; + if (activationHeight != null) { + return height >= activationHeight; + } else { + return false; + } +} diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index c60d796e4..5f23633bf 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -23,6 +23,7 @@ import { BlockExtended, CpfpInfo } from '../../interfaces/node-api.interface'; import { LiquidUnblinding } from './liquid-ublinding'; import { RelativeUrlPipe } from '../../shared/pipes/relative-url/relative-url.pipe'; import { Price, PriceService } from '../../services/price.service'; +import { isFeatureActive } from '../../bitcoin.utils'; @Component({ selector: 'app-transaction', @@ -438,9 +439,9 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { setFeatures(): void { if (this.tx) { - this.segwitEnabled = !this.tx.status.confirmed || this.tx.status.block_height >= 477120; - this.taprootEnabled = !this.tx.status.confirmed || this.tx.status.block_height >= 709632; - this.rbfEnabled = !this.tx.status.confirmed || this.tx.status.block_height > 399700; + this.segwitEnabled = !this.tx.status.confirmed || isFeatureActive(this.stateService.network, this.tx.status.block_height, 'segwit'); + this.taprootEnabled = !this.tx.status.confirmed || isFeatureActive(this.stateService.network, this.tx.status.block_height, 'taproot'); + this.rbfEnabled = !this.tx.status.confirmed || isFeatureActive(this.stateService.network, this.tx.status.block_height, 'rbf'); } else { this.segwitEnabled = false; this.taprootEnabled = false; diff --git a/frontend/src/app/components/tx-features/tx-features.component.ts b/frontend/src/app/components/tx-features/tx-features.component.ts index 9376a0c7c..ffc2f291d 100644 --- a/frontend/src/app/components/tx-features/tx-features.component.ts +++ b/frontend/src/app/components/tx-features/tx-features.component.ts @@ -1,6 +1,7 @@ import { Component, ChangeDetectionStrategy, OnChanges, Input } from '@angular/core'; -import { calcSegwitFeeGains } from '../../bitcoin.utils'; +import { calcSegwitFeeGains, isFeatureActive } from '../../bitcoin.utils'; import { Transaction } from '../../interfaces/electrs.interface'; +import { StateService } from '../../services/state.service'; @Component({ selector: 'app-tx-features', @@ -25,15 +26,17 @@ export class TxFeaturesComponent implements OnChanges { rbfEnabled: boolean; taprootEnabled: boolean; - constructor() { } + constructor( + private stateService: StateService, + ) { } ngOnChanges() { if (!this.tx) { return; } - this.segwitEnabled = !this.tx.status.confirmed || this.tx.status.block_height >= 477120; - this.taprootEnabled = !this.tx.status.confirmed || this.tx.status.block_height >= 709632; - this.rbfEnabled = !this.tx.status.confirmed || this.tx.status.block_height > 399700; + this.segwitEnabled = !this.tx.status.confirmed || isFeatureActive(this.stateService.network, this.tx.status.block_height, 'segwit'); + this.taprootEnabled = !this.tx.status.confirmed || isFeatureActive(this.stateService.network, this.tx.status.block_height, 'taproot'); + this.rbfEnabled = !this.tx.status.confirmed || isFeatureActive(this.stateService.network, this.tx.status.block_height, 'rbf'); this.segwitGains = calcSegwitFeeGains(this.tx); this.isRbfTransaction = this.tx.vin.some((v) => v.sequence < 0xfffffffe); this.isTaproot = this.tx.vin.some((v) => v.prevout && v.prevout.scriptpubkey_type === 'v1_p2tr');