@@ -214,6 +214,74 @@ class _MasternodesHomeViewState extends ConsumerState<MasternodesHomeView> {
214214 spendableBalance <
215215 _masternodeCollateralRaw + estimatedConsolidationFee.raw) {
216216 final feeDecimal = estimatedConsolidationFee.decimal;
217+
218+ final feeBuffer = Amount .fromDecimal (
219+ Decimal .parse ("0.00001" ),
220+ fractionDigits: wallet.cryptoCurrency.fractionDigits,
221+ );
222+ final desiredOnTransparent = estimatedConsolidationFee + feeBuffer;
223+
224+ Amount sparkFeeEstimate;
225+ try {
226+ sparkFeeEstimate = await wallet.estimateFeeForSpark (
227+ desiredOnTransparent,
228+ );
229+ } catch (_) {
230+ sparkFeeEstimate = estimatedConsolidationFee;
231+ }
232+ if (! mounted) return ;
233+
234+ final requiredFromSpark = desiredOnTransparent + sparkFeeEstimate;
235+ final canUnshieldFromSpark = sparkBalance >= requiredFromSpark.raw;
236+
237+ if (canUnshieldFromSpark) {
238+ final unshieldDecimal = requiredFromSpark.decimal;
239+ final shouldOpenSend = await showDialog <bool >(
240+ context: context,
241+ builder: (ctx) => StackDialog (
242+ title: "Unshield FIRO to cover consolidation fee?" ,
243+ message:
244+ "You have exactly 1000 FIRO on your transparent balance, "
245+ "but a network fee of $feeDecimal FIRO is needed to "
246+ "consolidate it into a single 1000 FIRO collateral UTXO.\n\n "
247+ "Your private Spark balance has enough to cover this fee. "
248+ "Do you want to unshield $unshieldDecimal FIRO from your "
249+ "private Spark balance to your transparent balance? Once "
250+ "this transaction is confirmed, click \" Create Masternode\" "
251+ "again to continue to the next step." ,
252+ leftButton: TextButton (
253+ style: Theme .of (
254+ ctx,
255+ ).extension < StackColors > ()! .getSecondaryEnabledButtonStyle (ctx),
256+ onPressed: () => Navigator .of (ctx).pop (),
257+ child: Text (
258+ "Cancel" ,
259+ style: STextStyles .button (ctx).copyWith (
260+ color: Theme .of (
261+ ctx,
262+ ).extension < StackColors > ()! .accentColorDark,
263+ ),
264+ ),
265+ ),
266+ rightButton: TextButton (
267+ style: Theme .of (
268+ ctx,
269+ ).extension < StackColors > ()! .getPrimaryEnabledButtonStyle (ctx),
270+ onPressed: () => Navigator .of (ctx).pop (true ),
271+ child: Text ("Open Send" , style: STextStyles .button (ctx)),
272+ ),
273+ ),
274+ );
275+ if (shouldOpenSend == true && mounted) {
276+ await _openCreateCollateralSendFlow (
277+ wallet,
278+ fromPrivate: true ,
279+ unshieldAmount: unshieldDecimal,
280+ );
281+ }
282+ return ;
283+ }
284+
217285 await showDialog <void >(
218286 context: context,
219287 builder: (ctx) => StackOkDialog (
0 commit comments