Add lightning node link previews

This commit is contained in:
Mononaut
2022-08-11 17:19:12 +00:00
parent 67ce4a956f
commit 18d18fa234
15 changed files with 322 additions and 15 deletions

View File

@@ -71,11 +71,13 @@ const defaultEnv: Env = {
export class StateService {
isBrowser: boolean = isPlatformBrowser(this.platformId);
network = '';
lightning = false;
blockVSize: number;
env: Env;
latestBlockHeight = -1;
networkChanged$ = new ReplaySubject<string>(1);
lightningChanged$ = new ReplaySubject<boolean>(1);
blocks$: ReplaySubject<[BlockExtended, boolean]>;
transactions$ = new ReplaySubject<TransactionStripped>(6);
conversions$ = new ReplaySubject<any>(1);
@@ -122,15 +124,18 @@ export class StateService {
if (this.isBrowser) {
this.setNetworkBasedonUrl(window.location.pathname);
this.setLightningBasedonUrl(window.location.pathname);
this.isTabHidden$ = fromEvent(document, 'visibilitychange').pipe(map(() => this.isHidden()), shareReplay());
} else {
this.setNetworkBasedonUrl('/');
this.setLightningBasedonUrl('/');
this.isTabHidden$ = new BehaviorSubject(false);
}
this.router.events.subscribe((event) => {
if (event instanceof NavigationStart) {
this.setNetworkBasedonUrl(event.url);
this.setLightningBasedonUrl(event.url);
}
});
@@ -198,6 +203,15 @@ export class StateService {
}
}
setLightningBasedonUrl(url: string) {
if (this.env.BASE_MODULE !== 'mempool') {
return;
}
const networkMatches = url.match(/\/lightning\//);
this.lightning = !!networkMatches;
this.lightningChanged$.next(this.lightning);
}
getHiddenProp(){
const prefixes = ['webkit', 'moz', 'ms', 'o'];
if ('hidden' in document) { return 'hidden'; }