CAKE-334 | applied unspent coins control to the app; added unspent_coins_info.dart; reworked createTransaction(), calculateEstimatedFee() and updateUnspent() methods in the electrum_wallet.dart; fixed unspent_coins_list_view_model.dart, unspent_coins_details_view_model.dart, unspent_coins_list_item.dart, unspent_coins_list_page.dart and unspent_coins_details_page.dart; fixed bitcoin_transaction_wrong_balance_exception.dart; added properties to bitcoin_unspent.dart; applied localization to unspent coins pages
parent
3f81f708e5
commit
20e0c830cf
@ -1,4 +1,10 @@
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
|
||||
class BitcoinTransactionWrongBalanceException implements Exception {
|
||||
BitcoinTransactionWrongBalanceException(this.currency);
|
||||
|
||||
final CryptoCurrency currency;
|
||||
|
||||
@override
|
||||
String toString() => 'Wrong balance. Not enough BTC on your balance.';
|
||||
String toString() => 'Wrong balance. Not enough ${currency.title} on your balance.';
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'unspent_coins_info.g.dart';
|
||||
|
||||
@HiveType(typeId: UnspentCoinsInfo.typeId)
|
||||
class UnspentCoinsInfo extends HiveObject {
|
||||
UnspentCoinsInfo({
|
||||
this.walletId,
|
||||
this.hash,
|
||||
this.isFrozen,
|
||||
this.isSending,
|
||||
this.note});
|
||||
|
||||
static const typeId = 9;
|
||||
static const boxName = 'Unspent';
|
||||
static const boxKey = 'unspentBoxKey';
|
||||
|
||||
@HiveField(0)
|
||||
String walletId;
|
||||
|
||||
@HiveField(1)
|
||||
String hash;
|
||||
|
||||
@HiveField(2)
|
||||
bool isFrozen;
|
||||
|
||||
@HiveField(3)
|
||||
bool isSending;
|
||||
|
||||
@HiveField(4)
|
||||
String note;
|
||||
}
|
@ -1,14 +1,33 @@
|
||||
class UnspentCoinsItem {
|
||||
UnspentCoinsItem({
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'unspent_coins_item.g.dart';
|
||||
|
||||
class UnspentCoinsItem = UnspentCoinsItemBase with _$UnspentCoinsItem;
|
||||
|
||||
abstract class UnspentCoinsItemBase with Store {
|
||||
UnspentCoinsItemBase({
|
||||
this.address,
|
||||
this.amount,
|
||||
this.hash,
|
||||
this.isFrozen,
|
||||
this.note,
|
||||
this.isSending = true});
|
||||
this.isSending});
|
||||
|
||||
@observable
|
||||
String address;
|
||||
|
||||
@observable
|
||||
String amount;
|
||||
|
||||
@observable
|
||||
String hash;
|
||||
|
||||
@observable
|
||||
bool isFrozen;
|
||||
|
||||
@observable
|
||||
String note;
|
||||
|
||||
final String address;
|
||||
final String amount;
|
||||
final bool isFrozen;
|
||||
final String note;
|
||||
final bool isSending;
|
||||
@observable
|
||||
bool isSending;
|
||||
}
|
@ -1,61 +1,58 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cake_wallet/bitcoin/electrum_wallet.dart';
|
||||
import 'package:cake_wallet/bitcoin/unspent_coins_info.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'unspent_coins_list_view_model.g.dart';
|
||||
|
||||
const List<Map<String, dynamic>> unspentCoinsMap = [
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.00358 BTC",
|
||||
"isFrozen" : true,
|
||||
"note" : "333cvgf23132132132132131321321314rwrtdggfdddewq ewqasfdxgdhgfgfszczcxgbhhhbcgbc"},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.00567894 BTC",
|
||||
"note" : "sfjskf"},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.00087 BTC",
|
||||
"isFrozen" : false},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.00012 BTC",
|
||||
"isFrozen" : true,
|
||||
"note" : "333cvgf23132132132132131321321314rwrtdggfdddewq ewqasfdxgdhgfgfszczcxgbhhhbcgbc"},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.00574 BTC",
|
||||
"note" : "sffsfsdsgs"},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.000482 BTC",
|
||||
"isFrozen" : false},
|
||||
<String, dynamic>{},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.00012 BTC",
|
||||
"isFrozen" : true,
|
||||
"note" : "333cvgf23132132132132131321321314rwrtdggfdddewq ewqasfdxgdhgfgfszczcxgbhhhbcgbc"},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.00574 BTC",
|
||||
"note" : "sffsfsdsgs"},
|
||||
<String, dynamic>{
|
||||
"address" : "bc1qm80mu5p3mf04a7cj7teymasf04dwpc3av2fwtr",
|
||||
"amount" : "0.000482 BTC",
|
||||
"isFrozen" : false},
|
||||
];
|
||||
|
||||
class UnspentCoinsListViewModel = UnspentCoinsListViewModelBase with _$UnspentCoinsListViewModel;
|
||||
|
||||
abstract class UnspentCoinsListViewModelBase with Store {
|
||||
UnspentCoinsListViewModelBase({
|
||||
@required WalletBase wallet,
|
||||
@required Box<UnspentCoinsInfo> unspentCoinsInfo}) {
|
||||
_unspentCoinsInfo = unspentCoinsInfo;
|
||||
_wallet = wallet as ElectrumWallet;
|
||||
_wallet.updateUnspent();
|
||||
}
|
||||
|
||||
ElectrumWallet _wallet;
|
||||
Box<UnspentCoinsInfo> _unspentCoinsInfo;
|
||||
|
||||
@computed
|
||||
ObservableList<UnspentCoinsItem> get items =>
|
||||
ObservableList.of(unspentCoinsMap.map((elem) =>
|
||||
UnspentCoinsItem(
|
||||
address: elem["address"] as String,
|
||||
amount: elem["amount"] as String,
|
||||
isFrozen: elem["isFrozen"] as bool,
|
||||
note: elem["note"] as String
|
||||
)));
|
||||
ObservableList.of(_wallet.unspentCoins.map((elem) {
|
||||
final amount = bitcoinAmountToString(amount: elem.value) +
|
||||
' ${_wallet.currency.title}';
|
||||
|
||||
return UnspentCoinsItem(
|
||||
address: elem.address.address,
|
||||
amount: amount,
|
||||
hash: elem.hash,
|
||||
isFrozen: elem.isFrozen,
|
||||
note: elem.note,
|
||||
isSending: elem.isSending
|
||||
);
|
||||
}));
|
||||
|
||||
Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async {
|
||||
try {
|
||||
final info = _unspentCoinsInfo.values
|
||||
.firstWhere((element) => element.walletId.contains(_wallet.id) &&
|
||||
element.hash.contains(item.hash));
|
||||
|
||||
info.isFrozen = item.isFrozen;
|
||||
info.isSending = item.isSending;
|
||||
info.note = item.note;
|
||||
|
||||
await info.save();
|
||||
await _wallet.updateUnspent();
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue