watchSwapStatus method
The live SwapStatus stream for one in-flight swap (spec §3.3/§7). Emits the
CURRENT status immediately on subscribe (so a re-subscribe after a background
gap re-renders at once), then polls at a bounded cadence. It NEVER completes
on a transient provider fault (a stall is retried behind the scenes, not a
dead stream); it completes only on a TERMINAL status (success/refunded/failed)
— drained first — or when the wallet is closed/swap is hard-killed. swapId
is the opaque id swapExecute returned.
Implementation
@override
Stream<SwapStatus> watchSwapStatus({required String swapId}) {
swapSubscribeCount++;
lastWatchedSwapId = swapId;
final controller = StreamController<SwapStatus>();
controller.onListen = () {
if (failSwapOnSubscribe) {
controller.addError('fake swap subscribe failure');
} else if (!holdSwapSubscribe) {
controller.add(swapCurrent);
}
// holdSwapSubscribe: connected but silent → the notifier stays loading.
};
controller.onCancel = () {
swapCancelCount++;
if (identical(_activeSwap, controller)) _activeSwap = null;
};
_activeSwap = controller;
return controller.stream;
}