diff --git a/lib/_model/wallet.dart b/lib/_model/wallet.dart index e7cd007f..446610c7 100644 --- a/lib/_model/wallet.dart +++ b/lib/_model/wallet.dart @@ -58,7 +58,7 @@ class Wallet with _$Wallet { // baseWalletType == BaseWalletType.Bitcoin ? lastGeneratedAddress : lastGeneratedLiqAddress; bool isTestnet() => network == BBNetwork.Testnet; - + bool isMain() => type == BBWalletType.main; bool isLiquid() => baseWalletType == BaseWalletType.Liquid; Wallet setLastAddress(Address address) { diff --git a/lib/_pkg/storage/migration0_1to0_2.dart b/lib/_pkg/storage/migration0_1to0_2.dart index 5dc64581..42224ecc 100644 --- a/lib/_pkg/storage/migration0_1to0_2.dart +++ b/lib/_pkg/storage/migration0_1to0_2.dart @@ -102,7 +102,7 @@ Future doMigration0_1to0_2( (w) => !w.isTestnet() && w.isInstant(), ); - if (mainWalletIdx != -1) { + if (mainWalletIdx != -1 && liqMainnetIdx != -1) { if (wallets.length > 2) { final tempMain = wallets[mainWalletIdx]; final tempLiq = wallets[liqMainnetIdx]; diff --git a/lib/locator.dart b/lib/locator.dart index 8c3e4c7d..cbc968ba 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -53,7 +53,7 @@ import 'package:flutter_animate/flutter_animate.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; -const bbVersion = '0.2.0-7'; +const bbVersion = '0.2.0-8'; GetIt locator = GetIt.instance; diff --git a/lib/send/bloc/send_cubit.dart b/lib/send/bloc/send_cubit.dart index e4ceced1..72920a46 100644 --- a/lib/send/bloc/send_cubit.dart +++ b/lib/send/bloc/send_cubit.dart @@ -257,7 +257,8 @@ class SendCubit extends Cubit { await _swapCubit.createSubSwapForSend( wallet: selectedWallet, - invoice: state.address, + address: state.address, + invoice: state.invoice!, amount: amt, isTestnet: _networkCubit.state.testnet, networkUrl: networkurl, @@ -528,10 +529,13 @@ class SendCubit extends Cubit { if (localWalletBloc == null) return; final wallet = localWalletBloc.state.wallet; - if (!wallet!.mainWallet) return; + // if (!wallet!.isMain()) { + // emit(state.copyWith(errSending: "Submarine swaps currently only supported via ")); + // return; + // }; final (wtxid, errBroadcast) = await _walletTx.broadcastTxWithWallet( - wallet: wallet, + wallet: wallet!, address: swap.scriptAddress, note: state.note, transaction: tx.copyWith( diff --git a/lib/swap/bloc/swap_cubit.dart b/lib/swap/bloc/swap_cubit.dart index d48864d4..ff71ae23 100644 --- a/lib/swap/bloc/swap_cubit.dart +++ b/lib/swap/bloc/swap_cubit.dart @@ -264,11 +264,12 @@ class SwapCubit extends Cubit { Future createSubSwapForSend({ required Wallet wallet, - required String invoice, + required String address, required int amount, String? label, required bool isTestnet, required String networkUrl, + required Invoice invoice, }) async { emit(state.copyWith(generatingSwapInv: true, errCreatingSwapInv: '')); @@ -335,49 +336,60 @@ class SwapCubit extends Cubit { ? (isLiq ? Chain.liquidTestnet : Chain.bitcoinTestnet) : (isLiq ? Chain.liquid : Chain.bitcoin); - final (swap, errCreatingInv) = await _swapBoltz.sendV2( - mnemonic: seed!.mnemonic, - index: wallet.revKeyIndex, - network: network, - electrumUrl: networkUrl, - boltzUrl: boltzurlV2, - isLiquid: isLiq, - invoice: invoice, + final storedSwapTxIdx = wallet.swaps.indexWhere( + (_) => _.invoice == invoice.invoice, ); - if (errCreatingInv != null) { - emit( - state.copyWith( - errCreatingSwapInv: errCreatingInv.toString(), - generatingSwapInv: false, - ), + + SwapTx swapTx; + if (storedSwapTxIdx != -1) { + swapTx = wallet.swaps[storedSwapTxIdx]; + } else { + final (swap, errCreatingInv) = await _swapBoltz.sendV2( + mnemonic: seed!.mnemonic, + index: wallet.revKeyIndex, + network: network, + electrumUrl: networkUrl, + boltzUrl: boltzurlV2, + isLiquid: isLiq, + invoice: address, ); - return; - } + if (errCreatingInv != null) { + emit( + state.copyWith( + errCreatingSwapInv: errCreatingInv.toString(), + generatingSwapInv: false, + ), + ); + return; + } - final updatedSwap = swap!.copyWith( - boltzFees: isLiq - ? fees.lbtcSubmarine.boltzFeesRate * amount ~/ 100 - : fees.btcSubmarine.boltzFeesRate * amount ~/ 100, - lockupFees: isLiq - ? fees.lbtcSubmarine.lockupFeesEstimate - : fees.btcSubmarine.lockupFeesEstimate, - claimFees: - isLiq ? fees.lbtcSubmarine.claimFees : fees.btcSubmarine.claimFees, - ); + final updatedSwap = swap!.copyWith( + boltzFees: isLiq + ? fees.lbtcSubmarine.boltzFeesRate * amount ~/ 100 + : fees.btcSubmarine.boltzFeesRate * amount ~/ 100, + lockupFees: isLiq + ? fees.lbtcSubmarine.lockupFeesEstimate + : fees.btcSubmarine.lockupFeesEstimate, + claimFees: + isLiq ? fees.lbtcSubmarine.claimFees : fees.btcSubmarine.claimFees, + ); - await _saveSwapToWallet( - swapTx: updatedSwap, - label: label, - wallet: wallet, - ); + swapTx = updatedSwap; - await Future.delayed(800.ms); + await _saveSwapToWallet( + swapTx: swapTx, + label: label, + wallet: wallet, + ); + + await Future.delayed(800.ms); + } emit( state.copyWith( generatingSwapInv: false, errCreatingSwapInv: '', - swapTx: updatedSwap, + swapTx: swapTx, ), ); diff --git a/lib/swap/send.dart b/lib/swap/send.dart index d5f3d0b5..cda38416 100644 --- a/lib/swap/send.dart +++ b/lib/swap/send.dart @@ -51,25 +51,26 @@ class _SwapFees extends StatelessWidget { @override Widget build(BuildContext context) { - final tx = context.select((SendCubit _) => _.state.tx); - final lockupFee = tx?.fee; - if (lockupFee == null) return const SizedBox.shrink(); + // final tx = context.select((SendCubit _) => _.state.tx); + // final lockupFee = tx?.fee; + // if (lockupFee == null) return const SizedBox.shrink(); - final allFees = context.select((SwapCubit cubit) => cubit.state.allFees); - if (allFees == null) return const SizedBox.shrink(); + // final allFees = context.select((SwapCubit cubit) => cubit.state.allFees); + // if (allFees == null) return const SizedBox.shrink(); - final isLiq = context.select( - (SendCubit cubit) => cubit.state.selectedWalletBloc!.state.isLiq(), - ); + final swaptx = context.select((SwapCubit _) => _.state.swapTx); + if (swaptx == null) return const SizedBox.shrink(); - final fees = isLiq ? allFees.lbtcSubmarine : allFees.btcSubmarine; + final lockupFee = swaptx.lockupFees; + if (lockupFee == null) return const SizedBox.shrink(); - final totalFees = fees.boltzFeesRate + fees.claimFees + lockupFee; + final fees = swaptx.totalFees(); + if (fees == null) return const SizedBox.shrink(); final amt = context.select( (CurrencyCubit _) => _.state.getAmountInUnits( - totalFees.toInt(), - isLiquid: isLiq, + fees, + isLiquid: swaptx.isLiquid(), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index c0d74997..b6e82d5f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: bb_mobile description: Bull Bitcoin Mobile Wallet publish_to: 'none' -version: 0.2.0-7+15 +version: 0.2.0-8+15 environment: sdk: ">=3.3.0 <4.0.0"