diff --git a/lib/application/dapps.dart b/lib/application/dapps.dart index 0ab498259..1c29c6a34 100644 --- a/lib/application/dapps.dart +++ b/lib/application/dapps.dart @@ -1,7 +1,7 @@ import 'package:aewallet/application/api_service.dart'; -import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/domain/models/dapp.dart'; import 'package:aewallet/infrastructure/repositories/dapps_repository.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -19,12 +19,11 @@ Future getDApp( String code, ) async { final apiService = ref.watch(apiServiceProvider); - final networkSettings = ref.watch( - SettingsProviders.settings.select((settings) => settings.network), - ); + final environment = ref.watch(environmentProvider); + return ref .watch(dAppsRepositoryProvider) - .getDApp(networkSettings.network, code, apiService); + .getDApp(environment, code, apiService); } @riverpod @@ -32,11 +31,9 @@ Future> getDAppsFromNetwork( Ref ref, ) async { final apiService = ref.watch(apiServiceProvider); - final networkSettings = ref.watch( - SettingsProviders.settings.select((settings) => settings.network), - ); + final environment = ref.watch(environmentProvider); final dAppsFromNetwork = await ref .read(dAppsRepositoryProvider) - .getDAppsFromNetwork(networkSettings.network, apiService); + .getDAppsFromNetwork(environment, apiService); return dAppsFromNetwork; } diff --git a/lib/application/dapps.g.dart b/lib/application/dapps.g.dart index 371579fea..3a27920b0 100644 --- a/lib/application/dapps.g.dart +++ b/lib/application/dapps.g.dart @@ -24,7 +24,7 @@ final dAppsRepositoryProvider = @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef DAppsRepositoryRef = AutoDisposeProviderRef; -String _$getDAppHash() => r'74094f96d68512dbd3eb1224e89265e4e3fad1c2'; +String _$getDAppHash() => r'99a3f23987c5566794003de0cbd6de2c44292da3'; /// Copied from Dart SDK class _SystemHash { @@ -175,7 +175,7 @@ class _GetDAppProviderElement extends AutoDisposeFutureProviderElement } String _$getDAppsFromNetworkHash() => - r'9d37f6aedc3ff3ae26f95705b4f04fc87b85ced9'; + r'70c9aa2a09b0a6638582979f82d6a122c2d1df38'; /// See also [getDAppsFromNetwork]. @ProviderFor(getDAppsFromNetwork) diff --git a/lib/application/feature_flags.dart b/lib/application/feature_flags.dart index fd5808fc2..51fa7fa37 100644 --- a/lib/application/feature_flags.dart +++ b/lib/application/feature_flags.dart @@ -1,6 +1,6 @@ import 'package:aewallet/application/api_service.dart'; -import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/infrastructure/repositories/feature_flags_repository.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/util/universal_platform.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -20,11 +20,9 @@ Future getFeatureFlag( String featureCode, ) async { final apiService = ref.watch(apiServiceProvider); - final networkSettings = ref.watch( - SettingsProviders.settings.select((settings) => settings.network), - ); + final environment = ref.watch(environmentProvider); return ref.watch(_featureFlagsRepositoryProvider).getFeatureFlag( - networkSettings.network, + environment, apiService, applicationCode, featureCode, diff --git a/lib/application/feature_flags.g.dart b/lib/application/feature_flags.g.dart index a6ba18692..8241e3a46 100644 --- a/lib/application/feature_flags.g.dart +++ b/lib/application/feature_flags.g.dart @@ -26,7 +26,7 @@ final _featureFlagsRepositoryProvider = // ignore: unused_element typedef _FeatureFlagsRepositoryRef = AutoDisposeProviderRef; -String _$getFeatureFlagHash() => r'3d889fb9e466efd3e438678c4202e674acaf884a'; +String _$getFeatureFlagHash() => r'f67578a123909d0ee008e69fa37dcabc4bc5aee3'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/application/network/provider.dart b/lib/application/network/provider.dart deleted file mode 100644 index 21e2ceac0..000000000 --- a/lib/application/network/provider.dart +++ /dev/null @@ -1,82 +0,0 @@ -/// SPDX-License-Identifier: AGPL-3.0-or-later - -import 'package:aewallet/model/available_networks.dart'; -import 'package:archethic_lib_dart/archethic_lib_dart.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'provider.g.dart'; - -@riverpod -String _networkLink( - Ref ref, { - required AvailableNetworks network, -}) { - final networkSetting = NetworksSetting( - network: network, - networkDevEndpoint: '', - ); - - final link = networkSetting.getLink(); - - return link; -} - -@riverpod -Future> _networkNodes( - Ref ref, { - required AvailableNetworks network, -}) async { - final link = ref.read( - _networkLinkProvider( - network: network, - ), - ); - - final nodeListMain = await ApiService( - link, - ).getNodeList(); - - return nodeListMain; -} - -@riverpod -Future _isReservedNodeUri( - Ref ref, { - required Uri uri, -}) async { - // Check if default uri is used - if (DefaultNetworksHost.archethicMainNetHost.value == uri.host) return true; - if (DefaultNetworksHost.archethicTestNetHost.value == uri.host) return true; - - // Check if reserved nodes of network is used - var nodeListMain = []; - try { - nodeListMain = await ref.watch( - _networkNodesProvider( - network: AvailableNetworks.archethicMainNet, - ).future, - ); - // ignore: empty_catches - } catch (e) {} - - var nodeListTest = []; - try { - nodeListTest = await ref.watch( - _networkNodesProvider( - network: AvailableNetworks.archethicTestNet, - ).future, - ); - // ignore: empty_catches - } catch (e) {} - - return nodeListMain.followedBy(nodeListTest).any( - (node) => node.ip == uri.host && node.port == uri.port, - ); -} - -abstract class NetworkProvider { - static const networkLink = _networkLinkProvider; - static const networkNodes = _networkNodesProvider; - static const isReservedNodeUri = _isReservedNodeUriProvider; -} diff --git a/lib/application/network/provider.g.dart b/lib/application/network/provider.g.dart deleted file mode 100644 index 04866a969..000000000 --- a/lib/application/network/provider.g.dart +++ /dev/null @@ -1,420 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'provider.dart'; - -// ************************************************************************** -// RiverpodGenerator -// ************************************************************************** - -String _$networkLinkHash() => r'1dc389164e6dd1fadbfc555b54db260a0032c45a'; - -/// Copied from Dart SDK -class _SystemHash { - _SystemHash._(); - - static int combine(int hash, int value) { - // ignore: parameter_assignments - hash = 0x1fffffff & (hash + value); - // ignore: parameter_assignments - hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); - return hash ^ (hash >> 6); - } - - static int finish(int hash) { - // ignore: parameter_assignments - hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); - // ignore: parameter_assignments - hash = hash ^ (hash >> 11); - return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); - } -} - -/// See also [_networkLink]. -@ProviderFor(_networkLink) -const _networkLinkProvider = _NetworkLinkFamily(); - -/// See also [_networkLink]. -class _NetworkLinkFamily extends Family { - /// See also [_networkLink]. - const _NetworkLinkFamily(); - - /// See also [_networkLink]. - _NetworkLinkProvider call({ - required AvailableNetworks network, - }) { - return _NetworkLinkProvider( - network: network, - ); - } - - @override - _NetworkLinkProvider getProviderOverride( - covariant _NetworkLinkProvider provider, - ) { - return call( - network: provider.network, - ); - } - - static const Iterable? _dependencies = null; - - @override - Iterable? get dependencies => _dependencies; - - static const Iterable? _allTransitiveDependencies = null; - - @override - Iterable? get allTransitiveDependencies => - _allTransitiveDependencies; - - @override - String? get name => r'_networkLinkProvider'; -} - -/// See also [_networkLink]. -class _NetworkLinkProvider extends AutoDisposeProvider { - /// See also [_networkLink]. - _NetworkLinkProvider({ - required AvailableNetworks network, - }) : this._internal( - (ref) => _networkLink( - ref as _NetworkLinkRef, - network: network, - ), - from: _networkLinkProvider, - name: r'_networkLinkProvider', - debugGetCreateSourceHash: - const bool.fromEnvironment('dart.vm.product') - ? null - : _$networkLinkHash, - dependencies: _NetworkLinkFamily._dependencies, - allTransitiveDependencies: - _NetworkLinkFamily._allTransitiveDependencies, - network: network, - ); - - _NetworkLinkProvider._internal( - super._createNotifier, { - required super.name, - required super.dependencies, - required super.allTransitiveDependencies, - required super.debugGetCreateSourceHash, - required super.from, - required this.network, - }) : super.internal(); - - final AvailableNetworks network; - - @override - Override overrideWith( - String Function(_NetworkLinkRef provider) create, - ) { - return ProviderOverride( - origin: this, - override: _NetworkLinkProvider._internal( - (ref) => create(ref as _NetworkLinkRef), - from: from, - name: null, - dependencies: null, - allTransitiveDependencies: null, - debugGetCreateSourceHash: null, - network: network, - ), - ); - } - - @override - AutoDisposeProviderElement createElement() { - return _NetworkLinkProviderElement(this); - } - - @override - bool operator ==(Object other) { - return other is _NetworkLinkProvider && other.network == network; - } - - @override - int get hashCode { - var hash = _SystemHash.combine(0, runtimeType.hashCode); - hash = _SystemHash.combine(hash, network.hashCode); - - return _SystemHash.finish(hash); - } -} - -@Deprecated('Will be removed in 3.0. Use Ref instead') -// ignore: unused_element -mixin _NetworkLinkRef on AutoDisposeProviderRef { - /// The parameter `network` of this provider. - AvailableNetworks get network; -} - -class _NetworkLinkProviderElement extends AutoDisposeProviderElement - with _NetworkLinkRef { - _NetworkLinkProviderElement(super.provider); - - @override - AvailableNetworks get network => (origin as _NetworkLinkProvider).network; -} - -String _$networkNodesHash() => r'b73184d08e3a705b6f8c9a5085a2b0adf202ab84'; - -/// See also [_networkNodes]. -@ProviderFor(_networkNodes) -const _networkNodesProvider = _NetworkNodesFamily(); - -/// See also [_networkNodes]. -class _NetworkNodesFamily extends Family>> { - /// See also [_networkNodes]. - const _NetworkNodesFamily(); - - /// See also [_networkNodes]. - _NetworkNodesProvider call({ - required AvailableNetworks network, - }) { - return _NetworkNodesProvider( - network: network, - ); - } - - @override - _NetworkNodesProvider getProviderOverride( - covariant _NetworkNodesProvider provider, - ) { - return call( - network: provider.network, - ); - } - - static const Iterable? _dependencies = null; - - @override - Iterable? get dependencies => _dependencies; - - static const Iterable? _allTransitiveDependencies = null; - - @override - Iterable? get allTransitiveDependencies => - _allTransitiveDependencies; - - @override - String? get name => r'_networkNodesProvider'; -} - -/// See also [_networkNodes]. -class _NetworkNodesProvider extends AutoDisposeFutureProvider> { - /// See also [_networkNodes]. - _NetworkNodesProvider({ - required AvailableNetworks network, - }) : this._internal( - (ref) => _networkNodes( - ref as _NetworkNodesRef, - network: network, - ), - from: _networkNodesProvider, - name: r'_networkNodesProvider', - debugGetCreateSourceHash: - const bool.fromEnvironment('dart.vm.product') - ? null - : _$networkNodesHash, - dependencies: _NetworkNodesFamily._dependencies, - allTransitiveDependencies: - _NetworkNodesFamily._allTransitiveDependencies, - network: network, - ); - - _NetworkNodesProvider._internal( - super._createNotifier, { - required super.name, - required super.dependencies, - required super.allTransitiveDependencies, - required super.debugGetCreateSourceHash, - required super.from, - required this.network, - }) : super.internal(); - - final AvailableNetworks network; - - @override - Override overrideWith( - FutureOr> Function(_NetworkNodesRef provider) create, - ) { - return ProviderOverride( - origin: this, - override: _NetworkNodesProvider._internal( - (ref) => create(ref as _NetworkNodesRef), - from: from, - name: null, - dependencies: null, - allTransitiveDependencies: null, - debugGetCreateSourceHash: null, - network: network, - ), - ); - } - - @override - AutoDisposeFutureProviderElement> createElement() { - return _NetworkNodesProviderElement(this); - } - - @override - bool operator ==(Object other) { - return other is _NetworkNodesProvider && other.network == network; - } - - @override - int get hashCode { - var hash = _SystemHash.combine(0, runtimeType.hashCode); - hash = _SystemHash.combine(hash, network.hashCode); - - return _SystemHash.finish(hash); - } -} - -@Deprecated('Will be removed in 3.0. Use Ref instead') -// ignore: unused_element -mixin _NetworkNodesRef on AutoDisposeFutureProviderRef> { - /// The parameter `network` of this provider. - AvailableNetworks get network; -} - -class _NetworkNodesProviderElement - extends AutoDisposeFutureProviderElement> with _NetworkNodesRef { - _NetworkNodesProviderElement(super.provider); - - @override - AvailableNetworks get network => (origin as _NetworkNodesProvider).network; -} - -String _$isReservedNodeUriHash() => r'a069da95adf0e5f07c485b10a98bf1bf3ae08108'; - -/// See also [_isReservedNodeUri]. -@ProviderFor(_isReservedNodeUri) -const _isReservedNodeUriProvider = _IsReservedNodeUriFamily(); - -/// See also [_isReservedNodeUri]. -class _IsReservedNodeUriFamily extends Family> { - /// See also [_isReservedNodeUri]. - const _IsReservedNodeUriFamily(); - - /// See also [_isReservedNodeUri]. - _IsReservedNodeUriProvider call({ - required Uri uri, - }) { - return _IsReservedNodeUriProvider( - uri: uri, - ); - } - - @override - _IsReservedNodeUriProvider getProviderOverride( - covariant _IsReservedNodeUriProvider provider, - ) { - return call( - uri: provider.uri, - ); - } - - static const Iterable? _dependencies = null; - - @override - Iterable? get dependencies => _dependencies; - - static const Iterable? _allTransitiveDependencies = null; - - @override - Iterable? get allTransitiveDependencies => - _allTransitiveDependencies; - - @override - String? get name => r'_isReservedNodeUriProvider'; -} - -/// See also [_isReservedNodeUri]. -class _IsReservedNodeUriProvider extends AutoDisposeFutureProvider { - /// See also [_isReservedNodeUri]. - _IsReservedNodeUriProvider({ - required Uri uri, - }) : this._internal( - (ref) => _isReservedNodeUri( - ref as _IsReservedNodeUriRef, - uri: uri, - ), - from: _isReservedNodeUriProvider, - name: r'_isReservedNodeUriProvider', - debugGetCreateSourceHash: - const bool.fromEnvironment('dart.vm.product') - ? null - : _$isReservedNodeUriHash, - dependencies: _IsReservedNodeUriFamily._dependencies, - allTransitiveDependencies: - _IsReservedNodeUriFamily._allTransitiveDependencies, - uri: uri, - ); - - _IsReservedNodeUriProvider._internal( - super._createNotifier, { - required super.name, - required super.dependencies, - required super.allTransitiveDependencies, - required super.debugGetCreateSourceHash, - required super.from, - required this.uri, - }) : super.internal(); - - final Uri uri; - - @override - Override overrideWith( - FutureOr Function(_IsReservedNodeUriRef provider) create, - ) { - return ProviderOverride( - origin: this, - override: _IsReservedNodeUriProvider._internal( - (ref) => create(ref as _IsReservedNodeUriRef), - from: from, - name: null, - dependencies: null, - allTransitiveDependencies: null, - debugGetCreateSourceHash: null, - uri: uri, - ), - ); - } - - @override - AutoDisposeFutureProviderElement createElement() { - return _IsReservedNodeUriProviderElement(this); - } - - @override - bool operator ==(Object other) { - return other is _IsReservedNodeUriProvider && other.uri == uri; - } - - @override - int get hashCode { - var hash = _SystemHash.combine(0, runtimeType.hashCode); - hash = _SystemHash.combine(hash, uri.hashCode); - - return _SystemHash.finish(hash); - } -} - -@Deprecated('Will be removed in 3.0. Use Ref instead') -// ignore: unused_element -mixin _IsReservedNodeUriRef on AutoDisposeFutureProviderRef { - /// The parameter `uri` of this provider. - Uri get uri; -} - -class _IsReservedNodeUriProviderElement - extends AutoDisposeFutureProviderElement with _IsReservedNodeUriRef { - _IsReservedNodeUriProviderElement(super.provider); - - @override - Uri get uri => (origin as _IsReservedNodeUriProvider).uri; -} -// ignore_for_file: type=lint -// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/application/settings/settings.dart b/lib/application/settings/settings.dart index a7ccd419e..6ffcb0256 100644 --- a/lib/application/settings/settings.dart +++ b/lib/application/settings/settings.dart @@ -3,7 +3,6 @@ import 'dart:ui'; import 'package:aewallet/domain/models/settings.dart'; import 'package:aewallet/domain/repositories/settings.dart'; import 'package:aewallet/model/available_language.dart'; -import 'package:aewallet/model/available_networks.dart'; import 'package:aewallet/model/primary_currency.dart'; import 'package:aewallet/util/get_it_instance.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' @@ -60,17 +59,8 @@ class SettingsNotifier extends StateNotifier { state.copyWith(activeRPCServer: activeRPCServer), ); - Future setNetwork(NetworksSetting selectedNetworkSettings) => _update( - state.copyWith(network: selectedNetworkSettings), - ); - - Future setNetworkDevEndpoint(String networkDevEndpoint) => _update( - state.copyWith( - network: NetworksSetting( - network: state.network.network, - networkDevEndpoint: networkDevEndpoint, - ), - ), + Future setEnvironment(aedappfm.Environment environment) => _update( + state.copyWith(environment: environment), ); Future selectPrimaryCurrency( diff --git a/lib/domain/models/settings.dart b/lib/domain/models/settings.dart index 5a500aa3b..21c781152 100644 --- a/lib/domain/models/settings.dart +++ b/lib/domain/models/settings.dart @@ -1,5 +1,4 @@ import 'package:aewallet/model/available_language.dart'; -import 'package:aewallet/model/available_networks.dart'; import 'package:aewallet/model/primary_currency.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; @@ -20,7 +19,7 @@ class Settings with _$Settings { const factory Settings({ required AvailablePrimaryCurrency primaryCurrency, required AvailableLanguage language, - required NetworksSetting network, + required aedappfm.Environment environment, required String languageSeed, required bool firstLaunch, required bool showBalances, @@ -37,10 +36,7 @@ class Settings with _$Settings { language: AvailableLanguage.english, languageSeed: '', mainScreenCurrentPage: 0, - network: NetworksSetting( - network: AvailableNetworks.archethicMainNet, - networkDevEndpoint: '', - ), + environment: aedappfm.Environment.mainnet, primaryCurrency: AvailablePrimaryCurrency(AvailablePrimaryCurrencyEnum.native), showBalances: true, diff --git a/lib/domain/models/settings.freezed.dart b/lib/domain/models/settings.freezed.dart index 69e8b4210..88d0bce50 100644 --- a/lib/domain/models/settings.freezed.dart +++ b/lib/domain/models/settings.freezed.dart @@ -19,7 +19,7 @@ mixin _$Settings { AvailablePrimaryCurrency get primaryCurrency => throw _privateConstructorUsedError; AvailableLanguage get language => throw _privateConstructorUsedError; - NetworksSetting get network => throw _privateConstructorUsedError; + aedappfm.Environment get environment => throw _privateConstructorUsedError; String get languageSeed => throw _privateConstructorUsedError; bool get firstLaunch => throw _privateConstructorUsedError; bool get showBalances => throw _privateConstructorUsedError; @@ -45,7 +45,7 @@ abstract class $SettingsCopyWith<$Res> { $Res call( {AvailablePrimaryCurrency primaryCurrency, AvailableLanguage language, - NetworksSetting network, + aedappfm.Environment environment, String languageSeed, bool firstLaunch, bool showBalances, @@ -73,7 +73,7 @@ class _$SettingsCopyWithImpl<$Res, $Val extends Settings> $Res call({ Object? primaryCurrency = null, Object? language = null, - Object? network = null, + Object? environment = null, Object? languageSeed = null, Object? firstLaunch = null, Object? showBalances = null, @@ -92,10 +92,10 @@ class _$SettingsCopyWithImpl<$Res, $Val extends Settings> ? _value.language : language // ignore: cast_nullable_to_non_nullable as AvailableLanguage, - network: null == network - ? _value.network - : network // ignore: cast_nullable_to_non_nullable - as NetworksSetting, + environment: null == environment + ? _value.environment + : environment // ignore: cast_nullable_to_non_nullable + as aedappfm.Environment, languageSeed: null == languageSeed ? _value.languageSeed : languageSeed // ignore: cast_nullable_to_non_nullable @@ -143,7 +143,7 @@ abstract class _$$SettingsImplCopyWith<$Res> $Res call( {AvailablePrimaryCurrency primaryCurrency, AvailableLanguage language, - NetworksSetting network, + aedappfm.Environment environment, String languageSeed, bool firstLaunch, bool showBalances, @@ -169,7 +169,7 @@ class __$$SettingsImplCopyWithImpl<$Res> $Res call({ Object? primaryCurrency = null, Object? language = null, - Object? network = null, + Object? environment = null, Object? languageSeed = null, Object? firstLaunch = null, Object? showBalances = null, @@ -188,10 +188,10 @@ class __$$SettingsImplCopyWithImpl<$Res> ? _value.language : language // ignore: cast_nullable_to_non_nullable as AvailableLanguage, - network: null == network - ? _value.network - : network // ignore: cast_nullable_to_non_nullable - as NetworksSetting, + environment: null == environment + ? _value.environment + : environment // ignore: cast_nullable_to_non_nullable + as aedappfm.Environment, languageSeed: null == languageSeed ? _value.languageSeed : languageSeed // ignore: cast_nullable_to_non_nullable @@ -234,7 +234,7 @@ class _$SettingsImpl extends _Settings { const _$SettingsImpl( {required this.primaryCurrency, required this.language, - required this.network, + required this.environment, required this.languageSeed, required this.firstLaunch, required this.showBalances, @@ -250,7 +250,7 @@ class _$SettingsImpl extends _Settings { @override final AvailableLanguage language; @override - final NetworksSetting network; + final aedappfm.Environment environment; @override final String languageSeed; @override @@ -270,7 +270,7 @@ class _$SettingsImpl extends _Settings { @override String toString() { - return 'Settings(primaryCurrency: $primaryCurrency, language: $language, network: $network, languageSeed: $languageSeed, firstLaunch: $firstLaunch, showBalances: $showBalances, testnetEnabled: $testnetEnabled, activeRPCServer: $activeRPCServer, mainScreenCurrentPage: $mainScreenCurrentPage, showPriceChart: $showPriceChart, priceChartIntervalOption: $priceChartIntervalOption)'; + return 'Settings(primaryCurrency: $primaryCurrency, language: $language, environment: $environment, languageSeed: $languageSeed, firstLaunch: $firstLaunch, showBalances: $showBalances, testnetEnabled: $testnetEnabled, activeRPCServer: $activeRPCServer, mainScreenCurrentPage: $mainScreenCurrentPage, showPriceChart: $showPriceChart, priceChartIntervalOption: $priceChartIntervalOption)'; } @override @@ -282,7 +282,8 @@ class _$SettingsImpl extends _Settings { other.primaryCurrency == primaryCurrency) && (identical(other.language, language) || other.language == language) && - (identical(other.network, network) || other.network == network) && + (identical(other.environment, environment) || + other.environment == environment) && (identical(other.languageSeed, languageSeed) || other.languageSeed == languageSeed) && (identical(other.firstLaunch, firstLaunch) || @@ -307,7 +308,7 @@ class _$SettingsImpl extends _Settings { runtimeType, primaryCurrency, language, - network, + environment, languageSeed, firstLaunch, showBalances, @@ -330,7 +331,7 @@ abstract class _Settings extends Settings { const factory _Settings( {required final AvailablePrimaryCurrency primaryCurrency, required final AvailableLanguage language, - required final NetworksSetting network, + required final aedappfm.Environment environment, required final String languageSeed, required final bool firstLaunch, required final bool showBalances, @@ -347,7 +348,7 @@ abstract class _Settings extends Settings { @override AvailableLanguage get language; @override - NetworksSetting get network; + aedappfm.Environment get environment; @override String get languageSeed; @override diff --git a/lib/domain/repositories/dapps/dapps_repository.dart b/lib/domain/repositories/dapps/dapps_repository.dart index a629678f5..d4f319bf6 100644 --- a/lib/domain/repositories/dapps/dapps_repository.dart +++ b/lib/domain/repositories/dapps/dapps_repository.dart @@ -1,17 +1,18 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later import 'package:aewallet/domain/models/dapp.dart'; -import 'package:aewallet/model/available_networks.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; import 'package:archethic_lib_dart/archethic_lib_dart.dart'; abstract class DAppsRepositoryInterface { Future> getDAppsFromNetwork( - AvailableNetworks network, + aedappfm.Environment environment, ApiService apiService, ); Future getDApp( - AvailableNetworks network, + aedappfm.Environment environment, String code, ApiService apiService, ); diff --git a/lib/domain/repositories/feature_flags/feature_flags_repository.dart b/lib/domain/repositories/feature_flags/feature_flags_repository.dart index 03daba8c2..174c92cfc 100644 --- a/lib/domain/repositories/feature_flags/feature_flags_repository.dart +++ b/lib/domain/repositories/feature_flags/feature_flags_repository.dart @@ -1,10 +1,11 @@ import 'package:aewallet/domain/models/feature_flags.dart'; -import 'package:aewallet/model/available_networks.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; import 'package:archethic_lib_dart/archethic_lib_dart.dart'; abstract class FeatureFlagsRepositoryInterface { Future getFeatureFlag( - AvailableNetworks network, + aedappfm.Environment environment, ApiService apiService, String applicationCode, String featureCode, @@ -12,7 +13,7 @@ abstract class FeatureFlagsRepositoryInterface { ); Future> getFeatureFlagsFromNetwork( - AvailableNetworks network, + aedappfm.Environment environment, ApiService apiService, ); } diff --git a/lib/infrastructure/datasources/preferences.hive.dart b/lib/infrastructure/datasources/preferences.hive.dart index fd30ebe4f..a9428fab4 100644 --- a/lib/infrastructure/datasources/preferences.hive.dart +++ b/lib/infrastructure/datasources/preferences.hive.dart @@ -3,7 +3,6 @@ import 'package:aewallet/domain/models/authentication.dart'; import 'package:aewallet/infrastructure/datasources/hive.extension.dart'; import 'package:aewallet/model/authentication_method.dart'; import 'package:aewallet/model/available_language.dart'; -import 'package:aewallet/model/available_networks.dart'; import 'package:aewallet/model/device_lock_timeout.dart'; import 'package:aewallet/model/primary_currency.dart'; import 'package:aewallet/model/privacy_mask_option.dart'; @@ -23,8 +22,7 @@ class PreferencesHiveDatasource { static const String curLanguage = 'archethic_wallet_cur_language'; static const String curPrimarySetting = 'archethic_wallet_cur_primary_setting'; - static const String curNetwork = 'archethic_wallet_cur_network'; - static const String curNetworkDevEndpoint = '_cur_network_dev_endpoint'; + static const String curEnvironment = 'archethic_wallet_cur_environment'; static const String curTheme = 'archethic_wallet_cur_theme'; static const String lock = 'archethic_wallet_lock'; static const String privacyMaskEnabled = @@ -118,21 +116,15 @@ class PreferencesHiveDatasource { )], ); - Future setNetwork(NetworksSetting network) async { - await _setValue(curNetwork, network.getIndex()); - await _setValue(curNetworkDevEndpoint, network.networkDevEndpoint); + Future setEnvironment(aedappfm.Environment environment) async { + await _setValue(curEnvironment, environment.index); } - NetworksSetting getNetwork() => NetworksSetting( - network: AvailableNetworks.values[_getValue( - curNetwork, - defaultValue: AvailableNetworks.archethicMainNet.index, - )], - networkDevEndpoint: _getValue( - curNetworkDevEndpoint, - defaultValue: '', - ), - ); + aedappfm.Environment getEnvironment() => + aedappfm.Environment.values[_getValue( + curEnvironment, + defaultValue: aedappfm.Environment.mainnet.index, + )]; Future setLanguageSeed(String v) => _setValue(languageSeed, v); diff --git a/lib/infrastructure/repositories/dapps_repository.dart b/lib/infrastructure/repositories/dapps_repository.dart index e2d838e49..6791bd302 100644 --- a/lib/infrastructure/repositories/dapps_repository.dart +++ b/lib/infrastructure/repositories/dapps_repository.dart @@ -2,7 +2,8 @@ import 'dart:convert'; import 'package:aewallet/domain/models/dapp.dart'; import 'package:aewallet/domain/repositories/dapps/dapps_repository.dart'; -import 'package:aewallet/model/available_networks.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; import 'package:archethic_lib_dart/archethic_lib_dart.dart'; import 'package:flutter/services.dart'; @@ -30,11 +31,11 @@ class DAppsRepositoryImpl implements DAppsRepositoryInterface { @override Future getDApp( - AvailableNetworks network, + aedappfm.Environment environment, String code, ApiService apiService, ) async { - final dapps = await getDAppsFromNetwork(network, apiService); + final dapps = await getDAppsFromNetwork(environment, apiService); if (dapps.isEmpty) return null; return dapps.firstWhere( @@ -44,22 +45,22 @@ class DAppsRepositoryImpl implements DAppsRepositoryInterface { @override Future> getDAppsFromNetwork( - AvailableNetworks network, + aedappfm.Environment environment, ApiService apiService, ) async { - switch (network) { + switch (environment) { // aeWallet-DApps-Conf service - case AvailableNetworks.archethicTestNet: + case aedappfm.Environment.testnet: return _getDAppsFromBlockchain( '00009087BB05F2D4DDBDFA833486CD303A805C5F73154473E5604BEB1C1512475B42', apiService, ); - case AvailableNetworks.archethicMainNet: + case aedappfm.Environment.mainnet: return _getDAppsFromBlockchain( '0000679EF0AF4ED6EDB1790B8E082880BD18632BB66190DE93422C8CFC7E57D678EE', apiService, ); - case AvailableNetworks.archethicDevNet: + case aedappfm.Environment.devnet: final dApps = await _getDAppsLocal(); return dApps; } diff --git a/lib/infrastructure/repositories/feature_flags_repository.dart b/lib/infrastructure/repositories/feature_flags_repository.dart index d6949b1f0..72efa39fa 100644 --- a/lib/infrastructure/repositories/feature_flags_repository.dart +++ b/lib/infrastructure/repositories/feature_flags_repository.dart @@ -2,20 +2,22 @@ import 'dart:convert'; import 'package:aewallet/domain/models/feature_flags.dart'; import 'package:aewallet/domain/repositories/feature_flags/feature_flags_repository.dart'; -import 'package:aewallet/model/available_networks.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; import 'package:archethic_lib_dart/archethic_lib_dart.dart'; import 'package:flutter/services.dart'; class FeatureFlagsRepositoryImpl implements FeatureFlagsRepositoryInterface { @override Future getFeatureFlag( - AvailableNetworks network, + aedappfm.Environment environment, ApiService apiService, String applicationCode, String featureCode, String platform, ) async { - final featureFlags = await getFeatureFlagsFromNetwork(network, apiService); + final featureFlags = + await getFeatureFlagsFromNetwork(environment, apiService); final application = featureFlags.firstWhere( (flag) => flag.applicationCode == applicationCode, orElse: () => const FeatureFlags(applicationCode: '', features: {}), @@ -62,21 +64,21 @@ class FeatureFlagsRepositoryImpl implements FeatureFlagsRepositoryInterface { @override Future> getFeatureFlagsFromNetwork( - AvailableNetworks network, + aedappfm.Environment environment, ApiService apiService, ) async { - switch (network) { - case AvailableNetworks.archethicTestNet: + switch (environment) { + case aedappfm.Environment.testnet: return _getFeatureFlagsFromBlockchain( '000052BA03493517C72F56960F2218873E710689EA5D702CF3BC28E84A8A4F79C78A', apiService, ); - case AvailableNetworks.archethicMainNet: + case aedappfm.Environment.mainnet: return _getFeatureFlagsFromBlockchain( '0000cf5e09b68d4d873e6cade7b4a951ea2eeadc148ce346120dfc96cf5879448d8c', apiService, ); - case AvailableNetworks.archethicDevNet: + case aedappfm.Environment.devnet: final featureFlags = await _getFeatureFlagsLocal(); return featureFlags; } diff --git a/lib/infrastructure/repositories/settings.dart b/lib/infrastructure/repositories/settings.dart index 9374eec02..02613a0ac 100644 --- a/lib/infrastructure/repositories/settings.dart +++ b/lib/infrastructure/repositories/settings.dart @@ -19,7 +19,7 @@ class SettingsRepository implements SettingsRepositoryInterface { language: loadedPreferences.getLanguage().language, languageSeed: loadedPreferences.getLanguageSeed(), mainScreenCurrentPage: loadedPreferences.getMainScreenCurrentPage(), - network: loadedPreferences.getNetwork(), + environment: loadedPreferences.getEnvironment(), primaryCurrency: loadedPreferences.getPrimaryCurrency(), showBalances: loadedPreferences.getShowBalances(), testnetEnabled: loadedPreferences.getTestnetEnabled(), @@ -37,7 +37,7 @@ class SettingsRepository implements SettingsRepositoryInterface { await loadedPreferences.setLanguageSeed(settings.languageSeed); await loadedPreferences .setMainScreenCurrentPage(settings.mainScreenCurrentPage); - await loadedPreferences.setNetwork(settings.network); + await loadedPreferences.setEnvironment(settings.environment); await loadedPreferences.setPrimaryCurrency(settings.primaryCurrency); await loadedPreferences.setShowBalances(settings.showBalances); await loadedPreferences.setTestnetEnabled(settings.testnetEnabled); diff --git a/lib/model/available_networks.dart b/lib/model/available_networks.dart deleted file mode 100644 index 255b7554f..000000000 --- a/lib/model/available_networks.dart +++ /dev/null @@ -1,69 +0,0 @@ -/// SPDX-License-Identifier: AGPL-3.0-or-later - -import 'package:aewallet/model/setting_item.dart'; -import 'package:flutter/material.dart'; - -enum AvailableNetworks { archethicMainNet, archethicTestNet, archethicDevNet } - -enum DefaultNetworksHost { - archethicMainNetHost('mainnet.archethic.net'), - archethicTestNetHost('testnet.archethic.net'); - - const DefaultNetworksHost(this.value); - final String value; -} - -@immutable -class NetworksSetting extends SettingSelectionItem { - const NetworksSetting({ - required this.network, - required this.networkDevEndpoint, - }); - - final AvailableNetworks network; - - final String networkDevEndpoint; - - String get notificationBackendUrl { - return 'https://push.archethic.net'; - } - - @override - String getDisplayName(BuildContext context) { - switch (network) { - case AvailableNetworks.archethicMainNet: - return 'Archethic Main Network'; - case AvailableNetworks.archethicTestNet: - return 'Archethic Test Network'; - case AvailableNetworks.archethicDevNet: - return 'Archethic Dev Network'; - } - } - - String getLink() { - switch (network) { - case AvailableNetworks.archethicMainNet: - return 'https://${DefaultNetworksHost.archethicMainNetHost.value}'; - case AvailableNetworks.archethicTestNet: - return 'https://${DefaultNetworksHost.archethicTestNetHost.value}'; - case AvailableNetworks.archethicDevNet: - return networkDevEndpoint; - } - } - - String getAEWebUri() { - switch (network) { - case AvailableNetworks.archethicMainNet: - return 'https://${DefaultNetworksHost.archethicMainNetHost.value}/api/web_hosting/'; - case AvailableNetworks.archethicTestNet: - return 'https://${DefaultNetworksHost.archethicTestNetHost.value}/api/web_hosting/'; - case AvailableNetworks.archethicDevNet: - return '$networkDevEndpoint/api/web_hosting/'; - } - } - - // For saving to shared prefs - int getIndex() { - return network.index; - } -} diff --git a/lib/modules/aeswap/application/session/provider.dart b/lib/modules/aeswap/application/session/provider.dart index 58a646136..c2dfbdcff 100644 --- a/lib/modules/aeswap/application/session/provider.dart +++ b/lib/modules/aeswap/application/session/provider.dart @@ -8,10 +8,9 @@ part 'provider.g.dart'; @riverpod Environment environment(Ref ref) { - final network = ref.watch( + return ref.watch( SettingsProviders.settings.select( - (settings) => settings.network, + (settings) => settings.environment, ), ); - return Environment.byEndpoint(network.getLink()); } diff --git a/lib/modules/aeswap/application/session/provider.g.dart b/lib/modules/aeswap/application/session/provider.g.dart index b9277f008..252e2b152 100644 --- a/lib/modules/aeswap/application/session/provider.g.dart +++ b/lib/modules/aeswap/application/session/provider.g.dart @@ -6,7 +6,7 @@ part of 'provider.dart'; // RiverpodGenerator // ************************************************************************** -String _$environmentHash() => r'b958bdd53feafb8997a8ae752f421ade34dcda0a'; +String _$environmentHash() => r'52e104689b8174555fe84537089f8cde6082a4b3'; /// See also [environment]. @ProviderFor(environment) diff --git a/lib/router/router.dart b/lib/router/router.dart index af81e56a2..b6cffff27 100644 --- a/lib/router/router.dart +++ b/lib/router/router.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'package:aewallet/infrastructure/rpc/deeplink_server.dart'; import 'package:aewallet/main.dart'; -import 'package:aewallet/model/available_networks.dart'; import 'package:aewallet/model/data/account_token.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_pair.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_pool.dart'; @@ -55,7 +54,7 @@ import 'package:aewallet/ui/views/transfer/bloc/state.dart'; import 'package:aewallet/ui/views/transfer/layouts/transfer_sheet.dart'; import 'package:aewallet/ui/widgets/components/dialog.dart'; import 'package:aewallet/ui/widgets/components/sheet_skeleton.dart'; -import 'package:aewallet/ui/widgets/dialogs/network_dialog.dart'; +import 'package:aewallet/ui/widgets/dialogs/environment_dialog.dart'; import 'package:aewallet/util/get_it_instance.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; diff --git a/lib/router/router.introduction.dart b/lib/router/router.introduction.dart index 3f1bfe2cc..756457376 100644 --- a/lib/router/router.introduction.dart +++ b/lib/router/router.introduction.dart @@ -69,10 +69,10 @@ final _introductionRoutes = [ ), ), GoRoute( - path: NetworkDialog.routerPage, - pageBuilder: (context, state) => DialogPage( + path: EnvironmentDialog.routerPage, + pageBuilder: (context, state) => DialogPage( barrierDismissible: false, - builder: (BuildContext context) => const NetworkDialog(), + builder: (BuildContext context) => const EnvironmentDialog(), ), ), ]; diff --git a/lib/ui/menu/settings/environment_change.dart b/lib/ui/menu/settings/environment_change.dart new file mode 100644 index 000000000..76822c908 --- /dev/null +++ b/lib/ui/menu/settings/environment_change.dart @@ -0,0 +1,177 @@ +/// SPDX-License-Identifier: AGPL-3.0-or-later +import 'package:aewallet/application/account/accounts_notifier.dart'; +import 'package:aewallet/application/session/session.dart'; +import 'package:aewallet/application/settings/settings.dart'; +import 'package:aewallet/application/usecases.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; +import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; +import 'package:aewallet/ui/themes/archethic_theme.dart'; +import 'package:aewallet/ui/themes/archethic_theme_base.dart'; +import 'package:aewallet/ui/util/accounts_dialog.dart'; +import 'package:aewallet/ui/util/ui_util.dart'; +import 'package:aewallet/ui/widgets/components/dialog.dart'; +import 'package:aewallet/ui/widgets/dialogs/environment_dialog.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:go_router/go_router.dart'; +import 'package:material_symbols_icons/symbols.dart'; + +class EnvironmentChange extends ConsumerWidget { + const EnvironmentChange({ + super.key, + }); + @override + Widget build(BuildContext context, WidgetRef ref) { + final environment = ref.watch(environmentProvider); + final selectedAccount = ref.watch( + accountsNotifierProvider.select( + (accounts) => accounts.valueOrNull?.selectedAccount, + ), + ); + final settings = ref.watch(SettingsProviders.settings); + final localizations = AppLocalizations.of(context)!; + + if (selectedAccount == null) return const SizedBox(); + + return InkWell( + onTap: settings.testnetEnabled + ? () async { + final _saveEnvironment = settings.environment; + final _selectedEnvironment = await context + .push(EnvironmentDialog.routerPage) as aedappfm.Environment?; + if (_selectedEnvironment == null) return; + if (_selectedEnvironment != _saveEnvironment) { + context.loadingOverlay.show( + title: AppLocalizations.of(context)!.pleaseWaitChangeNetwork, + ); + + final seed = + ref.read(sessionNotifierProvider).loggedIn?.wallet.seed; + + var keychainNetworkExists = false; + try { + await archethic.ApiService( + _selectedEnvironment.endpoint, + ).getKeychain(seed!); + keychainNetworkExists = true; + // ignore: empty_catches + } catch (e) {} + + if (keychainNetworkExists == false) { + final session = ref.read(sessionNotifierProvider); + + final accounts = await AccountsDialog.selectMultipleAccounts( + context: context, + accounts: session.loggedIn!.wallet.appKeychain.accounts, + confirmBtnLabel: + localizations.networkChangeCreateKeychainBtn, + dialogTitle: localizations.networkChangeHeader, + isModal: true, + header: Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: Column( + children: [ + Text( + localizations.networkChangeKeychainNotExists( + _selectedEnvironment.displayName, + ), + style: AppTextStyles.bodySmall(context), + ), + ], + ), + ), + ); + + final nameList = []; + if (accounts == null || accounts.isEmpty) { + return; + } + for (final account in accounts) { + nameList.add(account.name); + } + + try { + await ref + .read(createNewAppWalletCaseProvider) + .run(seed, nameList); + + UIUtil.showSnackbar( + 'création ok', + context, + ref, + ArchethicTheme.text, + ArchethicTheme.snackBarShadow, + duration: const Duration(milliseconds: 5000), + icon: Symbols.info, + ); + } catch (e) { + UIUtil.showSnackbar( + 'Pb avec création + $e', + context, + ref, + ArchethicTheme.text, + ArchethicTheme.snackBarShadow, + duration: const Duration(milliseconds: 5000), + ); + } + } + + try { + final languageSeed = ref.read( + SettingsProviders.settings.select( + (settings) => settings.languageSeed, + ), + ); + + await ref + .read(sessionNotifierProvider.notifier) + .restoreFromSeed( + seed: seed!, + languageCode: languageSeed, + ); + context.loadingOverlay.hide(); + } catch (e) { + context.loadingOverlay.hide(); + context.pop(); + } + } + } + : null, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 10), + child: Align( + child: Text( + environment.label, + style: AppTextStyles.bodyMediumSecondaryColor( + context, + ), + ), + ), + ), + if (settings.testnetEnabled) + Padding( + padding: const EdgeInsets.only(bottom: 8), + child: Row( + children: [ + const SizedBox( + width: 5, + ), + Icon( + Symbols.keyboard_arrow_down, + color: ArchethicThemeBase.neutral0, + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/lib/ui/menu/settings/main_settings_view.dart b/lib/ui/menu/settings/main_settings_view.dart index b5bf6b816..cb233ff86 100644 --- a/lib/ui/menu/settings/main_settings_view.dart +++ b/lib/ui/menu/settings/main_settings_view.dart @@ -44,7 +44,7 @@ class MainMenuView extends ConsumerWidget { children: [ ListView( children: [ - const NetworkChange(), + const EnvironmentChange(), const _SettingsListItem.spacer(), _SettingsListItem.title(text: localizations.information), const _SettingsListItem.spacer(), diff --git a/lib/ui/menu/settings/network_change.dart b/lib/ui/menu/settings/network_change.dart deleted file mode 100644 index 18e229f00..000000000 --- a/lib/ui/menu/settings/network_change.dart +++ /dev/null @@ -1,161 +0,0 @@ -/// SPDX-License-Identifier: AGPL-3.0-or-later -import 'package:aewallet/application/account/accounts_notifier.dart'; -import 'package:aewallet/application/session/session.dart'; -import 'package:aewallet/application/settings/settings.dart'; -import 'package:aewallet/application/usecases.dart'; -import 'package:aewallet/modules/aeswap/application/session/provider.dart'; -import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; -import 'package:aewallet/ui/themes/archethic_theme.dart'; -import 'package:aewallet/ui/themes/archethic_theme_base.dart'; -import 'package:aewallet/ui/util/accounts_dialog.dart'; -import 'package:aewallet/ui/util/ui_util.dart'; -import 'package:aewallet/ui/widgets/components/dialog.dart'; -import 'package:aewallet/ui/widgets/dialogs/network_dialog.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/localizations.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:go_router/go_router.dart'; -import 'package:material_symbols_icons/symbols.dart'; - -class NetworkChange extends ConsumerWidget { - const NetworkChange({ - super.key, - }); - @override - Widget build(BuildContext context, WidgetRef ref) { - final environment = ref.watch(environmentProvider); - final selectedAccount = ref.watch( - accountsNotifierProvider.select( - (accounts) => accounts.valueOrNull?.selectedAccount, - ), - ); - final settings = ref.watch(SettingsProviders.settings); - final localizations = AppLocalizations.of(context)!; - - if (selectedAccount == null) return const SizedBox(); - - return InkWell( - onTap: settings.testnetEnabled - ? () async { - final _saveNetwork = settings.network; - await context.push(NetworkDialog.routerPage); - final _settings = ref.read(SettingsProviders.settings); - if (_settings.network.network != _saveNetwork.network) { - context.loadingOverlay.show( - title: AppLocalizations.of(context)!.pleaseWaitChangeNetwork, - ); - final languageSeed = ref.read( - SettingsProviders.settings.select( - (settings) => settings.languageSeed, - ), - ); - final seed = - ref.read(sessionNotifierProvider).loggedIn?.wallet.seed; - if (seed != null) { - try { - await ref - .read(sessionNotifierProvider.notifier) - .restoreFromSeed( - seed: seed, - languageCode: languageSeed, - ); - context.loadingOverlay.hide(); - } catch (e) { - context.loadingOverlay.hide(); - context.pop(); - final session = ref.read(sessionNotifierProvider); - - final accounts = - await AccountsDialog.selectMultipleAccounts( - context: context, - accounts: session.loggedIn!.wallet.appKeychain.accounts, - confirmBtnLabel: - localizations.networkChangeCreateKeychainBtn, - dialogTitle: localizations.networkChangeHeader, - isModal: true, - header: Padding( - padding: const EdgeInsets.symmetric(vertical: 10), - child: Column( - children: [ - Text( - localizations.networkChangeKeychainNotExists( - _settings.network.getDisplayName(context), - ), - style: AppTextStyles.bodySmall(context), - ), - ], - ), - ), - ); - - final nameList = []; - if (accounts == null || accounts.isEmpty) { - return; - } - for (final account in accounts) { - nameList.add(account.name); - } - - try { - await ref - .read(createNewAppWalletCaseProvider) - .run(seed, nameList); - - UIUtil.showSnackbar( - 'création ok', - context, - ref, - ArchethicTheme.text, - ArchethicTheme.snackBarShadow, - duration: const Duration(milliseconds: 5000), - icon: Symbols.info, - ); - } catch (e) { - UIUtil.showSnackbar( - 'Pb avec création + $e', - context, - ref, - ArchethicTheme.text, - ArchethicTheme.snackBarShadow, - duration: const Duration(milliseconds: 5000), - ); - } - } - } - } - } - : null, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.only(bottom: 10), - child: Align( - child: Text( - environment.label, - style: AppTextStyles.bodyMediumSecondaryColor( - context, - ), - ), - ), - ), - if (settings.testnetEnabled) - Padding( - padding: const EdgeInsets.only(bottom: 8), - child: Row( - children: [ - const SizedBox( - width: 5, - ), - Icon( - Symbols.keyboard_arrow_down, - color: ArchethicThemeBase.neutral0, - ), - ], - ), - ), - ], - ), - ); - } -} diff --git a/lib/ui/menu/settings/settings_sheet.dart b/lib/ui/menu/settings/settings_sheet.dart index ede55aa58..90056b3ba 100644 --- a/lib/ui/menu/settings/settings_sheet.dart +++ b/lib/ui/menu/settings/settings_sheet.dart @@ -15,7 +15,7 @@ import 'package:aewallet/model/device_lock_timeout.dart'; import 'package:aewallet/model/privacy_mask_option.dart'; import 'package:aewallet/model/setting_item.dart'; import 'package:aewallet/modules/aeswap/application/session/provider.dart'; -import 'package:aewallet/ui/menu/settings/network_change.dart'; +import 'package:aewallet/ui/menu/settings/environment_change.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/archethic_theme_base.dart'; import 'package:aewallet/ui/themes/styles.dart'; diff --git a/lib/ui/util/network_choice_infos.dart b/lib/ui/util/network_choice_infos.dart index baa676ff7..5c68572ce 100644 --- a/lib/ui/util/network_choice_infos.dart +++ b/lib/ui/util/network_choice_infos.dart @@ -1,6 +1,5 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later - -import 'package:aewallet/application/settings/settings.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -15,8 +14,7 @@ class NetworkChoiceInfos extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final settings = ref.watch(SettingsProviders.settings); - final network = settings.network; + final environment = ref.watch(environmentProvider); Widget content = Container( padding: const EdgeInsets.only(right: 10), width: 230, @@ -47,7 +45,7 @@ class NetworkChoiceInfos extends ConsumerWidget { mainAxisAlignment: MainAxisAlignment.end, children: [ Text( - network.getDisplayName(context), + environment.displayName, overflow: TextOverflow.ellipsis, ), const SizedBox(width: 5), diff --git a/lib/ui/views/accounts/layouts/components/account_list_item.dart b/lib/ui/views/accounts/layouts/components/account_list_item.dart index 0fa4f568b..6736e2110 100644 --- a/lib/ui/views/accounts/layouts/components/account_list_item.dart +++ b/lib/ui/views/accounts/layouts/components/account_list_item.dart @@ -307,7 +307,7 @@ class _AccountListItemState extends ConsumerState onTap: () async { await launchUrl( Uri.parse( - '${ref.read(SettingsProviders.settings).network.getLink()}/explorer/chain?address=${widget.account.genesisAddress}', + '${ref.read(SettingsProviders.settings).environment.endpoint}/explorer/chain?address=${widget.account.genesisAddress}', ), mode: LaunchMode.externalApplication, ); diff --git a/lib/ui/views/intro/layouts/intro_new_wallet_get_first_infos.dart b/lib/ui/views/intro/layouts/intro_new_wallet_get_first_infos.dart index ea84589be..d314f357b 100644 --- a/lib/ui/views/intro/layouts/intro_new_wallet_get_first_infos.dart +++ b/lib/ui/views/intro/layouts/intro_new_wallet_get_first_infos.dart @@ -1,6 +1,7 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later import 'package:aewallet/application/connectivity_status.dart'; +import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/util/dimens.dart'; @@ -14,7 +15,9 @@ import 'package:aewallet/ui/widgets/components/dialog.dart'; import 'package:aewallet/ui/widgets/components/icon_network_warning.dart'; import 'package:aewallet/ui/widgets/components/sheet_skeleton.dart'; import 'package:aewallet/ui/widgets/components/sheet_skeleton_interface.dart'; -import 'package:aewallet/ui/widgets/dialogs/network_dialog.dart'; +import 'package:aewallet/ui/widgets/dialogs/environment_dialog.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -129,7 +132,19 @@ class _IntroNewWalletDisclaimerState ) : NetworkChoiceInfos( onTap: () async { - await context.push(NetworkDialog.routerPage); + final environment = + await context.push(EnvironmentDialog.routerPage); + if (environment != null) { + await ref + .read(SettingsProviders.settings.notifier) + .setEnvironment(environment as aedappfm.Environment); + await ref + .read(SettingsProviders.settings.notifier) + .setTestnetEnabled( + environment != aedappfm.Environment.mainnet, + ); + } + FocusScope.of(context).requestFocus(nameFocusNode); }, ), diff --git a/lib/ui/views/intro/layouts/intro_welcome.dart b/lib/ui/views/intro/layouts/intro_welcome.dart index b3bca76f4..1884e86c8 100755 --- a/lib/ui/views/intro/layouts/intro_welcome.dart +++ b/lib/ui/views/intro/layouts/intro_welcome.dart @@ -1,7 +1,6 @@ import 'package:aewallet/application/connectivity_status.dart'; import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/application/settings/version.dart'; -import 'package:aewallet/model/available_networks.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/archethic_theme_base.dart'; import 'package:aewallet/ui/themes/styles.dart'; @@ -13,8 +12,10 @@ import 'package:aewallet/ui/widgets/components/app_button_tiny.dart'; import 'package:aewallet/ui/widgets/components/icon_network_warning.dart'; import 'package:aewallet/ui/widgets/components/sheet_skeleton.dart'; import 'package:aewallet/ui/widgets/components/sheet_skeleton_interface.dart'; +import 'package:aewallet/ui/widgets/dialogs/environment_dialog.dart'; import 'package:aewallet/ui/widgets/dialogs/language_dialog.dart'; -import 'package:aewallet/ui/widgets/dialogs/network_dialog.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/localizations.dart'; @@ -336,12 +337,10 @@ class _ButtonNewWallet extends ConsumerWidget { key: const Key('newWallet'), onPressed: () async { if (cguChecked) { - await ref.read(SettingsProviders.settings.notifier).setNetwork( - const NetworksSetting( - network: AvailableNetworks.archethicMainNet, - networkDevEndpoint: '', - ), - ); + await ref + .read(SettingsProviders.settings.notifier) + .setEnvironment(aedappfm.Environment.mainnet); + context.go( IntroNewWalletGetFirstInfos.routerPage, ); @@ -371,7 +370,18 @@ class _ButtonImportWallet extends ConsumerWidget { key: const Key('importWallet'), onPressed: () async { if (cguChecked) { - await context.push(NetworkDialog.routerPage); + final environment = + await context.push(EnvironmentDialog.routerPage); + if (environment != null) { + await ref + .read(SettingsProviders.settings.notifier) + .setEnvironment(environment as aedappfm.Environment); + await ref + .read(SettingsProviders.settings.notifier) + .setTestnetEnabled( + environment != aedappfm.Environment.mainnet, + ); + } context.go(IntroImportSeedPage.routerPage); } }, diff --git a/lib/ui/views/main/components/menu_widget_wallet.dart b/lib/ui/views/main/components/menu_widget_wallet.dart index a6369efc4..a0959a5d2 100644 --- a/lib/ui/views/main/components/menu_widget_wallet.dart +++ b/lib/ui/views/main/components/menu_widget_wallet.dart @@ -1,7 +1,6 @@ import 'package:aewallet/application/account/accounts_notifier.dart'; import 'package:aewallet/application/connectivity_status.dart'; import 'package:aewallet/application/refresh_in_progress.dart'; -import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/ui/views/receive/receive_modal.dart'; import 'package:aewallet/ui/views/sheets/buy_sheet.dart'; @@ -104,7 +103,7 @@ class MenuWidgetWallet extends ConsumerWidget { } else { await launchUrl( Uri.parse( - '${ref.read(SettingsProviders.settings).network.getLink()}/faucet', + '${ref.read(environmentProvider).endpoint}/faucet', ), mode: LaunchMode.externalApplication, ); diff --git a/lib/ui/views/main/transactions_tab.dart b/lib/ui/views/main/transactions_tab.dart index 857dfbd85..dc7f88229 100644 --- a/lib/ui/views/main/transactions_tab.dart +++ b/lib/ui/views/main/transactions_tab.dart @@ -4,8 +4,8 @@ import 'dart:ui'; import 'package:aewallet/application/account/accounts_notifier.dart'; import 'package:aewallet/application/connectivity_status.dart'; -import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/model/blockchain/recent_transaction.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/util/dimens.dart'; @@ -65,7 +65,7 @@ class TransactionsTab extends ConsumerWidget { onPressed: () async { await launchUrl( Uri.parse( - '${ref.read(SettingsProviders.settings).network.getLink()}/explorer/chain?address=${accountSelected.genesisAddress}', + '${ref.read(environmentProvider).endpoint}/explorer/chain?address=${accountSelected.genesisAddress}', ), mode: LaunchMode.externalApplication, ); diff --git a/lib/ui/views/nft/layouts/components/nft_detail.dart b/lib/ui/views/nft/layouts/components/nft_detail.dart index 49d5fa1c2..6bf5e24bd 100755 --- a/lib/ui/views/nft/layouts/components/nft_detail.dart +++ b/lib/ui/views/nft/layouts/components/nft_detail.dart @@ -1,8 +1,8 @@ import 'package:aewallet/application/account/accounts_notifier.dart'; import 'package:aewallet/application/nft/nft.dart'; -import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/model/data/account.dart'; import 'package:aewallet/model/data/account_token.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/util/dimens.dart'; @@ -166,7 +166,7 @@ class _NFTDetailState extends ConsumerState onPressed: () async { await launchUrl( Uri.parse( - '${ref.read(SettingsProviders.settings).network.getLink()}/explorer/transaction/${widget.address}', + '${ref.read(environmentProvider).endpoint}/explorer/transaction/${widget.address}', ), mode: LaunchMode.externalApplication, ); diff --git a/lib/ui/views/nft/layouts/components/thumbnail/nft_thumbnail_aeweb.dart b/lib/ui/views/nft/layouts/components/thumbnail/nft_thumbnail_aeweb.dart index 93b3f8e5f..d088f3abb 100644 --- a/lib/ui/views/nft/layouts/components/thumbnail/nft_thumbnail_aeweb.dart +++ b/lib/ui/views/nft/layouts/components/thumbnail/nft_thumbnail_aeweb.dart @@ -1,6 +1,5 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later - -import 'package:aewallet/application/settings/settings.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/views/nft/layouts/components/thumbnail/nft_thumbnail_error.dart'; @@ -30,8 +29,8 @@ class NFTThumbnailAEWEB extends ConsumerWidget { final raw = TokenUtil.getAEWebUrlFromToken( properties, ); - final networkSettings = ref.watch( - SettingsProviders.settings.select((settings) => settings.network), + final environment = ref.watch( + environmentProvider, ); return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -45,19 +44,19 @@ class NFTThumbnailAEWEB extends ConsumerWidget { ? ClipRRect( borderRadius: BorderRadius.circular(20), child: ImageNetworkWidgeted( - url: networkSettings.getAEWebUri() + raw, + url: environment.aeHostingUri + raw, errorMessage: localizations.nftURLEmpty, ), ) : ImageNetworkWidgeted( - url: networkSettings.getAEWebUri() + raw, + url: environment.aeHostingUri + raw, errorMessage: localizations.nftURLEmpty, ), if (withContentInfo) Padding( padding: const EdgeInsets.all(10), child: SelectableText( - '${localizations.nftAEWebFrom}\n${networkSettings.getAEWebUri()}${raw!}', + '${localizations.nftAEWebFrom}\n${environment.aeHostingUri}${raw!}', style: ArchethicThemeStyles.textStyleSize12W100Primary, ), ), diff --git a/lib/ui/views/receive/layouts/components/explorer_button.dart b/lib/ui/views/receive/layouts/components/explorer_button.dart index 71fecc594..96d412f18 100644 --- a/lib/ui/views/receive/layouts/components/explorer_button.dart +++ b/lib/ui/views/receive/layouts/components/explorer_button.dart @@ -1,4 +1,4 @@ -import 'package:aewallet/application/settings/settings.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/ui/util/dimens.dart'; import 'package:aewallet/ui/widgets/components/app_button_tiny.dart'; import 'package:flutter/material.dart'; @@ -24,7 +24,7 @@ class ExplorerButton extends ConsumerWidget { onPressed: () async { await launchUrl( Uri.parse( - '${ref.read(SettingsProviders.settings).network.getLink()}/explorer/chain?address=$address', + '${ref.read(environmentProvider).endpoint}/explorer/chain?address=$address', ), mode: LaunchMode.externalApplication, ); diff --git a/lib/ui/views/rpc_command_receiver/get_endpoint/command_handler.dart b/lib/ui/views/rpc_command_receiver/get_endpoint/command_handler.dart index 27e50360d..b95a39610 100644 --- a/lib/ui/views/rpc_command_receiver/get_endpoint/command_handler.dart +++ b/lib/ui/views/rpc_command_receiver/get_endpoint/command_handler.dart @@ -17,10 +17,8 @@ class GetEndpointHandler extends CommandHandler { final settings = await settingsRepository.getSettings(const Locale('en')); - final endpointUrl = settings.network.getLink(); - return Result.success( - awc.GetEndpointResult(endpointUrl: endpointUrl), + awc.GetEndpointResult(endpointUrl: settings.environment.endpoint), ); }, ); diff --git a/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart b/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart index 49f2d9c2b..cb8df146a 100644 --- a/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart +++ b/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart @@ -1,6 +1,7 @@ import 'package:aewallet/application/account/accounts_notifier.dart'; import 'package:aewallet/application/connectivity_status.dart'; import 'package:aewallet/application/settings/settings.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/ui/views/aeswap_earn/bloc/provider.dart'; import 'package:aewallet/ui/views/aeswap_swap/layouts/swap_tab.dart'; @@ -162,7 +163,7 @@ class TokenDetailMenu extends ConsumerWidget { onTap: () async { await launchUrl( Uri.parse( - '${ref.read(SettingsProviders.settings).network.getLink()}/explorer/transaction/${aeToken.address}', + '${ref.read(environmentProvider).endpoint}/explorer/transaction/${aeToken.address}', ), mode: LaunchMode.externalApplication, ); diff --git a/lib/ui/views/transactions/transaction_infos_sheet.dart b/lib/ui/views/transactions/transaction_infos_sheet.dart index 2cf606f11..43eab3678 100755 --- a/lib/ui/views/transactions/transaction_infos_sheet.dart +++ b/lib/ui/views/transactions/transaction_infos_sheet.dart @@ -7,6 +7,7 @@ import 'package:aewallet/application/session/session.dart'; import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/model/data/account_balance.dart'; import 'package:aewallet/model/transaction_infos.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/util/account_formatters.dart'; @@ -70,7 +71,7 @@ class _TransactionInfosSheetState extends ConsumerState onPressed: () async { await launchUrl( Uri.parse( - '${ref.read(SettingsProviders.settings).network.getLink()}/explorer/transaction/${widget.notificationRecipientAddress}', + '${ref.read(environmentProvider).endpoint}/explorer/transaction/${widget.notificationRecipientAddress}', ), mode: LaunchMode.externalApplication, ); diff --git a/lib/ui/widgets/dialogs/environment_dialog.dart b/lib/ui/widgets/dialogs/environment_dialog.dart new file mode 100644 index 000000000..99e63c041 --- /dev/null +++ b/lib/ui/widgets/dialogs/environment_dialog.dart @@ -0,0 +1,58 @@ +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; +import 'package:aewallet/ui/themes/archethic_theme.dart'; +import 'package:aewallet/ui/themes/styles.dart'; +import 'package:aewallet/ui/widgets/components/picker_item.dart'; +import 'package:aewallet/ui/widgets/components/popup_dialog.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:go_router/go_router.dart'; + +class EnvironmentDialog extends ConsumerWidget { + const EnvironmentDialog({ + super.key, + }); + + static const routerPage = '/network_dialog'; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final currentEnvironment = ref.watch(environmentProvider); + + final localizations = AppLocalizations.of(context)!; + + final pickerItemsList = List.empty(growable: true); + for (final environment in aedappfm.Environment.values) { + pickerItemsList.add( + PickerItem( + environment.displayName, + environment.endpoint, + '${ArchethicTheme.assetsFolder}logo_white.png', + null, + environment, + true, + ), + ); + } + + return PopupDialog( + title: Padding( + padding: const EdgeInsets.only(bottom: 10), + child: Text( + localizations.networksHeader, + style: ArchethicThemeStyles.textStyleSize24W700Primary, + ), + ), + content: PickerWidget( + pickerItems: pickerItemsList, + selectedIndexes: [currentEnvironment.index], + onSelected: (value) async { + final environment = value.value; + context.pop(environment); + }, + ), + ); + } +} diff --git a/lib/ui/widgets/dialogs/network_dialog.dart b/lib/ui/widgets/dialogs/network_dialog.dart deleted file mode 100644 index 173635c08..000000000 --- a/lib/ui/widgets/dialogs/network_dialog.dart +++ /dev/null @@ -1,264 +0,0 @@ -import 'package:aewallet/application/network/provider.dart'; -import 'package:aewallet/application/settings/settings.dart'; -import 'package:aewallet/model/available_networks.dart'; -import 'package:aewallet/ui/themes/archethic_theme.dart'; -import 'package:aewallet/ui/themes/styles.dart'; -import 'package:aewallet/ui/util/dimens.dart'; -import 'package:aewallet/ui/util/ui_util.dart'; -import 'package:aewallet/ui/widgets/components/app_button_tiny.dart'; -import 'package:aewallet/ui/widgets/components/app_text_field.dart'; -import 'package:aewallet/ui/widgets/components/picker_item.dart'; -import 'package:aewallet/ui/widgets/components/popup_dialog.dart'; -import 'package:aewallet/util/url_util.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_gen/gen_l10n/localizations.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:go_router/go_router.dart'; - -class NetworkDialog extends ConsumerWidget { - const NetworkDialog({ - super.key, - }); - static const routerPage = '/network_dialog'; - - @override - Widget build(BuildContext context, WidgetRef ref) { - final curNetworksSetting = ref.watch( - SettingsProviders.settings.select((value) => value.network), - ); - - final localizations = AppLocalizations.of(context)!; - final endpointFocusNode = FocusNode(); - final endpointController = TextEditingController(); - - final pickerItemsList = List.empty(growable: true); - for (final value in AvailableNetworks.values) { - var _networkDevEndpoint = ''; - if (value == AvailableNetworks.archethicDevNet && - _networkDevEndpoint.isEmpty) { - _networkDevEndpoint = 'http://localhost:4000'; - } - final networkSetting = NetworksSetting( - network: value, - networkDevEndpoint: _networkDevEndpoint, - ); - pickerItemsList.add( - PickerItem( - networkSetting.getDisplayName(context), - networkSetting.getLink(), - '${ArchethicTheme.assetsFolder}logo_white.png', - null, - networkSetting, - true, - ), - ); - } - - return PopupDialog( - title: const _NetworkTitle(), - content: PickerWidget( - pickerItems: pickerItemsList, - selectedIndexes: [curNetworksSetting.getIndex()], - onSelected: (value) async { - final selectedNetworkSettings = value.value as NetworksSetting; - await ref - .read(SettingsProviders.settings.notifier) - .setNetwork(selectedNetworkSettings); - await ref.read(SettingsProviders.settings.notifier).setTestnetEnabled( - selectedNetworkSettings.network != - AvailableNetworks.archethicMainNet, - ); - - // If selected network is DevNet - // Show a dialog to enter a custom network - // else use the network selected - if (selectedNetworkSettings.network == - AvailableNetworks.archethicDevNet) { - endpointController.text = - selectedNetworkSettings.networkDevEndpoint; - - await showDialog( - barrierDismissible: false, - context: context, - useRootNavigator: false, - builder: (BuildContext context) { - return StatefulBuilder( - builder: (context, setState) { - return _NetworkDialogCustomInput( - endpointFocusNode: endpointFocusNode, - endpointController: endpointController, - onSubmitNetwork: () async { - void setError(String errorText) { - UIUtil.showSnackbar( - errorText, - context, - ref, - ArchethicTheme.text, - ArchethicTheme.snackBarShadow, - ); - } - - if (endpointController.text.isEmpty) { - setError(localizations.enterEndpointBlank); - return; - } - - if (!UrlUtil.isUrlValid(endpointController.text)) { - setError(localizations.enterEndpointNotValid); - return; - } - - final uriInput = - UrlUtil.convertUri(endpointController.text); - - if (await ref.watch( - NetworkProvider.isReservedNodeUri( - uri: uriInput, - ).future, - )) { - setError( - localizations.enterEndpointUseByNetwork, - ); - return; - } - - await ref - .read( - SettingsProviders.settings.notifier, - ) - .setNetwork( - NetworksSetting( - network: AvailableNetworks.archethicDevNet, - networkDevEndpoint: uriInput.toString(), - ), - ); - - context.pop(); - }, - ); - }, - ); - }, - ); - } - - context.pop(selectedNetworkSettings); - }, - ), - ); - } -} - -class _NetworkDialogCustomInput extends ConsumerWidget { - const _NetworkDialogCustomInput({ - required this.endpointFocusNode, - required this.endpointController, - required this.onSubmitNetwork, - }); - - final FocusNode endpointFocusNode; - final TextEditingController endpointController; - final Function() onSubmitNetwork; - - @override - Widget build(BuildContext context, WidgetRef ref) { - final localizations = AppLocalizations.of(context)!; - - return PopupDialog( - title: const Padding( - padding: EdgeInsets.only(bottom: 10), - child: _NetworkDevnetHeader(), - ), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - AppTextField( - key: const Key('networkChoice'), - leftMargin: 0, - rightMargin: 0, - focusNode: endpointFocusNode, - controller: endpointController, - labelText: localizations.enterEndpoint, - keyboardType: TextInputType.text, - style: ArchethicThemeStyles.textStyleSize14W600Primary, - inputFormatters: [ - LengthLimitingTextInputFormatter(200), - ], - ), - Text( - 'http://xxx.xxx.xxx.xxx:xxxx', - style: ArchethicThemeStyles.textStyleSize12W100Primary, - ), - const SizedBox(), - ], - ), - const SizedBox( - height: 20, - ), - Row( - children: [ - AppButtonTiny( - AppButtonTinyType.primary, - localizations.ok, - Dimens.buttonTopDimens, - key: const Key('addEndpoint'), - onPressed: onSubmitNetwork, - ), - ], - ), - ], - ), - ); - } -} - -class _NetworkTitle extends ConsumerWidget { - const _NetworkTitle(); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final localizations = AppLocalizations.of(context)!; - - return Padding( - padding: const EdgeInsets.only(bottom: 10), - child: Text( - localizations.networksHeader, - style: ArchethicThemeStyles.textStyleSize24W700Primary, - ), - ); - } -} - -class _NetworkDevnetHeader extends ConsumerWidget { - const _NetworkDevnetHeader(); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final localizations = AppLocalizations.of(context)!; - - return Column( - children: [ - Image.asset( - '${ArchethicTheme.assetsFolder}logo_white.png', - height: 30, - ), - Text( - key: const Key('networkName'), - ref.read(SettingsProviders.settings).network.getDisplayName(context), - style: ArchethicThemeStyles.textStyleSize10W100Primary, - ), - const SizedBox( - height: 20, - ), - Text( - localizations.enterEndpointHeader, - style: ArchethicThemeStyles.textStyleSize12W100Primary, - ), - ], - ); - } -}