diff --git a/lib/screens/preferences/sign_message_form.dart b/lib/screens/preferences/sign_message_form.dart index c88d46f51..383128c58 100644 --- a/lib/screens/preferences/sign_message_form.dart +++ b/lib/screens/preferences/sign_message_form.dart @@ -1,8 +1,10 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:formz/formz.dart'; import 'package:my_wit_wallet/util/get_localization.dart'; import 'package:my_wit_wallet/bloc/crypto/api_crypto.dart'; +import 'package:my_wit_wallet/screens/dashboard/bloc/dashboard_bloc.dart'; import 'package:my_wit_wallet/screens/preferences/general_config.dart'; import 'package:my_wit_wallet/screens/preferences/preferences_screen.dart'; import 'package:my_wit_wallet/shared/api_database.dart'; @@ -41,15 +43,11 @@ class SignMessageFormState extends State { List _formFocusElements() => [_messageFocusNode]; MessageInput _message = MessageInput.pure(); Map? signedMessage; - Wallet? _currentWallet; - String? _address; bool isLoading = false; @override void initState() { super.initState(); - _address = database.walletStorage.currentAccount.address; - _currentWallet = database.walletStorage.currentWallet; } @override @@ -143,7 +141,7 @@ class SignMessageFormState extends State { } } - Widget _buildMessageInput() { + Widget _buildMessageInput(String address) { final theme = Theme.of(context); return TextField( decoration: InputDecoration( @@ -161,7 +159,7 @@ class SignMessageFormState extends State { onSubmitted: (value) async { // hide keyboard FocusManager.instance.primaryFocus?.unfocus(); - _unlockKeychainAndSign(_message.value, _address); + _unlockKeychainAndSign(_message.value, address); }, onChanged: (String value) async { setMessage(_messageController.value.text); @@ -172,41 +170,56 @@ class SignMessageFormState extends State { ); } + Widget formBuilder(BuildContext context) { + return BlocBuilder( + builder: (BuildContext context, DashboardState state) { + String selectedAddress = Locator.instance + .get() + .walletStorage + .currentAccount + .address; + final Wallet currentWallet = + Locator.instance.get().walletStorage.currentWallet; + List externalAddresses = currentWallet + .orderedExternalAccounts() + .values + .map( + (Account account) => SelectItem(account.address, account.address)) + .toList(); + List masterAccountList = [ + SelectItem(currentWallet.masterAccount?.address ?? '', + currentWallet.masterAccount?.address ?? '') + ]; + bool isHdWallet = externalAddresses.length > 0; + return Form( + autovalidateMode: AutovalidateMode.disabled, + child: Column(children: [ + Select( + selectedItem: selectedAddress, + cropLabel: true, + listItems: isHdWallet ? externalAddresses : masterAccountList, + onChanged: (String? label) => { + if (label != null) setState(() => selectedAddress = label) + }), + SizedBox(height: 16), + _buildMessageInput(selectedAddress), + SizedBox(height: 16), + PaddedButton( + padding: EdgeInsets.zero, + text: localization.signMessage, + isLoading: isLoading, + type: ButtonType.primary, + enabled: true, + onPressed: () async { + await _unlockKeychainAndSign(_message.value, selectedAddress); + }) + ])); + }); + } + @override Widget build(BuildContext context) { _messageFocusNode.addListener(() => validateForm()); - List externalAddresses = _currentWallet! - .orderedExternalAccounts() - .values - .map((Account account) => SelectItem(account.address, account.address)) - .toList(); - List masterAccountList = [ - SelectItem(_currentWallet!.masterAccount?.address ?? '', - _currentWallet!.masterAccount?.address ?? '') - ]; - bool isHdWallet = externalAddresses.length > 0; - return Form( - autovalidateMode: AutovalidateMode.disabled, - child: Column(children: [ - Select( - selectedItem: _address ?? externalAddresses[0].label, - cropLabel: true, - cropMiddleLength: windowWidth > 550 ? null : 28, - listItems: isHdWallet ? externalAddresses : masterAccountList, - onChanged: (String? label) => - {if (label != null) setState(() => _address = label)}), - SizedBox(height: 16), - _buildMessageInput(), - SizedBox(height: 16), - PaddedButton( - padding: EdgeInsets.zero, - text: localization.signMessage, - isLoading: isLoading, - type: ButtonType.primary, - enabled: true, - onPressed: () async { - await _unlockKeychainAndSign(_message.value, _address); - }) - ])); + return formBuilder(context); } } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 4554882f3..0cacc7508 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,15 +6,11 @@ #include "generated_plugin_registrant.h" -#include #include #include #include void fl_register_plugins(FlPluginRegistry* registry) { - g_autoptr(FlPluginRegistrar) open_file_linux_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "OpenFileLinuxPlugin"); - open_file_linux_plugin_register_with_registrar(open_file_linux_registrar); g_autoptr(FlPluginRegistrar) screen_retriever_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin"); screen_retriever_plugin_register_with_registrar(screen_retriever_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 740cb3147..62f151fd7 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - open_file_linux screen_retriever url_launcher_linux window_manager diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 916c25b93..bfc7727f8 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,7 +7,6 @@ import Foundation import local_auth_darwin import mobile_scanner -import open_file_mac import path_provider_foundation import screen_retriever import shared_preferences_foundation @@ -17,7 +16,6 @@ import window_manager func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLALocalAuthPlugin.register(with: registry.registrar(forPlugin: "FLALocalAuthPlugin")) MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin")) - OpenFilePlugin.register(with: registry.registrar(forPlugin: "OpenFilePlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))