Skip to content

Commit

Permalink
Merge pull request #115 from peercoin/0.7.3._1
Browse files Browse the repository at this point in the history
0.7.3. 1
  • Loading branch information
Willy authored Dec 3, 2021
2 parents 8aa571c + 1dbb6f6 commit 2ac6ba3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
22 changes: 13 additions & 9 deletions lib/providers/activewallets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,11 @@ class ActiveWallets with ChangeNotifier {
var coin = AvailableCoins().getSpecificCoin(identifier);

openWallet.utxos.forEach((utxo) {
if (_totalInputValue <= (_txAmount + fee)) {
_totalInputValue += utxo.value;
inputTx.add(utxo);
if (utxo.value > 0) {
if (_totalInputValue <= (_txAmount + fee)) {
_totalInputValue += utxo.value;
inputTx.add(utxo);
}
}
});
var coinParams = AvailableCoins().getSpecificCoin(identifier);
Expand All @@ -526,10 +528,15 @@ class ActiveWallets with ChangeNotifier {
if (_needsChange == true) {
var changeAmount = _totalInputValue - _txAmount - fee;
log('change amount $changeAmount');
if (changeAmount < coin.minimumTxValue) {

if (changeAmount <= coin.minimumTxValue) {
//change is too small! no change output
_destroyedChange = changeAmount;
tx.addOutput(address, _txAmount - fee);
if (_txAmount == 0) {
tx.addOutput(address, _txAmount);
} else {
tx.addOutput(address, _txAmount - fee);
}
} else {
tx.addOutput(address, _txAmount);
tx.addOutput(_unusedAddress, changeAmount);
Expand All @@ -546,17 +553,14 @@ class ActiveWallets with ChangeNotifier {
//generate keyMap
Future<Map<int, Map>> generateKeyMap() async {
var keyMap = <int, Map>{};
var _usedUtxos = [];
for (var inputUtxo in inputTx) {
var inputKey = inputTx.indexOf(inputUtxo);
//find key to that utxo
for (var walletAddr in openWallet.addresses) {
if (walletAddr.address == inputUtxo.address &&
!_usedUtxos.contains(inputUtxo.hash)) {
if (walletAddr.address == inputUtxo.address) {
var wif = await getWif(identifier, walletAddr.address);
keyMap[inputKey] = ({'wif': wif, 'addr': inputUtxo.address});
tx.addInput(inputUtxo.hash, inputUtxo.txPos);
_usedUtxos.add(inputUtxo.hash);
}
}
}
Expand Down
33 changes: 21 additions & 12 deletions lib/widgets/wallet/send_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,34 @@ class _SendTabState extends State<SendTab> {
var _firstPress = true;
_buildResult = await buildTx(true);

int? _destroyedChange = _buildResult['destroyedChange'];
int _destroyedChange = _buildResult['destroyedChange'];
var _correctedDust = 0;
_txFee = _buildResult['fee'];
await showDialog(
context: context,
builder: (BuildContext context) {
String? _displayValue = _amountKey.currentState!.value;
_totalValue =
(double.parse(_amountKey.currentState!.value) * 1000000).toInt();
var amountInPutAsDouble =
double.parse(_amountKey.currentState!.value);
_totalValue = (amountInPutAsDouble * 1000000).toInt();
if (_totalValue == _wallet.balance) {
var newValue = double.parse(_amountKey.currentState!.value) -
(_txFee / 1000000);
var newValue = amountInPutAsDouble - (_txFee / 1000000);
_displayValue = newValue.toStringAsFixed(_availableCoin.fractions);
} else {
_totalValue = _totalValue + _txFee;
}
if (_destroyedChange! > 0) {
var newValue = (double.parse(_amountKey.currentState!.value) -
(_txFee / 1000000));
if (_destroyedChange > 0) {
var newValue = (amountInPutAsDouble - (_txFee / 1000000));
_displayValue = newValue.toString();
_totalValue = _totalValue - _txFee + _destroyedChange;

if (_amountKey.currentState!.value == '0') {
_displayValue = '0';
_correctedDust = _destroyedChange - _txFee;
} else {
_correctedDust = _destroyedChange;
}
_totalValue =
(amountInPutAsDouble * 1000000 + _destroyedChange).toInt();
}
return SimpleDialog(
title: Text(AppLocalizations.instance
Expand Down Expand Up @@ -166,10 +174,10 @@ class _SendTabState extends State<SendTab> {
'amount': '${_txFee / 1000000}',
'letter_code': '${_wallet.letterCode}'
})),
if (_destroyedChange > 0)
if (_correctedDust > 0)
Text(
AppLocalizations.instance.translate('send_dust', {
'amount': '${_destroyedChange / 1000000}',
'amount': '${_correctedDust / 1000000}',
'letter_code': '${_wallet.letterCode}'
}),
style: TextStyle(color: Theme.of(context).errorColor),
Expand Down Expand Up @@ -394,7 +402,8 @@ class _SendTabState extends State<SendTab> {
return AppLocalizations.instance
.translate('send_amount_small');
}
if (txValueInSatoshis > _wallet.balance) {
if (txValueInSatoshis > _wallet.balance ||
txValueInSatoshis == 0 && _wallet.balance == 0) {
return AppLocalizations.instance
.translate('send_amount_exceeds');
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: peercoin
description: A new Peercoin wallet.

version: 0.7.3+68
version: 0.7.3+69

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down

0 comments on commit 2ac6ba3

Please sign in to comment.