Skip to content

Commit 29802dd

Browse files
committed
update name functionality w/ basic json pretty view
1 parent 7dd919f commit 29802dd

File tree

6 files changed

+389
-96
lines changed

6 files changed

+389
-96
lines changed

lib/pages/namecoin_names/sub_widgets/name_details.dart

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:namecoin/namecoin.dart';
88
import '../../../models/isar/models/isar_models.dart';
99
import '../../../providers/db/main_db_provider.dart';
1010
import '../../../providers/global/secure_store_provider.dart';
11+
import '../../../providers/global/wallets_provider.dart';
1112
import '../../../themes/stack_colors.dart';
1213
import '../../../utilities/text_styles.dart';
1314
import '../../../utilities/util.dart';
@@ -105,6 +106,47 @@ class _ManageDomainsWidgetState extends ConsumerState<NameDetailsView> {
105106
}
106107
}
107108

109+
(String, Color) _getExpiry(int currentChainHeight, StackColors theme) {
110+
final String message;
111+
final Color color;
112+
113+
if (utxo?.blockHash == null) {
114+
message = "Expires in $blocksNameExpiration+ blocks";
115+
color = theme.accentColorGreen;
116+
} else {
117+
final remaining = opNameData?.expiredBlockLeft(
118+
currentChainHeight,
119+
false,
120+
);
121+
final semiRemaining = opNameData?.expiredBlockLeft(
122+
currentChainHeight,
123+
true,
124+
);
125+
126+
if (remaining == null) {
127+
color = theme.accentColorRed;
128+
message = "Expired";
129+
} else {
130+
message = "Expires in $remaining blocks";
131+
if (semiRemaining == null) {
132+
color = theme.accentColorYellow;
133+
} else {
134+
color = theme.accentColorGreen;
135+
}
136+
}
137+
}
138+
139+
return (message, color);
140+
}
141+
142+
bool _checkConfirmedUtxo(int currentHeight) {
143+
return (ref.read(pWallets).getWallet(widget.walletId) as NamecoinWallet)
144+
.checkUtxoConfirmed(
145+
utxo!,
146+
currentHeight,
147+
);
148+
}
149+
108150
@override
109151
void initState() {
110152
super.initState();
@@ -140,10 +182,13 @@ class _ManageDomainsWidgetState extends ConsumerState<NameDetailsView> {
140182
Widget build(BuildContext context) {
141183
final currentHeight = ref.watch(pWalletChainHeight(widget.walletId));
142184

143-
final isExpired = opNameData?.expired(currentHeight) == true;
144-
final isSemiExpired = opNameData?.expired(currentHeight, true) == true;
185+
final (message, color) = _getExpiry(
186+
currentHeight,
187+
Theme.of(context).extension<StackColors>()!,
188+
);
145189

146190
final canManage = utxo != null &&
191+
_checkConfirmedUtxo(currentHeight) &&
147192
(opNameData?.op == OpName.nameUpdate ||
148193
opNameData?.op == OpName.nameFirstUpdate);
149194

@@ -616,45 +661,11 @@ class _ManageDomainsWidgetState extends ConsumerState<NameDetailsView> {
616661
const SizedBox(
617662
height: 4,
618663
),
619-
Row(
620-
children: [
621-
SelectableText(
622-
isExpired
623-
? "Expired"
624-
: "${opNameData!.expiredBlockLeft(currentHeight)!}",
625-
style: STextStyles.w500_14(context).copyWith(
626-
color: isExpired
627-
? Theme.of(context)
628-
.extension<StackColors>()!
629-
.accentColorRed
630-
: isSemiExpired
631-
? Theme.of(context)
632-
.extension<StackColors>()!
633-
.accentColorYellow
634-
: Theme.of(context)
635-
.extension<StackColors>()!
636-
.accentColorGreen,
637-
),
638-
),
639-
if (!isExpired)
640-
Text(
641-
" blocks remaining",
642-
style:
643-
STextStyles.w500_14(context).copyWith(
644-
color: isExpired
645-
? Theme.of(context)
646-
.extension<StackColors>()!
647-
.accentColorRed
648-
: isSemiExpired
649-
? Theme.of(context)
650-
.extension<StackColors>()!
651-
.accentColorYellow
652-
: Theme.of(context)
653-
.extension<StackColors>()!
654-
.accentColorGreen,
655-
),
656-
),
657-
],
664+
SelectableText(
665+
message,
666+
style: STextStyles.w500_14(context).copyWith(
667+
color: color,
668+
),
658669
),
659670
],
660671
),

lib/pages/namecoin_names/sub_widgets/owned_name_card.dart

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,29 @@ class _OwnedNameCardState extends ConsumerState<OwnedNameCard> {
4343
final String message;
4444
final Color color;
4545

46-
final remaining = widget.opNameData.expiredBlockLeft(
47-
currentChainHeight,
48-
false,
49-
);
50-
final semiRemaining = widget.opNameData.expiredBlockLeft(
51-
currentChainHeight,
52-
true,
53-
);
54-
55-
if (remaining == null) {
56-
color = theme.accentColorRed;
57-
message = "Expired";
46+
if (widget.utxo.blockHash == null) {
47+
message = "Expires in $blocksNameExpiration+ blocks";
48+
color = theme.accentColorGreen;
5849
} else {
59-
message = "Expires in $remaining blocks";
60-
if (semiRemaining == null) {
61-
color = theme.accentColorYellow;
50+
final remaining = widget.opNameData.expiredBlockLeft(
51+
currentChainHeight,
52+
false,
53+
);
54+
final semiRemaining = widget.opNameData.expiredBlockLeft(
55+
currentChainHeight,
56+
true,
57+
);
58+
59+
if (remaining == null) {
60+
color = theme.accentColorRed;
61+
message = "Expired";
6262
} else {
63-
color = theme.accentColorGreen;
63+
message = "Expires in $remaining blocks";
64+
if (semiRemaining == null) {
65+
color = theme.accentColorYellow;
66+
} else {
67+
color = theme.accentColorGreen;
68+
}
6469
}
6570
}
6671

lib/pages/namecoin_names/sub_widgets/transfer_option_widget.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ class _TransferOptionWidgetState extends ConsumerState<TransferOptionWidget> {
198198
}
199199
}
200200
} catch (e, s) {
201-
Logging.instance.e("_preview failed", error: e, stackTrace: s);
201+
Logging.instance.e(
202+
"_preview transfer name failed",
203+
error: e,
204+
stackTrace: s,
205+
);
202206

203207
if (mounted) {
204208
String err = e.toString();

0 commit comments

Comments
 (0)