Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions bdk_demo/lib/core/constants/app_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ abstract final class AppConstants {

static const electrumFetchPrevTxouts = false;

static const syncSlowWarningAfter = Duration(seconds: 10);

static const syncTimeout = Duration(seconds: 12);

static const maxRecipients = 4;

static const maxLogEntries = 5000;
Expand Down
120 changes: 120 additions & 0 deletions bdk_demo/lib/core/constants/network_endpoints.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import 'package:bdk_demo/core/constants/app_constants.dart';
import 'package:bdk_demo/models/wallet_record.dart';

class NetworkEndpointOption {
const NetworkEndpointOption({
required this.id,
required this.label,
required this.url,
required this.clientType,
});

final String id;
final String label;
final String url;
final ClientType clientType;

EndpointConfig get config => EndpointConfig(clientType: clientType, url: url);
}

const signetEndpointOptions = [
NetworkEndpointOption(
id: 'mempool-signet',
label: 'Mempool.space',
url: 'ssl://mempool.space:60602',
clientType: ClientType.electrum,
),
NetworkEndpointOption(
id: 'mutinynet-signet',
label: 'Mutinynet',
url: 'ssl://mutinynet.com:60602',
clientType: ClientType.electrum,
),
NetworkEndpointOption(
id: 'emzy-signet',
label: 'Emzy.de',
url: 'ssl://electrum.emzy.de:53002',
clientType: ClientType.electrum,
),
NetworkEndpointOption(
id: 'wakiyamap-signet',
label: 'Wakiyamap',
url: 'ssl://signet-electrumx.wakiyamap.dev:50002',
clientType: ClientType.electrum,
),
];

const testnetEndpointOptions = [
NetworkEndpointOption(
id: 'blockstream-testnet',
label: 'Blockstream',
url: 'ssl://electrum.blockstream.info:60002',
clientType: ClientType.electrum,
),
NetworkEndpointOption(
id: 'aranguren-testnet',
label: 'Aranguren.org',
url: 'ssl://testnet.aranguren.org:51002',
clientType: ClientType.electrum,
),
NetworkEndpointOption(
id: 'qtornado-testnet',
label: 'Qtornado.com',
url: 'ssl://testnet.qtornado.com:51002',
clientType: ClientType.electrum,
),
NetworkEndpointOption(
id: 'c3soft-testnet',
label: 'C3-soft',
url: 'ssl://blackie.c3-soft.com:57006',
clientType: ClientType.electrum,
),
NetworkEndpointOption(
id: 'bestsrv-testnet',
label: 'Bestsrv.de',
url: 'ssl://v22019051929289916.bestsrv.de:50002',
clientType: ClientType.electrum,
),
];

List<NetworkEndpointOption> endpointOptionsFor(WalletNetwork network) {
return switch (network) {
WalletNetwork.signet => signetEndpointOptions,
WalletNetwork.testnet => testnetEndpointOptions,
WalletNetwork.regtest => const [],
};
}

EndpointConfig resolveEndpointConfig(
WalletNetwork network, {
String? selectedUrl,
}) {
final options = endpointOptionsFor(network);
if (selectedUrl != null) {
for (final option in options) {
if (option.url == selectedUrl) return option.config;
}
}

return defaultEndpoints[network] ?? options.first.config;
}

NetworkEndpointOption? selectedEndpointOption(
WalletNetwork network, {
String? selectedUrl,
}) {
if (selectedUrl == null) {
final options = endpointOptionsFor(network);
if (options.isEmpty) return null;
final defaultUrl = defaultEndpoints[network]?.url;
for (final option in options) {
if (option.url == defaultUrl) return option;
}
return options.first;
}

for (final option in endpointOptionsFor(network)) {
if (option.url == selectedUrl) return option;
}
return null;
}
20 changes: 18 additions & 2 deletions bdk_demo/lib/core/router/app_router.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'package:flutter_riverpod/misc.dart';
import 'package:go_router/go_router.dart';
import 'package:bdk_demo/features/home/home_page.dart';
import 'package:bdk_demo/features/transactions/transaction_detail_page.dart';
import 'package:bdk_demo/features/transactions/transactions_list_page.dart';
import 'package:bdk_demo/features/shared/widgets/placeholder_page.dart';
import 'package:bdk_demo/features/wallet_setup/active_wallets_page.dart';
import 'package:bdk_demo/features/wallet_setup/create_wallet_page.dart';
import 'package:bdk_demo/features/wallet_setup/recover_wallet_page.dart';
import 'package:bdk_demo/features/wallet_setup/wallet_choice_page.dart';
import 'package:bdk_demo/providers/connectivity_provider.dart';
import 'package:bdk_demo/providers/wallet_providers.dart';

abstract final class AppRoutes {
static const walletChoice = '/';
Expand All @@ -24,7 +28,18 @@ abstract final class AppRoutes {
static const recoveryData = '/recovery-data';
}

GoRouter createRouter() => GoRouter(
typedef RouterRead = T Function<T>(ProviderListenable<T> provider);

String? _sendRouteRedirect(RouterRead read) {
final hasActiveWallet =
read(activeWalletRecordProvider) != null &&
read(activeWalletProvider) != null;
if (!hasActiveWallet) return AppRoutes.home;
if (!read(isOnlineProvider)) return AppRoutes.home;
return null;
}

GoRouter createRouter(RouterRead read) => GoRouter(
initialLocation: AppRoutes.walletChoice,
routes: [
GoRoute(
Expand All @@ -51,7 +66,7 @@ GoRouter createRouter() => GoRouter(
GoRoute(
path: AppRoutes.home,
name: 'home',
builder: (context, state) => const PlaceholderPage(title: 'Home'),
builder: (context, state) => const HomePage(),
),
GoRoute(
path: AppRoutes.receive,
Expand All @@ -61,6 +76,7 @@ GoRouter createRouter() => GoRouter(
GoRoute(
path: AppRoutes.send,
name: 'send',
redirect: (context, state) => _sendRouteRedirect(read),
builder: (context, state) => const PlaceholderPage(title: 'Send'),
),
GoRoute(
Expand Down
Loading
Loading