2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/transaction_info.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2020-12-22 18:42:30 +00:00
|
|
|
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/transaction_details/textfield_list_item.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/transaction_details/transaction_details_list_item.dart';
|
2021-01-21 02:01:49 +00:00
|
|
|
import 'package:cake_wallet/src/screens/transaction_details/blockexplorer_list_item.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/transaction_direction.dart';
|
2020-12-22 18:42:30 +00:00
|
|
|
import 'package:cake_wallet/utils/date_formatter.dart';
|
|
|
|
import 'package:cake_wallet/entities/transaction_description.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2021-01-21 02:01:49 +00:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2022-01-31 12:08:38 +00:00
|
|
|
import 'package:cake_wallet/monero/monero.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cake_wallet/haven/haven.dart';
|
2020-12-22 18:42:30 +00:00
|
|
|
|
|
|
|
part 'transaction_details_view_model.g.dart';
|
|
|
|
|
2021-01-05 20:37:25 +00:00
|
|
|
class TransactionDetailsViewModel = TransactionDetailsViewModelBase
|
|
|
|
with _$TransactionDetailsViewModel;
|
2020-12-22 18:42:30 +00:00
|
|
|
|
|
|
|
abstract class TransactionDetailsViewModelBase with Store {
|
2021-01-05 20:37:25 +00:00
|
|
|
TransactionDetailsViewModelBase(
|
2022-10-12 17:09:57 +00:00
|
|
|
{required this.transactionInfo,
|
|
|
|
required this.transactionDescriptionBox,
|
|
|
|
required this.wallet,
|
|
|
|
required this.settingsStore})
|
|
|
|
: items = [],
|
|
|
|
isRecipientAddressShown = false,
|
|
|
|
showRecipientAddress = settingsStore.shouldSaveRecipientAddress {
|
2020-12-22 18:42:30 +00:00
|
|
|
final dateFormat = DateFormatter.withCurrentLocal();
|
|
|
|
final tx = transactionInfo;
|
|
|
|
|
2021-12-24 12:37:24 +00:00
|
|
|
if (wallet.type == WalletType.monero) {
|
2022-10-12 17:09:57 +00:00
|
|
|
final key = tx.additionalInfo['key'] as String?;
|
2022-02-03 12:37:32 +00:00
|
|
|
final accountIndex = tx.additionalInfo['accountIndex'] as int;
|
|
|
|
final addressIndex = tx.additionalInfo['addressIndex'] as int;
|
2022-10-12 17:09:57 +00:00
|
|
|
final feeFormatted = tx.feeFormatted();
|
2020-12-22 18:42:30 +00:00
|
|
|
final _items = [
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_transaction_id, value: tx.id),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_date,
|
|
|
|
value: dateFormat.format(tx.date)),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_amount,
|
|
|
|
value: tx.amountFormatted()),
|
2022-10-12 17:09:57 +00:00
|
|
|
if (feeFormatted != null)
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_fee, value: feeFormatted),
|
2022-01-31 12:08:38 +00:00
|
|
|
if (key?.isNotEmpty ?? false)
|
2022-10-12 17:09:57 +00:00
|
|
|
StandartListItem(title: S.current.transaction_key, value: key!)
|
2020-12-22 18:42:30 +00:00
|
|
|
];
|
|
|
|
|
2022-01-31 12:08:38 +00:00
|
|
|
if (tx.direction == TransactionDirection.incoming &&
|
|
|
|
accountIndex != null &&
|
|
|
|
addressIndex != null) {
|
|
|
|
try {
|
2022-10-12 17:09:57 +00:00
|
|
|
final address = monero!.getTransactionAddress(wallet, accountIndex, addressIndex);
|
|
|
|
final label = monero!.getSubaddressLabel(wallet, accountIndex, addressIndex);
|
2021-12-24 12:37:24 +00:00
|
|
|
|
2022-01-31 12:08:38 +00:00
|
|
|
if (address?.isNotEmpty ?? false) {
|
|
|
|
isRecipientAddressShown = true;
|
|
|
|
_items.add(
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_recipient_address,
|
|
|
|
value: address));
|
|
|
|
}
|
2022-04-12 15:38:47 +00:00
|
|
|
|
|
|
|
if (label?.isNotEmpty ?? false) {
|
|
|
|
_items.add(
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.address_label,
|
|
|
|
value: label)
|
|
|
|
);
|
|
|
|
}
|
2022-01-31 12:08:38 +00:00
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
|
|
|
}
|
|
|
|
}
|
2021-05-10 16:10:33 +00:00
|
|
|
|
2020-12-22 18:42:30 +00:00
|
|
|
items.addAll(_items);
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:37:24 +00:00
|
|
|
if (wallet.type == WalletType.bitcoin
|
|
|
|
|| wallet.type == WalletType.litecoin) {
|
2020-12-22 18:42:30 +00:00
|
|
|
final _items = [
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_transaction_id, value: tx.id),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_date,
|
|
|
|
value: dateFormat.format(tx.date)),
|
|
|
|
StandartListItem(
|
2021-01-05 20:37:25 +00:00
|
|
|
title: S.current.confirmations,
|
2022-10-12 17:09:57 +00:00
|
|
|
value: tx.confirmations.toString()),
|
2020-12-22 18:42:30 +00:00
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_amount,
|
|
|
|
value: tx.amountFormatted()),
|
2022-10-12 17:09:57 +00:00
|
|
|
if (tx.feeFormatted()?.isNotEmpty ?? false)
|
2020-12-23 13:04:57 +00:00
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_fee,
|
2022-10-12 17:09:57 +00:00
|
|
|
value: tx.feeFormatted()!),
|
2020-12-22 18:42:30 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
items.addAll(_items);
|
|
|
|
}
|
|
|
|
|
2022-03-30 15:57:04 +00:00
|
|
|
if (wallet.type == WalletType.haven) {
|
|
|
|
items.addAll([
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_transaction_id, value: tx.id),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_date,
|
|
|
|
value: dateFormat.format(tx.date)),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_amount,
|
|
|
|
value: tx.amountFormatted()),
|
2022-10-12 17:09:57 +00:00
|
|
|
if (tx.feeFormatted()?.isNotEmpty ?? false)
|
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_fee, value: tx.feeFormatted()!),
|
2022-03-30 15:57:04 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-08-04 14:38:03 +00:00
|
|
|
if (showRecipientAddress && !isRecipientAddressShown) {
|
2022-10-12 17:09:57 +00:00
|
|
|
try {
|
|
|
|
final recipientAddress = transactionDescriptionBox.values
|
|
|
|
.firstWhere((val) => val.id == transactionInfo.id)
|
|
|
|
.recipientAddress;
|
2020-12-22 18:42:30 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
if (recipientAddress?.isNotEmpty ?? false) {
|
|
|
|
items.add(StandartListItem(
|
|
|
|
title: S.current.transaction_details_recipient_address,
|
|
|
|
value: recipientAddress!));
|
|
|
|
}
|
|
|
|
} catch(_) {
|
|
|
|
// FIX-ME: Unhandled exception
|
2020-12-22 18:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:37:24 +00:00
|
|
|
final type = wallet.type;
|
2021-05-07 07:36:38 +00:00
|
|
|
|
|
|
|
items.add(BlockExplorerListItem(
|
2022-04-22 15:15:05 +00:00
|
|
|
title: S.current.view_in_block_explorer,
|
2021-05-07 07:36:38 +00:00
|
|
|
value: _explorerDescription(type),
|
|
|
|
onTap: () => launch(_explorerUrl(type, tx.id))));
|
|
|
|
|
2020-12-22 18:42:30 +00:00
|
|
|
final description = transactionDescriptionBox.values.firstWhere(
|
2021-01-05 20:37:25 +00:00
|
|
|
(val) => val.id == transactionInfo.id,
|
|
|
|
orElse: () => TransactionDescription(id: transactionInfo.id));
|
|
|
|
|
|
|
|
items.add(TextFieldListItem(
|
|
|
|
title: S.current.note_tap_to_change,
|
|
|
|
value: description.note,
|
|
|
|
onSubmitted: (value) {
|
|
|
|
description.transactionNote = value;
|
|
|
|
|
|
|
|
if (description.isInBox) {
|
2020-12-22 18:42:30 +00:00
|
|
|
description.save();
|
2021-01-05 20:37:25 +00:00
|
|
|
} else {
|
|
|
|
transactionDescriptionBox.add(description);
|
|
|
|
}
|
|
|
|
}));
|
2020-12-22 18:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final TransactionInfo transactionInfo;
|
|
|
|
final Box<TransactionDescription> transactionDescriptionBox;
|
|
|
|
final SettingsStore settingsStore;
|
2021-05-10 16:10:33 +00:00
|
|
|
final WalletBase wallet;
|
2020-12-22 18:42:30 +00:00
|
|
|
|
|
|
|
final List<TransactionDetailsListItem> items;
|
|
|
|
bool showRecipientAddress;
|
2021-08-04 14:38:03 +00:00
|
|
|
bool isRecipientAddressShown;
|
2021-05-07 07:36:38 +00:00
|
|
|
|
|
|
|
String _explorerUrl(WalletType type, String txId) {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.monero:
|
2022-04-22 16:17:43 +00:00
|
|
|
return 'https://monero.com/tx/${txId}';
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.bitcoin:
|
|
|
|
return 'https://www.blockchain.com/btc/tx/${txId}';
|
|
|
|
case WalletType.litecoin:
|
|
|
|
return 'https://blockchair.com/litecoin/transaction/${txId}';
|
2022-03-30 15:57:04 +00:00
|
|
|
case WalletType.haven:
|
|
|
|
return 'https://explorer.havenprotocol.org/search?value=${txId}';
|
2021-05-07 07:36:38 +00:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String _explorerDescription(WalletType type) {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.monero:
|
2022-04-22 16:17:43 +00:00
|
|
|
return S.current.view_transaction_on + 'Monero.com';
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.bitcoin:
|
2022-04-22 15:15:05 +00:00
|
|
|
return S.current.view_transaction_on + 'Blockchain.com';
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.litecoin:
|
2022-04-22 15:15:05 +00:00
|
|
|
return S.current.view_transaction_on + 'Blockchair.com';
|
2022-03-30 15:57:04 +00:00
|
|
|
case WalletType.haven:
|
2022-04-22 15:15:05 +00:00
|
|
|
return S.current.view_transaction_on + 'explorer.havenprotocol.org';
|
2021-05-07 07:36:38 +00:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 20:37:25 +00:00
|
|
|
}
|