Wallet picker follow-ups to #3717 (#3729)
What changed, and why it matters
This commit fixes address-selection bugs in Cake Wallet's address book and wallet picker. Before the fix, the app could suggest Bitcoin/Litecoin addresses that the sending wallet couldn't actually pay (for example, a hidden swap refund address, a Silent Payments address for a hardware wallet, or a Litecoin MWEB address). It also relied on the English word 'Active' in a translated name, so non-English users saw fewer wallets. The patch makes the picker choose only plain, broadly-supported addresses for buy/exchange flows and uses an untranslated label to decide which address is active.
Treat as a defensive bug-fix commit with possible funds-impact. Review the related PR #3717 and any prior release to confirm whether the buggy picker behavior reached production. Verify that hiddenAddresses correctly excludes all swap refund addresses and that no other callers still match on translated names. Consider whether a security advisory is warranted if users could have sent funds to unspendable/hidden addresses.
Security signals we found
Funds-loss risk: picker could select addresses the sender cannot pay (Silent Payments, MWEB, hidden refund addresses).
UI/logic bug: active-address detection relied on localized string matching, breaking for non-English users.
Address reuse/privacy concern: hidden swap refund addresses could be offered as buy/exchange destinations.
Partial fix follow-up: commit message notes iterative refinement and reverts an earlier Silent Payments opt-in.
New unit tests cover the changed selection logic.
Evidence from the diff
The commit refactors address selection in cw_bitcoin and the contact list. Key changes: (1) addressForBuy now skips hiddenAddresses, preventing swap refund addresses from being reused for buy-provider payouts; (2) WalletContact gains a raw, untranslated label field and isActive/isPickable getters, replacing fragile localized-name matching (name.contains('Active')); (3) Bitcoin’s Silent Payments and Litecoin’s MWEB pages now expose a regular SegWit address as ‘Active’ to senders that cannot build those output types; (4) Litecoin addressForBuy returns a regular P2WPKH address on the MWEB page; (5) tests are added for hidden-address skipping, SP/MWEB active-address behavior, and WalletContact pickability. The patch is explicitly framed as a follow-up fix to #3717 and includes co-author attribution to Claude Opus 5.5.
Changed components
cw_bitcoin/lib/bitcoin_wallet_addresses.dartcw_bitcoin/lib/litecoin_wallet_addresses.dartcw_bitcoin/test/bitcoin_wallet_addresses_picker_test.dartlib/entities/wallet_contact.dartlib/src/screens/contact/contact_list_page.dartlib/view_model/contact_list/contact_list_view_model.darttest/entities/wallet_contact_test.dartInspect captured patch +284 / −6
### cw_bitcoin/lib/bitcoin_wallet_addresses.dart
@@ -151,7 +151,8 @@ abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with S
e.accountIndex == currentAccountIndex &&
e.type == SegwitAddresType.p2wpkh &&
!e.isHidden &&
- !e.isUsed)
+ !e.isUsed &&
+ !hiddenAddresses.contains(e.address))
.address;
} catch (_) {
return super.addressForBuy;
### cw_bitcoin/lib/litecoin_wallet_addresses.dart
@@ -229,6 +229,30 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
return super.getChangeAddress();
}
+ // Not every sender can pay MWEB, so offer a regular address instead.
+ @override
+ String get addressForBuy {
+ if (addressPageType != SegwitAddresType.mweb) {
+ return super.addressForBuy;
+ }
+
+ try {
+ return super
+ .allAddresses
+ .firstWhere(
+ (e) =>
+ e.type == SegwitAddresType.p2wpkh &&
+ !e.isHidden &&
+ !e.isUsed &&
+ !e.isLegacyDerivation &&
+ !hiddenAddresses.contains(e.address),
+ )
+ .address;
+ } catch (_) {
+ return super.addressForBuy;
+ }
+ }
+
@override
String get addressForExchange {
// don't use mweb addresses for exchange refund address:
### cw_bitcoin/test/bitcoin_wallet_addresses_picker_test.dart
@@ -0,0 +1,194 @@
+import "package:bitcoin_base/bitcoin_base.dart";
+import "package:blockchain_utils/blockchain_utils.dart";
+import "package:cw_bitcoin/bitcoin_address_record.dart";
+import "package:cw_bitcoin/bitcoin_wallet_addresses.dart";
+import "package:cw_bitcoin/electrum_wallet_addresses.dart";
+import "package:cw_bitcoin/litecoin_wallet_addresses.dart";
+import "package:cw_bitcoin/payjoin/manager.dart";
+import "package:cw_bitcoin/utils.dart";
+import "package:cw_core/db/sqlite.dart";
+import "package:cw_core/wallet_info.dart";
+import "package:cw_core/wallet_type.dart";
+import "package:flutter_test/flutter_test.dart";
+import "package:sqflite_common_ffi/sqflite_ffi.dart";
+
+final _master = Bip32Slip10Secp256k1.fromSeed(List<int>.generate(64, (i) => i));
+
+Bip32Slip10Secp256k1 _hd(String path) => _master.derivePath(path) as Bip32Slip10Secp256k1;
+
+final _receiveHd = _hd("m/84'/0'/0'/0");
+final _changeHd = _hd("m/84'/0'/0'/1");
+final _receive = [
+ for (var i = 0; i < 5; i++)
+ generateP2WPKHAddress(hd: _receiveHd, network: BitcoinNetwork.mainnet, index: i),
+];
+
+final _ltcReceiveHd = _hd("m/84'/2'/0'/0");
+final _ltcChangeHd = _hd("m/84'/2'/0'/1");
+final _ltcReceive = [
+ for (var i = 0; i < 5; i++)
+ generateP2WPKHAddress(hd: _ltcReceiveHd, network: LitecoinNetwork.mainnet, index: i),
+];
+const _mweb = "ltcmweb1-placeholder";
+
+List<BitcoinAddressRecord> _records(List<String> receive, BasedUtxoNetwork network) => [
+ for (var i = 0; i < receive.length; i++)
+ BitcoinAddressRecord(
+ receive[i],
+ index: i,
+ type: SegwitAddresType.p2wpkh,
+ network: network,
+ ),
+ ];
+
+class _NoPayjoin implements PayjoinManager {
+ @override
+ dynamic noSuchMethod(Invocation invocation) => throw UnimplementedError();
+}
+
+class _BitcoinAddresses extends BitcoinWalletAddresses {
+ _BitcoinAddresses(super.walletInfo)
+ : super(
+ mainHdByTypeAndAccount: {
+ 0: {SegwitAddresType.p2wpkh: _receiveHd},
+ },
+ sideHdByTypeAndAccount: {
+ 0: {SegwitAddresType.p2wpkh: _changeHd},
+ },
+ accountIndexes: [0],
+ currentAccountIndex: 0,
+ legacyMainHd: _receiveHd,
+ legacySideHd: _changeHd,
+ network: BitcoinNetwork.mainnet,
+ isHardwareWallet: false,
+ payjoinManager: _NoPayjoin(),
+ masterHd: _master,
+ initialAddresses: [
+ ..._records(_receive, BitcoinNetwork.mainnet),
+ for (var i = 0; i < 3; i++)
+ BitcoinAddressRecord(
+ generateP2WPKHAddress(hd: _changeHd, network: BitcoinNetwork.mainnet, index: i),
+ index: i,
+ isHidden: true,
+ type: SegwitAddresType.p2wpkh,
+ network: BitcoinNetwork.mainnet,
+ ),
+ ],
+ );
+
+ @override
+ Future<void> saveAddressesInBox() async {}
+}
+
+class _LitecoinAddresses extends LitecoinWalletAddresses {
+ _LitecoinAddresses(super.walletInfo)
+ : super(
+ mainHdByTypeAndAccount: {
+ 0: {SegwitAddresType.p2wpkh: _ltcReceiveHd, SegwitAddresType.mweb: _ltcReceiveHd},
+ },
+ sideHdByTypeAndAccount: {
+ 0: {SegwitAddresType.p2wpkh: _ltcChangeHd, SegwitAddresType.mweb: _ltcChangeHd},
+ },
+ accountIndexes: [0],
+ currentAccountIndex: 0,
+ legacyMainHd: _ltcReceiveHd,
+ legacySideHd: _ltcChangeHd,
+ network: LitecoinNetwork.mainnet,
+ isHardwareWallet: false,
+ mwebHd: null,
+ mwebEnabled: true,
+ scanSecretOverride: null,
+ spendPubkeyOverride: null,
+ initialAddresses: [
+ ..._records(_ltcReceive, LitecoinNetwork.mainnet),
+ BitcoinAddressRecord(
+ _mweb,
+ index: 0,
+ type: SegwitAddresType.mweb,
+ network: LitecoinNetwork.mainnet,
+ ),
+ ],
+ );
+
+ @override
+ Future<void> saveAddressesInBox() async {}
+}
+
+WalletInfo _walletInfo(WalletType type, BitcoinAddressType? addressPageType) => WalletInfo.external(
+ id: "picker_test",
+ name: "picker_test",
+ type: type,
+ isRecovery: false,
+ restoreHeight: 0,
+ date: DateTime(2026),
+ dirPath: "",
+ path: "",
+ address: "",
+ )..addressPageType = addressPageType?.toString();
+
+Future<T> _ready<T extends ElectrumWalletAddresses>(T addresses) async {
+ // Lets the constructor's un-awaited used/hidden/manual loads land before the test edits them.
+ await addresses.walletInfo.getManualAddresses();
+ return addresses;
+}
+
+Future<_BitcoinAddresses> _bitcoin({BitcoinAddressType? addressPageType}) =>
+ _ready(_BitcoinAddresses(_walletInfo(WalletType.bitcoin, addressPageType)));
+
+Future<_LitecoinAddresses> _litecoin({BitcoinAddressType? addressPageType}) =>
+ _ready(_LitecoinAddresses(_walletInfo(WalletType.litecoin, addressPageType)));
+
+void main() {
+ setUpAll(() async {
+ sqfliteFfiInit();
+ db = await databaseFactoryFfi.openDatabase(inMemoryDatabasePath);
+ await db!.execute(
+ "CREATE TABLE walletInfoAddress "
+ "(walletInfoAddressId INTEGER PRIMARY KEY, walletInfoId INTEGER, type INTEGER, "
+ "address TEXT)",
+ );
+ });
+
+ test("addressForBuy skips hidden addresses", () async {
+ final addresses = await _bitcoin();
+ expect(addresses.addressForBuy, _receive[0]);
+
+ addresses.hiddenAddresses.add(_receive[0]);
+
+ expect(addresses.addressForBuy, _receive[1]);
+ });
+
+ test("on the Silent Payments page, the SegWit address is active", () async {
+ final addresses = await _bitcoin(addressPageType: SilentPaymentsAddresType.p2sp);
+ addresses.hiddenAddresses.add(_receive[0]);
+
+ await addresses.updateAddressesInBox();
+
+ expect(addresses.address, addresses.silentAddress.toString());
+ expect(addresses.addressesMap[_receive[1]], "Active");
+ expect(addresses.addressesMap[addresses.silentAddress.toString()], "Silent Payments");
+ expect(addresses.addressesMap.containsKey(_receive[0]), isFalse);
+ });
+
+ test("on the MWEB page, the MWEB address is active but buy uses a regular address", () async {
+ final addresses = await _litecoin(addressPageType: SegwitAddresType.mweb);
+ addresses.hiddenAddresses.add(_ltcReceive[0]);
+
+ await addresses.updateAddressesInBox();
+
+ expect(addresses.address, _mweb);
+ expect(addresses.addressesMap[_mweb], "Active - MWEB");
+ expect(addresses.addressesMap.values.where((label) => label.startsWith("Active")), hasLength(1));
+ expect(addresses.addressForBuy, _ltcReceive[1]);
+ });
+
+ test("on the Litecoin SegWit page, its own address stays active", () async {
+ final addresses = await _litecoin();
+
+ await addresses.updateAddressesInBox();
+
+ expect(addresses.addressForBuy, addresses.address);
+ expect(addresses.addressesMap[_ltcReceive[0]], "Active");
+ expect(addresses.addressesMap[_mweb], "MWEB");
+ });
+}
### lib/entities/wallet_contact.dart
@@ -3,7 +3,7 @@ import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_type.dart';
class WalletContact implements ContactBase {
- WalletContact(this.address, this.name, this.type, {this.walletType});
+ WalletContact(this.address, this.name, this.type, {this.walletType, this.label = ""});
@override
String address;
@@ -18,6 +18,18 @@ class WalletContact implements ContactBase {
/// Used for EVM chain filtering
final WalletType? walletType;
+ /// Untranslated address-map label, e.g. "Active - P2WPKH"; match on this, never on [name].
+ final String label;
+
+ bool get isActive => label.startsWith("Active");
+
+ bool get isPickable {
+ if (type == CryptoCurrency.btc || type == CryptoCurrency.ltc) {
+ return isActive;
+ }
+ return true;
+ }
+
String get displayName => "";
set displayName(String _) {}
### lib/src/screens/contact/contact_list_page.dart
@@ -213,7 +213,7 @@ class _ContactPageBodyState extends State<ContactPageBody> with SingleTickerProv
return generateRaw(context, contact);
} else {
final activeContact = groupContacts.firstWhere(
- (contact) => contact.name.contains('Active'),
+ (contact) => contact is WalletContact && contact.isActive,
orElse: () => groupContacts[0],
);
### lib/view_model/contact_list/contact_list_view_model.dart
@@ -107,6 +107,7 @@ abstract class ContactListViewModelBase with Store {
: info.network!.toLowerCase().contains("testnet"),
),
walletType: info.type,
+ label: label,
));
});
}
@@ -171,9 +172,7 @@ abstract class ContactListViewModelBase with Store {
bool _isValidForCurrency(ContactBase element, bool isWalletContact) {
if (_currency == null) return true;
- if (!element.name.contains('Active') &&
- isWalletContact &&
- (element.type == CryptoCurrency.btc || element.type == CryptoCurrency.ltc)) return false;
+ if (isWalletContact && element is WalletContact && !element.isPickable) return false;
final currencyMatches = element.type == _currency;
### test/entities/wallet_contact_test.dart
@@ -0,0 +1,48 @@
+import "package:cake_wallet/entities/wallet_contact.dart";
+import "package:cw_core/crypto_currency.dart";
+import "package:cw_core/wallet_type.dart";
+import "package:flutter_test/flutter_test.dart";
+
+WalletContact _contact(
+ String label, {
+ String name = "Savings",
+ CryptoCurrency type = CryptoCurrency.btc,
+ WalletType walletType = WalletType.bitcoin,
+}) =>
+ WalletContact("address", name, type, walletType: walletType, label: label);
+
+void main() {
+ group("WalletContact.isPickable", () {
+ test("offers the active address when its name is translated", () {
+ final contact = _contact("Active", name: "Savings (Aktiv)");
+
+ expect(contact.isPickable, isTrue);
+ });
+
+ test("hides a Bitcoin wallet's other address types", () {
+ expect(_contact("P2WPKH").isPickable, isFalse);
+ expect(_contact("LN").isPickable, isFalse);
+ expect(_contact("Silent Payments").isPickable, isFalse);
+ });
+
+ test("ignores a wallet name that contains Active", () {
+ final contact = _contact("P2TR", name: "Active Savings (P2TR)");
+
+ expect(contact.isPickable, isFalse);
+ });
+
+ test("applies the same rule to Litecoin", () {
+ final active = _contact("Active - P2WPKH", type: CryptoCurrency.ltc);
+ final other = _contact("MWEB", type: CryptoCurrency.ltc);
+
+ expect(active.isPickable, isTrue);
+ expect(other.isPickable, isFalse);
+ });
+
+ test("leaves single-address currencies alone", () {
+ final contact = _contact("", type: CryptoCurrency.eth, walletType: WalletType.ethereum);
+
+ expect(contact.isPickable, isTrue);
+ });
+ });
+}Why this scored 48/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.