Skip to content

Commit

Permalink
1.1.1 (#208)
Browse files Browse the repository at this point in the history
* version bump and 2do

* hint that enabling background notification can improve performance

* address book: add visibility toggle for sending addresses

* refactor

* changelog

* enable native FlutterCryptography

* cache getGenericBox

* move hive operations into EncryptedBox

* 2dos

* sent tab navigator: add jump to end and jump to front

* changelog

* intercept ege case where last recipient can not pay for fees because fees are too large (e.g. fee 0.42, last recipient 0.01)

* add unit tests

* rm unused import
  • Loading branch information
willyfromtheblock authored Dec 7, 2022
1 parent 55260b5 commit 00cc86f
Show file tree
Hide file tree
Showing 16 changed files with 1,950 additions and 193 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### **1.1.1** (2022-12-06)
* Address book: allow hiding of sending addresses
* Send tab: allow fast forwarding or rewiding to addresses

### **1.1.0** (2022-12-03)
* More CSV import fixes

Expand Down
2 changes: 2 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"send_enter_address": "Please enter an address",
"send_enter_amount": "Please enter an amount",
"send_errors_solve": "Please resolve errors …",
"send_errors_cant_pay_fees": "Can not pay for fees. $feesMissing $letter_code are presently missing. Consider removing addresses or reducing their transaction amount.",
"send_import_csv": "Import from CSV",
"send_fee": "Fee: -$amount $letter_code",
"send_invalid_address": "Invalid address",
Expand Down Expand Up @@ -305,6 +306,7 @@
"wallet_send_label_hint_metadata": "Metadata is unencrypted and will be publicly visible on the blockchain.",
"wallet_scan_appBar_title": "Scanning your imported seed",
"wallet_scan_notice": "This might take a while. Don't close this screen!",
"wallet_scan_notice_bg_notifications": "Enabling background notifications in App Settings can severely improve scanning reliability.",
"wallet_send": "Send",
"wallet_transactions": "Transactions",
"wallets_list": "Your wallets",
Expand Down
4 changes: 4 additions & 0 deletions lib/exceptions/exceptions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class CantPayForFeesException implements Exception {
int feesMissing;
CantPayForFeesException(this.feesMissing);
}
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cryptography_flutter/cryptography_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
Expand Down Expand Up @@ -123,6 +124,9 @@ void main() async {
}

if (!kIsWeb) {
// Enable Flutter cryptography
FlutterCryptography.enable();

//init logger
await FlutterLogs.initLogs(
logLevelsEnabled: [
Expand Down
16 changes: 10 additions & 6 deletions lib/providers/active_wallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:coinslib/src/utils/constants/op.dart';
import 'package:hex/hex.dart';
import 'package:peercoin/models/buildresult.dart';

import '../exceptions/exceptions.dart';
import '../models/available_coins.dart';
import '../models/coin_wallet.dart';
import '../tools/app_localizations.dart';
Expand All @@ -31,11 +32,10 @@ class ActiveWallets with ChangeNotifier {
ActiveWallets(this._encryptedBox);
late String _seedPhrase;
String _unusedAddress = '';
late Box _walletBox;
late Box<CoinWallet> _walletBox;
Box? _vaultBox;
final Map<String, String> _wifs = {};
// ignore: prefer_final_fields
Map<String?, CoinWallet?> _specificWalletCache = {};
final Map<String?, CoinWallet?> _specificWalletCache = {};
final Map<String, HDWallet> _hdWalletCache = {};

Future<void> init() async {
Expand Down Expand Up @@ -80,7 +80,7 @@ class ActiveWallets with ChangeNotifier {
}

List<CoinWallet> get activeWalletsValues {
return _walletBox.values.toList() as List<CoinWallet>;
return _walletBox.values.toList();
}

List get activeWalletsKeys {
Expand All @@ -96,8 +96,7 @@ class ActiveWallets with ChangeNotifier {
}

Future<void> addWallet(String name, String title, String letterCode) async {
var box = await Hive.openBox<CoinWallet>('wallets',
encryptionCipher: HiveAesCipher(await _encryptedBox.key as List<int>));
var box = await _encryptedBox.getWalletBox();
await box.put(name, CoinWallet(name, title, letterCode));
notifyListeners();
}
Expand Down Expand Up @@ -716,6 +715,11 @@ class ActiveWallets with ChangeNotifier {
'no change needed, tx amount $txAmount, fee $fee, reduced output added for ${recipients.keys.last} ${txAmount - fee}',
);
recipients.update(recipients.keys.last, (value) => value - fee);
if (recipients.values.last < coin.minimumTxValue) {
throw CantPayForFeesException(
recipients.values.last * -1,
);
}
txAmount = parseTxOutputValue(recipients);
feesHaveBeenDeductedFromRecipient = true;
}
Expand Down
18 changes: 14 additions & 4 deletions lib/providers/encrypted_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:hive/hive.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

import '../models/coin_wallet.dart';
import '../models/server.dart';

class EncryptedBox with ChangeNotifier {
final Map<String, Box> _cryptoBox = {};
Expand Down Expand Up @@ -77,14 +78,23 @@ class EncryptedBox with ChangeNotifier {
}

Future<Box?> getGenericBox(String name) async {
_cryptoBox[name] = await Hive.openBox(
name,
if (!_cryptoBox.containsKey(name)) {
_cryptoBox[name] = await Hive.openBox(
name,
encryptionCipher: HiveAesCipher(await key as Uint8List),
);
}
return _cryptoBox[name];
}

Future<Box<Server>> getServerBox(String identifier) async {
return await Hive.openBox<Server>(
'serverBox-$identifier',
encryptionCipher: HiveAesCipher(await key as Uint8List),
);
return _cryptoBox[name];
}

Future<Box> getWalletBox() async {
Future<Box<CoinWallet>> getWalletBox() async {
return await Hive.openBox<CoinWallet>(
'wallets',
encryptionCipher: HiveAesCipher(await key as Uint8List),
Expand Down
5 changes: 1 addition & 4 deletions lib/providers/servers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ class Servers with ChangeNotifier {

Future<void> init(String identifier) async {
LoggerWrapper.logInfo('Servers', 'init', 'init server provider');
_serverBox = await Hive.openBox<Server>(
'serverBox-$identifier',
encryptionCipher: HiveAesCipher(await _encryptedBox.key as List<int>),
);
_serverBox = await _encryptedBox.getServerBox(identifier);

final seedServers =
AvailableCoins.getSpecificCoin(identifier).electrumServers;
Expand Down
22 changes: 21 additions & 1 deletion lib/screens/wallet/wallet_import_scan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class _WalletImportScanScreenState extends State<WalletImportScanScreen> {
appBar: AppBar(
title: Center(
child: Text(
AppLocalizations.instance.translate('wallet_scan_appBar_title'),
AppLocalizations.instance.translate(
'wallet_scan_appBar_title',
),
),
),
),
Expand All @@ -52,6 +54,24 @@ class _WalletImportScanScreenState extends State<WalletImportScanScreen> {
Text(
AppLocalizations.instance.translate('wallet_scan_notice'),
),
if (_backgroundNotificationsAvailable == false)
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 20),
const Divider(),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(
AppLocalizations.instance.translate(
'wallet_scan_notice_bg_notifications',
),
textAlign: TextAlign.center,
),
),
],
),
const SizedBox(height: 20),
PeerButton(
text: AppLocalizations.instance
Expand Down
Loading

0 comments on commit 00cc86f

Please sign in to comment.