attachTo method

void attachTo({
  1. required String swapId,
  2. required SwapFlowDirection direction,
})

RE-ATTACH to a live swap by its durable record (W-swap-5, #366): the wallet screen's in-flight row / the guard-fault "view swap" hand the persisted id + coarse direction here, then push the swap screen — the tracking view re-opens the live status stream by id. A NO-OP while a transient step runs (defensive: never clobber an in-flight quote/execute), while the SAME swap is already attached (idempotent tap), and while ANY live SwapAwaitingDeposit holds the screen (crypto-review H2 + arch review H-A1, both probe-confirmed): its quote carries the IntoZec deposit address/amount/memo, which are deliberately NOT persisted, so replacing it with a bare SwapExecuted — same id OR a different row's — would one-tap-destroy the only copy of active payment instructions. The RICHER state always wins, unconditionally; the deposit screen's own markDepositSent (or its explicit leave) is the exit. The tapped OTHER swap stays one tap away in the home list once the deposit screen is done.

Implementation

void attachTo({
  required String swapId,
  required SwapFlowDirection direction,
}) {
  if (_inFlight) return;
  final current = state;
  if (current is SwapAwaitingDeposit) return;
  // BEFORE the same-id early return (#386, the converged HIGH): the
  // COMMON re-attach — tapping the home row of the swap already attached
  // after a back-nav exit from its NotFound card — is exactly a same-id
  // attach, and the #385 first cut's invalidate below the early return
  // never ran for it (the fix worked only when a DIFFERENT swap had the
  // screen). The idempotent-tap return itself stays: same id ⇒ the state
  // is already right, only the stale latch needed the kick.
  _repollStaleNotFound(swapId);
  if (current is SwapExecuted && current.swapId == swapId) return;
  // reattached (#367): the tracking view must not instruct an action only
  // the issuing process run could follow (the IntoZec deposit instructions
  // are deliberately not persisted).
  _set(SwapExecuted(swapId, direction, reattached: true));
}