update transaction details screen

This commit is contained in:
Serhii 2023-05-09 17:45:52 +03:00
parent 2f511dc2e7
commit 3eb297f953

View file

@ -32,10 +32,7 @@ abstract class TransactionDetailsViewModelBase with Store {
required this.settingsStore}) required this.settingsStore})
: items = ObservableList<TransactionDetailsListItem>(), : items = ObservableList<TransactionDetailsListItem>(),
isRecipientAddressShown = false, isRecipientAddressShown = false,
showRecipientAddress = settingsStore.shouldSaveRecipientAddress, showRecipientAddress = settingsStore.shouldSaveRecipientAddress {
fiatRateListItem = StandartListItem(
title: S.current.historical_fiat_rate,
value: '${S.current.fetching.toLowerCase()} ...') {
final dateFormat = DateFormatter.withCurrentLocal(); final dateFormat = DateFormatter.withCurrentLocal();
final tx = transactionInfo; final tx = transactionInfo;
@ -58,9 +55,6 @@ abstract class TransactionDetailsViewModelBase with Store {
if (feeFormatted != null) if (feeFormatted != null)
StandartListItem( StandartListItem(
title: S.current.transaction_details_fee, value: feeFormatted), title: S.current.transaction_details_fee, value: feeFormatted),
if (settingsStore.fiatApiMode != FiatApiMode.disabled &&
settingsStore.showHistoricalFiatRate)
fiatRateListItem,
if (key?.isNotEmpty ?? false) if (key?.isNotEmpty ?? false)
StandartListItem(title: S.current.transaction_key, value: key!) StandartListItem(title: S.current.transaction_key, value: key!)
]; ];
@ -114,10 +108,7 @@ abstract class TransactionDetailsViewModelBase with Store {
if (tx.feeFormatted()?.isNotEmpty ?? false) if (tx.feeFormatted()?.isNotEmpty ?? false)
StandartListItem( StandartListItem(
title: S.current.transaction_details_fee, title: S.current.transaction_details_fee,
value: tx.feeFormatted()!), value: tx.feeFormatted()!)
if (settingsStore.fiatApiMode != FiatApiMode.disabled &&
settingsStore.showHistoricalFiatRate)
fiatRateListItem,
]; ];
items.addAll(_items); items.addAll(_items);
@ -137,10 +128,7 @@ abstract class TransactionDetailsViewModelBase with Store {
value: tx.amountFormatted()), value: tx.amountFormatted()),
if (tx.feeFormatted()?.isNotEmpty ?? false) if (tx.feeFormatted()?.isNotEmpty ?? false)
StandartListItem( StandartListItem(
title: S.current.transaction_details_fee, value: tx.feeFormatted()!), title: S.current.transaction_details_fee, value: tx.feeFormatted()!)
if (settingsStore.fiatApiMode != FiatApiMode.disabled &&
settingsStore.showHistoricalFiatRate)
fiatRateListItem,
]); ]);
} }
@ -196,7 +184,6 @@ abstract class TransactionDetailsViewModelBase with Store {
final Box<TransactionDescription> transactionDescriptionBox; final Box<TransactionDescription> transactionDescriptionBox;
final SettingsStore settingsStore; final SettingsStore settingsStore;
final WalletBase wallet; final WalletBase wallet;
final StandartListItem fiatRateListItem;
final ObservableList<TransactionDetailsListItem> items; final ObservableList<TransactionDetailsListItem> items;
bool showRecipientAddress; bool showRecipientAddress;
@ -204,8 +191,10 @@ abstract class TransactionDetailsViewModelBase with Store {
@action @action
Future<void> getHistoricalFiatRate() async { Future<void> getHistoricalFiatRate() async {
final fiatRateItemIndex = items.indexWhere((element) => element == fiatRateListItem); if (settingsStore.fiatApiMode != FiatApiMode.disabled && settingsStore.showHistoricalFiatRate) {
if (fiatRateItemIndex == -1) return; var fiatRateItemIndex =
items.indexWhere((element) => element.title == S.current.transaction_details_fee);
fiatRateItemIndex = fiatRateItemIndex == -1 ? items.length - 3 : fiatRateItemIndex;
final fiat = settingsStore.fiatCurrency; final fiat = settingsStore.fiatCurrency;
@ -227,13 +216,14 @@ abstract class TransactionDetailsViewModelBase with Store {
default: default:
formattedFiatAmount; formattedFiatAmount;
} }
final historicalFiatAmountFormatted = formattedFiatAmount * historicalFiatRate; final historicalFiatAmountFormatted = formattedFiatAmount * historicalFiatRate;
items[fiatRateItemIndex] = StandartListItem( if (historicalFiatAmountFormatted > 0.0)
items.insert(
fiatRateItemIndex + 1,
StandartListItem(
title: S.current.historical_fiat_rate, title: S.current.historical_fiat_rate,
value: historicalFiatAmountFormatted > 0.0 value: historicalFiatAmountFormatted.toStringAsFixed(2) + ' ${fiat}'));
? historicalFiatAmountFormatted.toStringAsFixed(2) + ' ${fiat}' }
: 'no historical data');
} }
String _explorerUrl(WalletType type, String txId) { String _explorerUrl(WalletType type, String txId) {