Skip to content

Commit

Permalink
refactor: Major codebase cleanup (#415)
Browse files Browse the repository at this point in the history
* rearrange

* updates

* updates

* clean

* updates

* clean

* updates

* clean

* clean

* clean

* clean

* rename

* clean

* clean

* updates

* network cubit to bloc

* clean

* clean

* fixes

* fixes

* fixes

* clean

* fixes

* fixes

* fixes

* fixes

* fixes

* network fixes

* refactor AppWalletsRepository to use a list instead of BehaviorSubject for wallet services

* slow route fix

* send fixes
  • Loading branch information
mocodesmo authored Jan 7, 2025
1 parent c518ffb commit 5140ece
Show file tree
Hide file tree
Showing 116 changed files with 4,278 additions and 4,178 deletions.
4 changes: 4 additions & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
- provider: true
5 changes: 5 additions & 0 deletions lib/_model/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Wallet with _$Wallet {
@Default(0) int subKeyIndex,
// List<String>? labelTags,
// List<Bip329Label>? bip329Labels,
Address? firstAddress,
}) = _Wallet;
const Wallet._();

Expand Down Expand Up @@ -515,6 +516,10 @@ class Wallet with _$Wallet {
List<SwapTx> swapsToProcess() {
return swaps.where((swap) => swap.proceesTx() && !swap.failed()).toList();
}

int balanceSats() => balance ?? 0;

String balanceStr() => ((balance ?? 0) / 100000000).toStringAsFixed(8);
}

@freezed
Expand Down
6 changes: 3 additions & 3 deletions lib/_pkg/boltz/swap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import 'package:bb_mobile/_pkg/consts/configs.dart';
import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/storage/secure_storage.dart';
import 'package:bb_mobile/_pkg/storage/storage.dart';
import 'package:bb_mobile/_pkg/wallet/repository/network.dart';
import 'package:bb_mobile/_repository/wallet/internal_network.dart';
import 'package:boltz_dart/boltz_dart.dart';
import 'package:dio/dio.dart';

