stack_wallet/lib/widgets/trade_card.dart

118 lines
3.9 KiB
Dart
Raw Normal View History

2022-08-26 08:11:35 +00:00
import 'package:decimal/decimal.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/format.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
class TradeCard extends ConsumerWidget {
const TradeCard({
Key? key,
required this.trade,
required this.onTap,
}) : super(key: key);
final Trade trade;
2022-08-26 08:11:35 +00:00
final VoidCallback onTap;
2022-09-23 14:33:44 +00:00
String _fetchIconAssetForStatus(String statusString, BuildContext context) {
2022-08-26 08:11:35 +00:00
ChangeNowTransactionStatus? status;
try {
if (statusString.toLowerCase().startsWith("waiting")) {
statusString = "waiting";
}
status = changeNowTransactionStatusFromStringIgnoreCase(statusString);
} on ArgumentError catch (_) {
status = ChangeNowTransactionStatus.Failed;
}
switch (status) {
case ChangeNowTransactionStatus.New:
case ChangeNowTransactionStatus.Waiting:
case ChangeNowTransactionStatus.Confirming:
case ChangeNowTransactionStatus.Exchanging:
case ChangeNowTransactionStatus.Sending:
case ChangeNowTransactionStatus.Refunded:
case ChangeNowTransactionStatus.Verifying:
2022-09-23 14:33:44 +00:00
return Assets.svg.txExchangePending(context);
2022-08-26 08:11:35 +00:00
case ChangeNowTransactionStatus.Finished:
2022-09-23 14:33:44 +00:00
return Assets.svg.txExchange(context);
2022-08-26 08:11:35 +00:00
case ChangeNowTransactionStatus.Failed:
2022-09-23 14:33:44 +00:00
return Assets.svg.txExchangeFailed(context);
2022-08-26 08:11:35 +00:00
}
}
@override
Widget build(BuildContext context, WidgetRef ref) {
return GestureDetector(
onTap: onTap,
child: RoundedWhiteContainer(
child: Row(
children: [
Container(
width: 32,
height: 32,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(32),
),
child: Center(
child: SvgPicture.asset(
_fetchIconAssetForStatus(
trade.status,
2022-09-23 14:33:44 +00:00
context,
),
2022-08-26 08:11:35 +00:00
width: 32,
height: 32,
),
),
),
const SizedBox(
width: 12,
),
Expanded(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"${trade.payInCurrency.toUpperCase()}${trade.payOutCurrency.toUpperCase()}",
2022-09-22 22:17:21 +00:00
style: STextStyles.itemSubtitle12(context),
2022-08-26 08:11:35 +00:00
),
Text(
"${Decimal.tryParse(trade.payInAmount) ?? "..."} ${trade.payInCurrency.toUpperCase()}",
2022-09-22 22:17:21 +00:00
style: STextStyles.itemSubtitle12(context),
2022-08-26 08:11:35 +00:00
),
],
),
const SizedBox(
height: 2,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
trade.exchangeName,
2022-09-22 22:17:21 +00:00
style: STextStyles.label(context),
2022-08-26 08:11:35 +00:00
),
Text(
Format.extractDateFrom(
trade.timestamp.millisecondsSinceEpoch ~/ 1000),
2022-09-22 22:17:21 +00:00
style: STextStyles.label(context),
2022-08-26 08:11:35 +00:00
),
],
),
],
),
)
],
),
),
);
}
}