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';
|
2023-01-12 04:26:38 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
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';
|
2023-03-27 15:59:57 +00:00
|
|
|
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
2023-04-06 21:24:56 +00:00
|
|
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.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);
|
|
|
|
|
2023-01-12 04:26:38 +00:00
|
|
|
final Transaction transaction;
|
2022-08-26 08:11:35 +00:00
|
|
|
final String walletId;
|
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<TransactionCard> createState() => _TransactionCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TransactionCardState extends ConsumerState<TransactionCard> {
|
2023-01-12 04:26:38 +00:00
|
|
|
late final Transaction _transaction;
|
2023-01-10 23:53:09 +00:00
|
|
|
late final String walletId;
|
2023-03-27 15:59:57 +00:00
|
|
|
late final bool isTokenTx;
|
|
|
|
late final String prefix;
|
|
|
|
late final String unit;
|
|
|
|
late final Coin coin;
|
2023-01-10 23:53:09 +00:00
|
|
|
|
|
|
|
String whatIsIt(
|
2023-01-12 04:26:38 +00:00
|
|
|
TransactionType type,
|
2023-01-10 23:53:09 +00:00
|
|
|
Coin coin,
|
|
|
|
int currentHeight,
|
|
|
|
) {
|
|
|
|
if (coin == Coin.epicCash && _transaction.slateId == null) {
|
|
|
|
return "Restored Funds";
|
|
|
|
}
|
|
|
|
|
|
|
|
final confirmedStatus = _transaction.isConfirmed(
|
|
|
|
currentHeight,
|
|
|
|
coin.requiredConfirmations,
|
|
|
|
);
|
|
|
|
|
2023-01-17 18:31:07 +00:00
|
|
|
if (type != TransactionType.incoming &&
|
|
|
|
_transaction.subType == TransactionSubType.mint) {
|
2023-01-10 23:53:09 +00:00
|
|
|
// if (type == "Received") {
|
|
|
|
if (confirmedStatus) {
|
|
|
|
return "Anonymized";
|
|
|
|
} else {
|
|
|
|
return "Anonymizing";
|
|
|
|
}
|
|
|
|
// } else if (type == "Sent") {
|
|
|
|
// if (_transaction.confirmedStatus) {
|
|
|
|
// return "Sent MINT";
|
|
|
|
// } else {
|
|
|
|
// return "Sending MINT";
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// return type;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2023-01-12 04:26:38 +00:00
|
|
|
if (type == TransactionType.incoming) {
|
2023-01-10 23:53:09 +00:00
|
|
|
// if (_transaction.isMinting) {
|
|
|
|
// return "Minting";
|
|
|
|
// } else
|
|
|
|
if (confirmedStatus) {
|
|
|
|
return "Received";
|
|
|
|
} else {
|
|
|
|
return "Receiving";
|
|
|
|
}
|
2023-01-12 04:26:38 +00:00
|
|
|
} else if (type == TransactionType.outgoing) {
|
2023-01-10 23:53:09 +00:00
|
|
|
if (confirmedStatus) {
|
|
|
|
return "Sent";
|
|
|
|
} else {
|
|
|
|
return "Sending";
|
|
|
|
}
|
2023-03-08 19:29:05 +00:00
|
|
|
} else if (type == TransactionType.sentToSelf) {
|
|
|
|
return "Sent to self";
|
2023-01-10 23:53:09 +00:00
|
|
|
} else {
|
|
|
|
return type.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
walletId = widget.walletId;
|
|
|
|
_transaction = widget.transaction;
|
2023-03-27 15:59:57 +00:00
|
|
|
isTokenTx = _transaction.subType == TransactionSubType.ethToken;
|
|
|
|
if (Util.isDesktop) {
|
|
|
|
if (_transaction.type == TransactionType.outgoing) {
|
|
|
|
prefix = "-";
|
|
|
|
} else if (_transaction.type == TransactionType.incoming) {
|
|
|
|
prefix = "+";
|
|
|
|
} else {
|
|
|
|
prefix = "";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
prefix = "";
|
|
|
|
}
|
|
|
|
coin = ref
|
|
|
|
.read(walletsChangeNotifierProvider)
|
|
|
|
.getManager(widget.walletId)
|
|
|
|
.coin;
|
|
|
|
|
|
|
|
unit = isTokenTx
|
|
|
|
? ref
|
|
|
|
.read(mainDBProvider)
|
|
|
|
.getEthContractSync(_transaction.otherData!)!
|
|
|
|
.symbol
|
|
|
|
: coin.ticker;
|
2023-01-10 23:53:09 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final locale = ref.watch(
|
|
|
|
localeServiceChangeNotifierProvider.select((value) => value.locale));
|
|
|
|
|
|
|
|
final baseCurrency = ref
|
|
|
|
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
|
|
|
|
|
|
|
|
final price = ref
|
2023-03-27 15:59:57 +00:00
|
|
|
.watch(priceAnd24hChangeNotifierProvider.select((value) => isTokenTx
|
|
|
|
? value.getTokenPrice(_transaction.otherData!)
|
|
|
|
: value.getPrice(coin)))
|
2023-01-10 23:53:09 +00:00
|
|
|
.item1;
|
|
|
|
|
2023-01-30 18:03:23 +00:00
|
|
|
final currentHeight = ref.watch(walletsChangeNotifierProvider
|
|
|
|
.select((value) => value.getManager(walletId).currentHeight));
|
2023-01-10 23:53:09 +00:00
|
|
|
|
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
|
|
|
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) {
|
|
|
|
unawaited(showFloatingFlushBar(
|
|
|
|
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),
|
|
|
|
));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Util.isDesktop) {
|
2023-01-12 04:26:38 +00:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2023-01-10 23:53:09 +00:00
|
|
|
} else {
|
|
|
|
unawaited(
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
TransactionDetailsView.routeName,
|
|
|
|
arguments: Tuple3(
|
|
|
|
_transaction,
|
|
|
|
coin,
|
|
|
|
walletId,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2023-01-12 04:26:38 +00:00
|
|
|
TxIcon(
|
2023-01-10 23:53:09 +00:00
|
|
|
transaction: _transaction,
|
2023-03-27 15:59:57 +00:00
|
|
|
coin: coin,
|
2023-01-10 23:53:09 +00:00
|
|
|
currentHeight: currentHeight,
|
|
|
|
),
|
|
|
|
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(
|
2023-01-11 20:47:27 +00:00
|
|
|
_transaction.isCancelled
|
2023-01-10 23:53:09 +00:00
|
|
|
? "Cancelled"
|
|
|
|
: whatIsIt(
|
|
|
|
_transaction.type,
|
|
|
|
coin,
|
|
|
|
currentHeight,
|
|
|
|
),
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
|
|
|
Flexible(
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.scaleDown,
|
2022-08-26 08:11:35 +00:00
|
|
|
child: Builder(
|
|
|
|
builder: (_) {
|
2023-03-24 23:40:20 +00:00
|
|
|
final amount = _transaction.realAmount;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
return Text(
|
2023-04-05 22:06:31 +00:00
|
|
|
"$prefix${amount.localizedStringAsFixed(
|
2023-03-24 23:40:20 +00:00
|
|
|
locale: locale,
|
2023-03-27 15:59:57 +00:00
|
|
|
)} $unit",
|
2023-03-17 14:53:31 +00:00
|
|
|
style: STextStyles.itemSubtitle12(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: (_) {
|
2023-03-24 23:40:20 +00:00
|
|
|
final amount = _transaction.realAmount;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-10-17 22:07:40 +00:00
|
|
|
return Text(
|
2023-04-05 22:06:31 +00:00
|
|
|
"$prefix${Amount.fromDecimal(
|
|
|
|
amount.decimal * price,
|
|
|
|
fractionDigits: 2,
|
|
|
|
).localizedStringAsFixed(
|
2022-10-17 22:07:40 +00:00
|
|
|
locale: locale,
|
|
|
|
decimalPlaces: 2,
|
|
|
|
)} $baseCurrency",
|
|
|
|
style: STextStyles.label(context),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|