async function fillTargetWithRelayAddress()

in src/js/other-websites/inpage_menu.js [121:179]


async function fillTargetWithRelayAddress(generateClickEvt) {
  sendInPageEvent("click", "input-menu-reuse-alias");
  preventDefaultBehavior(generateClickEvt);

  generateClickEvt.target.classList.add("is-loading");

  const maskAddress = generateClickEvt.target.dataset.mask;
  const maskAddressId = generateClickEvt.target.dataset.maskId;

  const maskObject = masks.find(
    (mask) => mask.id === parseInt(maskAddressId, 10)
  );

  const currentUsedOnValue = maskObject.used_on;

  const currentPageHostName = await browser.runtime.sendMessage({
    method: "getCurrentPageHostname",
  });

  const used_on = checkAndStoreUsedOnDomain(
    currentUsedOnValue,
    currentPageHostName
  );
  
  const serverStoragePref = await getCachedServerStoragePref();

  if (serverStoragePref) {
    // Update server info with site usage
    browser.runtime.sendMessage({
      method: "patchMaskInfo",
      id: parseInt(maskAddressId, 10),
      data: {
        used_on,
      },
      options: {
        auth: true,
        mask_type: maskObject.mask_type,
      },
    });
  } else {
    // Add in used_on to current mask object and re-sync labels
    // TODO/BUG: Deleting masks drops this data
    maskObject.used_on = used_on;
    browser.storage.local.set({ relayAddresses: masks });
  }

  // TODO: Add telemetry event (?)

  browser.runtime.sendMessage({
    method: "fillInputWithAlias",
    message: {
      filter: "fillInputWithAlias",
      newRelayAddressResponse: {
        address: maskAddress,
        currentDomain: currentPageHostName,
      },
    },
  });
}