Skip to content

Commit

Permalink
fix: update address list when switching wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Oct 22, 2024
1 parent da16650 commit 01402ca
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
91 changes: 52 additions & 39 deletions lib/screens/preferences/sign_message_form.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -41,15 +43,11 @@ class SignMessageFormState extends State<SignMessageForm> {
List<FocusNode> _formFocusElements() => [_messageFocusNode];
MessageInput _message = MessageInput.pure();
Map<String, dynamic>? signedMessage;
Wallet? _currentWallet;
String? _address;
bool isLoading = false;

@override
void initState() {
super.initState();
_address = database.walletStorage.currentAccount.address;
_currentWallet = database.walletStorage.currentWallet;
}

@override
Expand Down Expand Up @@ -143,7 +141,7 @@ class SignMessageFormState extends State<SignMessageForm> {
}
}

Widget _buildMessageInput() {
Widget _buildMessageInput(String address) {
final theme = Theme.of(context);
return TextField(
decoration: InputDecoration(
Expand All @@ -161,7 +159,7 @@ class SignMessageFormState extends State<SignMessageForm> {
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);
Expand All @@ -172,41 +170,56 @@ class SignMessageFormState extends State<SignMessageForm> {
);
}

Widget formBuilder(BuildContext context) {
return BlocBuilder<DashboardBloc, DashboardState>(
builder: (BuildContext context, DashboardState state) {
String selectedAddress = Locator.instance
.get<ApiDatabase>()
.walletStorage
.currentAccount
.address;
final Wallet currentWallet =
Locator.instance.get<ApiDatabase>().walletStorage.currentWallet;
List<SelectItem> externalAddresses = currentWallet
.orderedExternalAccounts()
.values
.map(
(Account account) => SelectItem(account.address, account.address))
.toList();
List<SelectItem> 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<SelectItem> externalAddresses = _currentWallet!
.orderedExternalAccounts()
.values
.map((Account account) => SelectItem(account.address, account.address))
.toList();
List<SelectItem> 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);
}
}
4 changes: 0 additions & 4 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

#include "generated_plugin_registrant.h"

#include <open_file_linux/open_file_linux_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

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);
Expand Down
1 change: 0 additions & 1 deletion linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
open_file_linux
screen_retriever
url_launcher_linux
window_manager
Expand Down
2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand Down

0 comments on commit 01402ca

Please sign in to comment.