@@ -73,7 +73,9 @@ class JoinstrDatasource {
7373 denominationSat: pool.denominationSat,
7474 proxy: proxy,
7575 );
76- return jns.joinCoinjoin (poolRawJson: pool.rawJson, peer: peer);
76+ return _awaitBroadcast (
77+ jns.joinCoinjoin (poolRawJson: pool.rawJson, peer: peer),
78+ );
7779 });
7880 }
7981
@@ -99,19 +101,45 @@ class JoinstrDatasource {
99101 denominationSat: denominationSat,
100102 proxy: proxy,
101103 );
102- return jns.initiateCoinjoin (
103- config: jns.FfiPoolConfig (
104- denominationBtc: Joinstr .denominationBtc (denominationSat),
105- fee: feeRateSatPerVb,
106- maxDuration: BigInt .from (maxDuration.inSeconds),
107- peers: peers,
108- network: _network (wallet.network),
104+ return _awaitBroadcast (
105+ jns.initiateCoinjoin (
106+ config: jns.FfiPoolConfig (
107+ denominationBtc: Joinstr .denominationBtc (denominationSat),
108+ fee: feeRateSatPerVb,
109+ maxDuration: BigInt .from (maxDuration.inSeconds),
110+ peers: peers,
111+ network: _network (wallet.network),
112+ ),
113+ peer: peer,
109114 ),
110- peer: peer,
111115 );
112116 });
113117 }
114118
119+ /// Collapses the bindings' progress stream to the single result the rest of
120+ /// the app consumes: the txid once the coinjoin broadcasts. The intermediate
121+ /// steps are for a progress UI the domain layer does not model yet, so they
122+ /// are drained silently; the terminal `failed` step (and a stream that closes
123+ /// without any terminal step) surface as a [JoinstrException] .
124+ Future <String > _awaitBroadcast (Stream <jns.FfiCoinjoinUpdate > updates) async {
125+ await for (final update in updates) {
126+ switch (update.step) {
127+ case jns.FfiCoinjoinStep .done:
128+ final txid = update.txid;
129+ if (txid != null ) return txid;
130+ throw JoinstrException (JoinstrIssue .coinjoinFailed);
131+ case jns.FfiCoinjoinStep .failed:
132+ throw JoinstrException (
133+ JoinstrIssue .coinjoinFailed,
134+ detail: update.error,
135+ );
136+ default :
137+ continue ;
138+ }
139+ }
140+ throw JoinstrException (JoinstrIssue .coinjoinFailed);
141+ }
142+
115143 Future <jns.FfiPeerConfig > _peerConfig ({
116144 required Wallet wallet,
117145 required String mnemonic,
0 commit comments