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';
|
2022-10-03 00:54:35 +00:00
|
|
|
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
2023-05-09 15:21:04 +00:00
|
|
|
import 'package:stackwallet/models/isar/sw_theme.dart';
|
|
|
|
import 'package:stackwallet/themes/theme_providers.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/format.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-10-27 19:26:55 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2022-11-22 14:07:22 +00:00
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
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);
|
|
|
|
|
2022-10-03 00:54:35 +00:00
|
|
|
final Trade trade;
|
2022-08-26 08:11:35 +00:00
|
|
|
final VoidCallback onTap;
|
|
|
|
|
2023-05-09 15:21:04 +00:00
|
|
|
String _fetchIconAssetForStatus(String statusString, ThemeAssets assets) {
|
2022-08-26 08:11:35 +00:00
|
|
|
ChangeNowTransactionStatus? status;
|
|
|
|
try {
|
|
|
|
if (statusString.toLowerCase().startsWith("waiting")) {
|
2023-03-03 17:56:21 +00:00
|
|
|
statusString = "Waiting";
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
status = changeNowTransactionStatusFromStringIgnoreCase(statusString);
|
|
|
|
} on ArgumentError catch (_) {
|
2023-03-03 17:56:21 +00:00
|
|
|
switch (statusString.toLowerCase()) {
|
|
|
|
case "funds confirming":
|
|
|
|
case "processing payment":
|
2023-05-09 15:21:04 +00:00
|
|
|
return assets.txExchangePending;
|
2023-03-03 17:56:21 +00:00
|
|
|
|
|
|
|
case "completed":
|
2023-05-09 15:21:04 +00:00
|
|
|
return assets.txExchange;
|
2023-03-03 17:56:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
status = ChangeNowTransactionStatus.Failed;
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case ChangeNowTransactionStatus.New:
|
|
|
|
case ChangeNowTransactionStatus.Waiting:
|
|
|
|
case ChangeNowTransactionStatus.Confirming:
|
|
|
|
case ChangeNowTransactionStatus.Exchanging:
|
|
|
|
case ChangeNowTransactionStatus.Sending:
|
|
|
|
case ChangeNowTransactionStatus.Refunded:
|
|
|
|
case ChangeNowTransactionStatus.Verifying:
|
2023-05-09 15:21:04 +00:00
|
|
|
return assets.txExchangePending;
|
2022-08-26 08:11:35 +00:00
|
|
|
case ChangeNowTransactionStatus.Finished:
|
2023-05-09 15:21:04 +00:00
|
|
|
return assets.txExchange;
|
2022-08-26 08:11:35 +00:00
|
|
|
case ChangeNowTransactionStatus.Failed:
|
2023-05-09 15:21:04 +00:00
|
|
|
return assets.txExchangeFailed;
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-11-22 14:07:22 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
|
|
|
|
return ConditionalParent(
|
|
|
|
condition: isDesktop,
|
|
|
|
builder: (child) => MouseRegion(
|
|
|
|
cursor: SystemMouseCursors.click,
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: onTap,
|
|
|
|
child: RoundedWhiteContainer(
|
|
|
|
padding:
|
|
|
|
isDesktop ? const EdgeInsets.all(16) : const EdgeInsets.all(12),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(32),
|
|
|
|
),
|
|
|
|
child: Center(
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
_fetchIconAssetForStatus(
|
|
|
|
trade.status,
|
2023-05-09 15:21:04 +00:00
|
|
|
ref.watch(themeProvider.select((value) => value.assets)),
|
2022-11-22 14:07:22 +00:00
|
|
|
),
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
2022-09-23 14:33:44 +00:00
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-22 14:07:22 +00:00
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2022-11-22 14:07:22 +00:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"${trade.payInCurrency.toUpperCase()} → ${trade.payOutCurrency.toUpperCase()}",
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${isDesktop ? "-" : ""}${Decimal.tryParse(trade.payInAmount) ?? "..."} ${trade.payInCurrency.toUpperCase()}",
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
if (!isDesktop)
|
|
|
|
Text(
|
|
|
|
trade.exchangeName,
|
|
|
|
style: STextStyles.label(context),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
Format.extractDateFrom(
|
|
|
|
trade.timestamp.millisecondsSinceEpoch ~/ 1000),
|
|
|
|
style: STextStyles.label(context),
|
|
|
|
),
|
|
|
|
if (isDesktop)
|
|
|
|
Text(
|
|
|
|
trade.exchangeName,
|
|
|
|
style: STextStyles.label(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|