Merge pull request #4848 from mempool/mononaut/esplora-only-address-graph

Add backend type flag, disable address graphs for non-esplora
This commit is contained in:
softsimon 2024-04-01 19:11:54 +09:00 committed by GitHub
commit ecf1db0716
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 15 additions and 2 deletions

View file

@ -83,6 +83,7 @@ class WebsocketHandler {
const _blocks = blocks.getBlocks().slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT);
const da = difficultyAdjustment.getDifficultyAdjustment();
this.updateSocketDataFields({
'backend': config.MEMPOOL.BACKEND,
'mempoolInfo': memPool.getMempoolInfo(),
'vBytesPerSecond': memPool.getVBytesPerSecond(),
'blocks': _blocks,

View file

@ -51,7 +51,7 @@
</div>
</div>
<ng-container *ngIf="address && transactions && transactions.length > 2">
<ng-container *ngIf="(stateService.backend$ | async) === 'esplora' && address && transactions && transactions.length > 2">
<br>
<div class="box">
<div class="row">

View file

@ -44,7 +44,7 @@ export class AddressComponent implements OnInit, OnDestroy {
private route: ActivatedRoute,
private electrsApiService: ElectrsApiService,
private websocketService: WebsocketService,
private stateService: StateService,
public stateService: StateService,
private audioService: AudioService,
private apiService: ApiService,
private seoService: SeoService,

View file

@ -4,6 +4,7 @@ import { Transaction } from './electrs.interface';
import { BlockExtended, DifficultyAdjustment, RbfTree } from './node-api.interface';
export interface WebsocketResponse {
backend?: 'esplora' | 'electrum' | 'none';
block?: BlockExtended;
blocks?: BlockExtended[];
conversions?: any;

View file

@ -92,6 +92,7 @@ const defaultEnv: Env = {
export class StateService {
isBrowser: boolean = isPlatformBrowser(this.platformId);
isMempoolSpaceBuild = window['isMempoolSpaceBuild'] ?? false;
backend: 'esplora' | 'electrum' | 'none' = 'esplora';
network = '';
lightning = false;
blockVSize: number;
@ -99,6 +100,7 @@ export class StateService {
latestBlockHeight = -1;
blocks: BlockExtended[] = [];
backend$ = new BehaviorSubject<'esplora' | 'electrum' | 'none'>('esplora');
networkChanged$ = new ReplaySubject<string>(1);
lightningChanged$ = new ReplaySubject<boolean>(1);
blocksSubject$ = new BehaviorSubject<BlockExtended[]>([]);
@ -257,6 +259,10 @@ export class StateService {
const rateUnitPreference = this.storageService.getValue('rate-unit-preference');
this.rateUnits$ = new BehaviorSubject<string>(rateUnitPreference || 'vb');
this.backend$.subscribe(backend => {
this.backend = backend;
});
}
setNetworkBasedonUrl(url: string) {

View file

@ -62,6 +62,7 @@ export class WebsocketService {
if (theInitData.body.blocks) {
theInitData.body.blocks = theInitData.body.blocks.reverse();
}
this.stateService.backend$.next(theInitData.backend);
this.stateService.isLoadingWebSocket$.next(false);
this.handleResponse(theInitData.body);
this.startSubscription(false, true);
@ -290,6 +291,10 @@ export class WebsocketService {
handleResponse(response: WebsocketResponse) {
let reinitBlocks = false;
if (response.backend) {
this.stateService.backend$.next(response.backend);
}
if (response.blocks && response.blocks.length) {
const blocks = response.blocks;
this.stateService.resetBlocks(blocks);