mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
Fixes.
This commit is contained in:
parent
1188edd5b7
commit
4a2f1e48ff
7 changed files with 65 additions and 43 deletions
|
@ -7,7 +7,10 @@ import 'package:cake_wallet/entities/balance.dart';
|
|||
|
||||
class BitcoinBalance extends Balance {
|
||||
const BitcoinBalance({@required this.confirmed, @required this.unconfirmed})
|
||||
: super(const [BalanceDisplayMode.availableBalance]);
|
||||
: super(const [
|
||||
BalanceDisplayMode.availableBalance,
|
||||
BalanceDisplayMode.fullBalance
|
||||
]);
|
||||
|
||||
factory BitcoinBalance.fromJSON(String jsonSource) {
|
||||
if (jsonSource == null) {
|
||||
|
@ -38,7 +41,7 @@ class BitcoinBalance extends Balance {
|
|||
case BalanceDisplayMode.fullBalance:
|
||||
return totalFormatted;
|
||||
case BalanceDisplayMode.availableBalance:
|
||||
return totalFormatted;
|
||||
return confirmedFormatted;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
{@required String id,
|
||||
@required int height,
|
||||
@required int amount,
|
||||
@required int fee,
|
||||
@required TransactionDirection direction,
|
||||
@required bool isPending,
|
||||
@required DateTime date,
|
||||
|
@ -19,6 +20,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
this.id = id;
|
||||
this.height = height;
|
||||
this.amount = amount;
|
||||
this.fee = fee;
|
||||
this.direction = direction;
|
||||
this.date = date;
|
||||
this.isPending = isPending;
|
||||
|
@ -36,37 +38,42 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
: DateTime.now();
|
||||
final confirmations = obj['confirmations'] as int ?? 0;
|
||||
var direction = TransactionDirection.incoming;
|
||||
var inputsAmount = 0;
|
||||
var amount = 0;
|
||||
var totalOutAmount = 0;
|
||||
|
||||
for (dynamic vin in vins) {
|
||||
final vout = vin['vout'] as int;
|
||||
final out = vin['tx']['vout'][vout] as Map;
|
||||
final outAddresses =
|
||||
(out['scriptPubKey']['addresses'] as List<Object>)?.toSet();
|
||||
inputsAmount += doubleToBitcoinAmount(out['value'] as double ?? 0);
|
||||
|
||||
if (outAddresses?.intersection(addressesSet)?.isNotEmpty ?? false) {
|
||||
direction = TransactionDirection.outgoing;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final amount = vout.fold(0, (int acc, dynamic out) {
|
||||
for (dynamic out in vout) {
|
||||
final outAddresses =
|
||||
out['scriptPubKey']['addresses'] as List<Object> ?? [];
|
||||
final ntrs = outAddresses.toSet().intersection(addressesSet);
|
||||
var amount = acc;
|
||||
final value = doubleToBitcoinAmount(out['value'] as double ?? 0.0);
|
||||
totalOutAmount += value;
|
||||
|
||||
if ((direction == TransactionDirection.incoming && ntrs.isNotEmpty) ||
|
||||
(direction == TransactionDirection.outgoing && ntrs.isEmpty)) {
|
||||
amount += doubleToBitcoinAmount(out['value'] as double ?? 0.0);
|
||||
amount += value;
|
||||
}
|
||||
}
|
||||
|
||||
return amount;
|
||||
});
|
||||
final fee = inputsAmount - totalOutAmount;
|
||||
|
||||
return BitcoinTransactionInfo(
|
||||
id: id,
|
||||
height: height,
|
||||
isPending: false,
|
||||
fee: fee,
|
||||
direction: direction,
|
||||
amount: amount,
|
||||
date: date,
|
||||
|
@ -101,6 +108,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
id: tx.getId(),
|
||||
height: height,
|
||||
isPending: false,
|
||||
fee: null,
|
||||
direction: TransactionDirection.incoming,
|
||||
amount: amount,
|
||||
date: date,
|
||||
|
@ -112,6 +120,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
id: data['id'] as String,
|
||||
height: data['height'] as int,
|
||||
amount: data['amount'] as int,
|
||||
fee: data['fee'] as int,
|
||||
direction: parseTransactionDirectionFromInt(data['direction'] as int),
|
||||
date: DateTime.fromMillisecondsSinceEpoch(data['date'] as int),
|
||||
isPending: data['isPending'] as bool,
|
||||
|
@ -124,6 +133,11 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
String amountFormatted() =>
|
||||
'${formatAmount(bitcoinAmountToString(amount: amount))} BTC';
|
||||
|
||||
@override
|
||||
String feeFormatted() => fee != null
|
||||
? '${formatAmount(bitcoinAmountToString(amount: fee))} BTC'
|
||||
: '';
|
||||
|
||||
@override
|
||||
String fiatAmount() => _fiatAmount ?? '';
|
||||
|
||||
|
@ -135,6 +149,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
id: id,
|
||||
height: info.height,
|
||||
amount: info.amount,
|
||||
fee: info.fee,
|
||||
direction: direction ?? info.direction,
|
||||
date: date ?? info.date,
|
||||
isPending: isPending ?? info.isPending,
|
||||
|
@ -150,6 +165,7 @@ class BitcoinTransactionInfo extends TransactionInfo {
|
|||
m['date'] = date.millisecondsSinceEpoch;
|
||||
m['isPending'] = isPending;
|
||||
m['confirmations'] = confirmations;
|
||||
m['fee'] = fee;
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:cake_wallet/utils/mobx.dart';
|
|||
abstract class TransactionInfo extends Object with Keyable {
|
||||
String id;
|
||||
int amount;
|
||||
int fee;
|
||||
TransactionDirection direction;
|
||||
bool isPending;
|
||||
DateTime date;
|
||||
|
@ -11,6 +12,7 @@ abstract class TransactionInfo extends Object with Keyable {
|
|||
int confirmations;
|
||||
String amountFormatted();
|
||||
String fiatAmount();
|
||||
String feeFormatted();
|
||||
void changeFiatAmount(String amount);
|
||||
|
||||
@override
|
||||
|
|
|
@ -208,7 +208,7 @@ class S implements WidgetsLocalizations {
|
|||
String get send_error_currency => "Currency can only contain numbers";
|
||||
String get send_error_minimum_value => "Minimum value of amount is 0.01";
|
||||
String get send_estimated_fee => "Estimated fee:";
|
||||
String get send_fee => "Fee:";
|
||||
String get send_fee => "Fee";
|
||||
String get send_got_it => "Got it";
|
||||
String get send_name => "Name";
|
||||
String get send_new => "New";
|
||||
|
@ -396,7 +396,7 @@ class $de extends S {
|
|||
@override
|
||||
String get transaction_sent => "Transaktion gesendet!";
|
||||
@override
|
||||
String get send_fee => "Gebühr:";
|
||||
String get send_fee => "Gebühr";
|
||||
@override
|
||||
String get password => "Passwort";
|
||||
@override
|
||||
|
@ -1780,7 +1780,7 @@ class $ru extends S {
|
|||
@override
|
||||
String get transaction_sent => "Tранзакция отправлена!";
|
||||
@override
|
||||
String get send_fee => "Комиссия:";
|
||||
String get send_fee => "Комиссия";
|
||||
@override
|
||||
String get password => "Пароль";
|
||||
@override
|
||||
|
@ -2472,7 +2472,7 @@ class $ko extends S {
|
|||
@override
|
||||
String get transaction_sent => "거래가 전송되었습니다!";
|
||||
@override
|
||||
String get send_fee => "회비:";
|
||||
String get send_fee => "회비";
|
||||
@override
|
||||
String get password => "암호";
|
||||
@override
|
||||
|
@ -3164,7 +3164,7 @@ class $pt extends S {
|
|||
@override
|
||||
String get transaction_sent => "Transação enviada!";
|
||||
@override
|
||||
String get send_fee => "Taxa:";
|
||||
String get send_fee => "Taxa";
|
||||
@override
|
||||
String get password => "Senha";
|
||||
@override
|
||||
|
@ -3856,7 +3856,7 @@ class $uk extends S {
|
|||
@override
|
||||
String get transaction_sent => "Tранзакцію відправлено!";
|
||||
@override
|
||||
String get send_fee => "Комісія:";
|
||||
String get send_fee => "Комісія";
|
||||
@override
|
||||
String get password => "Пароль";
|
||||
@override
|
||||
|
@ -4548,7 +4548,7 @@ class $ja extends S {
|
|||
@override
|
||||
String get transaction_sent => "トランザクションが送信されました!";
|
||||
@override
|
||||
String get send_fee => "費用:";
|
||||
String get send_fee => "費用";
|
||||
@override
|
||||
String get password => "パスワード";
|
||||
@override
|
||||
|
@ -5244,7 +5244,7 @@ class $pl extends S {
|
|||
@override
|
||||
String get transaction_sent => "Transakcja wysłana!";
|
||||
@override
|
||||
String get send_fee => "Opłata:";
|
||||
String get send_fee => "Opłata";
|
||||
@override
|
||||
String get password => "Hasło";
|
||||
@override
|
||||
|
@ -5936,7 +5936,7 @@ class $es extends S {
|
|||
@override
|
||||
String get transaction_sent => "Transacción enviada!";
|
||||
@override
|
||||
String get send_fee => "Cuota:";
|
||||
String get send_fee => "Cuota";
|
||||
@override
|
||||
String get password => "Contraseña";
|
||||
@override
|
||||
|
@ -6628,7 +6628,7 @@ class $nl extends S {
|
|||
@override
|
||||
String get transaction_sent => "Transactie verzonden!";
|
||||
@override
|
||||
String get send_fee => "Vergoeding:";
|
||||
String get send_fee => "Vergoeding";
|
||||
@override
|
||||
String get password => "Wachtwoord";
|
||||
@override
|
||||
|
@ -7320,7 +7320,7 @@ class $zh extends S {
|
|||
@override
|
||||
String get transaction_sent => "交易已发送";
|
||||
@override
|
||||
String get send_fee => "費用:";
|
||||
String get send_fee => "費用";
|
||||
@override
|
||||
String get password => "密码";
|
||||
@override
|
||||
|
|
|
@ -18,8 +18,7 @@ class AddressPage extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Center(
|
||||
child: QRWidget(addressListViewModel: addressListViewModel),
|
||||
)
|
||||
),
|
||||
)),
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pushNamed(Routes.receive),
|
||||
child: Container(
|
||||
|
@ -30,21 +29,20 @@ class AddressPage extends StatelessWidget {
|
|||
borderRadius: BorderRadius.all(Radius.circular(25)),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).textTheme.subhead.color,
|
||||
width: 1
|
||||
),
|
||||
color: Theme.of(context).buttonColor
|
||||
),
|
||||
width: 1),
|
||||
color: Theme.of(context).buttonColor),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
S.of(context).accounts_subaddresses,
|
||||
addressListViewModel.hasAccounts
|
||||
? S.of(context).accounts_subaddresses
|
||||
: S.of(context).addresses,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white
|
||||
),
|
||||
color: Colors.white),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
|
|
|
@ -13,7 +13,8 @@ import 'package:cake_wallet/utils/date_formatter.dart';
|
|||
import 'package:hive/hive.dart';
|
||||
|
||||
class TransactionDetailsPage extends BasePage {
|
||||
TransactionDetailsPage(this.transactionInfo, bool showRecipientAddress, Box<TransactionDescription> transactionDescriptionBox)
|
||||
TransactionDetailsPage(this.transactionInfo, bool showRecipientAddress,
|
||||
Box<TransactionDescription> transactionDescriptionBox)
|
||||
: _items = [] {
|
||||
final dateFormat = DateFormatter.withCurrentLocal();
|
||||
final tx = transactionInfo;
|
||||
|
@ -30,9 +31,7 @@ class TransactionDetailsPage extends BasePage {
|
|||
StandartListItem(
|
||||
title: S.current.transaction_details_amount,
|
||||
value: tx.amountFormatted()),
|
||||
StandartListItem(
|
||||
title: S.current.send_fee,
|
||||
value: tx.feeFormatted())
|
||||
StandartListItem(title: S.current.send_fee, value: tx.feeFormatted())
|
||||
];
|
||||
|
||||
if (tx.key?.isNotEmpty ?? null) {
|
||||
|
@ -56,14 +55,18 @@ class TransactionDetailsPage extends BasePage {
|
|||
title: S.current.transaction_details_height, value: '${tx.height}'),
|
||||
StandartListItem(
|
||||
title: S.current.transaction_details_amount,
|
||||
value: tx.amountFormatted())
|
||||
value: tx.amountFormatted()),
|
||||
if (tx.feeFormatted()?.isNotEmpty)
|
||||
StandartListItem(title: S.current.send_fee, value: tx.feeFormatted())
|
||||
];
|
||||
|
||||
_items.addAll(items);
|
||||
}
|
||||
|
||||
if (showRecipientAddress) {
|
||||
final recipientAddress = transactionDescriptionBox.values.firstWhere((val) => val.id == transactionInfo.id, orElse: () => null)?.recipientAddress;
|
||||
final recipientAddress = transactionDescriptionBox.values
|
||||
.firstWhere((val) => val.id == transactionInfo.id, orElse: () => null)
|
||||
?.recipientAddress;
|
||||
|
||||
if (recipientAddress?.isNotEmpty ?? false) {
|
||||
_items.add(StandartListItem(
|
||||
|
|
|
@ -95,7 +95,7 @@ abstract class BalanceViewModelBase with Store {
|
|||
|
||||
if (_wallet is BitcoinWallet) {
|
||||
return WalletBalance(
|
||||
unlockedBalance: _wallet.balance.totalFormatted,
|
||||
unlockedBalance: _wallet.balance.confirmedFormatted,
|
||||
totalBalance: _wallet.balance.totalFormatted);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue