Fixes for litecoin transactions. Change fixed rate mode for exchange.

wownero
M 2 years ago
parent 18a1f60433
commit 989ef442ac

@ -0,0 +1,23 @@
import 'dart:typed_data';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
String addressFromOutput(Uint8List script, bitcoin.NetworkType networkType) {
try {
return bitcoin.P2PKH(
data: PaymentData(output: script),
network: networkType)
.data
.address;
} catch (_) {}
try {
return bitcoin.P2WPKH(
data: PaymentData(output: script),
network: networkType)
.data
.address;
} catch(_) {}
return null;
}

@ -1,7 +1,7 @@
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
import 'package:cw_bitcoin/address_from_output.dart';
import 'package:cw_bitcoin/bitcoin_address_record.dart';
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
import 'package:cw_core/transaction_direction.dart';
@ -9,26 +9,6 @@ import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/format_amount.dart';
import 'package:cw_core/wallet_type.dart';
String addressFromOutput(Uint8List script) {
try {
return bitcoin.P2PKH(
data: PaymentData(output: script),
network: bitcoin.bitcoin)
.data
.address;
} catch (_) {}
try {
return bitcoin.P2WPKH(
data: PaymentData(output: script),
network: bitcoin.bitcoin)
.data
.address;
} catch(_) {}
return null;
}
class ElectrumTransactionBundle {
ElectrumTransactionBundle(this.originalTransaction, {this.ins, this.time, this.confirmations});
final bitcoin.Transaction originalTransaction;
@ -114,8 +94,11 @@ class ElectrumTransactionInfo extends TransactionInfo {
}
factory ElectrumTransactionInfo.fromElectrumBundle(
ElectrumTransactionBundle bundle, WalletType type,
{@required Set<String> addresses, int height}) {
ElectrumTransactionBundle bundle,
WalletType type,
bitcoin.NetworkType networkType,
{@required Set<String> addresses,
int height}) {
final date = bundle.time != null
? DateTime.fromMillisecondsSinceEpoch(bundle.time * 1000)
: DateTime.now();
@ -129,7 +112,7 @@ class ElectrumTransactionInfo extends TransactionInfo {
final inputTransaction = bundle.ins[i];
final vout = input.index;
final outTransaction = inputTransaction.outs[vout];
final address = addressFromOutput(outTransaction.script);
final address = addressFromOutput(outTransaction.script, networkType);
inputAmount += outTransaction.value;
if (addresses.contains(address)) {
direction = TransactionDirection.outgoing;
@ -138,7 +121,7 @@ class ElectrumTransactionInfo extends TransactionInfo {
for (final out in bundle.originalTransaction.outs) {
totalOutAmount += out.value;
final address = addressFromOutput(out.script);
final address = addressFromOutput(out.script, networkType);
final addressExists = addresses.contains(address);
if ((direction == TransactionDirection.incoming && addressExists) ||
(direction == TransactionDirection.outgoing && !addressExists)) {

@ -505,7 +505,11 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
final tx = await getTransactionExpanded(hash: hash, height: height);
final addresses = walletAddresses.addresses.map((addr) => addr.address).toSet();
return ElectrumTransactionInfo.fromElectrumBundle(
tx,walletInfo.type, addresses: addresses, height: height);
tx,
walletInfo.type,
networkType,
addresses: addresses,
height: height);
}
@override

@ -317,21 +317,6 @@ class ExchangePage extends BasePage {
],
),
),
Padding(
padding: EdgeInsets.only(top: 12, left: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
StandardCheckbox(
key: checkBoxKey,
value: exchangeViewModel.isFixedRateMode,
caption: S.of(context).fixed_rate,
onChanged: (value) =>
exchangeViewModel.isFixedRateMode = value,
),
],
)
),
Padding(
padding: EdgeInsets.only(top: 30, left: 24, bottom: 24),
child: Row(
@ -743,42 +728,15 @@ class ExchangePage extends BasePage {
});
_receiveAmountFocus.addListener(() {
if (_receiveAmountFocus.hasFocus && !exchangeViewModel.isFixedRateMode) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).exchange,
alertContent: S.of(context).fixed_rate_alert,
leftButtonText: S.of(context).cancel,
rightButtonText: S.of(context).ok,
actionLeftButton: () {
FocusScope.of(context).unfocus();
Navigator.of(context).pop();
},
actionRightButton: () {
exchangeViewModel.isFixedRateMode = true;
checkBoxKey.currentState
.changeValue(exchangeViewModel.isFixedRateMode);
Navigator.of(context).pop();
});
});
}
exchangeViewModel.isFixedRateMode = true;
exchangeViewModel.changeReceiveAmount(
amount: receiveAmountController.text);
});
reaction((_) => exchangeViewModel.isFixedRateMode, (bool isFixedRateMode) {
if ((_receiveAmountFocus.hasFocus ||
exchangeViewModel.isReceiveAmountEntered) && !isFixedRateMode) {
FocusScope.of(context).unfocus();
receiveAmountController.text = '';
} else {
exchangeViewModel.changeDepositAmount(
amount: depositAmountController.text);
}
checkBoxKey.currentState
.changeValue(exchangeViewModel.isFixedRateMode);
exchangeViewModel.loadLimits();
_depositAmountFocus.addListener(() {
exchangeViewModel.isFixedRateMode = false;
exchangeViewModel.changeDepositAmount(
amount: depositAmountController.text);
});
_isReactionsSet = true;

@ -64,7 +64,7 @@ abstract class ExchangeViewModelBase with Store {
loadLimits();
reaction(
(_) => isFixedRateMode,
(Object _) => _defineIsReceiveAmountEditable());
(Object _) => loadLimits());
}
final WalletBase wallet;
@ -439,6 +439,6 @@ abstract class ExchangeViewModelBase with Store {
isReceiveAmountEditable = false;
}*/
//isReceiveAmountEditable = false;
isReceiveAmountEditable = (isFixedRateMode ?? false) && provider is ChangeNowExchangeProvider;
isReceiveAmountEditable = provider is ChangeNowExchangeProvider;
}
}

Loading…
Cancel
Save