Merge branch 'main' of https://github.com/cake-tech/cake_wallet into CW-492-moonpay

This commit is contained in:
fosse 2023-11-16 11:10:38 -05:00
commit 06c8a73889
42 changed files with 325 additions and 290 deletions

View file

@ -2,41 +2,41 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart';
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
import 'package:mobx/mobx.dart';
import 'package:rxdart/subjects.dart';
import 'package:flutter/foundation.dart';
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:cw_bitcoin/electrum_transaction_info.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:collection/collection.dart';
import 'package:cw_bitcoin/address_to_output_script.dart';
import 'package:cw_bitcoin/bitcoin_address_record.dart';
import 'package:cw_bitcoin/electrum_balance.dart';
import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart';
import 'package:cw_bitcoin/electrum_transaction_history.dart';
import 'package:cw_bitcoin/bitcoin_transaction_no_inputs_exception.dart';
import 'package:cw_bitcoin/bitcoin_transaction_priority.dart';
import 'package:cw_bitcoin/bitcoin_transaction_wrong_balance_exception.dart';
import 'package:cw_bitcoin/bitcoin_unspent.dart';
import 'package:cw_bitcoin/bitcoin_wallet_keys.dart';
import 'package:cw_bitcoin/electrum.dart';
import 'package:cw_bitcoin/electrum_balance.dart';
import 'package:cw_bitcoin/electrum_transaction_history.dart';
import 'package:cw_bitcoin/electrum_transaction_info.dart';
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
import 'package:cw_bitcoin/file.dart';
import 'package:cw_bitcoin/pending_bitcoin_transaction.dart';
import 'package:cw_bitcoin/script_hash.dart';
import 'package:cw_bitcoin/utils.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/sync_status.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_bitcoin/electrum.dart';
import 'package:hex/hex.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:collection/collection.dart';
import 'package:bip32/bip32.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/pathForWallet.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/sync_status.dart';
import 'package:cw_core/transaction_direction.dart';
import 'package:cw_core/transaction_priority.dart';
import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:flutter/foundation.dart';
import 'package:hex/hex.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:rxdart/subjects.dart';
part 'electrum_wallet.g.dart';
@ -79,8 +79,7 @@ abstract class ElectrumWalletBase
}
static bitcoin.HDWallet bitcoinCashHDWallet(Uint8List seedBytes) =>
bitcoin.HDWallet.fromSeed(seedBytes)
.derivePath("m/44'/145'/0'/0");
bitcoin.HDWallet.fromSeed(seedBytes).derivePath("m/44'/145'/0'/0");
static int estimatedTransactionSize(int inputsCount, int outputsCounts) =>
inputsCount * 146 + outputsCounts * 33 + 8;
@ -295,7 +294,9 @@ abstract class ElectrumWalletBase
final p2wpkh = bitcoin
.P2WPKH(
data: generatePaymentData(
hd: input.bitcoinAddressRecord.isHidden ? walletAddresses.sideHd : walletAddresses.mainHd,
hd: input.bitcoinAddressRecord.isHidden
? walletAddresses.sideHd
: walletAddresses.mainHd,
index: input.bitcoinAddressRecord.index),
network: networkType)
.data;
@ -467,18 +468,20 @@ abstract class ElectrumWalletBase
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
Future<void> updateUnspent() async {
final unspent = await Future.wait(walletAddresses
.addresses.map((address) => electrumClient
final unspent = await Future.wait(walletAddresses.addresses.map((address) => electrumClient
.getListUnspentWithAddress(address.address, networkType)
.then((unspent) => unspent
.map((unspent) {
.then((unspent) => unspent.map((unspent) {
try {
return BitcoinUnspent.fromJSON(address, unspent);
} catch(_) {
} catch (_) {
return null;
}
}).whereNotNull())));
unspentCoins = unspent.expand((e) => e).toList();
unspentCoins.forEach((coin) async {
final tx = await fetchTransactionInfo(hash: coin.hash, height: 0);
coin.isChange = tx!.direction == TransactionDirection.outgoing;
});
if (unspentCoinsInfo.isEmpty) {
unspentCoins.forEach((coin) => _addCoinInfo(coin));
@ -515,6 +518,7 @@ abstract class ElectrumWalletBase
address: coin.bitcoinAddressRecord.address,
value: coin.value,
vout: coin.vout,
isChange: coin.isChange,
);
await unspentCoinsInfo.add(newInfo);
@ -657,7 +661,7 @@ abstract class ElectrumWalletBase
final addresses = walletAddresses.addresses.toList();
final balanceFutures = <Future<Map<String, dynamic>>>[];
for (var i = 0; i < addresses.length; i++) {
final addressRecord = addresses[i] ;
final addressRecord = addresses[i];
final sh = scriptHash(addressRecord.address, networkType: networkType);
final balanceFuture = electrumClient.getBalance(sh);
balanceFutures.add(balanceFuture);

View file

@ -14,7 +14,9 @@ class UnspentCoinsInfo extends HiveObject {
required this.address,
required this.vout,
required this.value,
this.keyImage = null
this.keyImage = null,
this.isChange = false,
this.accountIndex = 0
});
static const typeId = UNSPENT_COINS_INFO_TYPE_ID;
@ -48,6 +50,12 @@ class UnspentCoinsInfo extends HiveObject {
@HiveField(8, defaultValue: null)
String? keyImage;
@HiveField(9, defaultValue: false)
bool isChange;
@HiveField(10, defaultValue: 0)
int accountIndex;
String get note => noteRaw ?? '';
set note(String value) => noteRaw = value;

View file

@ -2,6 +2,7 @@ class Unspent {
Unspent(this.address, this.hash, this.value, this.vout, this.keyImage)
: isSending = true,
isFrozen = false,
isChange = false,
note = '';
final String address;
@ -10,6 +11,7 @@ class Unspent {
final int vout;
final String? keyImage;
bool isChange;
bool isSending;
bool isFrozen;
String note;

View file

@ -841,6 +841,12 @@ extern "C"
return m_transaction_history->count();
}
TransactionInfoRow* get_transaction(char * txId)
{
Monero::TransactionInfo *row = m_transaction_history->transaction(std::string(txId));
return new TransactionInfoRow(row);
}
int LedgerExchange(
unsigned char *command,
unsigned int cmd_len,
@ -970,6 +976,15 @@ extern "C"
return result;
}
void freeze_coin(int index)
{
m_coins->setFrozen(index);
}
void thaw_coin(int index)
{
m_coins->thaw(index);
}
#ifdef __cplusplus
}

View file

@ -16,8 +16,20 @@ final coinNative = moneroApi
.lookup<NativeFunction<coin>>('coin')
.asFunction<GetCoin>();
final freezeCoinNative = moneroApi
.lookup<NativeFunction<freeze_coin>>('freeze_coin')
.asFunction<FreezeCoin>();
final thawCoinNative = moneroApi
.lookup<NativeFunction<thaw_coin>>('thaw_coin')
.asFunction<ThawCoin>();
void refreshCoins(int accountIndex) => refreshCoinsNative(accountIndex);
int countOfCoins() => coinsCountNative();
CoinsInfoRow getCoin(int index) => coinNative(index).ref;
void freezeCoin(int index) => freezeCoinNative(index);
void thawCoin(int index) => thawCoinNative(index);

View file

@ -1,6 +1,7 @@
import 'dart:ffi';
import 'package:cw_monero/api/structs/coins_info_row.dart';
import 'package:cw_monero/api/structs/pending_transaction.dart';
import 'package:cw_monero/api/structs/transaction_info_row.dart';
import 'package:cw_monero/api/structs/ut8_box.dart';
import 'package:ffi/ffi.dart';
@ -81,6 +82,8 @@ typedef account_set_label = Void Function(Int32 accountIndex, Pointer<Utf8> labe
typedef transactions_refresh = Void Function();
typedef get_transaction = Pointer<TransactionInfoRow> Function(Pointer<Utf8> txId);
typedef get_tx_key = Pointer<Utf8>? Function(Pointer<Utf8> txId);
typedef transactions_count = Int64 Function();
@ -139,3 +142,7 @@ typedef coins_count = Int64 Function();
// typedef coins_from_txid = Pointer<CoinsInfoRow> Function(Pointer<Utf8> txid);
typedef coin = Pointer<CoinsInfoRow> Function(Int32 index);
typedef freeze_coin = Void Function(Int32 index);
typedef thaw_coin = Void Function(Int32 index);

View file

@ -1,15 +1,16 @@
import 'dart:ffi';
import 'package:cw_monero/api/convert_utf8_to_string.dart';
import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart';
import 'package:cw_monero/api/monero_api.dart';
import 'package:cw_monero/api/monero_output.dart';
import 'package:cw_monero/api/signatures.dart';
import 'package:cw_monero/api/structs/pending_transaction.dart';
import 'package:cw_monero/api/structs/transaction_info_row.dart';
import 'package:cw_monero/api/structs/ut8_box.dart';
import 'package:cw_monero/api/types.dart';
import 'package:ffi/ffi.dart';
import 'package:flutter/foundation.dart';
import 'package:cw_monero/api/signatures.dart';
import 'package:cw_monero/api/types.dart';
import 'package:cw_monero/api/monero_api.dart';
import 'package:cw_monero/api/structs/transaction_info_row.dart';
import 'package:cw_monero/api/structs/pending_transaction.dart';
import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart';
final transactionsRefreshNative = moneroApi
.lookup<NativeFunction<transactions_refresh>>('transactions_refresh')
@ -38,6 +39,10 @@ final transactionCommitNative = moneroApi
final getTxKeyNative =
moneroApi.lookup<NativeFunction<get_tx_key>>('get_tx_key').asFunction<GetTxKey>();
final getTransactionNative = moneroApi
.lookup<NativeFunction<get_transaction>>('get_transaction')
.asFunction<GetTransaction>();
String getTxKey(String txId) {
final txIdPointer = txId.toNativeUtf8();
final keyPointer = getTxKeyNative(txIdPointer);
@ -65,6 +70,11 @@ List<TransactionInfoRow> getAllTransactions() {
.toList();
}
TransactionInfoRow getTransaction(String txId) {
final txIdPointer = txId.toNativeUtf8();
return getTransactionNative(txIdPointer).ref;
}
PendingTransactionDescription createTransactionSync(
{required String address,
required String paymentId,

View file

@ -1,6 +1,7 @@
import 'dart:ffi';
import 'package:cw_monero/api/structs/coins_info_row.dart';
import 'package:cw_monero/api/structs/pending_transaction.dart';
import 'package:cw_monero/api/structs/transaction_info_row.dart';
import 'package:cw_monero/api/structs/ut8_box.dart';
import 'package:ffi/ffi.dart';
@ -81,6 +82,8 @@ typedef AccountSetLabel = void Function(int accountIndex, Pointer<Utf8> label);
typedef TransactionsRefresh = void Function();
typedef GetTransaction = Pointer<TransactionInfoRow> Function(Pointer<Utf8> txId);
typedef GetTxKey = Pointer<Utf8>? Function(Pointer<Utf8> txId);
typedef TransactionsCount = int Function();
@ -139,3 +142,7 @@ typedef RefreshCoins = void Function(int);
typedef CoinsCount = int Function();
typedef GetCoin = Pointer<CoinsInfoRow> Function(int);
typedef FreezeCoin = void Function(int);
typedef ThawCoin = void Function(int);

View file

@ -1,28 +1,20 @@
import 'package:cw_core/unspent_transaction_output.dart';
import 'package:cw_monero/api/structs/coins_info_row.dart';
class MoneroUnspent {
MoneroUnspent(this.address, this.hash, this.keyImage, this.value, this.isFrozen, this.isUnlocked)
: isSending = true,
note = '';
class MoneroUnspent extends Unspent {
MoneroUnspent(
String address, String hash, String keyImage, int value, bool isFrozen, this.isUnlocked)
: super(address, hash, value, 0, keyImage) {
this.isFrozen = isFrozen;
}
MoneroUnspent.fromCoinsInfoRow(CoinsInfoRow coinsInfoRow)
: address = coinsInfoRow.getAddress(),
hash = coinsInfoRow.getHash(),
keyImage = coinsInfoRow.getKeyImage(),
value = coinsInfoRow.amount,
isFrozen = coinsInfoRow.frozen == 1,
isUnlocked = coinsInfoRow.unlocked == 1,
isSending = true,
note = '';
final String address;
final String hash;
final String keyImage;
final int value;
factory MoneroUnspent.fromCoinsInfoRow(CoinsInfoRow coinsInfoRow) => MoneroUnspent(
coinsInfoRow.getAddress(),
coinsInfoRow.getHash(),
coinsInfoRow.getKeyImage(),
coinsInfoRow.amount,
coinsInfoRow.frozen == 1,
coinsInfoRow.unlocked == 1);
final bool isUnlocked;
bool isFrozen;
bool isSending;
String note;
}

View file

@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'package:cw_core/account.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/monero_amount_format.dart';
@ -22,14 +23,14 @@ import 'package:cw_monero/api/transaction_history.dart' as transaction_history;
import 'package:cw_monero/api/wallet.dart' as monero_wallet;
import 'package:cw_monero/exceptions/monero_transaction_creation_exception.dart';
import 'package:cw_monero/exceptions/monero_transaction_no_inputs_exception.dart';
import 'package:cw_monero/pending_monero_transaction.dart';
import 'package:cw_monero/monero_transaction_creation_credentials.dart';
import 'package:cw_monero/monero_transaction_history.dart';
import 'package:cw_monero/monero_transaction_info.dart';
import 'package:cw_monero/monero_unspent.dart';
import 'package:cw_monero/monero_wallet_addresses.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_monero/pending_monero_transaction.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
part 'monero_wallet.g.dart';
@ -204,7 +205,7 @@ abstract class MoneroWalletBase
for (final utx in unspentCoins) {
if (utx.isSending) {
allInputsAmount += utx.value;
inputs.add(utx.keyImage);
inputs.add(utx.keyImage!);
}
}
final spendAllCoins = inputs.length == unspentCoins.length;
@ -395,7 +396,9 @@ abstract class MoneroWalletBase
for (var i = 0; i < coinCount; i++) {
final coin = getCoin(i);
if (coin.spent == 0) {
unspentCoins.add(MoneroUnspent.fromCoinsInfoRow(coin));
final unspent = MoneroUnspent.fromCoinsInfoRow(coin);
unspent.isChange = transaction_history.getTransaction(unspent.hash).direction == 1;
unspentCoins.add(unspent);
}
}
@ -406,8 +409,10 @@ abstract class MoneroWalletBase
if (unspentCoins.isNotEmpty) {
unspentCoins.forEach((coin) {
final coinInfoList = unspentCoinsInfo.values
.where((element) => element.walletId.contains(id) && element.hash.contains(coin.hash));
final coinInfoList = unspentCoinsInfo.values.where((element) =>
element.walletId.contains(id) &&
element.accountIndex == walletAddresses.account!.id &&
element.keyImage!.contains(coin.keyImage!));
if (coinInfoList.isNotEmpty) {
final coinInfo = coinInfoList.first;
@ -435,7 +440,9 @@ abstract class MoneroWalletBase
address: coin.address,
value: coin.value,
vout: 0,
keyImage: coin.keyImage);
keyImage: coin.keyImage,
isChange: coin.isChange,
accountIndex: walletAddresses.account!.id);
await unspentCoinsInfo.add(newInfo);
}
@ -443,12 +450,13 @@ abstract class MoneroWalletBase
Future<void> _refreshUnspentCoinsInfo() async {
try {
final List<dynamic> keys = <dynamic>[];
final currentWalletUnspentCoins =
unspentCoinsInfo.values.where((element) => element.walletId.contains(id));
final currentWalletUnspentCoins = unspentCoinsInfo.values.where((element) =>
element.walletId.contains(id) && element.accountIndex == walletAddresses.account!.id);
if (currentWalletUnspentCoins.isNotEmpty) {
currentWalletUnspentCoins.forEach((element) {
final existUnspentCoins = unspentCoins.where((coin) => element.hash.contains(coin.hash));
final existUnspentCoins =
unspentCoins.where((coin) => element.keyImage!.contains(coin.keyImage!));
if (existUnspentCoins.isEmpty) {
keys.add(element.key);
@ -566,7 +574,8 @@ abstract class MoneroWalletBase
int _getFrozenBalance() {
var frozenBalance = 0;
for (var coin in unspentCoinsInfo.values) {
for (var coin in unspentCoinsInfo.values.where((element) =>
element.walletId == id && element.accountIndex == walletAddresses.account!.id)) {
if (coin.isFrozen) frozenBalance += coin.value;
}

View file

@ -321,10 +321,7 @@ class CWMonero extends Monero {
@override
List<Unspent> getUnspents(Object wallet) {
final moneroWallet = wallet as MoneroWallet;
return moneroWallet.unspentCoins
.map((MoneroUnspent moneroUnspent) => Unspent(moneroUnspent.address, moneroUnspent.hash,
moneroUnspent.value, 0, moneroUnspent.keyImage))
.toList();
return moneroWallet.unspentCoins;
}
@override

View file

@ -1,15 +1,13 @@
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/screens/unspent_coins/widgets/unspent_coins_list_item.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_list_view_model.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
class UnspentCoinsListPage extends BasePage {
UnspentCoinsListPage({required this.unspentCoinsListViewModel});
@ -17,31 +15,10 @@ class UnspentCoinsListPage extends BasePage {
@override
String get title => S.current.unspent_coins_title;
//@override
//Widget trailing(BuildContext context) {
// final questionImage = Image.asset('assets/images/question_mark.png',
// color: Theme.of(context).extension<CakeTextTheme>()!.titleColor);
// return SizedBox(
// height: 20.0,
// width: 20.0,
// child: ButtonTheme(
// minWidth: double.minPositive,
// child: FlatButton(
// highlightColor: Colors.transparent,
// splashColor: Colors.transparent,
// padding: EdgeInsets.all(0),
// onPressed: () => showUnspentCoinsAlert(context),
// child: questionImage),
// ),
// );
//}
final UnspentCoinsListViewModel unspentCoinsListViewModel;
@override
Widget body(BuildContext context) =>
UnspentCoinsListForm(unspentCoinsListViewModel);
Widget body(BuildContext context) => UnspentCoinsListForm(unspentCoinsListViewModel);
}
class UnspentCoinsListForm extends StatefulWidget {
@ -50,8 +27,7 @@ class UnspentCoinsListForm extends StatefulWidget {
final UnspentCoinsListViewModel unspentCoinsListViewModel;
@override
UnspentCoinsListFormState createState() =>
UnspentCoinsListFormState(unspentCoinsListViewModel);
UnspentCoinsListFormState createState() => UnspentCoinsListFormState(unspentCoinsListViewModel);
}
class UnspentCoinsListFormState extends State<UnspentCoinsListForm> {
@ -59,16 +35,6 @@ class UnspentCoinsListFormState extends State<UnspentCoinsListForm> {
final UnspentCoinsListViewModel unspentCoinsListViewModel;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(afterLayout);
}
void afterLayout(dynamic _) {
//showUnspentCoinsAlert(context);
}
@override
Widget build(BuildContext context) {
return Container(
@ -76,8 +42,7 @@ class UnspentCoinsListFormState extends State<UnspentCoinsListForm> {
child: Observer(
builder: (_) => ListView.separated(
itemCount: unspentCoinsListViewModel.items.length,
separatorBuilder: (_, __) =>
SizedBox(height: 15),
separatorBuilder: (_, __) => SizedBox(height: 15),
itemBuilder: (_, int index) {
return Observer(builder: (_) {
final item = unspentCoinsListViewModel.items[index];
@ -86,9 +51,7 @@ class UnspentCoinsListFormState extends State<UnspentCoinsListForm> {
: item.address;
return GestureDetector(
onTap: () =>
Navigator.of(context)
.pushNamed(Routes.unspentCoinsDetails,
onTap: () => Navigator.of(context).pushNamed(Routes.unspentCoinsDetails,
arguments: [item, unspentCoinsListViewModel]),
child: UnspentCoinsListItem(
note: item.note,
@ -96,28 +59,14 @@ class UnspentCoinsListFormState extends State<UnspentCoinsListForm> {
address: address,
isSending: item.isSending,
isFrozen: item.isFrozen,
isChange: item.isChange,
onCheckBoxTap: item.isFrozen
? null
: () async {
item.isSending = !item.isSending;
await unspentCoinsListViewModel
.saveUnspentCoinInfo(item);}));
await unspentCoinsListViewModel.saveUnspentCoinInfo(item);
}));
});
}
)
)
);
})));
}
}
void showUnspentCoinsAlert(BuildContext context) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: '',
alertContent: 'Information about unspent coins',
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
}

View file

@ -1,8 +1,8 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/generated/i18n.dart';
class UnspentCoinsListItem extends StatelessWidget {
UnspentCoinsListItem({
@ -11,6 +11,7 @@ class UnspentCoinsListItem extends StatelessWidget {
required this.address,
required this.isSending,
required this.isFrozen,
required this.isChange,
this.onCheckBoxTap,
});
@ -19,6 +20,7 @@ class UnspentCoinsListItem extends StatelessWidget {
final String address;
final bool isSending;
final bool isFrozen;
final bool isChange;
final Function()? onCheckBoxTap;
@override
@ -27,9 +29,8 @@ class UnspentCoinsListItem extends StatelessWidget {
final selectedItemColor = Theme.of(context).primaryColor;
final itemColor = isSending ? selectedItemColor : unselectedItemColor;
final amountColor = isSending
? Colors.white
: Theme.of(context).extension<CakeTextTheme>()!.buttonTextColor;
final amountColor =
isSending ? Colors.white : Theme.of(context).extension<CakeTextTheme>()!.buttonTextColor;
final addressColor = isSending
? Colors.white.withOpacity(0.5)
: Theme.of(context).extension<CakeTextTheme>()!.buttonSecondaryTextColor;
@ -47,7 +48,8 @@ class UnspentCoinsListItem extends StatelessWidget {
child: StandardCheckbox(
iconColor: amountColor,
borderColor: addressColor,
value: isSending, onChanged: (value) => onCheckBoxTap?.call())),
value: isSending,
onChanged: (value) => onCheckBoxTap?.call())),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -57,9 +59,7 @@ class UnspentCoinsListItem extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
if (note.isNotEmpty)
AutoSizeText(
note,
@ -69,8 +69,8 @@ class UnspentCoinsListItem extends StatelessWidget {
),
AutoSizeText(
amount,
style:
TextStyle(color: amountColor, fontSize: 15, fontWeight: FontWeight.w600),
style: TextStyle(
color: amountColor, fontSize: 15, fontWeight: FontWeight.w600),
maxLines: 1,
)
]),
@ -84,23 +84,41 @@ class UnspentCoinsListItem extends StatelessWidget {
alignment: Alignment.center,
child: Text(
S.of(context).frozen,
style:
TextStyle(color: amountColor, fontSize: 7, fontWeight: FontWeight.w600),
))
style: TextStyle(
color: amountColor, fontSize: 7, fontWeight: FontWeight.w600),
)),
],
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AutoSizeText(
'${address.substring(0, 5)}...${address.substring(address.length-5)}', // ToDo: Maybe use address label
'${address.substring(0, 5)}...${address.substring(address.length - 5)}', // ToDo: Maybe use address label
style: TextStyle(
color: addressColor,
fontSize: 12,
),
maxLines: 1,
),
if (isChange)
Container(
height: 17,
padding: EdgeInsets.only(left: 6, right: 6),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.5)),
color: Colors.white),
alignment: Alignment.center,
child: Text(
S.of(context).unspent_change,
style: TextStyle(
color: itemColor,
fontSize: 7,
fontWeight: FontWeight.w600,
),
),
),
],
),
),

View file

@ -175,10 +175,8 @@ abstract class BalanceViewModelBase with Store {
return '---';
}
return _getFiatBalance(
price: price,
cryptoAmount: getFormattedFrozenBalance(walletBalance)) + ' ' + fiatCurrency.toString();
return _getFiatBalance(price: price, cryptoAmount: getFormattedFrozenBalance(walletBalance)) +
' ${fiatCurrency.toString()}';
}
@computed
@ -201,10 +199,8 @@ abstract class BalanceViewModelBase with Store {
return '---';
}
return _getFiatBalance(
price: price,
cryptoAmount: walletBalance.formattedAvailableBalance) + ' ' + fiatCurrency.toString();
return _getFiatBalance(price: price, cryptoAmount: walletBalance.formattedAvailableBalance) +
' ${fiatCurrency.toString()}';
}
@computed
@ -216,10 +212,8 @@ abstract class BalanceViewModelBase with Store {
return '---';
}
return _getFiatBalance(
price: price,
cryptoAmount: walletBalance.formattedAdditionalBalance) + ' ' + fiatCurrency.toString();
return _getFiatBalance(price: price, cryptoAmount: walletBalance.formattedAdditionalBalance) +
' ${fiatCurrency.toString()}';
}
@computed

View file

@ -12,6 +12,7 @@ abstract class UnspentCoinsItemBase with Store {
required this.isFrozen,
required this.note,
required this.isSending,
required this.isChange,
required this.amountRaw,
required this.vout,
required this.keyImage
@ -35,6 +36,9 @@ abstract class UnspentCoinsItemBase with Store {
@observable
bool isSending;
@observable
bool isChange;
@observable
int amountRaw;

View file

@ -1,10 +1,8 @@
import 'package:collection/collection.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cw_core/unspent_transaction_output.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/unspent_transaction_output.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart';
@ -26,66 +24,49 @@ abstract class UnspentCoinsListViewModelBase with Store {
@computed
ObservableList<UnspentCoinsItem> get items => ObservableList.of(_getUnspents().map((elem) {
final amount = formatAmountToString(elem.value) + ' ${wallet.currency.title}';
final info =
getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout, elem.keyImage);
return UnspentCoinsItem(
address: elem.address,
amount: amount,
amount: '${formatAmountToString(elem.value)} ${wallet.currency.title}',
hash: elem.hash,
isFrozen: info?.isFrozen ?? false,
note: info?.note ?? '',
isSending: info?.isSending ?? true,
isFrozen: info.isFrozen,
note: info.note,
isSending: info.isSending,
amountRaw: elem.value,
vout: elem.vout,
keyImage: elem.keyImage);
keyImage: elem.keyImage,
isChange: elem.isChange,
);
}));
Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async {
try {
final info =
getUnspentCoinInfo(item.hash, item.address, item.amountRaw, item.vout, item.keyImage);
if (info == null) {
final newInfo = UnspentCoinsInfo(
walletId: wallet.id,
hash: item.hash,
address: item.address,
value: item.amountRaw,
vout: item.vout,
isFrozen: item.isFrozen,
isSending: item.isSending,
noteRaw: item.note,
keyImage: item.keyImage);
await _unspentCoinsInfo.add(newInfo);
_updateUnspents();
wallet.updateBalance();
return;
}
info.isFrozen = item.isFrozen;
info.isSending = item.isSending;
info.note = item.note;
await info.save();
_updateUnspents();
wallet.updateBalance();
await _updateUnspents();
await wallet.updateBalance();
} catch (e) {
print(e.toString());
}
}
UnspentCoinsInfo? getUnspentCoinInfo(
String hash, String address, int value, int vout, String? keyImage) {
return _unspentCoinsInfo.values.firstWhereOrNull((element) =>
UnspentCoinsInfo getUnspentCoinInfo(
String hash, String address, int value, int vout, String? keyImage) =>
_unspentCoinsInfo.values.firstWhere((element) =>
element.walletId == wallet.id &&
element.hash == hash &&
element.address == address &&
element.value == value &&
element.vout == vout &&
element.keyImage == keyImage);
}
String formatAmountToString(int fullBalance) {
if (wallet.type == WalletType.monero)
@ -95,7 +76,7 @@ abstract class UnspentCoinsListViewModelBase with Store {
return '';
}
void _updateUnspents() {
Future<void> _updateUnspents() async {
if (wallet.type == WalletType.monero) return monero!.updateUnspents(wallet);
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type))
return bitcoin!.updateUnspents(wallet);

View file

@ -731,5 +731,6 @@
"camera_permission_is_required": ".ﺍﺮﻴﻣﺎﻜﻟﺍ ﻥﺫﺇ ﺏﻮﻠﻄﻣ",
"switchToETHWallet": "ﻯﺮﺧﺃ ﺓﺮﻣ ﺔﻟﻭﺎﺤﻤﻟﺍﻭ Ethereum ﺔﻈﻔﺤﻣ ﻰﻟﺇ ﻞﻳﺪﺒﺘﻟﺍ ﻰﺟﺮﻳ",
"moonpay_exchange_description": "تبديل العملة المشفرة سلسة.",
"kyc_required": "الحساب و KYC مطلوب"
"kyc_required": "الحساب و KYC مطلوب",
"unspent_change": "يتغير"
}

View file

@ -727,5 +727,6 @@
"camera_permission_is_required": "Изисква се разрешение за камерата.\nМоля, активирайте го от настройките на приложението.",
"switchToETHWallet": "Моля, преминете към портфейл Ethereum и опитайте отново",
"moonpay_exchange_description": "Безпроблемна размяна на криптовалута.",
"kyc_required": "Изисква се акаунт и KYC"
"kyc_required": "Изисква се акаунт и KYC",
"unspent_change": "Промяна"
}

View file

@ -727,5 +727,6 @@
"camera_permission_is_required": "Vyžaduje se povolení fotoaparátu.\nPovolte jej v nastavení aplikace.",
"switchToETHWallet": "Přejděte na peněženku Ethereum a zkuste to znovu",
"moonpay_exchange_description": "Bezproblémové výměny kryptoměny.",
"kyc_required": "Účet a KYC vyžadoval"
"kyc_required": "Účet a KYC vyžadoval",
"unspent_change": "Změna"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "Eine Kameraerlaubnis ist erforderlich.\nBitte aktivieren Sie es in den App-Einstellungen.",
"switchToETHWallet": "Bitte wechseln Sie zu einem Ethereum-Wallet und versuchen Sie es erneut",
"moonpay_exchange_description": "Nahtloser Kryptowährungstausch.",
"kyc_required": "Konto und KYC erforderlich"
"kyc_required": "Konto und KYC erforderlich",
"unspent_change": "Wechselgeld"
}

View file

@ -736,5 +736,6 @@
"camera_permission_is_required": "Camera permission is required. \nPlease enable it from app settings.",
"switchToETHWallet": "Please switch to an Ethereum wallet and try again",
"moonpay_exchange_description": "Seamless cryptocurrency swapping.",
"kyc_required": "Account and KYC required"
"kyc_required": "Account and KYC required",
"unspent_change": "Change"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "Se requiere permiso de la cámara.\nHabilítelo desde la configuración de la aplicación.",
"switchToETHWallet": "Cambie a una billetera Ethereum e inténtelo nuevamente.",
"moonpay_exchange_description": "Cambio de criptomonedas sin costuras.",
"kyc_required": "Cuenta y KYC requerido"
"kyc_required": "Cuenta y KYC requerido",
"unspent_change": "Cambiar"
}

View file

@ -730,10 +730,11 @@
"enter_seed_phrase": "Entrez votre phrase secrète (seed)",
"add_contact": "Ajouter le contact",
"exchange_provider_unsupported": "${providerName} n'est plus pris en charge !",
"domain_looks_up": "Recherches de domaine",
"domain_looks_up": "Résolution de nom",
"require_for_exchanges_to_external_wallets": "Exiger pour les échanges vers des portefeuilles externes",
"camera_permission_is_required": "L'autorisation de la caméra est requise.\nVeuillez l'activer à partir des paramètres de l'application.",
"switchToETHWallet": "Veuillez passer à un portefeuille (wallet) Ethereum et réessayer",
"moonpay_exchange_description": "Échange de crypto-monnaie sans couture.",
"kyc_required": "Compte et KYC requis"
"kyc_required": "Compte et KYC requis",
"camera_permission_is_required": "L'autorisation d'accès à la caméra est requise.\nVeuillez l'activer depuis les paramètres de l'application.",
"switchToETHWallet": "Veuillez passer à un portefeuille (wallet) Ethereum et réessayer",
"unspent_change": "Changement"
}

View file

@ -713,5 +713,6 @@
"camera_permission_is_required": "Ana buƙatar izinin kyamara.\nDa fatan za a kunna shi daga saitunan app.",
"switchToETHWallet": "Da fatan za a canza zuwa walat ɗin Ethereum kuma a sake gwadawa",
"moonpay_exchange_description": "Sumba crypptocurrency.",
"kyc_required": "Asusun da KyKC da ake buƙata"
"kyc_required": "Asusun da KyKC da ake buƙata",
"unspent_change": "Canza"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "कैमरे की अनुमति आवश्यक है.\nकृपया इसे ऐप सेटिंग से सक्षम करें।",
"switchToETHWallet": "कृपया एथेरियम वॉलेट पर स्विच करें और पुनः प्रयास करें",
"moonpay_exchange_description": "सीमलेस क्रिप्टोक्यूरेंसी स्वैपिंग।",
"kyc_required": "खाता और KYC की आवश्यकता है"
"kyc_required": "खाता और KYC की आवश्यकता है",
"unspent_change": "परिवर्तन"
}

View file

@ -733,5 +733,6 @@
"camera_permission_is_required": "Potrebno je dopuštenje kamere.\nOmogućite ga u postavkama aplikacije.",
"switchToETHWallet": "Prijeđite na Ethereum novčanik i pokušajte ponovno",
"moonpay_exchange_description": "Bešavna zamjena kriptovaluta.",
"kyc_required": "Potrebni su račun i KYC"
"kyc_required": "Potrebni su račun i KYC",
"unspent_change": "Promijeniti"
}

View file

@ -723,5 +723,6 @@
"camera_permission_is_required": "Izin kamera diperlukan.\nSilakan aktifkan dari pengaturan aplikasi.",
"switchToETHWallet": "Silakan beralih ke dompet Ethereum dan coba lagi",
"moonpay_exchange_description": "Pertukaran cryptocurrency yang mulus.",
"kyc_required": "Akun dan KYC diperlukan"
"kyc_required": "Akun dan KYC diperlukan",
"unspent_change": "Mengubah"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "È richiesta l'autorizzazione della fotocamera.\nAbilitalo dalle impostazioni dell'app.",
"switchToETHWallet": "Passa a un portafoglio Ethereum e riprova",
"moonpay_exchange_description": "Scambia di criptovaluta senza soluzione di continuità.",
"kyc_required": "Account e KYC richiesto"
"kyc_required": "Account e KYC richiesto",
"unspent_change": "Modifica"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "カメラの許可が必要です。\nアプリの設定から有効にしてください。",
"switchToETHWallet": "イーサリアムウォレットに切り替えてもう一度お試しください",
"moonpay_exchange_description": "シームレスな暗号通貨スワッピング。",
"kyc_required": "アカウントとKYCが必要です"
"kyc_required": "アカウントとKYCが必要です",
"unspent_change": "変化"
}

View file

@ -733,5 +733,6 @@
"camera_permission_is_required": "카메라 권한이 필요합니다.\n앱 설정에서 활성화해 주세요.",
"switchToETHWallet": "이더리움 지갑으로 전환한 후 다시 시도해 주세요.",
"moonpay_exchange_description": "원활한 cryptocurrency 스와핑.",
"kyc_required": "계정 및 KYC가 필요합니다"
"kyc_required": "계정 및 KYC가 필요합니다",
"unspent_change": "변화"
}

View file

@ -733,5 +733,6 @@
"camera_permission_is_required": "ကင်မရာခွင့်ပြုချက် လိုအပ်ပါသည်။\nအက်ပ်ဆက်တင်များမှ ၎င်းကိုဖွင့်ပါ။",
"switchToETHWallet": "ကျေးဇူးပြု၍ Ethereum ပိုက်ဆံအိတ်သို့ ပြောင်းပြီး ထပ်စမ်းကြည့်ပါ။",
"moonpay_exchange_description": "ချောမွေ့စွာ cryptocurrencrencrencrens",
"kyc_required": "အကောင့်နှင့် KYC လိုအပ်သည်"
"kyc_required": "အကောင့်နှင့် KYC လိုအပ်သည်",
"unspent_change": "ပေြာင်းလဲခြင်း"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "Cameratoestemming is vereist.\nSchakel dit in via de app-instellingen.",
"switchToETHWallet": "Schakel over naar een Ethereum-portemonnee en probeer het opnieuw",
"moonpay_exchange_description": "Naadloze cryptocurrency swapping.",
"kyc_required": "Account en KYC vereist"
"kyc_required": "Account en KYC vereist",
"unspent_change": "Wijziging"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "Wymagane jest pozwolenie na korzystanie z aparatu.\nWłącz tę funkcję w ustawieniach aplikacji.",
"switchToETHWallet": "Przejdź na portfel Ethereum i spróbuj ponownie",
"moonpay_exchange_description": "Bezproblemowa zamiana kryptowalut.",
"kyc_required": "Wymagane konto i KYC"
"kyc_required": "Wymagane konto i KYC",
"unspent_change": "Zmiana"
}

View file

@ -734,5 +734,6 @@
"camera_permission_is_required": "É necessária permissão da câmera.\nAtive-o nas configurações do aplicativo.",
"switchToETHWallet": "Mude para uma carteira Ethereum e tente novamente",
"moonpay_exchange_description": "Troca de criptomoeda sem costura.",
"kyc_required": "Conta e kyc necessário"
"kyc_required": "Conta e kyc necessário",
"unspent_change": "Mudar"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "Требуется разрешение камеры.\nПожалуйста, включите его в настройках приложения.",
"switchToETHWallet": "Пожалуйста, переключитесь на кошелек Ethereum и повторите попытку.",
"moonpay_exchange_description": "Беспланное обмена криптовалютой.",
"kyc_required": "Учетная запись и KYC требуются"
"kyc_required": "Учетная запись и KYC требуются",
"unspent_change": "Изменять"
}

View file

@ -733,5 +733,6 @@
"camera_permission_is_required": "ต้องได้รับอนุญาตจากกล้อง\nโปรดเปิดใช้งานจากการตั้งค่าแอป",
"switchToETHWallet": "โปรดเปลี่ยนไปใช้กระเป๋าเงิน Ethereum แล้วลองอีกครั้ง",
"moonpay_exchange_description": "การแลกเปลี่ยน cryptocurrency ไร้รอยต่อ",
"kyc_required": "ต้องมีบัญชีและ KYC"
"kyc_required": "ต้องมีบัญชีและ KYC",
"unspent_change": "เปลี่ยน"
}

View file

@ -730,5 +730,6 @@
"camera_permission_is_required": "Kinakailangan ang pahintulot sa camera.\nMangyaring paganahin ito mula sa mga setting ng app.",
"switchToETHWallet": "Mangyaring lumipat sa isang Ethereum wallet at subukang muli",
"moonpay_exchange_description": "Seamless cryptocurrency swapping.",
"kyc_required": "Kinakailangan ang account at KYC"
"kyc_required": "Kinakailangan ang account at KYC",
"unspent_change": "Baguhin"
}

View file

@ -733,5 +733,6 @@
"camera_permission_is_required": "Kamera izni gereklidir.\nLütfen uygulama ayarlarından etkinleştirin.",
"switchToETHWallet": "Lütfen bir Ethereum cüzdanına geçin ve tekrar deneyin",
"moonpay_exchange_description": "Kesintisiz kripto para değiştirme.",
"kyc_required": "Hesap ve KYC gerekli"
"kyc_required": "Hesap ve KYC gerekli",
"unspent_change": "Değiştirmek"
}

View file

@ -735,5 +735,6 @@
"camera_permission_is_required": "Потрібен дозвіл камери.\nУвімкніть його в налаштуваннях програми.",
"switchToETHWallet": "Перейдіть на гаманець Ethereum і повторіть спробу",
"moonpay_exchange_description": "Безшовна заміну криптовалюти.",
"kyc_required": "Потрібно рахунок та kyc"
"kyc_required": "Потрібно рахунок та kyc",
"unspent_change": "Зміна"
}