class SwapBoltz {
SwapBoltz({
required SecureStorage secureStorage,
required Dio dio,
required NetworkRepository networkRepository,
required InternalNetworkRepository networkRepository,
}) : _secureStorage = secureStorage,
_networkRepository = networkRepository,
_dio = dio;

final SecureStorage _secureStorage;
final Dio _dio;
final NetworkRepository _networkRepository;
final InternalNetworkRepository _networkRepository;

Future<(Invoice?, Err?)> decodeInvoice({
required String invoice,
Expand Down
13 changes: 7 additions & 6 deletions lib/_pkg/deep_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import 'dart:async';
import 'package:bb_mobile/_model/wallet.dart';
import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/bip21.dart';
import 'package:bb_mobile/home/bloc/home_cubit.dart';
import 'package:bb_mobile/network/bloc/network_cubit.dart';
import 'package:bb_mobile/home/bloc/home_bloc.dart';
import 'package:bb_mobile/network/bloc/event.dart';
import 'package:bb_mobile/network/bloc/network_bloc.dart';
import 'package:flutter/material.dart';
// import 'package:uni_links/uni_links.dart';

Expand Down Expand Up @@ -39,8 +40,8 @@ class DeepLink {
Future<Err?> handleUri({
required String link,
// required SettingsCubit settingsCubit,
required HomeCubit homeCubit,
required NetworkCubit networkCubit,
required HomeBloc homeCubit,
required NetworkBloc networkCubit,
required BuildContext context,
}) async {
try {
Expand All @@ -50,8 +51,8 @@ class DeepLink {
final address = bip21Obj.address;
final isTestnet = isTestnetAddress(address);
if (isTestnet == null) return Err('Invalid address');
final currentIsTestnet = networkCubit.state.testnet;
if (currentIsTestnet != isTestnet) networkCubit.toggleTestnet();
final currentIsTestnet = networkCubit.state.networkData.testnet;
if (currentIsTestnet != isTestnet) networkCubit.add(ToggleTestnet());
await Future.delayed(const Duration(milliseconds: 200));
final wallet = homeCubit.state.getFirstWithSpendableAndBalance(
isTestnet ? BBNetwork.Testnet : BBNetwork.Mainnet,
Expand Down
8 changes: 4 additions & 4 deletions lib/_pkg/migrations/migration0_1to0_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import 'package:bb_mobile/_pkg/wallet/bdk/sensitive_create.dart';
import 'package:bb_mobile/_pkg/wallet/create.dart';
import 'package:bb_mobile/_pkg/wallet/lwk/create.dart';
import 'package:bb_mobile/_pkg/wallet/lwk/sensitive_create.dart';
import 'package:bb_mobile/_pkg/wallet/repository/sensitive_storage.dart';
import 'package:bb_mobile/_pkg/wallet/repository/storage.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_repository/wallet/internal_wallets.dart';
import 'package:bb_mobile/_repository/wallet/sensitive_wallet_storage.dart';
import 'package:bb_mobile/_repository/wallet/wallet_storage.dart';

// int mainWalletIndex = 0;
// int testWalletIndex = 0;
Expand Down Expand Up @@ -331,7 +331,7 @@ Future<List<Wallet>> createLiquidWallet(
Seed? liquidTestnetSeed,
HiveStorage hiveStorage,
) async {
final WalletsRepository walletRep = WalletsRepository();
final InternalWalletsRepository walletRep = InternalWalletsRepository();
final BDKCreate bdkCreate = BDKCreate(walletsRepository: walletRep);
final BDKSensitiveCreate bdkSensitiveCreate =
BDKSensitiveCreate(walletsRepository: walletRep, bdkCreate: bdkCreate);
Expand Down
2 changes: 1 addition & 1 deletion lib/_pkg/migrations/migration0_2to0_3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:bb_mobile/_model/wallet.dart';
import 'package:bb_mobile/_pkg/storage/hive.dart';
import 'package:bb_mobile/_pkg/storage/secure_storage.dart';
import 'package:bb_mobile/_pkg/storage/storage.dart';
import 'package:bb_mobile/_pkg/wallet/repository/sensitive_storage.dart';
import 'package:bb_mobile/_repository/wallet/sensitive_wallet_storage.dart';
import 'package:boltz_dart/boltz_dart.dart';

Future<void> doMigration0_2to0_3(
Expand Down
13 changes: 7 additions & 6 deletions lib/_pkg/payjoin/manager.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:isolate';
import 'dart:math';
import 'dart:typed_data';

import 'package:bb_mobile/_model/wallet.dart';
import 'package:bb_mobile/_pkg/error.dart';
Expand Down Expand Up @@ -218,7 +217,7 @@ class PayjoinManager {
SendPort? mainToIsolateSendPort;

receivePort.listen((message) async {
print('Receiver isolate: $message');
// print('Receiver isolate: $message');
if (message is Map<String, dynamic>) {
try {
switch (message['type']) {
Expand Down Expand Up @@ -325,10 +324,12 @@ class PayjoinManager {
if (senderErr != null) throw senderErr;

final filteredReceivers = receiverSessions
.where((session) =>
session.walletId == wallet.id &&
session.status != PayjoinSessionStatus.success &&
session.status != PayjoinSessionStatus.unrecoverable)
.where(
(session) =>
session.walletId == wallet.id &&
session.status != PayjoinSessionStatus.success &&
session.status != PayjoinSessionStatus.unrecoverable,
)
.toList();
final filteredSenders = senderSessions.where((session) {
return session.walletId == wallet.id &&
Expand Down
1 change: 1 addition & 0 deletions lib/_pkg/storage/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class StorageKeys {
static const wallets = 'wallets';
static const settings = 'settings';
static const network = 'network';
static const networkReposity = 'networkReposity';
static const networkFees = 'networkFees';
static const currency = 'currency';
static const lighting = 'lighting';
Expand Down
6 changes: 3 additions & 3 deletions lib/_pkg/wallet/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/_interface.dart';
import 'package:bb_mobile/_pkg/wallet/bdk/address.dart';
import 'package:bb_mobile/_pkg/wallet/lwk/address.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_repository/wallet/internal_wallets.dart';

class WalletAddress implements IWalletAddress {
WalletAddress({
required WalletsRepository walletsRepository,
required InternalWalletsRepository walletsRepository,
required BDKAddress bdkAddress,
required LWKAddress lwkAddress,
}) : _walletsRepository = walletsRepository,
_bdkAddress = bdkAddress,
_lwkAddress = lwkAddress;

final WalletsRepository _walletsRepository;
final InternalWalletsRepository _walletsRepository;
final BDKAddress _bdkAddress;
final LWKAddress _lwkAddress;

Expand Down
6 changes: 3 additions & 3 deletions lib/_pkg/wallet/balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/_interface.dart';
import 'package:bb_mobile/_pkg/wallet/bdk/balance.dart';
import 'package:bb_mobile/_pkg/wallet/lwk/balance.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_repository/wallet/internal_wallets.dart';

class WalletBalance implements IWalletBalance {
WalletBalance({
required WalletsRepository walletsRepository,
required InternalWalletsRepository walletsRepository,
required BDKBalance bdkBalance,
required LWKBalance lwkBalance,
}) : _walletsRepository = walletsRepository,
_bdkBalance = bdkBalance,
_lwkBalance = lwkBalance;

final WalletsRepository _walletsRepository;
final InternalWalletsRepository _walletsRepository;
final BDKBalance _bdkBalance;
final LWKBalance _lwkBalance;

Expand Down
6 changes: 3 additions & 3 deletions lib/_pkg/wallet/bdk/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import 'package:bb_mobile/_model/address.dart';
import 'package:bb_mobile/_model/cold_card.dart';
import 'package:bb_mobile/_model/wallet.dart';
import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_pkg/wallet/utils.dart';
import 'package:bb_mobile/_repository/wallet/internal_wallets.dart';
import 'package:bdk_flutter/bdk_flutter.dart' as bdk;
import 'package:path_provider/path_provider.dart';

class BDKCreate {
BDKCreate({required WalletsRepository walletsRepository})
BDKCreate({required InternalWalletsRepository walletsRepository})
: _walletsRepository = walletsRepository;

final WalletsRepository _walletsRepository;
final InternalWalletsRepository _walletsRepository;

Future<(bdk.Wallet?, Err?)> loadPublicBdkWallet(
Wallet wallet,
Expand Down
6 changes: 3 additions & 3 deletions lib/_pkg/wallet/bdk/sensitive_create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import 'package:bb_mobile/_model/wallet.dart';
import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/bdk/create.dart';
import 'package:bb_mobile/_pkg/wallet/create.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_pkg/wallet/utils.dart';
import 'package:bb_mobile/_repository/wallet/internal_wallets.dart';
import 'package:bdk_flutter/bdk_flutter.dart' as bdk;
import 'package:path_provider/path_provider.dart';

class BDKSensitiveCreate {
BDKSensitiveCreate({
required WalletsRepository walletsRepository,
required InternalWalletsRepository walletsRepository,
required BDKCreate bdkCreate,
}) : _walletsRepository = walletsRepository,
_bdkCreate = bdkCreate;

final WalletsRepository _walletsRepository;
final InternalWalletsRepository _walletsRepository;
final BDKCreate _bdkCreate;

Future<(List<String>?, Err?)> createMnemonic() async {
Expand Down
8 changes: 4 additions & 4 deletions lib/_pkg/wallet/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/_interface.dart';
import 'package:bb_mobile/_pkg/wallet/bdk/create.dart';
import 'package:bb_mobile/_pkg/wallet/lwk/create.dart';
import 'package:bb_mobile/_pkg/wallet/repository/storage.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_repository/wallet/internal_wallets.dart';
import 'package:bb_mobile/_repository/wallet/wallet_storage.dart';

class WalletCreate implements IWalletCreate {
WalletCreate({
required WalletsRepository walletsRepository,
required InternalWalletsRepository walletsRepository,
required LWKCreate lwkCreate,
required BDKCreate bdkCreate,
required WalletsStorageRepository walletsStorageRepository,
Expand All @@ -17,7 +17,7 @@ class WalletCreate implements IWalletCreate {
_bdkCreate = bdkCreate,
_walletsStorageRepository = walletsStorageRepository;

final WalletsRepository _walletsRepository;
final InternalWalletsRepository _walletsRepository;
final WalletsStorageRepository _walletsStorageRepository;

final LWKCreate _lwkCreate;
Expand Down
6 changes: 3 additions & 3 deletions lib/_pkg/wallet/lwk/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import 'package:bb_mobile/_model/transaction.dart';
import 'package:bb_mobile/_model/wallet.dart';
import 'package:bb_mobile/_pkg/boltz/swap.dart';
import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/repository/network.dart';
import 'package:bb_mobile/_repository/wallet/internal_network.dart';
import 'package:convert/convert.dart';
import 'package:lwk_dart/lwk_dart.dart' as lwk;

class LWKTransactions {
LWKTransactions({
required NetworkRepository networkRepository,
required InternalNetworkRepository networkRepository,
required SwapBoltz swapBoltz,
}) : _networkRepository = networkRepository,
_swapBoltz = swapBoltz;

final NetworkRepository _networkRepository;
final InternalNetworkRepository _networkRepository;
final SwapBoltz _swapBoltz;

Transaction addOutputAddresses(Address newAddress, Transaction tx) {
Expand Down
6 changes: 3 additions & 3 deletions lib/_pkg/wallet/network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import 'dart:async';
import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/_interface.dart';
import 'package:bb_mobile/_pkg/wallet/bdk/network.dart';
import 'package:bb_mobile/_pkg/wallet/repository/network.dart';
import 'package:bb_mobile/_repository/wallet/internal_network.dart';

class WalletNetwork implements IWalletNetwork {
WalletNetwork({
required NetworkRepository networkRepository,
required InternalNetworkRepository networkRepository,
required BDKNetwork bdkNetwork,
// required Logger logger,
}) : _networkRepository = networkRepository,
_bdkNetwork = bdkNetwork;

final NetworkRepository _networkRepository;
final InternalNetworkRepository _networkRepository;
final BDKNetwork _bdkNetwork;
// final Logger _logger;

Expand Down
43 changes: 0 additions & 43 deletions lib/_pkg/wallet/repository/network.dart

This file was deleted.

14 changes: 7 additions & 7 deletions lib/_pkg/wallet/sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import 'package:bb_mobile/_pkg/error.dart';
import 'package:bb_mobile/_pkg/wallet/_interface.dart';
import 'package:bb_mobile/_pkg/wallet/bdk/sync.dart';
import 'package:bb_mobile/_pkg/wallet/lwk/sync.dart';
import 'package:bb_mobile/_pkg/wallet/repository/network.dart';
import 'package:bb_mobile/_pkg/wallet/repository/storage.dart';
import 'package:bb_mobile/_pkg/wallet/repository/wallets.dart';
import 'package:bb_mobile/_repository/wallet/internal_network.dart';
import 'package:bb_mobile/_repository/wallet/internal_wallets.dart';
import 'package:bb_mobile/_repository/wallet/wallet_storage.dart';
import 'package:bb_mobile/locator.dart';

class WalletSync implements IWalletSync {
WalletSync({
required WalletsRepository walletsRepository,
required NetworkRepository networkRepository,
required InternalWalletsRepository walletsRepository,
required InternalNetworkRepository networkRepository,
required BDKSync bdkSync,
required LWKSync lwkSync,
}) : _walletsRepository = walletsRepository,
_networkRepository = networkRepository,
_bdkSync = bdkSync,
_lwkSync = lwkSync;

final WalletsRepository _walletsRepository;
final NetworkRepository _networkRepository;
final InternalWalletsRepository _walletsRepository;
final InternalNetworkRepository _networkRepository;
final BDKSync _bdkSync;
final LWKSync _lwkSync;

Expand Down
Loading

0 comments on commit 5140ece

Please sign in to comment.