Cw 1551 quick bitcoin wallet sync (#3446)

* add Wallet Accounts page and integrate UI

* account model refactor

* add walletInfoAccount table and API

* add WalletAccountList API

* add multi-account support for Electrum wallets

* add Bitcoin lightning card and card style handling

* refine account filtering and card selection

* update current account balance on wallet changes

* update configure.dar

* Use named parameters for card design

* Add Bitcoin account handling and refactor lookup

* refactor dashboard

* refactor cards UI and account balance handling

* Improve Bitcoin account selection and balances

* restrict unspent coin usage to current account

* filter transactions by current Bitcoin account

* refactor electrum wallet

* refactor address generation

* add accountIndex to address fetch logic

* Update configure.dart

* reload transactions on Bitcoin account change

* restore multiple BTC accounts and improve fetch

* show account balance with in btc

* track account index in Bitcoin transactions

* discover btc BIP39 accounts during restore

* fix account switching and card ordering bugs

* fix card customizer

* limit account name length in modal

* update BTC account list balance display

* auto-reformat

* formating fix

* skip HD map validation

* fix 0 balance issue

* minor fix

* quick bitcoin wallet sync

* restore shuffle change output

* restore address lookup fix

* Update electrum.dart

* remove account customizer

* Merge branch 'CW-1142-Add-accounts-feature-to-BTC' into CW-1551-Quick-Bitcoin-Wallet-Sync

* probe only segwit in account discovery

* add account discovery limit and tracking

* Improve Electrum sync account handling [skip ci]

* remove legacy monero account and address list UI

* rework BTC account balance refres

* avoid unnecessary BTC account reloads

* refactor account header in addresses page

* fix blank popup when editing an account

* fix: dedupe UTXO balance

* minor fix

* add Bitcoin current account API

* Apply batched suggestions from code review [skip ci]

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

* address PR review comments [skip ci]

* remove account customizer and fix accounts init

* restrict extra BTC accounts to SegWit

* add BTC multi-account toggle

* Fix BTC sync gating and account balance update

* minor fix

* Update electrum_wallet.dart

* store selected account on WalletInfo

* Refine wallet account reset visibility

* refactor BTC address prep and move accounts page

* refactor account stack and customizer routing

* migrate legacy Lightning card styles

* unify dashboard account change state

* fix account routing and Electrum balances

* fix account setup and wallet cards UI

* disable Bitcoin Accounts for all hardware

* merge conflicts fix

* minor fixes

* update cards_view [skip ci]

* reverted cards view update [skip ci]

* fix asset name

* moved the transaction filtering into the electrum wallet

* localization

* disable accounts for watch-only wallets

* fix: stop card render from switching the wallet account

* fix: restore Lightning transactions in tx history

* minor fix

* fix: skip duplicate legacy address generation [skip ci]

* fix: correct account balance/design mismatch bugs

* addressing review comments

---------

Co-authored-by: Robert Malikowski <malikowskirobert@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii
2026-10-03 00:44:57 +02:00
committed by GitHub
co-authored by Omar Hatem Robert Malikowski
parent 0503d54290
commit d7ebf42814
84 changed files with 3991 additions and 2186 deletions
@@ -1,4 +1,5 @@
import 'package:bloc/bloc.dart';
import "package:cake_wallet/bitcoin/bitcoin.dart";
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/wownero/wownero.dart';
import "package:cw_core/balance_card_style_settings.dart";
@@ -30,6 +31,9 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
add(_Init());
}
bool get _accountNameEnabled =>
!lightningMode && _wallet.walletInfo.isMultiAccountsEnabled == true;
List<Gradient> _updateAvailableColors(CardDesign currentDesign) {
final list = List<Gradient>.from(CardDesign.allGradients, growable: true);
if (CardDesign.specialDesignsForCurrencies[_wallet.currency] != null) {
@@ -83,23 +87,9 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
}
void _init(_Init event, Emitter<CardCustomizerState> emit) async {
late final account;
if (_wallet.type == WalletType.monero) {
account = monero!.getCurrentAccount(_wallet);
} else if (_wallet.type == WalletType.wownero) {
account = wownero!.getCurrentAccount(_wallet);
} else {
account = null;
}
final accountName = (account?.label ?? "") as String;
late final int accountIndex;
if (account != null) {
accountIndex = account.id as int;
} else if (lightningMode) {
accountIndex = 0;
} else {
accountIndex = -1;
}
final accountInfo = await _getCurrentAccountInfo();
final accountName = accountInfo.accountName;
final accountIndex = accountInfo.accountIndex;
final curr = lightningMode ? CryptoCurrency.btcln : _wallet.currency;
final currentDesignSettings = await _loadCurrentDesignSettings(accountIndex);
final currentDesign = CardDesign.fromStyleSettings(currentDesignSettings, curr);
@@ -123,6 +113,39 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
selectedIconIndex: selectedIconIndex));
}
Future<({String accountName, int accountIndex})> _getCurrentAccountInfo() async {
if (lightningMode) {
return (accountName: "", accountIndex: -2);
}
final account = await _resolveCurrentAccount();
if (!_accountNameEnabled) {
return (accountName: "", accountIndex: account.accountIndex);
}
return account;
}
Future<({String accountName, int accountIndex})> _resolveCurrentAccount() async {
if (_wallet.type == WalletType.monero) {
final account = monero!.getCurrentAccount(_wallet);
return (accountName: account.label, accountIndex: account.id);
}
if (_wallet.type == WalletType.wownero) {
final account = wownero!.getCurrentAccount(_wallet);
return (accountName: account.label, accountIndex: account.id);
}
if (_wallet.type == WalletType.bitcoin) {
final account = await bitcoin!.getCurrentAccount(_wallet);
return (accountName: account.label, accountIndex: account.id);
}
return (accountName: "", accountIndex: -1);
}
void _onDesignSelected(CardDesignSelected event, Emitter<CardCustomizerState> emit) {
final newColors = _updateAvailableColors(state.availableDesigns[event.newDesignIndex]);
late final int newColorIndex;
@@ -152,32 +175,34 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
emit(state.copyWith(accountName: event.newAccountName));
}
void _onDesignSaved(DesignSaved event, Emitter<CardCustomizerState> emit) {
BalanceCardStyleSettings.fromCardDesign(
Future<void> _onDesignSaved(DesignSaved event, Emitter<CardCustomizerState> emit) async {
await BalanceCardStyleSettings.fromCardDesign(
walletInfoId: _wallet.walletInfo.internalId,
accountIndex: state.accountIndex,
cardOrder: state.cardOrder,
design: state.selectedDesign,
iconStyleIndex: state.selectedIconIndex,
gradientIndexOverride: state.selectedColorIndex)
.insert()
.then((value) {
emit(CardCustomizerSaved(
state.selectedDesignIndex,
state.selectedColorIndex,
state.availableDesigns,
state.availableColors,
state.accountName,
state.accountIndex,
state.displaySats,
state.cardOrder,
availableIconPaths: state.availableIconPaths,
selectedIconIndex: state.selectedIconIndex));
});
saveAccountName();
.insert();
await saveAccountName();
emit(CardCustomizerSaved(
state.selectedDesignIndex,
state.selectedColorIndex,
state.availableDesigns,
state.availableColors,
state.accountName,
state.accountIndex,
state.displaySats,
state.cardOrder,
availableIconPaths: state.availableIconPaths,
selectedIconIndex: state.selectedIconIndex));
}
Future<void> saveAccountName() async {
if (!_accountNameEnabled) return;
if (_wallet.type == WalletType.monero) {
await saveMoneroAccountName();
}
@@ -185,6 +210,9 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
if (_wallet.type == WalletType.wownero) {
await saveWowneroAccountName();
}
if (_wallet.type == WalletType.bitcoin && !lightningMode) {
await saveBitcoinAccountName();
}
}
Future<void> saveMoneroAccountName() async {
@@ -202,4 +230,11 @@ class CardCustomizerBloc extends Bloc<CardCustomizerEvent, CardCustomizerState>
await _wallet.save();
}
Future<void> saveBitcoinAccountName() async {
await _wallet.walletInfo.renameAccount(
accountIndex: state.accountIndex,
label: state.accountName,
);
}
}