Cw-343-a-list-of-previously-used-addresses (#1248)

* add used addresses list

* generate new address button

* fix wallet type issue

* fix addresses button title

* update selectButton

* show all wallet addresses

* add tx amount and balance

* fix ui

* remove cashAddr format

* fix generating new address issue

* disable autogenerating

* fix cashAddr format

* minor fix

* add search bar

* Update address_cell.dart

* fix merge conflict

* address labeling feature

* review fixes

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii
2024-01-23 07:15:24 +02:00
committed by GitHub
co-authored by Omar Hatem
parent d664f0a16f
commit 9754d67601
20 changed files with 664 additions and 330 deletions
@@ -1,3 +1,4 @@
import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.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,63 +157,27 @@ class AddressPage extends BasePage {
amountController: _amountController,
isLight: dashboardViewModel.settingsStore.currentTheme.type ==
ThemeType.light))),
SizedBox(height: 16),
Observer(builder: (_) {
if (addressListViewModel.hasAddressList) {
return GestureDetector(
onTap: () async => dashboardViewModel.isAutoGenerateSubaddressesEnabled
return SelectButton(
text: addressListViewModel.buttonTitle,
onTap: () async => dashboardViewModel.isAutoGenerateSubaddressesEnabled &&
(WalletType.monero == addressListViewModel.wallet.type ||
WalletType.haven == addressListViewModel.wallet.type)
? 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,
padding: EdgeInsets.only(left: 24, right: 12),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(25)),
border: Border.all(
color:
Theme.of(context).extension<BalancePageTheme>()!.cardBorderColor,
width: 1),
color: Theme.of(context)
.extension<SyncIndicatorTheme>()!
.syncedBackgroundColor),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Observer(
builder: (_) {
String label = addressListViewModel.hasAccounts
? S.of(context).accounts_subaddresses
: S.of(context).addresses;
if (dashboardViewModel.isAutoGenerateSubaddressesEnabled) {
label = addressListViewModel.hasAccounts
? S.of(context).accounts
: S.of(context).account;
}
return Text(
label,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.extension<SyncIndicatorTheme>()!
.textColor),
);
},
),
Icon(
Icons.arrow_forward_ios,
size: 14,
color: Theme.of(context).extension<SyncIndicatorTheme>()!.textColor,
)
],
),
),
textColor: Theme.of(context).extension<SyncIndicatorTheme>()!.textColor,
color: Theme.of(context).extension<SyncIndicatorTheme>()!.syncedBackgroundColor,
borderColor: Theme.of(context).extension<BalancePageTheme>()!.cardBorderColor,
arrowColor: Theme.of(context).extension<SyncIndicatorTheme>()!.textColor,
textSize: 14,
height: 50,
);
} else if (dashboardViewModel.isAutoGenerateSubaddressesEnabled ||
addressListViewModel.showElectrumAddressDisclaimer) {
addressListViewModel.isElectrumWallet) {
return Text(S.of(context).electrum_address_disclaimer,
textAlign: TextAlign.center,
style: TextStyle(
@@ -11,29 +11,37 @@ class SelectButton extends StatelessWidget {
this.isSelected = false,
this.showTrailingIcon = true,
this.height = 60,
this.textSize = 18,
this.color,
this.textColor,
this.arrowColor,
this.borderColor,
});
final Image? image;
final String text;
final double textSize;
final bool isSelected;
final VoidCallback onTap;
final bool showTrailingIcon;
final double height;
final Color? color;
final Color? textColor;
final Color? arrowColor;
final Color? borderColor;
@override
Widget build(BuildContext context) {
final color = isSelected
? Colors.green
: Theme.of(context).cardColor;
final textColor = isSelected
final backgroundColor = color ?? (isSelected ? Colors.green : Theme.of(context).cardColor);
final effectiveTextColor = textColor ?? (isSelected
? Theme.of(context).extension<WalletListTheme>()!.restoreWalletButtonTextColor
: Theme.of(context).extension<CakeTextTheme>()!.buttonTextColor;
final arrowColor = isSelected
: Theme.of(context).extension<CakeTextTheme>()!.buttonTextColor);
final effectiveArrowColor = arrowColor ?? (isSelected
? Theme.of(context).extension<WalletListTheme>()!.restoreWalletButtonTextColor
: Theme.of(context).extension<FilterTheme>()!.titlesColor;
: Theme.of(context).extension<FilterTheme>()!.titlesColor);
final selectArrowImage = Image.asset('assets/images/select_arrow.png',
color: arrowColor);
color: effectiveArrowColor);
return GestureDetector(
onTap: onTap,
@@ -44,7 +52,9 @@ class SelectButton extends StatelessWidget {
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(30)),
color: color
color: backgroundColor,
border: borderColor != null ? Border.all(color: borderColor!) : null,
),
child: Row(
mainAxisSize: MainAxisSize.max,
@@ -63,9 +73,9 @@ class SelectButton extends StatelessWidget {
child: Text(
text,
style: TextStyle(
fontSize: 18,
fontSize: textSize,
fontWeight: FontWeight.w500,
color: textColor
color: effectiveTextColor,
),
),
)
+23 -14
View File
@@ -49,7 +49,7 @@ class ReceivePage extends BasePage {
bool get gradientBackground => true;
@override
bool get resizeToAvoidBottomInset => false;
bool get resizeToAvoidBottomInset => true;
final FocusNode _cryptoAmountFocus;
@@ -99,10 +99,11 @@ class ReceivePage extends BasePage {
@override
Widget body(BuildContext context) {
final isElectrumWallet = addressListViewModel.isElectrumWallet;
return (addressListViewModel.type == WalletType.monero ||
addressListViewModel.type == WalletType.haven ||
addressListViewModel.type == WalletType.nano ||
addressListViewModel.type == WalletType.banano)
isElectrumWallet)
? KeyboardActions(
config: KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
@@ -140,7 +141,9 @@ class ReceivePage extends BasePage {
if (item is WalletAccountListHeader) {
cell = HeaderTile(
onTap: () async {
showTrailingButton: true,
walletAddressListViewModel: addressListViewModel,
trailingButtonTap: () async {
if (addressListViewModel.type == WalletType.monero ||
addressListViewModel.type == WalletType.haven) {
await showPopUp<void>(
@@ -153,7 +156,7 @@ class ReceivePage extends BasePage {
}
},
title: S.of(context).accounts,
icon: Icon(
trailingIcon: Icon(
Icons.arrow_forward_ios,
size: 14,
color: Theme.of(context).extension<ReceivePageTheme>()!.iconsColor,
@@ -161,16 +164,21 @@ class ReceivePage extends BasePage {
}
if (item is WalletAddressListHeader) {
cell = HeaderTile(
onTap: () =>
Navigator.of(context).pushNamed(Routes.newSubaddress),
title: S.of(context).addresses,
icon: Icon(
Icons.add,
size: 20,
color: Theme.of(context).extension<ReceivePageTheme>()!.iconsColor,
));
}
cell = HeaderTile(
title: S.of(context).addresses,
walletAddressListViewModel: addressListViewModel,
showTrailingButton: !addressListViewModel.isAutoGenerateSubaddressEnabled,
showSearchButton: true,
trailingButtonTap: () =>
Navigator.of(context).pushNamed(Routes.newSubaddress),
trailingIcon: Icon(
Icons.add,
size: 20,
color: Theme.of(context)
.extension<ReceivePageTheme>()!
.iconsColor,
));
}
if (item is WalletAddressListItem) {
cell = Observer(builder: (_) {
@@ -185,6 +193,7 @@ class ReceivePage extends BasePage {
return AddressCell.fromItem(item,
isCurrent: isCurrent,
hasBalance: addressListViewModel.isElectrumWallet,
backgroundColor: backgroundColor,
textColor: textColor,
onTap: (_) => addressListViewModel.setAddress(item),
+134 -46
View File
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_item.dart';
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
class AddressCell extends StatelessWidget {
AddressCell(
@@ -12,13 +13,18 @@ class AddressCell extends StatelessWidget {
required this.backgroundColor,
required this.textColor,
this.onTap,
this.onEdit});
this.onEdit,
this.txCount,
this.balance,
this.isChange = false,
this.hasBalance = false});
factory AddressCell.fromItem(WalletAddressListItem item,
{required bool isCurrent,
required Color backgroundColor,
required Color textColor,
Function(String)? onTap,
bool hasBalance = false,
Function()? onEdit}) =>
AddressCell(
address: item.address,
@@ -28,7 +34,11 @@ class AddressCell extends StatelessWidget {
backgroundColor: backgroundColor,
textColor: textColor,
onTap: onTap,
onEdit: onEdit);
onEdit: onEdit,
txCount: item.txCount,
balance: item.balance,
isChange: item.isChange,
hasBalance: hasBalance);
final String address;
final String name;
@@ -38,17 +48,22 @@ class AddressCell extends StatelessWidget {
final Color textColor;
final Function(String)? onTap;
final Function()? onEdit;
final int? txCount;
final String? balance;
final bool isChange;
final bool hasBalance;
String get label {
if (name.isEmpty){
if(address.length<=16){
return address;
}else{
return address.substring(0,8)+'...'+
address.substring(address.length-8,address.length);
}
}else{
return name;
static const int addressPreviewLength = 8;
String get formattedAddress {
final formatIfCashAddr = address.replaceAll('bitcoincash:', '');
if (formatIfCashAddr.length <= (name.isNotEmpty ? 16 : 43)) {
return formatIfCashAddr;
} else {
return formatIfCashAddr.substring(0, addressPreviewLength) +
'...' +
formatIfCashAddr.substring(formatIfCashAddr.length - addressPreviewLength, formatIfCashAddr.length);
}
}
@@ -59,41 +74,114 @@ class AddressCell extends StatelessWidget {
child: Container(
width: double.infinity,
color: backgroundColor,
padding: EdgeInsets.only(left: 24, right: 24, top: 28, bottom: 28),
child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14,
color: textColor,
),
padding: EdgeInsets.only(left: 24, right: 24, top: 20, bottom: 20),
child: Row(
children: [
Expanded(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
if (isChange)
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Container(
height: 20,
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.5)),
color: textColor),
alignment: Alignment.center,
child: Text(
S.of(context).unspent_change,
style: TextStyle(
color: backgroundColor,
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
),
),
if (name.isNotEmpty)
Text(
'$name - ',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: textColor,
),
),
AutoSizeText(
formattedAddress,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: isChange ? 10 : 14,
color: textColor,
),
),
],
),
if (hasBalance)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [
Text(
'Balance: $balance',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: textColor,
),
),
Text(
'${S.of(context).transactions.toLowerCase()}: $txCount',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: textColor,
),
),
],
),
),
],
),
),
],
),
));
return Semantics(
label: S.of(context).slidable,
selected: isCurrent,
enabled: !isCurrent,
child: Slidable(
key: Key(address),
startActionPane: _actionPane(context),
endActionPane: _actionPane(context),
child: cell,
),
);
return onEdit == null
? cell
: Semantics(
label: S.of(context).slidable,
selected: isCurrent,
enabled: !isCurrent,
child: Slidable(
key: Key(address),
startActionPane: _actionPane(context),
endActionPane: _actionPane(context),
child: cell,
),
);
}
ActionPane _actionPane(BuildContext context) => ActionPane(
motion: const ScrollMotion(),
extentRatio: 0.3,
children: [
SlidableAction(
onPressed: (_) => onEdit?.call(),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
icon: Icons.edit,
label: S.of(context).edit,
),
],
);
motion: const ScrollMotion(),
extentRatio: 0.3,
children: [
SlidableAction(
onPressed: (_) => onEdit?.call(),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
icon: Icons.edit,
label: S.of(context).edit,
),
],
);
}
+101 -37
View File
@@ -1,50 +1,114 @@
import 'package:flutter/material.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/themes/extensions/receive_page_theme.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
import 'package:flutter/material.dart';
class HeaderTile extends StatelessWidget {
class HeaderTile extends StatefulWidget {
HeaderTile({
required this.onTap,
required this.title,
required this.icon
required this.walletAddressListViewModel,
this.showSearchButton = false,
this.showTrailingButton = false,
this.trailingButtonTap,
this.trailingIcon,
});
final VoidCallback onTap;
final String title;
final Icon icon;
final WalletAddressListViewModel walletAddressListViewModel;
final bool showSearchButton;
final bool showTrailingButton;
final VoidCallback? trailingButtonTap;
final Icon? trailingIcon;
@override
_HeaderTileState createState() => _HeaderTileState();
}
class _HeaderTileState extends State<HeaderTile> {
bool _isSearchActive = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: EdgeInsets.only(
left: 24,
right: 24,
top: 24,
bottom: 24
),
color: Theme.of(context).extension<ReceivePageTheme>()!.tilesBackgroundColor,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
title,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Theme.of(context).extension<ReceivePageTheme>()!.tilesTextColor),
),
Container(
height: 32,
width: 32,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).extension<ReceivePageTheme>()!.iconsBackgroundColor),
child: icon,
)
],
),
final searchIcon = Image.asset("assets/images/search_icon.png",
color: Theme.of(context).extension<ReceivePageTheme>()!.iconsColor);
return Container(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
color: Theme.of(context).extension<ReceivePageTheme>()!.tilesBackgroundColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
_isSearchActive
? Expanded(
child: TextField(
onChanged: (value) => widget.walletAddressListViewModel.updateSearchText(value),
cursorColor: Theme.of(context).extension<ReceivePageTheme>()!.tilesTextColor,
cursorWidth: 0.5,
decoration: InputDecoration(
hintText: '${S.of(context).search}...',
isDense: true,
contentPadding: EdgeInsets.zero,
hintStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Theme.of(context).extension<ReceivePageTheme>()!.tilesTextColor),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Theme.of(context).dividerColor),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Theme.of(context).dividerColor),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Theme.of(context).dividerColor),
),
),
autofocus: true,
),
)
: Text(
widget.title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Theme.of(context).extension<ReceivePageTheme>()!.tilesTextColor),
),
Row(
children: [
if (widget.showSearchButton)
GestureDetector(
onTap: () {
setState(() {
_isSearchActive = !_isSearchActive;
widget.walletAddressListViewModel.updateSearchText('');
});
},
child: Container(
height: 32,
width: 32,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context)
.extension<ReceivePageTheme>()!
.iconsBackgroundColor),
child: searchIcon,
)),
const SizedBox(width: 8),
if (widget.showTrailingButton)
GestureDetector(
onTap: widget.trailingButtonTap,
child: Container(
height: 32,
width: 32,
decoration: BoxDecoration(
shape: BoxShape.circle,
color:
Theme.of(context).extension<ReceivePageTheme>()!.iconsBackgroundColor),
child: widget.trailingIcon,
),
),
],
),
],
),
);
}
@@ -1,3 +1,4 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:cake_wallet/entities/qr_view_data.dart';
import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
import 'package:cake_wallet/routes.dart';
@@ -6,6 +7,7 @@ import 'package:cake_wallet/src/screens/receive/widgets/currency_input_field.dar
import 'package:cake_wallet/utils/brightness_util.dart';
import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@@ -144,9 +146,10 @@ class QRWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Text(
child: AutoSizeText(
addressListViewModel.address.address,
textAlign: TextAlign.center,
maxLines: addressListViewModel.wallet.type == WalletType.monero ? 2 : 1,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,