View file

@ -727,5 +727,6 @@
"camera_permission_is_required": "۔ﮯﮨ ﺭﺎﮐﺭﺩ ﺕﺯﺎﺟﺍ ﯽﮐ ﮮﺮﻤﯿﮐ",
"switchToETHWallet": "۔ﮟﯾﺮﮐ ﺶﺷﻮﮐ ﮦﺭﺎﺑﻭﺩ ﺭﻭﺍ ﮟﯾﺮﮐ ﭻﺋﻮﺳ ﺮﭘ ﭧﯿﻟﺍﻭ Ethereum ﻡﺮﮐ ﮦﺍﺮﺑ",
"moonpay_exchange_description": "ہموار کریپٹوکرنسی تبادلہ کرنا۔",
"kyc_required": "اکاؤنٹ اور کے وائی سی کی ضرورت ہے"
"kyc_required": "اکاؤنٹ اور کے وائی سی کی ضرورت ہے",
"unspent_change": "تبدیل کریں"
}

View file

@ -729,5 +729,6 @@
"camera_permission_is_required": "A nilo igbanilaaye kamẹra.\nJọwọ jeki o lati app eto.",
"switchToETHWallet": "Jọwọ yipada si apamọwọ Ethereum ki o tun gbiyanju lẹẹkansi",
"moonpay_exchange_description": "Iboju ti ko ni itiju.",
"kyc_required": "Akọọlẹ ati KYC beere"
"kyc_required": "Akọọlẹ ati KYC beere",
"unspent_change": "Yipada"
}

View file

@ -734,5 +734,6 @@
"camera_permission_is_required": "需要相机许可。\n请从应用程序设置中启用它。",
"switchToETHWallet": "请切换到以太坊钱包并重试",
"moonpay_exchange_description": "无缝加密货币交换。",
"kyc_required": "帐户和KYC需要"
"kyc_required": "帐户和KYC需要",
"unspent_change": "改变"
}