Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
saiy2k committed May 17, 2024
2 parents d0b9874 + 9bb2599 commit ba46736
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 53 deletions.
2 changes: 1 addition & 1 deletion lib/_model/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/_pkg/storage/migration0_1to0_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Future<void> 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];
Expand Down
2 changes: 1 addition & 1 deletion lib/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 7 additions & 3 deletions lib/send/bloc/send_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ class SendCubit extends Cubit<SendState> {

await _swapCubit.createSubSwapForSend(
wallet: selectedWallet,
invoice: state.address,
address: state.address,
invoice: state.invoice!,
amount: amt,
isTestnet: _networkCubit.state.testnet,
networkUrl: networkurl,
Expand Down Expand Up @@ -528,10 +529,13 @@ class SendCubit extends Cubit<SendState> {
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(
Expand Down
80 changes: 46 additions & 34 deletions lib/swap/bloc/swap_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ class SwapCubit extends Cubit<SwapState> {

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: ''));

Expand Down Expand Up @@ -335,49 +336,60 @@ class SwapCubit extends Cubit<SwapState> {
? (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,
),
);

Expand Down
25 changes: 13 additions & 12 deletions lib/swap/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit ba46736

Please sign in to comment.