2022-09-06 21:51:22 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
|
|
|
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
|
|
|
import 'package:stackwallet/pages/wallet_view/sub_widgets/tx_icon.dart';
|
|
|
|
import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart';
|
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
|
|
|
import 'package:stackwallet/utilities/format.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-10-27 19:26:55 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2022-10-29 19:35:03 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
|
|
|
|
class TransactionCard extends ConsumerStatefulWidget {
|
|
|
|
const TransactionCard({
|
|
|
|
Key? key,
|
|
|
|
required this.transaction,
|
|
|
|
required this.walletId,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final Transaction transaction;
|
|
|
|
final String walletId;
|
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<TransactionCard> createState() => _TransactionCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TransactionCardState extends ConsumerState<TransactionCard> {
|
|
|
|
late final Transaction _transaction;
|
|
|
|
late final String walletId;
|
|
|
|
|
|
|
|
String whatIsIt(String type, Coin coin) {
|
|
|
|
if (coin == Coin.epicCash && _transaction.slateId == null) {
|
|
|
|
return "Restored Funds";
|
|
|
|
}
|
2022-09-06 23:27:14 +00:00
|
|
|
|
|
|
|
if (_transaction.subType == "mint") {
|
|
|
|
// if (type == "Received") {
|
|
|
|
if (_transaction.confirmedStatus) {
|
|
|
|
return "Anonymized";
|
|
|
|
} else {
|
|
|
|
return "Anonymizing";
|
|
|
|
}
|
|
|
|
// } else if (type == "Sent") {
|
|
|
|
// if (_transaction.confirmedStatus) {
|
|
|
|
// return "Sent MINT";
|
|
|
|
// } else {
|
|
|
|
// return "Sending MINT";
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// return type;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
if (type == "Received") {
|
2022-09-06 23:27:14 +00:00
|
|
|
// if (_transaction.isMinting) {
|
|
|
|
// return "Minting";
|
|
|
|
// } else
|
|
|
|
if (_transaction.confirmedStatus) {
|
2022-08-26 08:11:35 +00:00
|
|
|
return "Received";
|
|
|
|
} else {
|
|
|
|
return "Receiving";
|
|
|
|
}
|
|
|
|
} else if (type == "Sent") {
|
|
|
|
if (_transaction.confirmedStatus) {
|
|
|
|
return "Sent";
|
|
|
|
} else {
|
|
|
|
return "Sending";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
walletId = widget.walletId;
|
|
|
|
_transaction = widget.transaction;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final locale = ref.watch(
|
|
|
|
localeServiceChangeNotifierProvider.select((value) => value.locale));
|
|
|
|
final manager = ref.watch(walletsChangeNotifierProvider
|
|
|
|
.select((value) => value.getManager(walletId)));
|
|
|
|
|
|
|
|
final baseCurrency = ref
|
|
|
|
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
|
|
|
|
|
|
|
|
final coin = manager.coin;
|
|
|
|
|
|
|
|
final price = ref
|
|
|
|
.watch(priceAnd24hChangeNotifierProvider
|
|
|
|
.select((value) => value.getPrice(coin)))
|
|
|
|
.item1;
|
|
|
|
|
2022-11-02 14:49:19 +00:00
|
|
|
String prefix = "";
|
2022-10-27 19:26:55 +00:00
|
|
|
if (Util.isDesktop) {
|
|
|
|
if (_transaction.txType == "Sent") {
|
|
|
|
prefix = "-";
|
|
|
|
} else if (_transaction.txType == "Received") {
|
|
|
|
prefix = "+";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
return Material(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
2022-08-26 08:11:35 +00:00
|
|
|
elevation: 0,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(Constants.size.circularBorderRadius),
|
|
|
|
),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(6),
|
|
|
|
child: RawMaterialButton(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
if (coin == Coin.epicCash && _transaction.slateId == null) {
|
2022-09-06 21:51:22 +00:00
|
|
|
unawaited(showFloatingFlushBar(
|
2022-08-26 08:11:35 +00:00
|
|
|
context: context,
|
|
|
|
message:
|
|
|
|
"Restored Epic funds from your Seed have no Data.\nUse Stack Backup to keep your transaction history.",
|
|
|
|
type: FlushBarType.warning,
|
|
|
|
duration: const Duration(seconds: 5),
|
2022-09-06 21:51:22 +00:00
|
|
|
));
|
2022-08-26 08:11:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-29 19:35:03 +00:00
|
|
|
if (Util.isDesktop) {
|
|
|
|
await showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => DesktopDialog(
|
|
|
|
maxHeight: MediaQuery.of(context).size.height - 64,
|
|
|
|
maxWidth: 580,
|
|
|
|
child: TransactionDetailsView(
|
|
|
|
transaction: _transaction,
|
|
|
|
coin: coin,
|
|
|
|
walletId: walletId,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
unawaited(
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
TransactionDetailsView.routeName,
|
|
|
|
arguments: Tuple3(
|
|
|
|
_transaction,
|
|
|
|
coin,
|
|
|
|
walletId,
|
|
|
|
),
|
2022-10-27 19:26:55 +00:00
|
|
|
),
|
2022-10-29 19:35:03 +00:00
|
|
|
);
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
TxIcon(transaction: _transaction),
|
|
|
|
const SizedBox(
|
|
|
|
width: 14,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
// crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
child: Text(
|
|
|
|
_transaction.isCancelled
|
|
|
|
? "Cancelled"
|
|
|
|
: whatIsIt(_transaction.txType, coin),
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
|
|
|
Flexible(
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
child: Builder(
|
|
|
|
builder: (_) {
|
2022-09-28 23:15:16 +00:00
|
|
|
final amount = coin == Coin.monero
|
2022-08-26 08:11:35 +00:00
|
|
|
? (_transaction.amount ~/ 10000)
|
2022-09-28 23:15:16 +00:00
|
|
|
: coin == Coin.wownero
|
|
|
|
? (_transaction.amount ~/ 1000)
|
|
|
|
: _transaction.amount;
|
2022-08-26 08:11:35 +00:00
|
|
|
return Text(
|
2022-10-27 19:26:55 +00:00
|
|
|
"$prefix${Format.satoshiAmountToPrettyString(amount, locale)} ${coin.ticker}",
|
2022-09-24 21:52:03 +00:00
|
|
|
style:
|
|
|
|
STextStyles.itemSubtitle12_600(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
// crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
child: Text(
|
|
|
|
Format.extractDateFrom(_transaction.timestamp),
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.label(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-10-17 22:07:40 +00:00
|
|
|
if (ref.watch(prefsChangeNotifierProvider
|
|
|
|
.select((value) => value.externalCalls)))
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
|
|
|
if (ref.watch(prefsChangeNotifierProvider
|
|
|
|
.select((value) => value.externalCalls)))
|
|
|
|
Flexible(
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
child: Builder(
|
|
|
|
builder: (_) {
|
|
|
|
// TODO: modify Format.<functions> to take optional Coin parameter so this type oif check isn't done in ui
|
|
|
|
int value = _transaction.amount;
|
|
|
|
if (coin == Coin.monero) {
|
|
|
|
value = (value ~/ 10000);
|
|
|
|
} else if (coin == Coin.wownero) {
|
|
|
|
value = (value ~/ 1000);
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-10-17 22:07:40 +00:00
|
|
|
return Text(
|
2022-10-27 19:26:55 +00:00
|
|
|
"$prefix${Format.localizedStringAsFixed(
|
2022-10-17 22:07:40 +00:00
|
|
|
value: Format.satoshisToAmount(value) *
|
|
|
|
price,
|
|
|
|
locale: locale,
|
|
|
|
decimalPlaces: 2,
|
|
|
|
)} $baseCurrency",
|
|
|
|
style: STextStyles.label(context),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|