All files / app/components/home/transaction-list transaction-list-context-menu.ts

0% Statements 0/16
0% Branches 0/3
0% Functions 0/3
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                                                                                                                                                           
import { features } from '../../../constants/index';
import { Transaction } from '@stacks/stacks-blockchain-api-types';
import { hasMemo, getRecipientAddress } from '@utils/tx-utils';
 
export function registerHandler(el: HTMLButtonElement | null, handler: (e: Event) => void) {
  Iif (el === null) return;
  el.addEventListener('contextmenu', handler);
}
 
export function deregisterHandler(el: HTMLButtonElement | null, handler: (e: Event) => void) {
  Iif (el === null) return;
  el.removeEventListener('contextmenu', handler);
}
interface TxListContextMenu {
  tx: Transaction;
  copy: {
    txid: string;
    recipientAddress: string;
    memo: string;
    date: string;
    txDetails: string;
    explorerLink: string;
  };
}
 
export function createTxListContextMenu(event: Event, { tx, copy }: TxListContextMenu) {
  event.preventDefault();
  Iif (!features.txContentMenus) return;
  const menuItems: { menu: Electron.MenuItemConstructorOptions; textToCopy?: string }[] = [
    {
      menu: {
        label: 'Copy to clipboard',
        enabled: false,
      },
    },
    { menu: { type: 'separator' } },
    {
      textToCopy: copy.txid,
      menu: {
        label: 'Transaction ID',
      },
    },
    {
      textToCopy: copy.recipientAddress,
      menu: {
        label: 'Recipient address',
        visible: !!getRecipientAddress(tx),
      },
    },
    {
      textToCopy: copy.memo,
      menu: {
        label: 'Memo',
        visible: hasMemo(tx),
      },
    },
    {
      textToCopy: copy.date,
      menu: {
        label: 'Timestamp',
      },
    },
    {
      textToCopy: copy.txDetails,
      menu: {
        label: 'Transaction (as JSON)',
      },
    },
    {
      textToCopy: copy.explorerLink,
      menu: {
        label: 'Explorer link',
      },
    },
  ];
  main.contextMenu(menuItems);
}