fix nano sending, update restore page wording, and other minor fixes (#1130)

* fix nano sending, update restore page wording, and other minor fixes

* fix bch address parsing

* minor code enhancement [skip ci]

* Register the main secure storage as the long lived instance of secure storage throughout the app session

---------

Co-authored-by: Serhii <borodenko.sv@gmail.com>
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Matthew Fosse
2023-10-17 18:59:41 +03:00
committed by GitHub
co-authored by Serhii OmarHatem
parent 69a77d4f71
commit 98a9edc656
34 changed files with 160 additions and 84 deletions
+2 -1
View File
@@ -248,6 +248,7 @@ Future<void> setup({
required Box<Order> ordersSource,
required Box<UnspentCoinsInfo> unspentCoinsInfoSource,
required Box<AnonpayInvoiceInfo> anonpayInvoiceInfoSource,
required FlutterSecureStorage secureStorage,
}) async {
_walletInfoSource = walletInfoSource;
_nodeSource = nodeSource;
@@ -289,7 +290,7 @@ Future<void> setup({
getIt.registerFactory<Box<Node>>(() => _nodeSource);
getIt.registerFactory<Box<Node>>(() => _powNodeSource, instanceName: Node.boxName + "pow");
getIt.registerSingleton<FlutterSecureStorage>(FlutterSecureStorage());
getIt.registerSingleton<FlutterSecureStorage>(secureStorage);
getIt.registerSingleton(AuthenticationStore());
getIt.registerSingleton<WalletListStore>(WalletListStore());
getIt.registerSingleton(NodeListStoreBase.instance);
+7 -1
View File
@@ -46,7 +46,13 @@ class AddressResolver {
}
final match = RegExp(addressPattern).firstMatch(raw);
return match?.group(0)?.replaceAll(RegExp('[^0-9a-zA-Z]'), '');
return match?.group(0)?.replaceAllMapped(RegExp('[^0-9a-zA-Z]|bitcoincash:|nano_'), (Match match) {
String group = match.group(0)!;
if (group.startsWith('bitcoincash:') || group.startsWith('nano_')) {
return group;
}
return '';
});
}
Future<ParsedAddress> resolve(String text, String ticker) async {
+3 -2
View File
@@ -163,7 +163,7 @@ Future<void> initializeAppConfigs() async {
secureStorage: secureStorage,
anonpayInvoiceInfo: anonpayInvoiceInfo,
initialMigrationVersion: 23);
}
}
Future<void> initialSetup(
{required SharedPreferences sharedPreferences,
@@ -202,7 +202,8 @@ Future<void> initialSetup(
transactionDescriptionBox: transactionDescriptions,
ordersSource: ordersSource,
anonpayInvoiceInfoSource: anonpayInvoiceInfo,
unspentCoinsInfoSource: unspentCoinsInfoSource);
unspentCoinsInfoSource: unspentCoinsInfoSource,
secureStorage: secureStorage);
await bootstrap(navigatorKey);
monero?.onStartup();
}
+15 -3
View File
@@ -406,6 +406,13 @@ class CWNanoUtil extends NanoUtil {
late String publicAddress;
if (seedKey != null) {
if (seedKey.length == 64) {
try {
mnemonic = nanoUtil!.seedToMnemonic(seedKey);
} catch (e) {
print("not a valid 'nano' seed key");
}
}
if (derivationType == DerivationType.bip39) {
publicAddress = await hdSeedToAddress(seedKey, 0);
} else if (derivationType == DerivationType.nano) {
@@ -429,7 +436,8 @@ class CWNanoUtil extends NanoUtil {
AccountInfoResponse? accountInfo = await nanoClient.getAccountInfo(publicAddress);
if (accountInfo == null) {
accountInfo = AccountInfoResponse(frontier: "", balance: "0", representative: "", confirmationHeight: 0);
accountInfo = AccountInfoResponse(
frontier: "", balance: "0", representative: "", confirmationHeight: 0);
}
accountInfo.address = publicAddress;
return accountInfo;
@@ -449,7 +457,11 @@ class CWNanoUtil extends NanoUtil {
if (seedKey?.length == 128) {
return [DerivationType.bip39];
} else if (seedKey?.length == 64) {
return [DerivationType.nano];
try {
mnemonic = nanoUtil!.seedToMnemonic(seedKey!);
} catch (e) {
print("not a valid 'nano' seed key");
}
}
late String publicAddressStandard;
@@ -503,7 +515,7 @@ class CWNanoUtil extends NanoUtil {
// we don't know for sure:
return [DerivationType.nano, DerivationType.bip39];
} catch (e) {
return [DerivationType.unknown];
return [DerivationType.nano, DerivationType.bip39];
}
}
}
@@ -124,9 +124,16 @@ class WalletRestoreFromKeysFromState extends State<WalletRestoreFromKeysFrom> {
Widget _restoreFromKeysFormFields() {
if (widget.displayPrivateKeyField) {
// the term "private key" isn't actually what we're accepting here, and it's confusing to
// users of the nano community, what this form actually accepts (when importing for nano) is a nano seed in it's hex form, referred to in code as a "seed key"
// so we should change the placeholder text to reflect this
// supporting actual nano private keys is possible, but it's super niche in the nano community / they're not really used
bool nanoBased = widget.walletRestoreViewModel.type == WalletType.nano ||
widget.walletRestoreViewModel.type == WalletType.banano;
return AddressTextField(
controller: privateKeyController,
placeholder: S.of(context).private_key,
placeholder: nanoBased ? S.of(context).seed_key : S.of(context).private_key,
options: [AddressTextFieldOption.paste],
buttonColor: Theme.of(context).hintColor,
onPushPasteButton: (_) {
+2 -1
View File
@@ -1,3 +1,4 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cake_wallet/src/widgets/validable_annotated_editable_text.dart';
@@ -75,7 +76,7 @@ class SeedWidgetState extends State<SeedWidget> {
Positioned(
top: 10,
left: 0,
child: Text('Enter your seed',
child: Text(S.of(context).enter_seed_phrase,
style: TextStyle(
fontSize: 16.0, color: Theme.of(context).hintColor))),
Padding(
+12 -17
View File
@@ -185,15 +185,15 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
@computed
bool get hasCoinControl =>
wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.litecoin ||
wallet.type == WalletType.monero ||
wallet.type == WalletType.bitcoinCash;
wallet.type == WalletType.litecoin ||
wallet.type == WalletType.monero ||
wallet.type == WalletType.bitcoinCash;
@computed
bool get isElectrumWallet =>
wallet.type == WalletType.bitcoin ||
wallet.type == WalletType.litecoin ||
wallet.type == WalletType.bitcoinCash;
wallet.type == WalletType.litecoin ||
wallet.type == WalletType.bitcoinCash;
@computed
bool get hasFees => wallet.type != WalletType.nano && wallet.type != WalletType.banano;
@@ -281,7 +281,6 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
List<bool> conditionsList = [];
for (var output in outputs) {
final show = checkThroughChecksToDisplayTOTP(output.extractedAddress);
conditionsList.add(show);
}
@@ -350,31 +349,27 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
Object _credentials() {
final priority = _settingsStore.priority[wallet.type];
if (priority == null) throw Exception('Priority is null for wallet type: ${wallet.type}');
if (priority == null && wallet.type != WalletType.nano) {
throw Exception('Priority is null for wallet type: ${wallet.type}');
}
switch (wallet.type) {
case WalletType.bitcoin:
case WalletType.litecoin:
case WalletType.bitcoinCash:
return bitcoin!.createBitcoinTransactionCredentials(outputs, priority: priority);
return bitcoin!.createBitcoinTransactionCredentials(outputs, priority: priority!);
case WalletType.monero:
return monero!
.createMoneroTransactionCreationCredentials(outputs: outputs, priority: priority);
.createMoneroTransactionCreationCredentials(outputs: outputs, priority: priority!);
case WalletType.haven:
return haven!.createHavenTransactionCreationCredentials(
outputs: outputs, priority: priority, assetType: selectedCryptoCurrency.title);
outputs: outputs, priority: priority!, assetType: selectedCryptoCurrency.title);
case WalletType.ethereum:
final priority = _settingsStore.priority[wallet.type];
if (priority == null) {
throw Exception('Priority is null for wallet type: ${wallet.type}');
}
return ethereum!.createEthereumTransactionCredentials(outputs,
priority: priority, currency: selectedCryptoCurrency);
priority: priority!, currency: selectedCryptoCurrency);
case WalletType.nano:
return nano!.createNanoTransactionCredentials(outputs);
default: