← Back to Pull requests

Matches welcome: share public trade list via /t/:id #240

Open
bjax13 opened this pull request with 848 lines diff across 16 files
View on GitHub
bjax13 bjax13 commented on Nov 29, 2026 04:36 UTC
Author

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->

Summary

Replaces the Matches welcome panel Share your list placeholder with a working share flow that points at the collector's public trade list at /t/:shareId.

Behavior

  • On welcome panel load (prefs + collection ready): refresh an existing public list, recover tombstoned ids, or enable a new public share so the URL is ready before tap (required for iOS navigator.share user activation).

  • On click: only runs native share / clipboard copy against the prepared URL (no Firestore writes in the click handler).

  • Share UX: navigator.canShare when available; clipboard with writeText → execCommand fallback; manual copy link if both fail.

  • Analytics: trade_list_shared with method (native | copy); AbortError does not emit the event.
  • How to verify on hosted app

    1. Deploy via Front end only deploy after merge.
    2. Sign in → /matches?welcome=1 → wait until Share your list enables (not “Loading…” / “Preparing…”).
    3. Tap Share: mobile should open the share sheet; desktop should copy or show manual link.
    4. Open /t/:id in a private window.

    Tests

    npm run check · cd frontend && npm run test:coverage

    Coverage for prep-on-load, tombstone minting, prefs-not-ready, AbortError, clipboard failure UI, and click path without refreshPublicShare/enablePublicShare.

    Deploy steps

    Hosting-only frontend deploy.
    <!-- CURSOR_AGENT_PR_BODY_END -->

    <div><a href="https://cursor.com/agents/bc-308c9ab2-0504-5b4f-be2f-c4d10db54fc9?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/background-agent?bcId=bc-308c9ab2-0504-5b4f-be2f-c4d10db54fc9&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

    Diff: 848 lines (+824 / -24) across 16 files Reviewer: chatgpt-codex-connector[bot] Review duration: 8246m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.77) × (1 − Review Confidence (0.75)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.77 · 848 lines diff across 16 files
    0.77
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.60 · 5 substantive comment(s)
    0.60
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    75%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    8 items
    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 29, 2026 04:37 UTC
    Bot

    <!-- codex-pull-request-review-summary -->
    <!-- codex-review-state:v1 {"code_review":{"commit_sha":"63d99fda3695a03eee5fcad1b82d9317d2626467","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->

    <details>
    <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>

    This comment shows the latest Codex review activity on this pull request.

    | Review | Status | Commit | Review trigger |
    | --- | --- | --- | --- |
    | 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-29T04:40:34.450459Z">2026-11-29T04:40:34.450459Z</relative-time> | 63d99fd | PR opened |

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 29, 2026 04:40 UTC
    Reviewer

    <!-- codex-review-receipt:v1 -->

    💡 Codex Review

    Here are some automated review suggestions for this pull request.

    Reviewed commit: 63d99fda36

    <details> <summary>ℹ️ About Codex in GitHub</summary>
    <br/>

    Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review".
  • If Codex has suggestions, it will comment; otherwise it will react with 👍.

    Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    </details>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Nov 29, 2026 04:40 UTC
    Code Review
    frontend/src/pages/Matches/components/MatchesWelcomeShare.jsx:1
    @@ -0,0 +1,135 @@
    +import { useEffect, useMemo, useState } from "react";
    +import { TRADE_LIST_SHARED } from "../../../analytics/events.js";
    +import { captureEvent } from "../../../analytics/posthog.js";
    +import { useAuth } from "../../../contexts/AuthContext";
    +import { useTradeShare } from "../../../hooks/useTradeShare.js";
    +import { shareTradeListLink } from "../../../lib/shareTradeListLink.js";
    +import {
    +  DEFAULT_MATCH_KEEP_BY_LANE,
    +  subscribeUserPreferences,
    +} from "../../../lib/userPreferences.js";
    +import { useUserCollection } from "../../Collection/hooks/useUserCollection.js";
    +import { buildShareUrl } from "../../Collection/utils/isoUftPost.js";
    +
    +export default function MatchesWelcomeShare() {
    +  const { user } = useAuth();
    +  const ownerUid = user?.uid ?? null;
    +  const { entries, status: collectionStatus } = useUserCollection(ownerUid);
    +  const [publicShareId, setPublicShareId] = useState("");
    +  const [matchKeep, setMatchKeep] = useState(() => ({ ...DEFAULT_MATCH_KEEP_BY_LANE }));
    +  const [discordHandle, setDiscordHandle] = useState("");
    +  const [matchRegion, setMatchRegion] = useState("");
    +  const [shareMessage, setShareMessage] = useState(null);
    +  const [shareError, setShareError] = useState(null);
    +  const [sharing, setSharing] = useState(false);
    +
    +  useEffect(() => {
    +    if (!ownerUid) {
    +      setPublicShareId("");
    +      setMatchKeep({ ...DEFAULT_MATCH_KEEP_BY_LANE });
    +      setDiscordHandle("");
    +      setMatchRegion("");
    +      return undefined;
    +    }
    +    return subscribeUserPreferences(ownerUid, (prefs) => {
    +      setPublicShareId(prefs.publicShareId || "");
    +      setMatchKeep(prefs.matchKeep);
    +      setDiscordHandle(prefs.discordHandle || "");
    +      setMatchRegion(prefs.matchRegion || "");
    +    });
    +  }, [ownerUid]);
    +
    +  const shareDisplayName = useMemo(() => {
    +    const fromProfile = typeof user?.displayName === "string" ? user.displayName.trim() : "";
    +    if (fromProfile) {
    +      return fromProfile;
    +    }
    +    const emailLocal = typeof user?.email === "string" ? user.email.split("@")[0]?.trim() : "";
    +    return emailLocal || "Collector";
    +  }, [user?.displayName, user?.email]);
    +
    +  const {
    +    busy: shareBusy,
    +    enableShare,
    +    refreshShare,
    +    error: tradeShareError,
    +  } = useTradeShare({
    +    userId: ownerUid,
    +    entries: entries ?? [],
    +    matchKeep,
    +    displayName: shareDisplayName,
    +    discordHandle,
    +    region: matchRegion,
    +    publicShareId,
    +  });
    +
    +  const collectionLoading = collectionStatus === "loading";
    +  const controlsDisabled = !ownerUid || collectionLoading || sharing || shareBusy;

    <sub><sub>!P2 Badge</sub></sub> Block sharing after collection-load errors

    If the initial collection read fails, useUserCollection leaves entries empty and sets the status to error, but this guard still enables sharing. If the share write succeeds, it can create an empty public list or overwrite an existing snapshot with an empty one; disable sharing on collection errors as well.

    Useful? React with 👍 / 👎.

    <!-- codex-code-review-finding:v1 -->

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on code on Nov 29, 2026 04:40 UTC
    Code Review
    frontend/src/pages/Matches/components/MatchesWelcomeShare.jsx:1
    @@ -0,0 +1,135 @@
    +import { useEffect, useMemo, useState } from "react";
    +import { TRADE_LIST_SHARED } from "../../../analytics/events.js";
    +import { captureEvent } from "../../../analytics/posthog.js";
    +import { useAuth } from "../../../contexts/AuthContext";
    +import { useTradeShare } from "../../../hooks/useTradeShare.js";
    +import { shareTradeListLink } from "../../../lib/shareTradeListLink.js";
    +import {
    +  DEFAULT_MATCH_KEEP_BY_LANE,
    +  subscribeUserPreferences,
    +} from "../../../lib/userPreferences.js";
    +import { useUserCollection } from "../../Collection/hooks/useUserCollection.js";
    +import { buildShareUrl } from "../../Collection/utils/isoUftPost.js";
    +
    +export default function MatchesWelcomeShare() {
    +  const { user } = useAuth();
    +  const ownerUid = user?.uid ?? null;
    +  const { entries, status: collectionStatus } = useUserCollection(ownerUid);
    +  const [publicShareId, setPublicShareId] = useState("");
    +  const [matchKeep, setMatchKeep] = useState(() => ({ ...DEFAULT_MATCH_KEEP_BY_LANE }));
    +  const [discordHandle, setDiscordHandle] = useState("");
    +  const [matchRegion, setMatchRegion] = useState("");
    +  const [shareMessage, setShareMessage] = useState(null);
    +  const [shareError, setShareError] = useState(null);
    +  const [sharing, setSharing] = useState(false);
    +
    +  useEffect(() => {
    +    if (!ownerUid) {
    +      setPublicShareId("");
    +      setMatchKeep({ ...DEFAULT_MATCH_KEEP_BY_LANE });
    +      setDiscordHandle("");
    +      setMatchRegion("");
    +      return undefined;
    +    }
    +    return subscribeUserPreferences(ownerUid, (prefs) => {
    +      setPublicShareId(prefs.publicShareId || "");
    +      setMatchKeep(prefs.matchKeep);
    +      setDiscordHandle(prefs.discordHandle || "");
    +      setMatchRegion(prefs.matchRegion || "");
    +    });
    +  }, [ownerUid]);
    +
    +  const shareDisplayName = useMemo(() => {
    +    const fromProfile = typeof user?.displayName === "string" ? user.displayName.trim() : "";
    +    if (fromProfile) {
    +      return fromProfile;
    +    }
    +    const emailLocal = typeof user?.email === "string" ? user.email.split("@")[0]?.trim() : "";
    +    return emailLocal || "Collector";
    +  }, [user?.displayName, user?.email]);
    +
    +  const {
    +    busy: shareBusy,
    +    enableShare,
    +    refreshShare,
    +    error: tradeShareError,
    +  } = useTradeShare({
    +    userId: ownerUid,
    +    entries: entries ?? [],
    +    matchKeep,
    +    displayName: shareDisplayName,
    +    discordHandle,
    +    region: matchRegion,
    +    publicShareId,
    +  });
    +
    +  const collectionLoading = collectionStatus === "loading";
    +  const controlsDisabled = !ownerUid || collectionLoading || sharing || shareBusy;
    +
    +  async function handleShare() {
    +    if (controlsDisabled) {
    +      return;
    +    }
    +    setShareMessage(null);
    +    setShareError(null);
    +    setSharing(true);
    +    try {
    +      let shareId = publicShareId;
    +      if (shareId) {
    +        await refreshShare();
    +      } else {
    +        shareId = await enableShare();
    +      }
    +      if (!shareId) {
    +        setShareError("Could not turn on your public trade list. Try again from Collection.");
    +        return;
    +      }
    +
    +      const url = buildShareUrl({ shareId, campaign: "trade_list" });

    <sub><sub>!P2 Badge</sub></sub> Use a trade-list UTM medium for these links

    This call changes only the campaign, while buildShareUrl hardcodes utm_medium=iso_uft. Consequently, links shared from Matches are attributed as ISO/UFT rather than trade-list traffic, which misclassifies the resulting pageviews; allow this call to set the medium too.

    Useful? React with 👍 / 👎.

    <!-- codex-code-review-finding:v1 -->

    cursor[bot] cursor[bot] commented on code on Nov 29, 2026 05:03 UTC
    Code Review
    frontend/src/pages/Matches/components/MatchesWelcomeShare.jsx:1
    @@ -0,0 +1,230 @@
    +import { useEffect, useMemo, useRef, useState } from "react";
    +import { TRADE_LIST_SHARED } from "../../../analytics/events.js";
    +import { captureEvent } from "../../../analytics/posthog.js";
    +import { useAuth } from "../../../contexts/AuthContext";
    +import { CopyToClipboardError } from "../../../lib/copyToClipboard.js";
    +import { shareTradeListLink } from "../../../lib/shareTradeListLink.js";
    +import {
    +  buildShareDocument,
    +  enablePublicShare,
    +  fetchShareSnapshot,
    +  generateShareId,
    +  refreshPublicShare,
    +  revokePublicShare,
    +} from "../../../lib/tradeShares.js";
    +import {
    +  DEFAULT_MATCH_KEEP_BY_LANE,
    +  subscribeUserPreferences,
    +} from "../../../lib/userPreferences.js";
    +import { useUserCollection } from "../../Collection/hooks/useUserCollection.js";
    +import { buildShareUrl } from "../../Collection/utils/isoUftPost.js";
    +
    +export default function MatchesWelcomeShare() {
    +  const { user } = useAuth();
    +  const ownerUid = user?.uid ?? null;
    +  const { entries, status: collectionStatus } = useUserCollection(ownerUid);
    +  const [prefsShareId, setPrefsShareId] = useState("");
    +  const [prefsReady, setPrefsReady] = useState(false);
    +  const [matchKeep, setMatchKeep] = useState(() => ({ ...DEFAULT_MATCH_KEEP_BY_LANE }));
    +  const [discordHandle, setDiscordHandle] = useState("");
    +  const [matchRegion, setMatchRegion] = useState("");
    +  const [shareUrl, setShareUrl] = useState(null);
    +  const [prepError, setPrepError] = useState(null);
    +  const [prepInProgress, setPrepInProgress] = useState(false);
    +  const [shareMessage, setShareMessage] = useState(null);
    +  const [shareError, setShareError] = useState(null);
    +  const [manualCopyUrl, setManualCopyUrl] = useState(null);
    +  const [sharing, setSharing] = useState(false);
    +  const prepRequestRef = useRef(0);
    +
    +  useEffect(() => {
    +    if (!ownerUid) {
    +      setPrefsShareId("");
    +      setPrefsReady(false);
    +      setMatchKeep({ ...DEFAULT_MATCH_KEEP_BY_LANE });
    +      setDiscordHandle("");
    +      setMatchRegion("");
    +      setShareUrl(null);
    +      return undefined;
    +    }
    +    setPrefsReady(false);
    +    return subscribeUserPreferences(ownerUid, (prefs) => {
    +      setPrefsShareId(prefs.publicShareId || "");
    +      setMatchKeep(prefs.matchKeep);
    +      setDiscordHandle(prefs.discordHandle || "");
    +      setMatchRegion(prefs.matchRegion || "");
    +      setPrefsReady(true);
    +    });
    +  }, [ownerUid]);
    +
    +  const shareDisplayName = useMemo(() => {
    +    const fromProfile = typeof user?.displayName === "string" ? user.displayName.trim() : "";
    +    if (fromProfile) {
    +      return fromProfile;
    +    }
    +    const emailLocal = typeof user?.email === "string" ? user.email.split("@")[0]?.trim() : "";
    +    return emailLocal || "Collector";
    +  }, [user?.displayName, user?.email]);
    +
    +  const sharePayload = useMemo(
    +    () =>
    +      buildShareDocument({
    +        ownerUid,
    +        displayName: shareDisplayName,
    +        entries: entries ?? [],
    +        matchKeep,
    +        discordHandle,
    +        region: matchRegion,
    +      }),
    +    [ownerUid, shareDisplayName, entries, matchKeep, discordHandle, matchRegion],
    +  );
    +
    +  const collectionLoading = collectionStatus === "loading";
    +  const collectionErrored = collectionStatus === "error";
    +  const shareReady = Boolean(shareUrl) && !prepInProgress;
    +  const controlsDisabled =
    +    !ownerUid || !prefsReady || collectionLoading || collectionErrored || !shareReady || sharing;
    +
    +  useEffect(() => {
    +    if (!ownerUid || !prefsReady || collectionLoading || collectionErrored) {
    +      setShareUrl(null);
    +      return undefined;
    +    }
    +
    +    const requestId = prepRequestRef.current + 1;
    +    prepRequestRef.current = requestId;
    +    let cancelled = false;
    +
    +    const prepareShare = async () => {
    +      setPrepInProgress(true);
    +      setPrepError(null);
    +      setShareUrl(null);
    +      setManualCopyUrl(null);
    +
    +      try {
    +        let shareId = prefsShareId;
    +
    +        if (shareId) {
    +          const snapshot = await fetchShareSnapshot(shareId);
    +          if (!snapshot) {
    +            try {
    +              await revokePublicShare({ userId: ownerUid, shareId });
    +            } catch (revokeErr) {
    +              console.error("Failed to clear tombstoned trade list share", revokeErr);
    +            }
    +            shareId = "";
    +          }
    +        }
    +
    +        if (shareId) {
    +          await refreshPublicShare({ userId: ownerUid, shareId, payload: sharePayload });
    +        } else {
    +          shareId = generateShareId();
    +          await enablePublicShare({ userId: ownerUid, shareId, payload: sharePayload });

    <!-- CURSOR_AUTOMATION_ID: ee6edd68-b302-11f1-bb68-864e54d14197 | RUN_ID: bc-243f08e0-d88d-49f6-912a-e7818516e933 -->
    🔒 Agentic Security Review
    Severity: HIGH

    This useEffect writes a world-readable shares/{shareId} snapshot (and sets publicShareId) as soon as the welcome panel mounts, including enablePublicShare when the user has never opted in and after a revoked/tombstoned id. Opening /matches?welcome=1 is the normal post-onboarding path and only requires a signed-in session, so collectors can have ISO/UFT lists, ownerUid, display name (email local-part fallback), and Discord/region published without clicking Share.

    Impact: Anyone who later obtains that share id can get the document without auth (firestore.rules allow public get on non-revoked shares). Collection’s enableShare() is click-gated; this path is not.

    <div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjAwNzUxNTdiLWQ2NTctNDA4NS05OGY2LTc0Mzc5YWE1YTBhNCIsImVuY3J5cHRpb25LZXkiOiJobG9jRUo2OUl4eVZsNWYxc3cyVjFuMDVGSU11U3JjYXlMRFh0LVpWUFNBIiwiYnJhbmNoIjoiY3Vyc29yL21hdGNoZXMtc2hhcmUtdHJhZGUtbGlzdC00ZmM5IiwicmVwb093bmVyIjoiYmpheDEzIiwicmVwb05hbWUiOiJMb3N0RGVja3MiLCJwcm92aWRlciI6ImdpdGh1YiIsImhvc3RuYW1lIjoiZ2l0aHViLmNvbSJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjAwNzUxNTdiLWQ2NTctNDA4NS05OGY2LTc0Mzc5YWE1YTBhNCIsImVuY3J5cHRpb25LZXkiOiJobG9jRUo2OUl4eVZsNWYxc3cyVjFuMDVGSU11U3JjYXlMRFh0LVpWUFNBIiwiYnJhbmNoIjoiY3Vyc29yL21hdGNoZXMtc2hhcmUtdHJhZGUtbGlzdC00ZmM5IiwicmVwb093bmVyIjoiYmpheDEzIiwicmVwb05hbWUiOiJMb3N0RGVja3MiLCJwck51bWJlciI6MjQwLCJjb21taXRTaGEiOiJlZmZiNmJhZTA4YWI3MDc4NTY1NjVjMTAzNmZhYjJjYzhjNTk5Nzg4IiwicHJvdmlkZXIiOiJnaXRodWIiLCJob3N0bmFtZSI6ImdpdGh1Yi5jb20ifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>

    <sup>Reviewed by Cursor Security Reviewer for commit effb6bae08ab707856565c1036fab2cc8c599788. Configure here.</sup>

    cursor[bot] cursor[bot] commented on Nov 29, 2026 05:03 UTC
    Reviewer

    <details>
    <summary>Stale comment</summary>

    <blockquote>

    </blockquote>

    </details>

    cursor[bot] cursor[bot] commented on code on Nov 29, 2026 05:04 UTC
    Code Review
    frontend/src/pages/Matches/components/MatchesWelcomeShare.jsx:1
    @@ -0,0 +1,230 @@
    +import { useEffect, useMemo, useRef, useState } from "react";
    +import { TRADE_LIST_SHARED } from "../../../analytics/events.js";
    +import { captureEvent } from "../../../analytics/posthog.js";
    +import { useAuth } from "../../../contexts/AuthContext";
    +import { CopyToClipboardError } from "../../../lib/copyToClipboard.js";
    +import { shareTradeListLink } from "../../../lib/shareTradeListLink.js";
    +import {
    +  buildShareDocument,
    +  enablePublicShare,
    +  fetchShareSnapshot,
    +  generateShareId,
    +  refreshPublicShare,
    +  revokePublicShare,
    +} from "../../../lib/tradeShares.js";
    +import {
    +  DEFAULT_MATCH_KEEP_BY_LANE,
    +  subscribeUserPreferences,
    +} from "../../../lib/userPreferences.js";
    +import { useUserCollection } from "../../Collection/hooks/useUserCollection.js";
    +import { buildShareUrl } from "../../Collection/utils/isoUftPost.js";
    +
    +export default function MatchesWelcomeShare() {
    +  const { user } = useAuth();
    +  const ownerUid = user?.uid ?? null;
    +  const { entries, status: collectionStatus } = useUserCollection(ownerUid);
    +  const [prefsShareId, setPrefsShareId] = useState("");
    +  const [prefsReady, setPrefsReady] = useState(false);
    +  const [matchKeep, setMatchKeep] = useState(() => ({ ...DEFAULT_MATCH_KEEP_BY_LANE }));
    +  const [discordHandle, setDiscordHandle] = useState("");
    +  const [matchRegion, setMatchRegion] = useState("");
    +  const [shareUrl, setShareUrl] = useState(null);
    +  const [prepError, setPrepError] = useState(null);
    +  const [prepInProgress, setPrepInProgress] = useState(false);
    +  const [shareMessage, setShareMessage] = useState(null);
    +  const [shareError, setShareError] = useState(null);
    +  const [manualCopyUrl, setManualCopyUrl] = useState(null);
    +  const [sharing, setSharing] = useState(false);
    +  const prepRequestRef = useRef(0);
    +
    +  useEffect(() => {
    +    if (!ownerUid) {
    +      setPrefsShareId("");
    +      setPrefsReady(false);
    +      setMatchKeep({ ...DEFAULT_MATCH_KEEP_BY_LANE });
    +      setDiscordHandle("");
    +      setMatchRegion("");
    +      setShareUrl(null);
    +      return undefined;
    +    }
    +    setPrefsReady(false);
    +    return subscribeUserPreferences(ownerUid, (prefs) => {
    +      setPrefsShareId(prefs.publicShareId || "");
    +      setMatchKeep(prefs.matchKeep);
    +      setDiscordHandle(prefs.discordHandle || "");
    +      setMatchRegion(prefs.matchRegion || "");
    +      setPrefsReady(true);
    +    });
    +  }, [ownerUid]);
    +
    +  const shareDisplayName = useMemo(() => {
    +    const fromProfile = typeof user?.displayName === "string" ? user.displayName.trim() : "";
    +    if (fromProfile) {
    +      return fromProfile;
    +    }
    +    const emailLocal = typeof user?.email === "string" ? user.email.split("@")[0]?.trim() : "";
    +    return emailLocal || "Collector";
    +  }, [user?.displayName, user?.email]);
    +
    +  const sharePayload = useMemo(
    +    () =>
    +      buildShareDocument({
    +        ownerUid,
    +        displayName: shareDisplayName,
    +        entries: entries ?? [],
    +        matchKeep,
    +        discordHandle,
    +        region: matchRegion,
    +      }),
    +    [ownerUid, shareDisplayName, entries, matchKeep, discordHandle, matchRegion],
    +  );
    +
    +  const collectionLoading = collectionStatus === "loading";
    +  const collectionErrored = collectionStatus === "error";
    +  const shareReady = Boolean(shareUrl) && !prepInProgress;
    +  const controlsDisabled =
    +    !ownerUid || !prefsReady || collectionLoading || collectionErrored || !shareReady || sharing;
    +
    +  useEffect(() => {
    +    if (!ownerUid || !prefsReady || collectionLoading || collectionErrored) {
    +      setShareUrl(null);
    +      return undefined;
    +    }
    +
    +    const requestId = prepRequestRef.current + 1;
    +    prepRequestRef.current = requestId;
    +    let cancelled = false;
    +
    +    const prepareShare = async () => {
    +      setPrepInProgress(true);
    +      setPrepError(null);
    +      setShareUrl(null);
    +      setManualCopyUrl(null);
    +
    +      try {
    +        let shareId = prefsShareId;
    +
    +        if (shareId) {
    +          const snapshot = await fetchShareSnapshot(shareId);
    +          if (!snapshot) {
    +            try {
    +              await revokePublicShare({ userId: ownerUid, shareId });
    +            } catch (revokeErr) {
    +              console.error("Failed to clear tombstoned trade list share", revokeErr);
    +            }
    +            shareId = "";
    +          }
    +        }
    +
    +        if (shareId) {
    +          await refreshPublicShare({ userId: ownerUid, shareId, payload: sharePayload });
    +        } else {
    +          shareId = generateShareId();
    +          await enablePublicShare({ userId: ownerUid, shareId, payload: sharePayload });

    Intentional for this PR: iOS Safari requires navigator.share inside the click’s user activation, so we cannot await enablePublicShare / refreshPublicShare in handleShare. Preparing the /t/:id snapshot when the welcome panel mounts is the same opt-in public-list model as Collection’s “Share a public trade list link” toggle (which also writes shares/{id} before copy). This component only mounts on /matches?welcome=1, not every Matches visit.

    Assignees
    bjax13 bjax13
    Labels
    risk: low confidence: 75.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 76.5% (HIGH) · Higher = larger blast radius
    76.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 75.1% · Lower = rushed or shallow review
    75.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.1% · Safe to merge
    19.1%