Skip to content

Commit

Permalink
0.9.6 (#170)
Browse files Browse the repository at this point in the history
* version bump

* restore wallet list loading animation

* basic ssl server support (non web)

* server settings: fix visual glitch

* server handling improvements

* changelog

* show fiat balance in wallet list

* remove magic number 1 million

* build transaction should take double for amount

* formatting

* send tab: groundwork for fiat options

* make decimalProduct final

* allow sending in fiat currency

* test for ssl server

* fix e2e

* review
  • Loading branch information
willyfromtheblock authored Jul 6, 2022
1 parent 67026cc commit d841d32
Show file tree
Hide file tree
Showing 25 changed files with 902 additions and 511 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### **0.9.6** (2022-07-06)
* Send tab: Allow sending in FIAT currency
* Wallet list will now show balance in FIAT
* SSL servers are now available (not on web)

### **0.9.5** (2022-06-24)
* Setup legal: fix container heights on smaller screens
* Performance upgrades under the hood
Expand Down
1 change: 1 addition & 0 deletions assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"server_add_title": "Neuen Server hinzufügen",
"server_add_input_empty": "Bitte URL eingeben",
"server_add_no_wss": "Muss mit wss:// beginnen\nAndere Protokolle werden derzeit nicht unterstützt",
"server_add_no_wss_or_ssl": "Muss mit wss:// oder ssl:// beginnen\nAndere Protokolle werden derzeit nicht unterstützt",
"server_add_no_port": "Muss Port beinhalten, z. B. :50004",
"server_add_server_exists": "Hinzufügen fehlgeschlagen: Server bereits vorhanden.",
"server_add_server_no_connection": "Verbindung zu Server fehlgeschlagen.",
Expand Down
2 changes: 2 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"send": "Send",
"send_address": "Address",
"send_add_metadata": "Add Metadata",
"send_fiat_switch": "Amount in $currency",
"send_amount": "Amount",
"send_amount_below_minimum": "Minimum output is $amount. \nPlease chose an amount greater or equal to it.",
"send_amount_below_minimum_unable": "Minimum output is $amount. \nYou don't have enough funds to pay for the fees.",
Expand All @@ -220,6 +221,7 @@
"server_add_input_label": "Server URL",
"server_add_input_empty": "Please enter a URL",
"server_add_no_wss": "Must start with wss://\nOther protocols are currently not supported",
"server_add_no_wss_or_ssl": "Must start with wss:// or ssl://\nOther protocols are currently not supported",
"server_add_no_port": "Must contain a port, e.g. :50004",
"server_add_server_exists": "Adding failed: Server already exists.",
"server_add_server_no_connection": "Connection to server failed.",
Expand Down
15 changes: 12 additions & 3 deletions lib/models/available_coins.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:math';

import 'package:coinslib/coinslib.dart';
import 'coin.dart';

class AvailableCoins {
final Map<String, Coin> _availableCoinList = {
static final Map<String, Coin> _availableCoinList = {
'peercoin': Coin(
name: 'peercoin',
displayName: 'Peercoin',
Expand Down Expand Up @@ -53,11 +55,18 @@ class AvailableCoins {
),
};

Map<String, Coin> get availableCoins {
static Map<String, Coin> get availableCoins {
return _availableCoinList;
}

Coin getSpecificCoin(identifier) {
static Coin getSpecificCoin(String identifier) {
return _availableCoinList[identifier]!;
}

static int getDecimalProduct({required String identifier}) {
return pow(
10,
getSpecificCoin(identifier).fractions,
).toInt();
}
}
81 changes: 46 additions & 35 deletions lib/providers/active_wallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ActiveWallets with ChangeNotifier {
Future<String?> getAddressFromDerivationPath(
String identifier, int account, int chain, int address,
[master = false]) async {
final network = AvailableCoins().getSpecificCoin(identifier).networkType;
final network = AvailableCoins.getSpecificCoin(identifier).networkType;
var hdWallet = HDWallet.fromSeed(
seedPhraseUint8List(await seedPhrase),
network: network,
Expand Down Expand Up @@ -135,7 +135,7 @@ class ActiveWallets with ChangeNotifier {

Future<void> generateUnusedAddress(String identifier) async {
var openWallet = getSpecificCoinWallet(identifier);
final network = AvailableCoins().getSpecificCoin(identifier).networkType;
final network = AvailableCoins.getSpecificCoin(identifier).networkType;
var hdWallet = HDWallet.fromSeed(
seedPhraseUint8List(await seedPhrase),
network: network,
Expand Down Expand Up @@ -313,6 +313,10 @@ class ActiveWallets with ChangeNotifier {
//check if that tx is already in the db
var txInWallet = openWallet.transactions;
var isInWallet = false;
final decimalProduct = AvailableCoins.getDecimalProduct(
identifier: identifier,
);

for (var walletTx in txInWallet) {
if (walletTx.txid == tx['txid']) {
isInWallet = true;
Expand Down Expand Up @@ -341,23 +345,24 @@ class ActiveWallets with ChangeNotifier {
for (var vOut in voutList) {
final asMap = vOut as Map;
if (asMap['scriptPubKey']['type'] != 'nulldata') {
asMap['scriptPubKey']['addresses'].forEach((addr) {
if (openWallet.addresses.firstWhereOrNull(
(element) => element.address == addr) !=
null) {
//address is ours, add new tx
final txValue = (vOut['value'] * 1000000).toInt();

//increase notification value for addr
final addrInWallet = openWallet.addresses
.firstWhere((element) => element.address == addr);
addrInWallet.newNotificationBackendCount =
addrInWallet.notificationBackendCount + 1;
openWallet.save();

//write tx
openWallet.putTransaction(
WalletTransaction(
asMap['scriptPubKey']['addresses'].forEach(
(addr) {
if (openWallet.addresses.firstWhereOrNull(
(element) => element.address == addr) !=
null) {
//address is ours, add new tx
final txValue = (vOut['value'] * decimalProduct).toInt();

//increase notification value for addr
final addrInWallet = openWallet.addresses
.firstWhere((element) => element.address == addr);
addrInWallet.newNotificationBackendCount =
addrInWallet.notificationBackendCount + 1;
openWallet.save();

//write tx
openWallet.putTransaction(
WalletTransaction(
txid: tx['txid'],
timestamp: tx['blocktime'] ?? 0,
value: txValue,
Expand All @@ -367,10 +372,12 @@ class ActiveWallets with ChangeNotifier {
broadCasted: true,
confirmations: tx['confirmations'] ?? 0,
broadcastHex: '',
opReturn: ''),
);
}
});
opReturn: '',
),
);
}
},
);
}
}

Expand Down Expand Up @@ -530,7 +537,7 @@ class ActiveWallets with ChangeNotifier {
String identifier,
String address,
) async {
var network = AvailableCoins().getSpecificCoin(identifier).networkType;
var network = AvailableCoins.getSpecificCoin(identifier).networkType;
var openWallet = getSpecificCoinWallet(identifier);
var walletAddress = openWallet.addresses
.firstWhereOrNull((element) => element.address == address);
Expand Down Expand Up @@ -562,16 +569,20 @@ class ActiveWallets with ChangeNotifier {
Future<Map> buildTransaction({
required String identifier,
required String address,
required String amount,
required double amount,
required int fee,
String opReturn = '',
bool firstPass = true,
List<WalletUtxo>? paperWalletUtxos,
String paperWalletPrivkey = '',
}) async {
//convert amount
var _txAmount = (double.parse(amount) * 1000000).toInt();
var openWallet = getSpecificCoinWallet(identifier);
final _decimalProduct = AvailableCoins.getDecimalProduct(
identifier: identifier,
);

var _txAmount = (amount * _decimalProduct).toInt();
var _openWallet = getSpecificCoinWallet(identifier);
var _hex = '';
var _destroyedChange = 0;

Expand All @@ -589,7 +600,7 @@ class ActiveWallets with ChangeNotifier {

//check if tx needs change
var _needsChange = true;
if (_txAmount == openWallet.balance || paperWalletUtxos != null) {
if (_txAmount == _openWallet.balance || paperWalletUtxos != null) {
_needsChange = false;
LoggerWrapper.logInfo(
'ActiveWallets',
Expand All @@ -604,14 +615,14 @@ class ActiveWallets with ChangeNotifier {
}

//define utxo pool
var utxoPool = paperWalletUtxos ?? openWallet.utxos;
var utxoPool = paperWalletUtxos ?? _openWallet.utxos;

if (_txAmount <= openWallet.balance || paperWalletUtxos != null) {
if (_txAmount <= _openWallet.balance || paperWalletUtxos != null) {
if (utxoPool.isNotEmpty) {
//find eligible input utxos
var _totalInputValue = 0;
var inputTx = <WalletUtxo>[];
var coin = AvailableCoins().getSpecificCoin(identifier);
var coin = AvailableCoins.getSpecificCoin(identifier);

for (var utxo in utxoPool) {
if (utxo.value > 0) {
Expand All @@ -627,7 +638,7 @@ class ActiveWallets with ChangeNotifier {
}
}

var coinParams = AvailableCoins().getSpecificCoin(identifier);
var coinParams = AvailableCoins.getSpecificCoin(identifier);
var network = coinParams.networkType;

//start building tx
Expand Down Expand Up @@ -674,7 +685,7 @@ class ActiveWallets with ChangeNotifier {
for (var inputUtxo in inputTx) {
var inputKey = inputTx.indexOf(inputUtxo);
//find key to that utxo
for (var walletAddr in openWallet.addresses) {
for (var walletAddr in _openWallet.addresses) {
if (walletAddr.address == inputUtxo.address) {
var wif = paperWalletUtxos != null
? paperWalletPrivkey
Expand Down Expand Up @@ -706,7 +717,7 @@ class ActiveWallets with ChangeNotifier {
final intermediate = tx.build();
var number = ((intermediate.txSize) / 1000 * coin.feePerKb)
.toStringAsFixed(coin.fractions);
var asDouble = double.parse(number) * 1000000;
var asDouble = double.parse(number) * _decimalProduct;
var requiredFeeInSatoshis = asDouble.toInt();

LoggerWrapper.logInfo(
Expand Down Expand Up @@ -782,7 +793,7 @@ class ActiveWallets with ChangeNotifier {
}

String getScriptHash(String identifier, String address) {
var network = AvailableCoins().getSpecificCoin(identifier).networkType;
var network = AvailableCoins.getSpecificCoin(identifier).networkType;
var script = Address.addressToOutputScript(address, network);
var hash = sha256.convert(script).toString();
return (reverseString(hash));
Expand Down
Loading

0 comments on commit d841d32

Please sign in to comment.