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';
|
2023-08-04 17:01:49 +00:00
|
|
|
import 'package:intl/src/intl/date_format.dart';
|
2020-12-22 18:42:30 +00:00
|
|
|
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';
|
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 = [],
|
2023-08-04 17:01:49 +00:00
|
|
|
isRecipientAddressShown = false,
|
|
|
|
showRecipientAddress = settingsStore.shouldSaveRecipientAddress {
|
2020-12-22 18:42:30 +00:00
|
|
|
final dateFormat = DateFormatter.withCurrentLocal();
|
|
|
|
final tx = transactionInfo;
|
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
switch (wallet.type) {
|
|
|
|
case WalletType.monero:
|
|
|
|
_addMoneroListItems(tx, dateFormat);
|
|
|
|
break;
|
|
|
|
case WalletType.bitcoin:
|
|
|
|
case WalletType.litecoin:
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.bitcoinCash:
|
2023-08-04 17:01:49 +00:00
|
|
|
_addElectrumListItems(tx, dateFormat);
|
|
|
|
break;
|
|
|
|
case WalletType.haven:
|
|
|
|
_addHavenListItems(tx, dateFormat);
|
|
|
|
break;
|
|
|
|
case WalletType.ethereum:
|
|
|
|
_addEthereumListItems(tx, dateFormat);
|
|
|
|
break;
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
|
|
|
_addNanoListItems(tx, dateFormat);
|
|
|
|
break;
|
2023-12-02 02:26:43 +00:00
|
|
|
case WalletType.polygon:
|
|
|
|
_addPolygonListItems(tx, dateFormat);
|
|
|
|
break;
|
2023-08-04 17:01:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
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(
|
2023-08-04 17:01:49 +00:00
|
|
|
title: S.current.transaction_details_recipient_address, value: recipientAddress!));
|
2022-10-12 17:09:57 +00:00
|
|
|
}
|
2023-08-04 17:01:49 +00:00
|
|
|
} catch (_) {
|
2022-10-12 17:09:57 +00:00
|
|
|
// 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),
|
2023-03-31 19:14:22 +00:00
|
|
|
onTap: () {
|
|
|
|
try {
|
|
|
|
launch(_explorerUrl(type, tx.id));
|
|
|
|
} catch (e) {}
|
|
|
|
}));
|
2021-05-07 07:36:38 +00:00
|
|
|
|
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:
|
2022-11-29 17:05:38 +00:00
|
|
|
return 'https://mempool.space/tx/${txId}';
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.litecoin:
|
|
|
|
return 'https://blockchair.com/litecoin/transaction/${txId}';
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.bitcoinCash:
|
|
|
|
return 'https://blockchair.com/bitcoin-cash/transaction/${txId}';
|
2022-03-30 15:57:04 +00:00
|
|
|
case WalletType.haven:
|
|
|
|
return 'https://explorer.havenprotocol.org/search?value=${txId}';
|
2023-08-04 17:01:49 +00:00
|
|
|
case WalletType.ethereum:
|
|
|
|
return 'https://etherscan.io/tx/${txId}';
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
|
|
|
return 'https://nanolooker.com/block/${txId}';
|
|
|
|
case WalletType.banano:
|
2023-12-02 02:26:43 +00:00
|
|
|
return 'https://bananolooker.com/block/${txId}';
|
|
|
|
case WalletType.polygon:
|
|
|
|
return 'https://polygonscan.com/tx/${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-11-29 17:05:38 +00:00
|
|
|
return S.current.view_transaction_on + 'mempool.space';
|
2021-05-07 07:36:38 +00:00
|
|
|
case WalletType.litecoin:
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.bitcoinCash:
|
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';
|
2023-08-04 17:01:49 +00:00
|
|
|
case WalletType.ethereum:
|
|
|
|
return S.current.view_transaction_on + 'etherscan.io';
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
|
|
|
return S.current.view_transaction_on + 'nanolooker.com';
|
|
|
|
case WalletType.banano:
|
|
|
|
return S.current.view_transaction_on + 'bananolooker.com';
|
2023-12-02 02:26:43 +00:00
|
|
|
case WalletType.polygon:
|
|
|
|
return S.current.view_transaction_on + 'polygonscan.com';
|
2021-05-07 07:36:38 +00:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2023-08-04 17:01:49 +00:00
|
|
|
|
|
|
|
void _addMoneroListItems(TransactionInfo tx, DateFormat dateFormat) {
|
|
|
|
final key = tx.additionalInfo['key'] as String?;
|
|
|
|
final accountIndex = tx.additionalInfo['accountIndex'] as int;
|
|
|
|
final addressIndex = tx.additionalInfo['addressIndex'] as int;
|
|
|
|
final feeFormatted = tx.feeFormatted();
|
|
|
|
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()),
|
|
|
|
if (feeFormatted != null)
|
|
|
|
StandartListItem(title: S.current.transaction_details_fee, value: feeFormatted),
|
|
|
|
if (key?.isNotEmpty ?? false) StandartListItem(title: S.current.transaction_key, value: key!),
|
|
|
|
];
|
|
|
|
|
|
|
|
if (tx.direction == TransactionDirection.incoming) {
|
|
|
|
try {
|
|
|
|
final address = monero!.getTransactionAddress(wallet, accountIndex, addressIndex);
|
|
|
|
final label = monero!.getSubaddressLabel(wallet, accountIndex, addressIndex);
|
|
|
|
|
|
|
|
if (address.isNotEmpty) {
|
|
|
|
isRecipientAddressShown = true;
|
|
|
|
_items.add(StandartListItem(
|
|
|
|
title: S.current.transaction_details_recipient_address,
|
|
|
|
value: address,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (label.isNotEmpty) {
|
|
|
|
_items.add(StandartListItem(title: S.current.address_label, value: label));
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
print(e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
items.addAll(_items);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _addElectrumListItems(TransactionInfo tx, DateFormat dateFormat) {
|
|
|
|
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.confirmations, value: tx.confirmations.toString()),
|
|
|
|
StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
|
|
StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()),
|
|
|
|
if (tx.feeFormatted()?.isNotEmpty ?? false)
|
|
|
|
StandartListItem(title: S.current.transaction_details_fee, value: tx.feeFormatted()!),
|
|
|
|
];
|
|
|
|
|
|
|
|
items.addAll(_items);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _addHavenListItems(TransactionInfo tx, DateFormat dateFormat) {
|
|
|
|
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()),
|
|
|
|
if (tx.feeFormatted()?.isNotEmpty ?? false)
|
|
|
|
StandartListItem(title: S.current.transaction_details_fee, value: tx.feeFormatted()!),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _addEthereumListItems(TransactionInfo tx, DateFormat dateFormat) {
|
|
|
|
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.confirmations, value: tx.confirmations.toString()),
|
|
|
|
StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
|
|
StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()),
|
|
|
|
if (tx.feeFormatted()?.isNotEmpty ?? false)
|
|
|
|
StandartListItem(title: S.current.transaction_details_fee, value: tx.feeFormatted()!),
|
2023-09-14 19:12:41 +00:00
|
|
|
if (showRecipientAddress && tx.to != null)
|
|
|
|
StandartListItem(title: S.current.transaction_details_recipient_address, value: tx.to!),
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
if (tx.direction == TransactionDirection.incoming && tx.from != null)
|
|
|
|
StandartListItem(title: S.current.transaction_details_source_address, value: tx.from!),
|
2023-08-04 17:01:49 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
items.addAll(_items);
|
|
|
|
}
|
2023-10-05 01:09:07 +00:00
|
|
|
|
|
|
|
void _addNanoListItems(TransactionInfo tx, DateFormat dateFormat) {
|
|
|
|
final _items = [
|
|
|
|
StandartListItem(title: S.current.transaction_details_transaction_id, value: tx.id),
|
2024-01-11 23:00:41 +00:00
|
|
|
if (showRecipientAddress && tx.to != null)
|
|
|
|
StandartListItem(title: S.current.transaction_details_recipient_address, value: tx.to!),
|
|
|
|
if (showRecipientAddress && tx.from != null)
|
|
|
|
StandartListItem(title: S.current.transaction_details_source_address, value: tx.from!),
|
|
|
|
StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()),
|
2023-10-05 01:09:07 +00:00
|
|
|
StandartListItem(
|
|
|
|
title: S.current.transaction_details_date, value: dateFormat.format(tx.date)),
|
2024-01-11 23:00:41 +00:00
|
|
|
StandartListItem(title: S.current.confirmed_tx, value: (tx.confirmations > 0).toString()),
|
2023-10-05 01:09:07 +00:00
|
|
|
StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
|
|
];
|
|
|
|
|
|
|
|
items.addAll(_items);
|
|
|
|
}
|
2023-12-02 02:26:43 +00:00
|
|
|
|
|
|
|
void _addPolygonListItems(TransactionInfo tx, DateFormat dateFormat) {
|
|
|
|
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.confirmations, value: tx.confirmations.toString()),
|
|
|
|
StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
|
|
StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()),
|
|
|
|
if (tx.feeFormatted()?.isNotEmpty ?? false)
|
|
|
|
StandartListItem(title: S.current.transaction_details_fee, value: tx.feeFormatted()!),
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
if (showRecipientAddress && tx.to != null && tx.direction == TransactionDirection.outgoing)
|
2023-12-02 02:26:43 +00:00
|
|
|
StandartListItem(title: S.current.transaction_details_recipient_address, value: tx.to!),
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
if (tx.direction == TransactionDirection.incoming && tx.from != null)
|
|
|
|
StandartListItem(title: S.current.transaction_details_source_address, value: tx.from!),
|
2023-12-02 02:26:43 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
items.addAll(_items);
|
|
|
|
}
|
2021-01-05 20:37:25 +00:00
|
|
|
}
|