mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-29 06:59:30 +00:00
66301ff247
* initial commit
* creating and restoring a wallet
* [skip ci] add transaction priority
* fix send and unspent screen
* fix transaction priority type
* replace Unspend with BitcoinUnspent
* add transaction creation
* fix transaction details screen
* minor fix
* fix create side wallet
* basic transaction creation flow
* fix fiat amount calculation
* edit wallet
* minor fix
* fix address book parsing
* merge commit fixes
* minor fixes
* Update gradle.properties
* fix bch unspent coins
* minor fix
* fix BitcoinCashTransactionPriority
* Fetch tags first before switching to one of them
* Update build_haven.sh
* Update build_haven.sh
* Update build_haven.sh
* Update build_haven.sh
* update transaction build function
* Update build_haven.sh
* add ability to rename and delete
* fix address format
* Update pubspec.lock
* Revert "fix address format"
This reverts commit 1549bf4d8c
.
* fix address format for exange
* restore from qr
* Update configure.dart
* [skip ci] minor fix
* fix default fee rate
* Update onramper_buy_provider.dart
* Update wallet_address_list_view_model.dart
* PR comments fixes
* Update exchange_view_model.dart
* fix merge conflict
* Update address_validator.dart
* merge fixes
* update initialMigrationVersion
* move cw_bitbox to Cake tech
* PR fixes
* PR fixes
* Fix configure.dart brackets
* update the new version text after macos
* dummy change to run workflow
* Fix Nano restore from QR issue
Fix Conflicts with main
* PR fixes
* Update app_config.sh
---------
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
253 lines
9.8 KiB
Dart
253 lines
9.8 KiB
Dart
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:cw_core/transaction_info.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
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';
|
|
import 'package:cake_wallet/src/screens/transaction_details/blockexplorer_list_item.dart';
|
|
import 'package:cw_core/transaction_direction.dart';
|
|
import 'package:cake_wallet/utils/date_formatter.dart';
|
|
import 'package:cake_wallet/entities/transaction_description.dart';
|
|
import 'package:hive/hive.dart';
|
|
import 'package:intl/src/intl/date_format.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
import 'package:cake_wallet/monero/monero.dart';
|
|
|
|
part 'transaction_details_view_model.g.dart';
|
|
|
|
class TransactionDetailsViewModel = TransactionDetailsViewModelBase
|
|
with _$TransactionDetailsViewModel;
|
|
|
|
abstract class TransactionDetailsViewModelBase with Store {
|
|
TransactionDetailsViewModelBase(
|
|
{required this.transactionInfo,
|
|
required this.transactionDescriptionBox,
|
|
required this.wallet,
|
|
required this.settingsStore})
|
|
: items = [],
|
|
isRecipientAddressShown = false,
|
|
showRecipientAddress = settingsStore.shouldSaveRecipientAddress {
|
|
final dateFormat = DateFormatter.withCurrentLocal();
|
|
final tx = transactionInfo;
|
|
|
|
switch (wallet.type) {
|
|
case WalletType.monero:
|
|
_addMoneroListItems(tx, dateFormat);
|
|
break;
|
|
case WalletType.bitcoin:
|
|
case WalletType.litecoin:
|
|
case WalletType.bitcoinCash:
|
|
_addElectrumListItems(tx, dateFormat);
|
|
break;
|
|
case WalletType.haven:
|
|
_addHavenListItems(tx, dateFormat);
|
|
break;
|
|
case WalletType.ethereum:
|
|
_addEthereumListItems(tx, dateFormat);
|
|
break;
|
|
case WalletType.nano:
|
|
_addNanoListItems(tx, dateFormat);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (showRecipientAddress && !isRecipientAddressShown) {
|
|
try {
|
|
final recipientAddress = transactionDescriptionBox.values
|
|
.firstWhere((val) => val.id == transactionInfo.id)
|
|
.recipientAddress;
|
|
|
|
if (recipientAddress?.isNotEmpty ?? false) {
|
|
items.add(StandartListItem(
|
|
title: S.current.transaction_details_recipient_address, value: recipientAddress!));
|
|
}
|
|
} catch (_) {
|
|
// FIX-ME: Unhandled exception
|
|
}
|
|
}
|
|
|
|
final type = wallet.type;
|
|
|
|
items.add(BlockExplorerListItem(
|
|
title: S.current.view_in_block_explorer,
|
|
value: _explorerDescription(type),
|
|
onTap: () {
|
|
try {
|
|
launch(_explorerUrl(type, tx.id));
|
|
} catch (e) {}
|
|
}));
|
|
|
|
final description = transactionDescriptionBox.values.firstWhere(
|
|
(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) {
|
|
description.save();
|
|
} else {
|
|
transactionDescriptionBox.add(description);
|
|
}
|
|
}));
|
|
}
|
|
|
|
final TransactionInfo transactionInfo;
|
|
final Box<TransactionDescription> transactionDescriptionBox;
|
|
final SettingsStore settingsStore;
|
|
final WalletBase wallet;
|
|
|
|
final List<TransactionDetailsListItem> items;
|
|
bool showRecipientAddress;
|
|
bool isRecipientAddressShown;
|
|
|
|
String _explorerUrl(WalletType type, String txId) {
|
|
switch (type) {
|
|
case WalletType.monero:
|
|
return 'https://monero.com/tx/${txId}';
|
|
case WalletType.bitcoin:
|
|
return 'https://mempool.space/tx/${txId}';
|
|
case WalletType.litecoin:
|
|
return 'https://blockchair.com/litecoin/transaction/${txId}';
|
|
case WalletType.bitcoinCash:
|
|
return 'https://blockchair.com/bitcoin-cash/transaction/${txId}';
|
|
case WalletType.haven:
|
|
return 'https://explorer.havenprotocol.org/search?value=${txId}';
|
|
case WalletType.ethereum:
|
|
return 'https://etherscan.io/tx/${txId}';
|
|
case WalletType.nano:
|
|
return 'https://nanolooker.com/block/${txId}';
|
|
case WalletType.banano:
|
|
return 'https://bananolooker.com/block/${txId}';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
String _explorerDescription(WalletType type) {
|
|
switch (type) {
|
|
case WalletType.monero:
|
|
return S.current.view_transaction_on + 'Monero.com';
|
|
case WalletType.bitcoin:
|
|
return S.current.view_transaction_on + 'mempool.space';
|
|
case WalletType.litecoin:
|
|
case WalletType.bitcoinCash:
|
|
return S.current.view_transaction_on + 'Blockchair.com';
|
|
case WalletType.haven:
|
|
return S.current.view_transaction_on + 'explorer.havenprotocol.org';
|
|
case WalletType.ethereum:
|
|
return S.current.view_transaction_on + 'etherscan.io';
|
|
case WalletType.nano:
|
|
return S.current.view_transaction_on + 'nanolooker.com';
|
|
case WalletType.banano:
|
|
return S.current.view_transaction_on + 'bananolooker.com';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
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()!),
|
|
if (showRecipientAddress && tx.to != null)
|
|
StandartListItem(title: S.current.transaction_details_recipient_address, value: tx.to!),
|
|
];
|
|
|
|
items.addAll(_items);
|
|
}
|
|
|
|
|
|
void _addNanoListItems(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 > 0).toString()),
|
|
StandartListItem(title: S.current.transaction_details_height, value: '${tx.height}'),
|
|
StandartListItem(title: S.current.transaction_details_amount, value: tx.amountFormatted()),
|
|
];
|
|
|
|
items.addAll(_items);
|
|
}
|
|
}
|