pubkey.component.ts raw

   1  import { Component, Input, OnInit } from '@angular/core';
   2  import { NostrHelper } from '@common';
   3  import { IconButtonComponent } from "../icon-button/icon-button.component";
   4  
   5  @Component({
   6    // eslint-disable-next-line @angular-eslint/component-selector
   7    selector: 'lib-pubkey',
   8    imports: [IconButtonComponent],
   9    templateUrl: './pubkey.component.html',
  10    styleUrl: './pubkey.component.scss',
  11  })
  12  export class PubkeyComponent implements OnInit {
  13    @Input({ required: true }) value!: string;
  14    @Input() first = 9;
  15    @Input() last = 5;
  16    @Input() color = '#dee2e6bf';
  17  
  18    npub: string | undefined;
  19    npubString: string | undefined;
  20  
  21    ngOnInit(): void {
  22      const pubkeyObject = NostrHelper.getNostrPubkeyObject(this.value);
  23      this.npub = pubkeyObject.npub;
  24      this.npubString = NostrHelper.splitKey(
  25        pubkeyObject.npub,
  26        this.first,
  27        this.last
  28      );
  29    }
  30  
  31    copyToClipboard() {
  32      if (!this.npub) {
  33        return;
  34      }
  35  
  36      navigator.clipboard.writeText(this.npub);
  37    }
  38  }
  39