mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 09:29:48 +00:00
add list of used electrum addresses
This commit is contained in:
parent
d756b367d3
commit
9883965cb3
6 changed files with 226 additions and 11 deletions
|
@ -86,6 +86,10 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
return acc;
|
||||
});
|
||||
|
||||
List<BitcoinAddressRecord> get usedAddressList =>
|
||||
addresses.where((element) => element.isUsed).toList();
|
||||
|
||||
|
||||
Future<void> discoverAddresses() async {
|
||||
await _discoverAddresses(mainHd, false);
|
||||
await _discoverAddresses(sideHd, true);
|
||||
|
|
|
@ -35,6 +35,7 @@ import 'package:cake_wallet/src/screens/nano_accounts/nano_account_list_page.dar
|
|||
import 'package:cake_wallet/src/screens/nodes/pow_node_create_or_edit_page.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/anonpay_invoice_page.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/anonpay_receive_page.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/widgets/electrum_address_list_page.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/wallet_restore_choose_derivation.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/display_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/domain_lookups_page.dart';
|
||||
|
@ -660,6 +661,9 @@ Future<void> setup({
|
|||
getIt.registerFactory(
|
||||
() => NanoAccountListPage(accountListViewModel: getIt.get<NanoAccountListViewModel>()));
|
||||
|
||||
getIt.registerFactory(
|
||||
() => ElectrumAddressListPage(wallet: getIt.get<AppStore>().wallet!));
|
||||
|
||||
/*getIt.registerFactory(() {
|
||||
final wallet = getIt.get<AppStore>().wallet;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:cake_wallet/src/screens/receive/widgets/electrum_address_list_page.dart';
|
||||
import 'package:cake_wallet/themes/extensions/keyboard_theme.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
|
@ -15,6 +16,7 @@ import 'package:cake_wallet/utils/share_util.dart';
|
|||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/widgets/qr_widget.dart';
|
||||
|
@ -155,12 +157,29 @@ class AddressPage extends BasePage {
|
|||
amountController: _amountController,
|
||||
isLight: dashboardViewModel.settingsStore.currentTheme.type ==
|
||||
ThemeType.light))),
|
||||
if (dashboardViewModel.isAutoGenerateSubaddressesEnabled ||
|
||||
addressListViewModel.showElectrumAddressDisclaimer)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(S.of(context).electrum_address_disclaimer,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Theme.of(context).extension<BalancePageTheme>()!.labelTextColor)),
|
||||
),
|
||||
Observer(builder: (_) {
|
||||
if (addressListViewModel.hasAddressList) {
|
||||
if (addressListViewModel.hasAddressList || addressListViewModel.hasElectrumAddressList) {
|
||||
return GestureDetector(
|
||||
onTap: () async => dashboardViewModel.isAutoGenerateSubaddressesEnabled
|
||||
onTap: () async =>
|
||||
addressListViewModel.hasElectrumAddressList ?
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (_) => getIt.get<ElectrumAddressListPage>())
|
||||
:
|
||||
dashboardViewModel.isAutoGenerateSubaddressesEnabled
|
||||
? await showPopUp<void>(
|
||||
context: context, builder: (_) => getIt.get<MoneroAccountListPage>())
|
||||
context: context,
|
||||
builder: (_) => getIt.get<MoneroAccountListPage>())
|
||||
: Navigator.of(context).pushNamed(Routes.receive),
|
||||
child: Container(
|
||||
height: 50,
|
||||
|
@ -210,13 +229,6 @@ class AddressPage extends BasePage {
|
|||
),
|
||||
),
|
||||
);
|
||||
} else if (dashboardViewModel.isAutoGenerateSubaddressesEnabled ||
|
||||
addressListViewModel.showElectrumAddressDisclaimer) {
|
||||
return Text(S.of(context).electrum_address_disclaimer,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Theme.of(context).extension<BalancePageTheme>()!.labelTextColor));
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
|
119
lib/src/screens/receive/widgets/electrum_address_list_page.dart
Normal file
119
lib/src/screens/receive/widgets/electrum_address_list_page.dart
Normal file
|
@ -0,0 +1,119 @@
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/widgets/electrum_address_tile.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_background.dart';
|
||||
import 'package:cake_wallet/src/widgets/picker_inner_wrapper_widget.dart';
|
||||
import 'package:cake_wallet/src/widgets/search_bar_widget.dart';
|
||||
import 'package:cake_wallet/src/widgets/section_divider.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class ElectrumAddressListPage extends StatefulWidget {
|
||||
const ElectrumAddressListPage({required WalletBase wallet})
|
||||
: this._wallet = wallet;
|
||||
|
||||
final WalletBase _wallet;
|
||||
|
||||
@override
|
||||
State<ElectrumAddressListPage> createState() =>
|
||||
_ElectrumAddressListPageState(wallet: _wallet);
|
||||
}
|
||||
|
||||
class _ElectrumAddressListPageState extends State<ElectrumAddressListPage> {
|
||||
_ElectrumAddressListPageState({required WalletBase wallet})
|
||||
: this._wallet = wallet is ElectrumWallet ? wallet : null;
|
||||
|
||||
final ElectrumWallet? _wallet;
|
||||
final ScrollController controller = ScrollController();
|
||||
late TextEditingController searchController;
|
||||
late List<BitcoinAddressRecord> filteredAddresses;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
searchController = TextEditingController();
|
||||
filteredAddresses = getAddresses();
|
||||
searchController.addListener(() {
|
||||
filterAddresses();
|
||||
});
|
||||
}
|
||||
|
||||
List<BitcoinAddressRecord> getAddresses() =>
|
||||
_wallet?.walletAddresses.usedAddressList ?? [];
|
||||
|
||||
void filterAddresses() {
|
||||
String searchText = searchController.text.toLowerCase();
|
||||
setState(() {
|
||||
filteredAddresses = getAddresses().where((address) {
|
||||
return address.address.toLowerCase().contains(searchText);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double itemHeight = 65;
|
||||
double buttonHeight = 62;
|
||||
|
||||
return getAddresses().isEmpty
|
||||
? GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: AlertBackground(child: PlaceholderWidget(context)))
|
||||
: PickerInnerWrapperWidget(
|
||||
title: 'Address List',
|
||||
itemsHeight: (itemHeight * filteredAddresses.length) + buttonHeight,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8, left: 12, right: 12),
|
||||
child: SearchBarWidget(
|
||||
searchController: searchController,
|
||||
borderRadius: 12,
|
||||
hintText: 'Search address'),
|
||||
),
|
||||
Expanded(
|
||||
child: Scrollbar(
|
||||
controller: controller,
|
||||
child: ListView.separated(
|
||||
padding: EdgeInsets.zero,
|
||||
controller: controller,
|
||||
separatorBuilder: (context, index) =>
|
||||
const HorizontalSectionDivider(),
|
||||
itemCount: filteredAddresses.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = filteredAddresses[index];
|
||||
return ElectrumAddressTile(
|
||||
address: item.address,
|
||||
isChange: item.isHidden,
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: item.address));
|
||||
showBar<void>(
|
||||
context,
|
||||
S.of(context).transaction_details_copied(
|
||||
S.of(context).address));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget PlaceholderWidget(BuildContext context) {
|
||||
return Center(
|
||||
child: Text(
|
||||
'Your previous used addresses will appear here',
|
||||
style: TextStyle(fontSize: 14, color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
71
lib/src/screens/receive/widgets/electrum_address_tile.dart
Normal file
71
lib/src/screens/receive/widgets/electrum_address_tile.dart
Normal file
|
@ -0,0 +1,71 @@
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/themes/extensions/account_list_theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ElectrumAddressTile extends StatelessWidget {
|
||||
ElectrumAddressTile({
|
||||
required this.address,
|
||||
required this.isChange,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final String address;
|
||||
final bool isChange;
|
||||
final Function() onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color =
|
||||
Theme.of(context).extension<AccountListTheme>()!.tilesBackgroundColor;
|
||||
final textColor =
|
||||
Theme.of(context).extension<AccountListTheme>()!.tilesTextColor;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.symmetric(horizontal: 24),
|
||||
color: color,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(child: SizedBox()),
|
||||
Expanded(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.fitWidth,
|
||||
child: Text(
|
||||
address,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontFamily: 'Lato',
|
||||
color: Theme.of(context)
|
||||
.extension<AccountListTheme>()!
|
||||
.tilesAmountColor,
|
||||
decoration: TextDecoration.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
child: Text(
|
||||
isChange ? S.of(context).unspent_change : '',
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontFamily: 'Lato',
|
||||
color: textColor,
|
||||
decoration: TextDecoration.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -331,6 +331,11 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
|
|||
wallet.type == WalletType.litecoin ||
|
||||
wallet.type == WalletType.bitcoinCash;
|
||||
|
||||
bool get hasElectrumAddressList =>
|
||||
wallet.type == WalletType.litecoin ||
|
||||
wallet.type == WalletType.bitcoinCash ||
|
||||
wallet.type == WalletType.bitcoin;
|
||||
|
||||
List<ListItem> _baseItems;
|
||||
|
||||
final YatStore yatStore;
|
||||
|
|
Loading…
Reference in a new issue