clean up unused code, imports, and formatting

This commit is contained in:
julian 2023-05-08 08:36:05 -06:00
parent c8655d56bc
commit 3f5cfcbfaf
5 changed files with 103 additions and 98 deletions

View file

@ -1,20 +1,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/widgets/choose_coin_view.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/advanced_views/debug_view.dart'; import 'package:stackwallet/pages/settings_views/global_settings_view/advanced_views/debug_view.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/advanced_views/manage_explorer_view.dart';
import 'package:stackwallet/pages/stack_privacy_calls.dart'; import 'package:stackwallet/pages/stack_privacy_calls.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/providers/global/prefs_provider.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/choose_coin_view.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart'; import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'manage_explorer_view.dart';
class AdvancedSettingsView extends StatelessWidget { class AdvancedSettingsView extends StatelessWidget {
const AdvancedSettingsView({ const AdvancedSettingsView({
Key? key, Key? key,
@ -240,7 +239,10 @@ class AdvancedSettingsView extends StatelessWidget {
), ),
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed(ChooseCoinView.routeName, Navigator.of(context).pushNamed(ChooseCoinView.routeName,
arguments: const Tuple3<String, String, String>("Manage block explorers", "block explorer", ManageExplorerView.routeName)); arguments: const Tuple3<String, String, String>(
"Manage block explorers",
"block explorer",
ManageExplorerView.routeName));
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(

View file

@ -1,13 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/utilities/block_explorers.dart'; import 'package:stackwallet/utilities/block_explorers.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import '../../../../widgets/rounded_white_container.dart';
class ManageExplorerView extends ConsumerStatefulWidget { class ManageExplorerView extends ConsumerStatefulWidget {
const ManageExplorerView({ const ManageExplorerView({
@ -24,85 +23,95 @@ class ManageExplorerView extends ConsumerStatefulWidget {
} }
class _ManageExplorerViewState extends ConsumerState<ManageExplorerView> { class _ManageExplorerViewState extends ConsumerState<ManageExplorerView> {
late TextEditingController textEditingController; late TextEditingController textEditingController;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
textEditingController = TextEditingController(text: getBlockExplorerTransactionUrlFor(coin: widget.coin, txid: "[TXID]").toString().replaceAll("%5BTXID%5D", "[TXID]")); textEditingController = TextEditingController(
text:
getBlockExplorerTransactionUrlFor(coin: widget.coin, txid: "[TXID]")
.toString()
.replaceAll("%5BTXID%5D", "[TXID]"));
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Background( return Background(
child: Scaffold( child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()! backgroundColor: Theme.of(context).extension<StackColors>()!.background,
.background, appBar: AppBar(
appBar: AppBar( leading: AppBarBackButton(
leading: AppBarBackButton( onPressed: () {
onPressed: () { Navigator.of(context).pop();
Navigator.of(context).pop(); },
}, ),
), title: Text(
title: Text( "${widget.coin.prettyName} block explorer",
"${widget.coin.prettyName} block explorer", style: STextStyles.navBarTitle(context),
style: STextStyles.navBarTitle(context), ),
), ),
), body: Padding(
body: Padding( padding: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16), child: Column(
child: Column( children: [
children: [ Expanded(
Expanded(child: Column( child: Column(
children: [ children: [
TextField( TextField(
controller: textEditingController, controller: textEditingController,
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
),
),
const SizedBox(
height: 8,
),
RoundedWhiteContainer(
child: Center(
child: Text(
"Edit your block explorer above. Keep in mind that "
"every block explorer has a slightly different URL "
"scheme.\n\nPaste in your block explorer of choice,"
" then edit in [TXID] where the transaction ID "
"should go, and Stack Wallet will auto fill the "
"transaction ID in that place of URL.",
style: STextStyles.itemSubtitle(context),
), ),
), ),
const SizedBox(height: 8,), ),
RoundedWhiteContainer( ],
child: Center( )),
child: Text( Align(
"Edit your block explorer above. Keep in mind that every block explorer has a slightly different URL scheme.\n\n" alignment: Alignment.bottomCenter,
"Paste in your block explorer of choice, then edit in [TXID] where the transaction ID should go, and Stack Wallet will auto fill the transaction ID in that place of URL.", child: ConstrainedBox(
style: STextStyles.itemSubtitle(context), constraints: const BoxConstraints(
),
),
),
],
)),
Align(
alignment: Alignment.bottomCenter,
child: ConstrainedBox(constraints: const BoxConstraints(
minWidth: 480, minWidth: 480,
minHeight: 70, minHeight: 70,
), ),
child: TextButton( child: TextButton(
style: Theme.of(context) style: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.getPrimaryEnabledButtonStyle(context), .getPrimaryEnabledButtonStyle(context),
onPressed: () { onPressed: () {
textEditingController.text = textEditingController.text.trim(); textEditingController.text =
setBlockExplorerForCoin(coin: widget.coin, url: Uri.parse(textEditingController.text)).then((value) => textEditingController.text.trim();
Navigator.of(context).pop() setBlockExplorerForCoin(
); coin: widget.coin,
}, url: Uri.parse(textEditingController.text))
child: Text( .then((value) => Navigator.of(context).pop());
"Save", },
style: STextStyles.button(context), child: Text(
), "Save",
style: STextStyles.button(context),
), ),
), ),
) ),
], )
],
), ),
), ),
), ),
); );
} }
} }

View file

@ -1,11 +1,7 @@
import 'dart:ffi'; import 'package:stackwallet/db/isar/main_db.dart';
import 'package:stackwallet/models/isar/models/block_explorer.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import '../db/hive/db.dart';
import '../db/isar/main_db.dart';
import '../models/isar/models/block_explorer.dart';
Uri getDefaultBlockExplorerUrlFor({ Uri getDefaultBlockExplorerUrlFor({
required Coin coin, required Coin coin,
required String txid, required String txid,
@ -24,7 +20,7 @@ Uri getDefaultBlockExplorerUrlFor({
case Coin.dogecoinTestNet: case Coin.dogecoinTestNet:
return Uri.parse("https://chain.so/tx/DOGETEST/$txid"); return Uri.parse("https://chain.so/tx/DOGETEST/$txid");
case Coin.epicCash: case Coin.epicCash:
// TODO: Handle this case. // TODO: Handle this case.
throw UnimplementedError("missing block explorer for epic cash"); throw UnimplementedError("missing block explorer for epic cash");
case Coin.ethereum: case Coin.ethereum:
return Uri.parse("https://etherscan.io/tx/$txid"); return Uri.parse("https://etherscan.io/tx/$txid");
@ -48,22 +44,28 @@ Uri getDefaultBlockExplorerUrlFor({
} }
} }
Future<int> setBlockExplorerForCoin( /// returns internal Isar ID for the inserted object/record
{required Coin coin, required Uri url} Future<int> setBlockExplorerForCoin({
) async { required Coin coin,
await MainDB.instance.putTransactionBlockExplorer(TransactionBlockExplorer(ticker: coin.ticker, url: url.toString())); required Uri url,
return 0; }) async {
return await MainDB.instance.putTransactionBlockExplorer(
TransactionBlockExplorer(
ticker: coin.ticker,
url: url.toString(),
),
);
} }
Uri getBlockExplorerTransactionUrlFor({ Uri getBlockExplorerTransactionUrlFor({
required Coin coin, required Coin coin,
required String txid, required String txid,
}) { }) {
var url = MainDB.instance.getTransactionBlockExplorer(coin: coin)?.url.toString(); String? url = MainDB.instance.getTransactionBlockExplorer(coin: coin)?.url;
if (url == null) { if (url == null) {
return getDefaultBlockExplorerUrlFor(coin: coin, txid: txid); return getDefaultBlockExplorerUrlFor(coin: coin, txid: txid);
} else { } else {
url = url.replaceAll("%5BTXID%5D", txid); url = url.replaceAll("%5BTXID%5D", txid);
return Uri.parse(url); return Uri.parse(url);
} }
} }

View file

@ -7,8 +7,6 @@ import 'package:stackwallet/utilities/enums/sync_type_enum.dart';
import 'package:stackwallet/utilities/theme/color_theme.dart'; import 'package:stackwallet/utilities/theme/color_theme.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
import 'enums/coin_enum.dart';
class Prefs extends ChangeNotifier { class Prefs extends ChangeNotifier {
Prefs._(); Prefs._();
static final Prefs _instance = Prefs._(); static final Prefs _instance = Prefs._();

View file

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/manage_nodes_views/coin_nodes_view.dart';
import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
@ -65,7 +64,7 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {
}, },
), ),
title: Text( title: Text(
widget.title ?? "Choose Coin", widget.title,
style: STextStyles.navBarTitle(context), style: STextStyles.navBarTitle(context),
), ),
), ),
@ -80,12 +79,7 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
...coins.map( ...coins.map(
(coin) { (coin) {
final count = ref
.watch(nodeServiceChangeNotifierProvider
.select((value) => value.getNodesFor(coin)))
.length;
return Padding( return Padding(
padding: const EdgeInsets.all(4), padding: const EdgeInsets.all(4),
child: RoundedWhiteContainer( child: RoundedWhiteContainer(
@ -98,7 +92,7 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {
), ),
), ),
materialTapTargetSize: materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap, MaterialTapTargetSize.shrinkWrap,
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed( Navigator.of(context).pushNamed(
widget.nextRouteName, widget.nextRouteName,
@ -121,7 +115,7 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
"${coin.prettyName} ${widget.coinAdditional ?? ""}", "${coin.prettyName} ${widget.coinAdditional}",
style: STextStyles.titleBold12(context), style: STextStyles.titleBold12(context),
), ),
], ],
@ -141,4 +135,4 @@ class _ChooseCoinViewState extends ConsumerState<ChooseCoinView> {
), ),
); );
} }
} }