ChemPal Documentation - v1.18.0
    Preparing search index...

    Function addPriceAlert

    • Starts watching a product. Storage is called before anything is awaited, so the write survives the popup closing right after.

      Parameters

      • product: Product

        The product, with all its sizes

      Returns Promise<boolean>

      Whether it could be watched

      await addPriceAlert(product); // true
      await addPriceAlert({ ...product, cacheKey: undefined }); // false
      export async function addPriceAlert(product: Product): Promise<boolean> {
      const id = productSeriesKey(product);
      const ref = toProductRef(product);
      if (!id || !ref) return false;

      const alert: PriceAlert = {
      id,
      supplier: product.supplier,
      ref,
      title: product.title,
      permalink: product.permalink ?? product.url,
      createdAt: Date.now(),
      failures: 0,
      lastPrices: collectNativePrices(product),
      };
      await cstorage.local.set({ [priceAlertKey(id)]: alert });
      void trackEvent('price_alert_created', { supplier: alert.supplier });
      return true;
      }