Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import '../../../../widgets/desktop/secondary_button.dart';
import '../../../../widgets/rounded_white_container.dart';

class DesktopManageBlockExplorersDialog extends ConsumerWidget {
const DesktopManageBlockExplorersDialog({
super.key,
});
const DesktopManageBlockExplorersDialog({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -41,9 +39,8 @@ class DesktopManageBlockExplorersDialog extends ConsumerWidget {
);

final coins = AppConfig.coins
.where(
(e) => showTestNet || e.network == CryptoCurrencyNetwork.main,
)
.where((e) => showTestNet || e.network == CryptoCurrencyNetwork.main)
.where(hasDefaultBlockExplorer)
.toList();

return DesktopDialog(
Expand All @@ -67,16 +64,10 @@ class DesktopManageBlockExplorersDialog extends ConsumerWidget {
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 32,
right: 32,
bottom: 32,
),
padding: const EdgeInsets.only(left: 32, right: 32, bottom: 32),
child: ListView.separated(
itemCount: coins.length,
separatorBuilder: (_, __) => const SizedBox(
height: 12,
),
separatorBuilder: (_, __) => const SizedBox(height: 12),
itemBuilder: (_, index) {
final coin = coins[index];

Expand All @@ -91,24 +82,18 @@ class DesktopManageBlockExplorersDialog extends ConsumerWidget {
child: Row(
children: [
SvgPicture.file(
File(
ref.watch(coinIconProvider(coin)),
),
File(ref.watch(coinIconProvider(coin))),
width: 24,
height: 24,
),
const SizedBox(
width: 12,
),
const SizedBox(width: 12),
Expanded(
child: Text(
"${coin.prettyName} block explorer",
style: STextStyles.desktopTextSmall(context),
),
),
const SizedBox(
width: 12,
),
const SizedBox(width: 12),
SvgPicture.asset(
Assets.svg.chevronRight,
width: 20,
Expand All @@ -122,9 +107,7 @@ class DesktopManageBlockExplorersDialog extends ConsumerWidget {
useSafeArea: false,
barrierDismissible: true,
builder: (context) {
return _DesktopEditBlockExplorerDialog(
coin: coin,
);
return _DesktopEditBlockExplorerDialog(coin: coin);
},
);
},
Expand Down Expand Up @@ -157,9 +140,10 @@ class _DesktopEditBlockExplorerDialogState
@override
void initState() {
_textEditingController = TextEditingController(
text: getBlockExplorerTransactionUrlFor(coin: widget.coin, txid: "[TXID]")
.toString()
.replaceAll("%5BTXID%5D", "[TXID]"),
text: getBlockExplorerTransactionUrlFor(
coin: widget.coin,
txid: "[TXID]",
).toString().replaceAll("%5BTXID%5D", "[TXID]"),
);
_focusNode = FocusNode();
super.initState();
Expand Down Expand Up @@ -194,11 +178,7 @@ class _DesktopEditBlockExplorerDialogState
],
),
Padding(
padding: const EdgeInsets.only(
left: 32,
right: 32,
bottom: 32,
),
padding: const EdgeInsets.only(left: 32, right: 32, bottom: 32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -215,12 +195,11 @@ class _DesktopEditBlockExplorerDialogState
style: STextStyles.field(context),
),
),
const SizedBox(
height: 16,
),
const SizedBox(height: 16),
RoundedWhiteContainer(
borderColor:
Theme.of(context).extension<StackColors>()!.textSubtitle6,
borderColor: Theme.of(context)
.extension<StackColors>()!
.textSubtitle6,
child: Text(
"Edit your block explorer above. Keep in mind that"
" every block explorer has a slightly different URL scheme."
Expand All @@ -232,9 +211,7 @@ class _DesktopEditBlockExplorerDialogState
style: STextStyles.desktopTextExtraExtraSmall(context),
),
),
const SizedBox(
height: 16,
),
const SizedBox(height: 16),
Row(
children: [
Expanded(
Expand All @@ -244,21 +221,18 @@ class _DesktopEditBlockExplorerDialogState
onPressed: Navigator.of(context).pop,
),
),
const SizedBox(
width: 16,
),
const SizedBox(width: 16),
Expanded(
child: PrimaryButton(
label: "Save",
buttonHeight: ButtonHeight.l,
onPressed: () async {
_textEditingController.text =
_textEditingController.text.trim();
_textEditingController.text = _textEditingController
.text
.trim();
await setBlockExplorerForCoin(
coin: widget.coin,
url: Uri.parse(
_textEditingController.text,
),
url: Uri.parse(_textEditingController.text),
);

if (mounted) {
Expand Down
22 changes: 16 additions & 6 deletions lib/utilities/block_explorers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ Future<int> setBlockExplorerForCoin({
required Uri url,
}) async {
return await MainDB.instance.putTransactionBlockExplorer(
TransactionBlockExplorer(
ticker: coin.ticker,
url: url.toString(),
),
TransactionBlockExplorer(ticker: coin.ticker, url: url.toString()),
);
}

Expand All @@ -30,12 +27,25 @@ Uri getBlockExplorerTransactionUrlFor({
required CryptoCurrency coin,
required String txid,
}) {
String? url =
MainDB.instance.getTransactionBlockExplorer(cryptoCurrency: coin)?.url;
String? url = MainDB.instance
.getTransactionBlockExplorer(cryptoCurrency: coin)
?.url;
if (url == null) {
return coin.defaultBlockExplorer(txid);
} else {
url = url.replaceAll("%5BTXID%5D", txid);
return Uri.parse(url);
}
}

/// Whether [coin] has a default block explorer. Coins without one throw from
/// [CryptoCurrency.defaultBlockExplorer], so they cannot be offered where an
/// explorer URL is shown or edited.
bool hasDefaultBlockExplorer(CryptoCurrency coin) {
try {
coin.defaultBlockExplorer("[TXID]");
return true;
} catch (_) {
return false;
}
}
108 changes: 47 additions & 61 deletions lib/widgets/choose_coin_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';

import '../providers/providers.dart';
import '../app_config.dart';
import '../pages/settings_views/global_settings_view/advanced_views/manage_explorer_view.dart';
import '../themes/coin_icon_provider.dart';
import '../themes/stack_colors.dart';
import '../utilities/block_explorers.dart';
import '../utilities/constants.dart';
import '../utilities/text_styles.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
Expand Down Expand Up @@ -59,6 +62,9 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {
_coins.removeWhere(
(e) => e.identifier == Firo(CryptoCurrencyNetwork.test).identifier,
);
if (widget.nextRouteName == ManageExplorerView.routeName) {
_coins.removeWhere((e) => !hasDefaultBlockExplorer(e));
}
super.initState();
}

Expand All @@ -75,11 +81,7 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {

final List<CryptoCurrency> coins = showTestNet
? _coins
: _coins
.where(
(e) => e.network == CryptoCurrencyNetwork.main,
)
.toList();
: _coins.where((e) => e.network == CryptoCurrencyNetwork.main).toList();

return Background(
child: Scaffold(
Expand All @@ -90,73 +92,57 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {
Navigator.of(context).pop();
},
),
title: Text(
widget.title,
style: STextStyles.navBarTitle(context),
),
title: Text(widget.title, style: STextStyles.navBarTitle(context)),
),
body: Padding(
padding: const EdgeInsets.only(
top: 12,
left: 12,
right: 12,
),
padding: const EdgeInsets.only(top: 12, left: 12, right: 12),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
...coins.map(
(coin) {
return Padding(
padding: const EdgeInsets.all(4),
child: RoundedWhiteContainer(
padding: const EdgeInsets.all(0),
child: RawMaterialButton(
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
...coins.map((coin) {
return Padding(
padding: const EdgeInsets.all(4),
child: RoundedWhiteContainer(
padding: const EdgeInsets.all(0),
child: RawMaterialButton(
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
onPressed: () {
Navigator.of(context).pushNamed(
widget.nextRouteName,
arguments: coin,
);
},
child: Padding(
padding: const EdgeInsets.all(12),
child: Row(
children: [
SvgPicture.file(
File(
ref.watch(coinIconProvider(coin)),
),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: () {
Navigator.of(context)
.pushNamed(widget.nextRouteName, arguments: coin);
},
child: Padding(
padding: const EdgeInsets.all(12),
child: Row(
children: [
SvgPicture.file(
File(ref.watch(coinIconProvider(coin))),
width: 24,
height: 24,
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${coin.prettyName} ${widget.coinAdditional}",
style: STextStyles.titleBold12(context),
),
width: 24,
height: 24,
),
const SizedBox(
width: 12,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${coin.prettyName} ${widget.coinAdditional}",
style: STextStyles.titleBold12(context),
),
],
),
],
),
],
),
],
),
),
),
);
},
),
),
);
}),
],
),
),
Expand Down
Loading
Loading