mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 09:29:48 +00:00
Cw 498 improve wallet accounts (#1152)
* CW-498 Call updateTransactions on account change * CW-498 Code Cleanup * CW-498 Add Wallet Address to trade to match transactions to trades * CW-498 Fix containsAddress to include only addresses of account * Handle nullability for fromWalletAddress --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
5bd382f186
commit
e5d99313eb
13 changed files with 206 additions and 230 deletions
|
@ -36,4 +36,6 @@ abstract class WalletAddresses {
|
||||||
print(e.toString());
|
print(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool containsAddress(String address) => addressesMap.containsKey(address);
|
||||||
}
|
}
|
|
@ -63,14 +63,14 @@ abstract class HavenWalletAddressesBase extends WalletAddressesWithAccount<Accou
|
||||||
|
|
||||||
bool validate() {
|
bool validate() {
|
||||||
accountList.update();
|
accountList.update();
|
||||||
final accountListLength = accountList.accounts.length ?? 0;
|
final accountListLength = accountList.accounts.length;
|
||||||
|
|
||||||
if (accountListLength <= 0) {
|
if (accountListLength <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
subaddressList.update(accountIndex: accountList.accounts.first.id);
|
subaddressList.update(accountIndex: accountList.accounts.first.id);
|
||||||
final subaddressListLength = subaddressList.subaddresses.length ?? 0;
|
final subaddressListLength = subaddressList.subaddresses.length;
|
||||||
|
|
||||||
if (subaddressListLength <= 0) {
|
if (subaddressListLength <= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -84,4 +84,8 @@ abstract class HavenWalletAddressesBase extends WalletAddressesWithAccount<Accou
|
||||||
subaddress = subaddressList.subaddresses.first;
|
subaddress = subaddressList.subaddresses.first;
|
||||||
address = subaddress!.address;
|
address = subaddress!.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool containsAddress(String address) =>
|
||||||
|
addressInfos[account?.id ?? 0]?.any((it) => it.address == address) ?? false;
|
||||||
}
|
}
|
|
@ -57,9 +57,7 @@ abstract class MoneroWalletBase
|
||||||
walletAddresses = MoneroWalletAddresses(walletInfo, transactionHistory);
|
walletAddresses = MoneroWalletAddresses(walletInfo, transactionHistory);
|
||||||
|
|
||||||
_onAccountChangeReaction = reaction((_) => walletAddresses.account, (Account? account) {
|
_onAccountChangeReaction = reaction((_) => walletAddresses.account, (Account? account) {
|
||||||
if (account == null) {
|
if (account == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
balance = ObservableMap<CryptoCurrency, MoneroBalance>.of(<CryptoCurrency, MoneroBalance>{
|
balance = ObservableMap<CryptoCurrency, MoneroBalance>.of(<CryptoCurrency, MoneroBalance>{
|
||||||
currency: MoneroBalance(
|
currency: MoneroBalance(
|
||||||
|
@ -67,6 +65,7 @@ abstract class MoneroWalletBase
|
||||||
unlockedBalance: monero_wallet.getUnlockedBalance(accountIndex: account.id))
|
unlockedBalance: monero_wallet.getUnlockedBalance(accountIndex: account.id))
|
||||||
});
|
});
|
||||||
_updateSubAddress(isEnabledAutoGenerateSubaddress, account: account);
|
_updateSubAddress(isEnabledAutoGenerateSubaddress, account: account);
|
||||||
|
_askForUpdateTransactionHistory();
|
||||||
});
|
});
|
||||||
|
|
||||||
reaction((_) => isEnabledAutoGenerateSubaddress, (bool enabled) {
|
reaction((_) => isEnabledAutoGenerateSubaddress, (bool enabled) {
|
||||||
|
@ -362,9 +361,7 @@ abstract class MoneroWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> changePassword(String password) async {
|
Future<void> changePassword(String password) async => monero_wallet.setPasswordSync(password);
|
||||||
monero_wallet.setPasswordSync(password);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> getNodeHeight() async => monero_wallet.getNodeHeight();
|
Future<int> getNodeHeight() async => monero_wallet.getNodeHeight();
|
||||||
|
|
||||||
|
@ -499,9 +496,8 @@ abstract class MoneroWalletBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getSubaddressLabel(int accountIndex, int addressIndex) {
|
String getSubaddressLabel(int accountIndex, int addressIndex) =>
|
||||||
return monero_wallet.getSubaddressLabel(accountIndex, addressIndex);
|
monero_wallet.getSubaddressLabel(accountIndex, addressIndex);
|
||||||
}
|
|
||||||
|
|
||||||
List<MoneroTransactionInfo> _getAllTransactionsOfAccount(int? accountIndex) => transaction_history
|
List<MoneroTransactionInfo> _getAllTransactionsOfAccount(int? accountIndex) => transaction_history
|
||||||
.getAllTransactions()
|
.getAllTransactions()
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
import 'package:cw_core/account.dart';
|
||||||
import 'package:cw_core/address_info.dart';
|
import 'package:cw_core/address_info.dart';
|
||||||
|
import 'package:cw_core/subaddress.dart';
|
||||||
import 'package:cw_core/wallet_addresses.dart';
|
import 'package:cw_core/wallet_addresses.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:cw_core/account.dart';
|
|
||||||
import 'package:cw_monero/api/wallet.dart';
|
import 'package:cw_monero/api/wallet.dart';
|
||||||
import 'package:cw_monero/monero_account_list.dart';
|
import 'package:cw_monero/monero_account_list.dart';
|
||||||
import 'package:cw_monero/monero_subaddress_list.dart';
|
import 'package:cw_monero/monero_subaddress_list.dart';
|
||||||
import 'package:cw_core/subaddress.dart';
|
|
||||||
import 'package:cw_monero/monero_transaction_history.dart';
|
import 'package:cw_monero/monero_transaction_history.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
|
|
||||||
|
@ -112,4 +112,8 @@ abstract class MoneroWalletAddressesBase extends WalletAddresses with Store {
|
||||||
subaddress = subaddressList.subaddresses.last;
|
subaddress = subaddressList.subaddresses.last;
|
||||||
address = subaddress!.address;
|
address = subaddress!.address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool containsAddress(String address) =>
|
||||||
|
addressInfos[account?.id ?? 0]?.any((it) => it.address == address) ?? false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Trade extends HiveObject {
|
||||||
this.password,
|
this.password,
|
||||||
this.providerId,
|
this.providerId,
|
||||||
this.providerName,
|
this.providerName,
|
||||||
|
this.fromWalletAddress
|
||||||
}) {
|
}) {
|
||||||
if (provider != null) providerRaw = provider.raw;
|
if (provider != null) providerRaw = provider.raw;
|
||||||
|
|
||||||
|
@ -101,6 +102,9 @@ class Trade extends HiveObject {
|
||||||
@HiveField(16)
|
@HiveField(16)
|
||||||
String? providerName;
|
String? providerName;
|
||||||
|
|
||||||
|
@HiveField(17)
|
||||||
|
String? fromWalletAddress;
|
||||||
|
|
||||||
static Trade fromMap(Map<String, Object?> map) {
|
static Trade fromMap(Map<String, Object?> map) {
|
||||||
return Trade(
|
return Trade(
|
||||||
id: map['id'] as String,
|
id: map['id'] as String,
|
||||||
|
@ -110,7 +114,9 @@ class Trade extends HiveObject {
|
||||||
createdAt:
|
createdAt:
|
||||||
map['date'] != null ? DateTime.fromMillisecondsSinceEpoch(map['date'] as int) : null,
|
map['date'] != null ? DateTime.fromMillisecondsSinceEpoch(map['date'] as int) : null,
|
||||||
amount: map['amount'] as String,
|
amount: map['amount'] as String,
|
||||||
walletId: map['wallet_id'] as String);
|
walletId: map['wallet_id'] as String,
|
||||||
|
fromWalletAddress: map['from_wallet_address'] as String?
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
|
@ -121,7 +127,8 @@ class Trade extends HiveObject {
|
||||||
'output': to.serialize(),
|
'output': to.serialize(),
|
||||||
'date': createdAt != null ? createdAt!.millisecondsSinceEpoch : null,
|
'date': createdAt != null ? createdAt!.millisecondsSinceEpoch : null,
|
||||||
'amount': amount,
|
'amount': amount,
|
||||||
'wallet_id': walletId
|
'wallet_id': walletId,
|
||||||
|
'from_wallet_address': fromWalletAddress
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,8 +120,6 @@ class CWMoneroWalletDetails extends MoneroWalletDetails {
|
||||||
@computed
|
@computed
|
||||||
@override
|
@override
|
||||||
MoneroBalance get balance {
|
MoneroBalance get balance {
|
||||||
final moneroWallet = _wallet as MoneroWallet;
|
|
||||||
final balance = moneroWallet.balance;
|
|
||||||
throw Exception('Unimplemented');
|
throw Exception('Unimplemented');
|
||||||
// return MoneroBalance();
|
// return MoneroBalance();
|
||||||
//return MoneroBalance(
|
//return MoneroBalance(
|
||||||
|
@ -132,14 +130,10 @@ class CWMoneroWalletDetails extends MoneroWalletDetails {
|
||||||
|
|
||||||
class CWMonero extends Monero {
|
class CWMonero extends Monero {
|
||||||
@override
|
@override
|
||||||
MoneroAccountList getAccountList(Object wallet) {
|
MoneroAccountList getAccountList(Object wallet) => CWMoneroAccountList(wallet);
|
||||||
return CWMoneroAccountList(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MoneroSubaddressList getSubaddressList(Object wallet) {
|
MoneroSubaddressList getSubaddressList(Object wallet) => CWMoneroSubaddressList(wallet);
|
||||||
return CWMoneroSubaddressList(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TransactionHistoryBase getTransactionHistory(Object wallet) {
|
TransactionHistoryBase getTransactionHistory(Object wallet) {
|
||||||
|
@ -148,19 +142,13 @@ class CWMonero extends Monero {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MoneroWalletDetails getMoneroWalletDetails(Object wallet) {
|
MoneroWalletDetails getMoneroWalletDetails(Object wallet) => CWMoneroWalletDetails(wallet);
|
||||||
return CWMoneroWalletDetails(wallet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int getHeigthByDate({required DateTime date}) {
|
int getHeightByDate({required DateTime date}) => getMoneroHeigthByDate(date: date);
|
||||||
return getMoneroHeigthByDate(date: date);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TransactionPriority getDefaultTransactionPriority() {
|
TransactionPriority getDefaultTransactionPriority() => MoneroTransactionPriority.automatic;
|
||||||
return MoneroTransactionPriority.automatic;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TransactionPriority getMoneroTransactionPrioritySlow() => MoneroTransactionPriority.slow;
|
TransactionPriority getMoneroTransactionPrioritySlow() => MoneroTransactionPriority.slow;
|
||||||
|
@ -170,14 +158,11 @@ class CWMonero extends Monero {
|
||||||
MoneroTransactionPriority.automatic;
|
MoneroTransactionPriority.automatic;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TransactionPriority deserializeMoneroTransactionPriority({required int raw}) {
|
TransactionPriority deserializeMoneroTransactionPriority({required int raw}) =>
|
||||||
return MoneroTransactionPriority.deserialize(raw: raw);
|
MoneroTransactionPriority.deserialize(raw: raw);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<TransactionPriority> getTransactionPriorities() {
|
List<TransactionPriority> getTransactionPriorities() => MoneroTransactionPriority.all;
|
||||||
return MoneroTransactionPriority.all;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> getMoneroWordList(String language) {
|
List<String> getMoneroWordList(String language) {
|
||||||
|
@ -209,41 +194,37 @@ class CWMonero extends Monero {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletCredentials createMoneroRestoreWalletFromKeysCredentials(
|
WalletCredentials createMoneroRestoreWalletFromKeysCredentials(
|
||||||
{required String name,
|
{required String name,
|
||||||
required String spendKey,
|
required String spendKey,
|
||||||
required String viewKey,
|
required String viewKey,
|
||||||
required String address,
|
required String address,
|
||||||
required String password,
|
required String password,
|
||||||
required String language,
|
required String language,
|
||||||
required int height}) {
|
required int height}) =>
|
||||||
return MoneroRestoreWalletFromKeysCredentials(
|
MoneroRestoreWalletFromKeysCredentials(
|
||||||
name: name,
|
name: name,
|
||||||
spendKey: spendKey,
|
spendKey: spendKey,
|
||||||
viewKey: viewKey,
|
viewKey: viewKey,
|
||||||
address: address,
|
address: address,
|
||||||
password: password,
|
password: password,
|
||||||
language: language,
|
language: language,
|
||||||
height: height);
|
height: height);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletCredentials createMoneroRestoreWalletFromSeedCredentials(
|
WalletCredentials createMoneroRestoreWalletFromSeedCredentials(
|
||||||
{required String name,
|
{required String name,
|
||||||
required String password,
|
required String password,
|
||||||
required int height,
|
required int height,
|
||||||
required String mnemonic}) {
|
required String mnemonic}) =>
|
||||||
return MoneroRestoreWalletFromSeedCredentials(
|
MoneroRestoreWalletFromSeedCredentials(
|
||||||
name: name, password: password, height: height, mnemonic: mnemonic);
|
name: name, password: password, height: height, mnemonic: mnemonic);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletCredentials createMoneroNewWalletCredentials({
|
WalletCredentials createMoneroNewWalletCredentials({
|
||||||
required String name,
|
required String name,
|
||||||
required String language,
|
required String language,
|
||||||
String? password,
|
String? password}) =>
|
||||||
}) {
|
MoneroNewWalletCredentials(name: name, password: password, language: language);
|
||||||
return MoneroNewWalletCredentials(name: name, password: password, language: language);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> getKeys(Object wallet) {
|
Map<String, String> getKeys(Object wallet) {
|
||||||
|
@ -259,43 +240,37 @@ class CWMonero extends Monero {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Object createMoneroTransactionCreationCredentials(
|
Object createMoneroTransactionCreationCredentials(
|
||||||
{required List<Output> outputs, required TransactionPriority priority}) {
|
{required List<Output> outputs, required TransactionPriority priority}) =>
|
||||||
return MoneroTransactionCreationCredentials(
|
MoneroTransactionCreationCredentials(
|
||||||
outputs: outputs
|
outputs: outputs
|
||||||
.map((out) => OutputInfo(
|
.map((out) => OutputInfo(
|
||||||
fiatAmount: out.fiatAmount,
|
fiatAmount: out.fiatAmount,
|
||||||
cryptoAmount: out.cryptoAmount,
|
cryptoAmount: out.cryptoAmount,
|
||||||
address: out.address,
|
address: out.address,
|
||||||
note: out.note,
|
note: out.note,
|
||||||
sendAll: out.sendAll,
|
sendAll: out.sendAll,
|
||||||
extractedAddress: out.extractedAddress,
|
extractedAddress: out.extractedAddress,
|
||||||
isParsedAddress: out.isParsedAddress,
|
isParsedAddress: out.isParsedAddress,
|
||||||
formattedCryptoAmount: out.formattedCryptoAmount))
|
formattedCryptoAmount: out.formattedCryptoAmount))
|
||||||
.toList(),
|
.toList(),
|
||||||
priority: priority as MoneroTransactionPriority);
|
priority: priority as MoneroTransactionPriority);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Object createMoneroTransactionCreationCredentialsRaw(
|
Object createMoneroTransactionCreationCredentialsRaw(
|
||||||
{required List<OutputInfo> outputs, required TransactionPriority priority}) {
|
{required List<OutputInfo> outputs, required TransactionPriority priority}) =>
|
||||||
return MoneroTransactionCreationCredentials(
|
MoneroTransactionCreationCredentials(
|
||||||
outputs: outputs, priority: priority as MoneroTransactionPriority);
|
outputs: outputs, priority: priority as MoneroTransactionPriority);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String formatterMoneroAmountToString({required int amount}) {
|
String formatterMoneroAmountToString({required int amount}) =>
|
||||||
return moneroAmountToString(amount: amount);
|
moneroAmountToString(amount: amount);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double formatterMoneroAmountToDouble({required int amount}) {
|
double formatterMoneroAmountToDouble({required int amount}) =>
|
||||||
return moneroAmountToDouble(amount: amount);
|
moneroAmountToDouble(amount: amount);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int formatterMoneroParseAmount({required String amount}) {
|
int formatterMoneroParseAmount({required String amount}) => moneroParseAmount(amount: amount);
|
||||||
return moneroParseAmount(amount: amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Account getCurrentAccount(Object wallet) {
|
Account getCurrentAccount(Object wallet) {
|
||||||
|
@ -312,9 +287,7 @@ class CWMonero extends Monero {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onStartup() {
|
void onStartup() => monero_wallet_api.onStartup();
|
||||||
monero_wallet_api.onStartup();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int getTransactionInfoAccountId(TransactionInfo tx) {
|
int getTransactionInfoAccountId(TransactionInfo tx) {
|
||||||
|
@ -324,9 +297,8 @@ class CWMonero extends Monero {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
WalletService createMoneroWalletService(
|
WalletService createMoneroWalletService(
|
||||||
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource) {
|
Box<WalletInfo> walletInfoSource, Box<UnspentCoinsInfo> unspentCoinSource) =>
|
||||||
return MoneroWalletService(walletInfoSource, unspentCoinSource);
|
MoneroWalletService(walletInfoSource, unspentCoinSource);
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
|
String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
|
||||||
|
|
|
@ -36,16 +36,13 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
||||||
restoreHeightController.addListener(() {
|
restoreHeightController.addListener(() {
|
||||||
if (restoreHeightController.text.isNotEmpty) {
|
if (restoreHeightController.text.isNotEmpty) {
|
||||||
widget.onHeightOrDateEntered?.call(true);
|
widget.onHeightOrDateEntered?.call(true);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
widget.onHeightOrDateEntered?.call(false);
|
widget.onHeightOrDateEntered?.call(false);
|
||||||
dateController.text = '';
|
dateController.text = '';
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
_changeHeight(restoreHeightController.text != null &&
|
_changeHeight(
|
||||||
restoreHeightController.text.isNotEmpty
|
restoreHeightController.text.isNotEmpty ? int.parse(restoreHeightController.text) : 0);
|
||||||
? int.parse(restoreHeightController.text)
|
|
||||||
: 0);
|
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
_changeHeight(0);
|
_changeHeight(0);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +114,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _selectDate(BuildContext context) async {
|
Future<void> _selectDate(BuildContext context) async {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final date = await getDate(
|
final date = await getDate(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -126,7 +123,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
||||||
lastDate: now);
|
lastDate: now);
|
||||||
|
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
final height = monero!.getHeigthByDate(date: date);
|
final height = monero!.getHeightByDate(date: date);
|
||||||
setState(() {
|
setState(() {
|
||||||
dateController.text = DateFormat('yyyy-MM-dd').format(date);
|
dateController.text = DateFormat('yyyy-MM-dd').format(date);
|
||||||
restoreHeightController.text = '$height';
|
restoreHeightController.text = '$height';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:cw_core/wallet_base.dart';
|
|
||||||
import 'package:mobx/mobx.dart';
|
|
||||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
||||||
|
import 'package:cw_core/wallet_base.dart';
|
||||||
|
import 'package:mobx/mobx.dart';
|
||||||
|
|
||||||
part'trade_filter_store.g.dart';
|
part'trade_filter_store.g.dart';
|
||||||
|
|
||||||
|
@ -87,29 +87,31 @@ abstract class TradeFilterStoreBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TradeListItem> filtered({required List<TradeListItem> trades, required WalletBase wallet}) {
|
List<TradeListItem> filtered({required List<TradeListItem> trades, required WalletBase wallet}) {
|
||||||
final _trades =
|
final _trades = trades
|
||||||
trades.where((item) => item.trade.walletId == wallet.id).toList();
|
.where((item) => item.trade.walletId == wallet.id && isTradeInAccount(item, wallet))
|
||||||
|
.toList();
|
||||||
final needToFilter = !displayAllTrades;
|
final needToFilter = !displayAllTrades;
|
||||||
|
|
||||||
return needToFilter
|
return needToFilter
|
||||||
? _trades
|
? _trades
|
||||||
.where((item) =>
|
.where((item) =>
|
||||||
(displayXMRTO &&
|
(displayXMRTO && item.trade.provider == ExchangeProviderDescription.xmrto) ||
|
||||||
item.trade.provider == ExchangeProviderDescription.xmrto) ||
|
(displaySideShift &&
|
||||||
(displaySideShift &&
|
item.trade.provider == ExchangeProviderDescription.sideShift) ||
|
||||||
item.trade.provider == ExchangeProviderDescription.sideShift) ||
|
(displayChangeNow &&
|
||||||
(displayChangeNow &&
|
item.trade.provider == ExchangeProviderDescription.changeNow) ||
|
||||||
item.trade.provider ==
|
(displayMorphToken &&
|
||||||
ExchangeProviderDescription.changeNow) ||
|
item.trade.provider == ExchangeProviderDescription.morphToken) ||
|
||||||
(displayMorphToken &&
|
(displaySimpleSwap &&
|
||||||
item.trade.provider ==
|
item.trade.provider == ExchangeProviderDescription.simpleSwap) ||
|
||||||
ExchangeProviderDescription.morphToken)
|
(displayTrocador && item.trade.provider == ExchangeProviderDescription.trocador) ||
|
||||||
||(displaySimpleSwap &&
|
(displayExolix && item.trade.provider == ExchangeProviderDescription.exolix))
|
||||||
item.trade.provider ==
|
.toList()
|
||||||
ExchangeProviderDescription.simpleSwap)
|
|
||||||
||(displayTrocador && item.trade.provider == ExchangeProviderDescription.trocador)
|
|
||||||
||(displayExolix && item.trade.provider == ExchangeProviderDescription.exolix))
|
|
||||||
.toList()
|
|
||||||
: _trades;
|
: _trades;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isTradeInAccount(TradeListItem item, WalletBase wallet) =>
|
||||||
|
item.trade.fromWalletAddress == null
|
||||||
|
? true
|
||||||
|
: wallet.walletAddresses.containsAddress(item.trade.fromWalletAddress!);
|
||||||
}
|
}
|
|
@ -1,36 +1,36 @@
|
||||||
import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart';
|
import 'package:cake_wallet/entities/auto_generate_subaddress_status.dart';
|
||||||
|
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||||
import 'package:cake_wallet/entities/buy_provider_types.dart';
|
import 'package:cake_wallet/entities/buy_provider_types.dart';
|
||||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||||
import 'package:cake_wallet/store/anonpay/anonpay_transactions_store.dart';
|
|
||||||
import 'package:cake_wallet/view_model/dashboard/anonpay_transaction_list_item.dart';
|
|
||||||
import 'package:cake_wallet/view_model/settings/sync_mode.dart';
|
|
||||||
import 'package:cake_wallet/wallet_type_utils.dart';
|
|
||||||
import 'package:cw_core/transaction_history.dart';
|
|
||||||
import 'package:cw_core/balance.dart';
|
|
||||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
|
||||||
import 'package:cw_core/transaction_info.dart';
|
|
||||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
import 'package:cake_wallet/monero/monero.dart';
|
||||||
|
import 'package:cake_wallet/store/anonpay/anonpay_transactions_store.dart';
|
||||||
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:cake_wallet/store/dashboard/orders_store.dart';
|
import 'package:cake_wallet/store/dashboard/orders_store.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/trade_filter_store.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
||||||
|
import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/store/yat/yat_store.dart';
|
import 'package:cake_wallet/store/yat/yat_store.dart';
|
||||||
import 'package:cake_wallet/utils/mobx.dart';
|
import 'package:cake_wallet/utils/mobx.dart';
|
||||||
|
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||||
|
import 'package:cake_wallet/view_model/dashboard/anonpay_transaction_list_item.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
|
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
|
||||||
|
import 'package:cake_wallet/view_model/dashboard/formatted_item_list.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/order_list_item.dart';
|
import 'package:cake_wallet/view_model/dashboard/order_list_item.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/transaction_list_item.dart';
|
import 'package:cake_wallet/view_model/dashboard/transaction_list_item.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
import 'package:cake_wallet/view_model/settings/sync_mode.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:cake_wallet/wallet_type_utils.dart';
|
||||||
import 'package:cw_core/wallet_base.dart';
|
import 'package:cw_core/balance.dart';
|
||||||
import 'package:cw_core/sync_status.dart';
|
import 'package:cw_core/sync_status.dart';
|
||||||
|
import 'package:cw_core/transaction_history.dart';
|
||||||
|
import 'package:cw_core/transaction_info.dart';
|
||||||
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:cake_wallet/store/app_store.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
|
||||||
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
|
||||||
import 'package:cake_wallet/store/dashboard/trade_filter_store.dart';
|
|
||||||
import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart';
|
|
||||||
import 'package:cake_wallet/view_model/dashboard/formatted_item_list.dart';
|
|
||||||
import 'package:cake_wallet/monero/monero.dart';
|
|
||||||
|
|
||||||
part 'dashboard_view_model.g.dart';
|
part 'dashboard_view_model.g.dart';
|
||||||
|
|
||||||
|
@ -47,69 +47,69 @@ abstract class DashboardViewModelBase with Store {
|
||||||
required this.yatStore,
|
required this.yatStore,
|
||||||
required this.ordersStore,
|
required this.ordersStore,
|
||||||
required this.anonpayTransactionsStore})
|
required this.anonpayTransactionsStore})
|
||||||
: hasSellAction = false,
|
: hasSellAction = false,
|
||||||
hasBuyAction = false,
|
hasBuyAction = false,
|
||||||
hasExchangeAction = false,
|
hasExchangeAction = false,
|
||||||
isShowFirstYatIntroduction = false,
|
isShowFirstYatIntroduction = false,
|
||||||
isShowSecondYatIntroduction = false,
|
isShowSecondYatIntroduction = false,
|
||||||
isShowThirdYatIntroduction = false,
|
isShowThirdYatIntroduction = false,
|
||||||
filterItems = {
|
filterItems = {
|
||||||
S.current.transactions: [
|
S.current.transactions: [
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => transactionFilterStore.displayAll,
|
value: () => transactionFilterStore.displayAll,
|
||||||
caption: S.current.all_transactions,
|
caption: S.current.all_transactions,
|
||||||
onChanged: transactionFilterStore.toggleAll),
|
onChanged: transactionFilterStore.toggleAll),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => transactionFilterStore.displayIncoming,
|
value: () => transactionFilterStore.displayIncoming,
|
||||||
caption: S.current.incoming,
|
caption: S.current.incoming,
|
||||||
onChanged:transactionFilterStore.toggleIncoming),
|
onChanged: transactionFilterStore.toggleIncoming),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => transactionFilterStore.displayOutgoing,
|
value: () => transactionFilterStore.displayOutgoing,
|
||||||
caption: S.current.outgoing,
|
caption: S.current.outgoing,
|
||||||
onChanged: transactionFilterStore.toggleOutgoing),
|
onChanged: transactionFilterStore.toggleOutgoing),
|
||||||
// FilterItem(
|
// FilterItem(
|
||||||
// value: () => false,
|
// value: () => false,
|
||||||
// caption: S.current.transactions_by_date,
|
// caption: S.current.transactions_by_date,
|
||||||
// onChanged: null),
|
// onChanged: null),
|
||||||
],
|
],
|
||||||
S.current.trades: [
|
S.current.trades: [
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => tradeFilterStore.displayAllTrades,
|
value: () => tradeFilterStore.displayAllTrades,
|
||||||
caption: S.current.all_trades,
|
caption: S.current.all_trades,
|
||||||
onChanged: () => tradeFilterStore
|
onChanged: () =>
|
||||||
.toggleDisplayExchange(ExchangeProviderDescription.all)),
|
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.all)),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => tradeFilterStore.displayChangeNow,
|
value: () => tradeFilterStore.displayChangeNow,
|
||||||
caption: ExchangeProviderDescription.changeNow.title,
|
caption: ExchangeProviderDescription.changeNow.title,
|
||||||
onChanged: () => tradeFilterStore
|
onChanged: () =>
|
||||||
.toggleDisplayExchange(ExchangeProviderDescription.changeNow)),
|
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.changeNow)),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => tradeFilterStore.displaySideShift,
|
value: () => tradeFilterStore.displaySideShift,
|
||||||
caption: ExchangeProviderDescription.sideShift.title,
|
caption: ExchangeProviderDescription.sideShift.title,
|
||||||
onChanged: () => tradeFilterStore
|
onChanged: () =>
|
||||||
.toggleDisplayExchange(ExchangeProviderDescription.sideShift)),
|
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.sideShift)),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => tradeFilterStore.displaySimpleSwap,
|
value: () => tradeFilterStore.displaySimpleSwap,
|
||||||
caption: ExchangeProviderDescription.simpleSwap.title,
|
caption: ExchangeProviderDescription.simpleSwap.title,
|
||||||
onChanged: () => tradeFilterStore
|
onChanged: () =>
|
||||||
.toggleDisplayExchange(ExchangeProviderDescription.simpleSwap)),
|
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.simpleSwap)),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => tradeFilterStore.displayTrocador,
|
value: () => tradeFilterStore.displayTrocador,
|
||||||
caption: ExchangeProviderDescription.trocador.title,
|
caption: ExchangeProviderDescription.trocador.title,
|
||||||
onChanged: () => tradeFilterStore
|
onChanged: () =>
|
||||||
.toggleDisplayExchange(ExchangeProviderDescription.trocador)),
|
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.trocador)),
|
||||||
FilterItem(
|
FilterItem(
|
||||||
value: () => tradeFilterStore.displayExolix,
|
value: () => tradeFilterStore.displayExolix,
|
||||||
caption: ExchangeProviderDescription.exolix.title,
|
caption: ExchangeProviderDescription.exolix.title,
|
||||||
onChanged: () => tradeFilterStore
|
onChanged: () =>
|
||||||
.toggleDisplayExchange(ExchangeProviderDescription.exolix)),
|
tradeFilterStore.toggleDisplayExchange(ExchangeProviderDescription.exolix)),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
subname = '',
|
subname = '',
|
||||||
name = appStore.wallet!.name,
|
name = appStore.wallet!.name,
|
||||||
type = appStore.wallet!.type,
|
type = appStore.wallet!.type,
|
||||||
transactions = ObservableList<TransactionListItem>(),
|
transactions = ObservableList<TransactionListItem>(),
|
||||||
wallet = appStore.wallet! {
|
wallet = appStore.wallet! {
|
||||||
name = wallet.name;
|
name = wallet.name;
|
||||||
type = wallet.type;
|
type = wallet.type;
|
||||||
isShowFirstYatIntroduction = false;
|
isShowFirstYatIntroduction = false;
|
||||||
|
@ -222,9 +222,8 @@ abstract class DashboardViewModelBase with Store {
|
||||||
BalanceDisplayMode get balanceDisplayMode => appStore.settingsStore.balanceDisplayMode;
|
BalanceDisplayMode get balanceDisplayMode => appStore.settingsStore.balanceDisplayMode;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
bool get shouldShowMarketPlaceInDashboard {
|
bool get shouldShowMarketPlaceInDashboard =>
|
||||||
return appStore.settingsStore.shouldShowMarketPlaceInDashboard;
|
appStore.settingsStore.shouldShowMarketPlaceInDashboard;
|
||||||
}
|
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
List<TradeListItem> get trades =>
|
List<TradeListItem> get trades =>
|
||||||
|
|
|
@ -1,25 +1,18 @@
|
||||||
|
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||||
import 'package:cake_wallet/exchange/trade.dart';
|
import 'package:cake_wallet/exchange/trade.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
|
||||||
|
|
||||||
class TradeListItem extends ActionListItem {
|
class TradeListItem extends ActionListItem {
|
||||||
TradeListItem({
|
TradeListItem({required this.trade, required this.settingsStore});
|
||||||
required this.trade,
|
|
||||||
required this.settingsStore});
|
|
||||||
|
|
||||||
final Trade trade;
|
final Trade trade;
|
||||||
final SettingsStore settingsStore;
|
final SettingsStore settingsStore;
|
||||||
|
|
||||||
BalanceDisplayMode get displayMode => settingsStore.balanceDisplayMode;
|
BalanceDisplayMode get displayMode => settingsStore.balanceDisplayMode;
|
||||||
|
|
||||||
String get tradeFormattedAmount {
|
String get tradeFormattedAmount =>
|
||||||
return trade.amount != null
|
displayMode == BalanceDisplayMode.hiddenBalance ? '---' : trade.amountFormatted();
|
||||||
? displayMode == BalanceDisplayMode.hiddenBalance
|
|
||||||
? '---'
|
|
||||||
: trade.amountFormatted()
|
|
||||||
: trade.amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
DateTime get date => trade.createdAt!;
|
DateTime get date => trade.createdAt!;
|
||||||
|
|
|
@ -491,6 +491,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||||
final trade =
|
final trade =
|
||||||
await provider.createTrade(request: request, isFixedRateMode: isFixedRateMode);
|
await provider.createTrade(request: request, isFixedRateMode: isFixedRateMode);
|
||||||
trade.walletId = wallet.id;
|
trade.walletId = wallet.id;
|
||||||
|
trade.fromWalletAddress = wallet.walletAddresses.address;
|
||||||
tradesStore.setTrade(trade);
|
tradesStore.setTrade(trade);
|
||||||
await trades.add(trade);
|
await trades.add(trade);
|
||||||
tradeState = TradeIsCreatedSuccessfully(trade: trade);
|
tradeState = TradeIsCreatedSuccessfully(trade: trade);
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:cake_wallet/nano/nano.dart';
|
|
||||||
import 'package:cake_wallet/store/app_store.dart';
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:cw_core/transaction_direction.dart';
|
import 'package:cw_core/transaction_direction.dart';
|
||||||
import 'package:cw_core/transaction_info.dart';
|
import 'package:cw_core/transaction_info.dart';
|
||||||
|
@ -194,7 +193,7 @@ abstract class WalletKeysViewModelBase with Store {
|
||||||
|
|
||||||
int _getRestoreHeightByTransactions(WalletType type, DateTime date) {
|
int _getRestoreHeightByTransactions(WalletType type, DateTime date) {
|
||||||
if (type == WalletType.monero) {
|
if (type == WalletType.monero) {
|
||||||
return monero!.getHeigthByDate(date: date);
|
return monero!.getHeightByDate(date: date);
|
||||||
} else if (type == WalletType.haven) {
|
} else if (type == WalletType.haven) {
|
||||||
return haven!.getHeightByDate(date: date);
|
return haven!.getHeightByDate(date: date);
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,7 @@ abstract class Monero {
|
||||||
|
|
||||||
String getSubaddressLabel(Object wallet, int accountIndex, int addressIndex);
|
String getSubaddressLabel(Object wallet, int accountIndex, int addressIndex);
|
||||||
|
|
||||||
int getHeigthByDate({required DateTime date});
|
int getHeightByDate({required DateTime date});
|
||||||
TransactionPriority getDefaultTransactionPriority();
|
TransactionPriority getDefaultTransactionPriority();
|
||||||
TransactionPriority getMoneroTransactionPrioritySlow();
|
TransactionPriority getMoneroTransactionPrioritySlow();
|
||||||
TransactionPriority getMoneroTransactionPriorityAutomatic();
|
TransactionPriority getMoneroTransactionPriorityAutomatic();
|
||||||
|
|
Loading…
Reference in a new issue