Skip to content

Commit 219b42d

Browse files
committed
feat: address label editing to receive page
closes #374
1 parent 51db6c7 commit 219b42d

2 files changed

Lines changed: 126 additions & 0 deletions

File tree

lib/pages/receive_view/receive_view.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
1717
import 'package:flutter_svg/flutter_svg.dart';
1818
import 'package:isar_community/isar.dart';
1919

20+
import '../../db/isar/main_db.dart';
2021
import '../../models/isar/models/isar_models.dart';
2122
import '../../models/keys/view_only_wallet_data.dart';
2223
import '../../notifications/show_flush_bar.dart';
@@ -46,6 +47,7 @@ import '../../widgets/background.dart';
4647
import '../../widgets/conditional_parent.dart';
4748
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
4849
import '../../widgets/custom_buttons/blue_text_button.dart';
50+
import '../../widgets/custom_buttons/simple_edit_button.dart';
4951
import '../../widgets/custom_loading_overlay.dart';
5052
import '../../widgets/desktop/primary_button.dart';
5153
import '../../widgets/desktop/secondary_button.dart';
@@ -792,6 +794,58 @@ class _ReceiveViewState extends ConsumerState<ReceiveView> {
792794
),
793795
),
794796
const SizedBox(height: 12),
797+
Builder(
798+
builder: (context) {
799+
final label = MainDB.instance.getAddressLabelSync(
800+
walletId,
801+
address,
802+
);
803+
final labelValue = label?.value ?? "";
804+
return RoundedWhiteContainer(
805+
child: Row(
806+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
807+
children: [
808+
Expanded(
809+
child: Text(
810+
labelValue.isNotEmpty
811+
? labelValue
812+
: "No label",
813+
style: STextStyles.itemSubtitle(context),
814+
),
815+
),
816+
SimpleEditButton(
817+
editValue: labelValue,
818+
editLabel: "label",
819+
overrideTitle: "Edit label",
820+
onValueChanged: (value) {
821+
final existingLabel =
822+
MainDB.instance.getAddressLabelSync(
823+
walletId,
824+
address,
825+
);
826+
if (existingLabel != null) {
827+
MainDB.instance.putAddressLabel(
828+
existingLabel.copyWith(label: value),
829+
);
830+
} else {
831+
MainDB.instance.putAddressLabel(
832+
AddressLabel(
833+
walletId: walletId,
834+
addressString: address,
835+
value: value,
836+
tags: null,
837+
),
838+
);
839+
}
840+
setState(() {});
841+
},
842+
),
843+
],
844+
),
845+
);
846+
},
847+
),
848+
const SizedBox(height: 12),
795849
PrimaryButton(
796850
label: "Copy address",
797851
onPressed: () {

lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_receive.dart

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:flutter_svg/flutter_svg.dart';
1818
import 'package:isar_community/isar.dart';
1919
import 'package:tuple/tuple.dart';
2020

21+
import '../../../../db/isar/main_db.dart';
2122
import '../../../../models/isar/models/isar_models.dart';
2223
import '../../../../models/keys/view_only_wallet_data.dart';
2324
import '../../../../notifications/show_flush_bar.dart';
@@ -51,6 +52,7 @@ import '../../../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart'
5152
import '../../../../wallets/wallet/wallet_mixin_interfaces/view_only_option_interface.dart';
5253
import '../../../../widgets/conditional_parent.dart';
5354
import '../../../../widgets/custom_buttons/app_bar_icon_button.dart';
55+
import '../../../../widgets/custom_buttons/simple_edit_button.dart';
5456
import '../../../../widgets/custom_loading_overlay.dart';
5557
import '../../../../widgets/desktop/desktop_dialog.dart';
5658
import '../../../../widgets/desktop/primary_button.dart';
@@ -762,6 +764,76 @@ class _DesktopReceiveState extends ConsumerState<DesktopReceive> {
762764
),
763765
),
764766

767+
const SizedBox(height: 12),
768+
Builder(
769+
builder: (context) {
770+
final label = MainDB.instance.getAddressLabelSync(
771+
walletId,
772+
address,
773+
);
774+
final labelValue = label?.value ?? "";
775+
return Container(
776+
decoration: BoxDecoration(
777+
border: Border.all(
778+
color: Theme.of(
779+
context,
780+
).extension<StackColors>()!.backgroundAppBar,
781+
width: 1,
782+
),
783+
borderRadius: BorderRadius.circular(
784+
Constants.size.circularBorderRadius,
785+
),
786+
),
787+
child: RoundedWhiteContainer(
788+
child: Row(
789+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
790+
children: [
791+
Expanded(
792+
child: Text(
793+
labelValue.isNotEmpty ? labelValue : "No label",
794+
style: STextStyles.desktopTextExtraExtraSmall(
795+
context,
796+
).copyWith(
797+
color: Theme.of(
798+
context,
799+
).extension<StackColors>()!.textDark,
800+
),
801+
),
802+
),
803+
SimpleEditButton(
804+
editValue: labelValue,
805+
editLabel: "label",
806+
overrideTitle: "Edit label",
807+
onValueChanged: (value) {
808+
final existingLabel =
809+
MainDB.instance.getAddressLabelSync(
810+
walletId,
811+
address,
812+
);
813+
if (existingLabel != null) {
814+
MainDB.instance.putAddressLabel(
815+
existingLabel.copyWith(label: value),
816+
);
817+
} else {
818+
MainDB.instance.putAddressLabel(
819+
AddressLabel(
820+
walletId: walletId,
821+
addressString: address,
822+
value: value,
823+
tags: null,
824+
),
825+
);
826+
}
827+
setState(() {});
828+
},
829+
),
830+
],
831+
),
832+
),
833+
);
834+
},
835+
),
836+
765837
if (canGen) const SizedBox(height: 20),
766838

767839
if (canGen)

0 commit comments

Comments
 (0)