stack_wallet/lib/pages/exchange_view/trade_details_view.dart

1429 lines
56 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
2022-09-03 18:37:54 +00:00
import 'dart:async';
import 'dart:io';
2022-09-03 18:37:54 +00:00
2022-08-26 08:11:35 +00:00
import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../app_config.dart';
import '../../models/exchange/change_now/exchange_transaction_status.dart';
import '../../models/isar/models/blockchain_data/transaction.dart';
import '../../models/isar/stack_theme.dart';
import '../../notifications/show_flush_bar.dart';
import '../../providers/global/trades_service_provider.dart';
import '../../providers/providers.dart';
import '../../route_generator.dart';
import '../../services/exchange/change_now/change_now_exchange.dart';
import '../../services/exchange/exchange.dart';
import '../../services/exchange/majestic_bank/majestic_bank_exchange.dart';
2024-07-01 19:02:08 +00:00
import '../../services/exchange/nanswap/nanswap_exchange.dart';
import '../../services/exchange/simpleswap/simpleswap_exchange.dart';
import '../../services/exchange/trocador/trocador_exchange.dart';
import '../../themes/stack_colors.dart';
import '../../themes/theme_providers.dart';
import '../../utilities/amount/amount.dart';
import '../../utilities/amount/amount_formatter.dart';
import '../../utilities/assets.dart';
import '../../utilities/clipboard_interface.dart';
import '../../utilities/constants.dart';
import '../../utilities/format.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
import '../../wallets/crypto_currency/crypto_currency.dart';
import '../../widgets/background.dart';
import '../../widgets/conditional_parent.dart';
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../widgets/custom_buttons/blue_text_button.dart';
import '../../widgets/desktop/desktop_dialog.dart';
import '../../widgets/desktop/secondary_button.dart';
import '../../widgets/qr.dart';
import '../../widgets/rounded_container.dart';
import '../../widgets/rounded_white_container.dart';
import '../../widgets/stack_dialog.dart';
import '../wallet_view/transaction_views/edit_note_view.dart';
import '../wallet_view/transaction_views/transaction_details_view.dart';
import 'edit_trade_note_view.dart';
import 'send_from_view.dart';
2022-08-26 08:11:35 +00:00
class TradeDetailsView extends ConsumerStatefulWidget {
const TradeDetailsView({
2024-05-15 21:20:45 +00:00
super.key,
2022-08-26 08:11:35 +00:00
required this.tradeId,
required this.transactionIfSentFromStack,
required this.walletId,
required this.walletName,
this.clipboard = const ClipboardWrapper(),
2024-05-15 21:20:45 +00:00
});
2022-08-26 08:11:35 +00:00
static const String routeName = "/tradeDetails";
final String tradeId;
final ClipboardInterface clipboard;
final Transaction? transactionIfSentFromStack;
final String? walletId;
final String? walletName;
@override
ConsumerState<TradeDetailsView> createState() => _TradeDetailsViewState();
}
class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
late final String tradeId;
late final ClipboardInterface clipboard;
late final Transaction? transactionIfSentFromStack;
late final String? walletId;
@override
initState() {
tradeId = widget.tradeId;
clipboard = widget.clipboard;
transactionIfSentFromStack = widget.transactionIfSentFromStack;
walletId = widget.walletId;
2022-09-03 18:37:54 +00:00
if (ref.read(prefsChangeNotifierProvider).externalCalls) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final trade = ref
.read(tradesServiceProvider)
.trades
.firstWhere((e) => e.tradeId == tradeId);
2022-09-03 18:37:54 +00:00
if (mounted) {
final exchange = Exchange.fromName(trade.exchangeName);
final response = await exchange.updateTrade(trade);
2022-09-03 18:37:54 +00:00
if (mounted && response.value != null) {
await ref
.read(tradesServiceProvider)
.edit(trade: response.value!, shouldNotifyListeners: true);
}
2022-09-03 18:37:54 +00:00
}
});
}
2022-08-26 08:11:35 +00:00
super.initState();
}
2023-05-18 18:52:48 +00:00
String _fetchIconAssetForStatus(String statusString, IThemeAssets assets) {
2022-08-26 08:11:35 +00:00
ChangeNowTransactionStatus? status;
try {
if (statusString.toLowerCase().startsWith("waiting")) {
statusString = "Waiting";
}
status = changeNowTransactionStatusFromStringIgnoreCase(statusString);
} on ArgumentError catch (_) {
2023-03-03 17:56:21 +00:00
switch (statusString.toLowerCase()) {
case "funds confirming":
case "processing payment":
return assets.txExchangePending;
2023-03-03 17:56:21 +00:00
case "completed":
return assets.txExchange;
2023-03-03 17:56:21 +00:00
default:
status = ChangeNowTransactionStatus.Failed;
2023-02-16 15:05:46 +00:00
}
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:
return assets.txExchangePending;
2022-08-26 08:11:35 +00:00
case ChangeNowTransactionStatus.Finished:
return assets.txExchange;
2022-08-26 08:11:35 +00:00
case ChangeNowTransactionStatus.Failed:
return assets.txExchangeFailed;
2022-08-26 08:11:35 +00:00
}
}
@override
Widget build(BuildContext context) {
final bool sentFromStack =
transactionIfSentFromStack != null && walletId != null;
2024-05-15 21:20:45 +00:00
final trade = ref.watch(
tradesServiceProvider.select(
(value) => value.trades.firstWhere((e) => e.tradeId == tradeId),
),
);
2022-08-26 08:11:35 +00:00
final bool hasTx = sentFromStack ||
!(trade.status == "New" ||
trade.status == "new" ||
trade.status == "Waiting" ||
trade.status == "waiting" ||
trade.status == "Refunded" ||
trade.status == "refunded" ||
trade.status == "Closed" ||
trade.status == "closed" ||
trade.status == "Expired" ||
trade.status == "expired" ||
trade.status == "Failed" ||
trade.status == "failed");
2022-08-26 08:11:35 +00:00
2022-12-13 00:17:02 +00:00
//todo: check if print needed
2023-02-16 15:05:46 +00:00
// debugPrint("walletId: $walletId");
// debugPrint("transactionIfSentFromStack: $transactionIfSentFromStack");
2022-12-13 00:17:02 +00:00
// debugPrint("sentFromStack: $sentFromStack");
// debugPrint("hasTx: $hasTx");
// debugPrint("trade: ${trade.toString()}");
2022-08-26 08:11:35 +00:00
final sendAmount =
Decimal.tryParse(trade.payInAmount) ?? Decimal.parse("-1");
2022-09-03 18:37:54 +00:00
2022-11-09 19:12:41 +00:00
final isDesktop = Util.isDesktop;
return ConditionalParent(
condition: !isDesktop,
builder: (child) => Background(
child: Scaffold(
2022-11-09 19:12:41 +00:00
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
leading: AppBarBackButton(
onPressed: () async {
Navigator.of(context).pop();
},
),
title: Text(
"Trade details",
style: STextStyles.navBarTitle(context),
),
2022-11-09 19:12:41 +00:00
),
body: Padding(
padding: const EdgeInsets.all(12),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(4),
child: child,
),
2022-11-09 19:12:41 +00:00
),
),
2022-08-26 08:11:35 +00:00
),
),
2022-11-09 19:12:41 +00:00
child: Padding(
padding: isDesktop
? const EdgeInsets.only(left: 32)
: const EdgeInsets.all(0),
child: BranchedParent(
condition: isDesktop,
conditionBranchBuilder: (children) => Padding(
padding: const EdgeInsets.only(
right: 20,
),
child: Padding(
padding: const EdgeInsets.only(
right: 12,
),
2022-11-22 14:07:22 +00:00
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
RoundedWhiteContainer(
2022-11-29 19:45:19 +00:00
borderColor: Theme.of(context)
.extension<StackColors>()!
.backgroundAppBar,
2022-11-22 14:07:22 +00:00
padding: const EdgeInsets.all(0),
child: ListView(
primary: false,
shrinkWrap: true,
children: children,
),
),
if (!hasTx &&
AppConfig.isStackCoin(trade.payInCurrency) &&
2022-11-22 14:07:22 +00:00
(trade.status == "New" ||
trade.status == "new" ||
trade.status == "waiting" ||
trade.status == "Waiting"))
const SizedBox(
height: 32,
),
if (!hasTx &&
AppConfig.isStackCoin(trade.payInCurrency) &&
2022-11-22 14:07:22 +00:00
(trade.status == "New" ||
trade.status == "new" ||
trade.status == "waiting" ||
trade.status == "Waiting"))
SecondaryButton(
label: "Send from Stack",
buttonHeight: ButtonHeight.l,
onPressed: () {
2024-05-15 21:20:45 +00:00
CryptoCurrency coin;
try {
coin = AppConfig.getCryptoCurrencyForTicker(
2024-05-15 21:20:45 +00:00
trade.payInCurrency,
)!;
} catch (_) {
coin = AppConfig.getCryptoCurrencyByPrettyName(
2024-05-15 21:20:45 +00:00
trade.payInCurrency,
);
}
2023-12-10 18:42:37 +00:00
final amount = Amount.fromDecimal(
sendAmount,
2024-05-15 21:20:45 +00:00
fractionDigits: coin.fractionDigits,
2023-12-10 18:42:37 +00:00
);
2023-04-05 22:06:31 +00:00
final address = trade.payInAddress;
2022-11-22 14:07:22 +00:00
Navigator.of(context).pushNamed(
SendFromView.routeName,
arguments: Tuple4(
coin,
amount,
address,
trade,
),
);
},
),
const SizedBox(
height: 32,
),
],
2022-11-09 19:12:41 +00:00
),
),
),
otherBranchBuilder: (children) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: isDesktop ? MainAxisSize.min : MainAxisSize.max,
children: children,
),
children: [
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(0)
: const EdgeInsets.all(12),
child: Container(
decoration: isDesktop
? BoxDecoration(
color: Theme.of(context)
.extension<StackColors>()!
2022-11-29 19:45:19 +00:00
.backgroundAppBar,
2022-11-09 19:12:41 +00:00
borderRadius: BorderRadius.vertical(
top: Radius.circular(
Constants.size.circularBorderRadius,
),
),
)
: null,
child: Padding(
padding: isDesktop
? const EdgeInsets.all(12)
: const EdgeInsets.all(0),
2022-08-26 08:11:35 +00:00
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2022-11-09 19:12:41 +00:00
if (isDesktop)
Row(
children: [
SvgPicture.file(
File(
_fetchIconAssetForStatus(
trade.status,
2023-05-18 18:52:48 +00:00
ref.watch(themeAssetsProvider),
),
),
2022-11-09 19:12:41 +00:00
width: 32,
height: 32,
),
const SizedBox(
width: 16,
),
SelectableText(
2023-03-10 22:01:34 +00:00
"Swap service",
2022-11-09 19:12:41 +00:00
style: STextStyles.desktopTextMedium(context),
),
],
),
2022-08-26 08:11:35 +00:00
Column(
2022-11-09 19:12:41 +00:00
crossAxisAlignment: isDesktop
? CrossAxisAlignment.end
: CrossAxisAlignment.start,
2022-08-26 08:11:35 +00:00
children: [
SelectableText(
"${trade.payInCurrency.toUpperCase()}${trade.payOutCurrency.toUpperCase()}",
2022-09-22 22:17:21 +00:00
style: STextStyles.titleBold12(context),
2022-08-26 08:11:35 +00:00
),
const SizedBox(
height: 4,
),
2024-05-15 21:20:45 +00:00
Builder(
builder: (context) {
String text;
try {
final coin =
AppConfig.getCryptoCurrencyForTicker(
2024-05-15 21:20:45 +00:00
trade.payInCurrency,
)!;
2024-05-15 21:20:45 +00:00
final amount = sendAmount.toAmount(
fractionDigits: coin.fractionDigits,
);
text = ref
.watch(pAmountFormatter(coin))
.format(amount);
} catch (_) {
text = sendAmount.toStringAsFixed(
2023-04-05 22:06:31 +00:00
trade.payInCurrency.toLowerCase() == "xmr"
? 12
2024-05-15 21:20:45 +00:00
: 8,
);
}
2023-04-05 22:06:31 +00:00
2024-05-15 21:20:45 +00:00
return SelectableText(
"-$text ${trade.payInCurrency.toUpperCase()}",
style: STextStyles.itemSubtitle(context),
);
},
),
2022-08-26 08:11:35 +00:00
],
),
2022-11-09 19:12:41 +00:00
if (!isDesktop)
Container(
width: 32,
height: 32,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(32),
),
child: Center(
child: SvgPicture.file(
File(
_fetchIconAssetForStatus(
trade.status,
2023-05-18 18:52:48 +00:00
ref.watch(themeAssetsProvider),
),
),
2022-11-09 19:12:41 +00:00
width: 32,
height: 32,
),
2022-08-26 08:11:35 +00:00
),
),
],
),
),
2022-11-09 19:12:41 +00:00
),
),
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
2022-11-09 19:12:41 +00:00
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Status",
style: STextStyles.itemSubtitle(context),
),
if (trade.exchangeName ==
MajesticBankExchange.exchangeName &&
trade.status == "Completed")
Row(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
onTap: () {
showDialog<void>(
context: context,
builder: (context) => const StackOkDialog(
title: "Trade Info",
message:
"Majestic Bank does not store order data indefinitely",
),
);
},
child: SvgPicture.asset(
Assets.svg.circleInfo,
height: 20,
width: 20,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
),
],
2024-05-15 21:20:45 +00:00
),
],
2022-08-26 08:11:35 +00:00
),
const SizedBox(
2022-11-09 19:12:41 +00:00
height: 4,
),
SelectableText(
trade.status,
style: STextStyles.itemSubtitle(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.colorForStatus(trade.status),
),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
],
),
),
if (!sentFromStack && !hasTx)
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
if (!sentFromStack && !hasTx)
RoundedContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
2022-11-22 14:07:22 +00:00
color: isDesktop
? Theme.of(context).extension<StackColors>()!.popupBG
: Theme.of(context)
.extension<StackColors>()!
.warningBackground,
child: ConditionalParent(
condition: isDesktop,
builder: (child) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Amount",
style: STextStyles.desktopTextExtraExtraSmall(
2024-05-15 21:20:45 +00:00
context,
),
2022-11-22 14:07:22 +00:00
),
const SizedBox(
height: 2,
),
Text(
"${trade.payInAmount} ${trade.payInCurrency.toUpperCase()}",
style: STextStyles.desktopTextExtraExtraSmall(
2024-05-15 21:20:45 +00:00
context,
).copyWith(
2022-11-22 14:07:22 +00:00
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
),
],
),
IconCopyButton(
data: trade.payInAmount,
),
],
2022-11-09 19:12:41 +00:00
),
2022-11-22 14:07:22 +00:00
const SizedBox(
height: 6,
),
child,
],
),
child: RichText(
text: TextSpan(
2024-05-15 21:20:45 +00:00
text:
"You must send at least ${sendAmount.toStringAsFixed(
trade.payInCurrency.toLowerCase() == "xmr" ? 12 : 8,
)} ${trade.payInCurrency.toUpperCase()}. ",
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.accentColorRed,
)
: STextStyles.label(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.warningForeground,
),
children: [
TextSpan(
text:
"If you send less than ${sendAmount.toStringAsFixed(
trade.payInCurrency.toLowerCase() == "xmr" ? 12 : 8,
)} ${trade.payInCurrency.toUpperCase()}, your transaction may not be converted and it may not be refunded.",
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(
context,
).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.accentColorRed,
)
: STextStyles.label(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.warningForeground,
),
),
],
),
2022-11-22 14:07:22 +00:00
),
2022-11-09 19:12:41 +00:00
),
),
if (sentFromStack)
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
if (sentFromStack)
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Sent from",
style: STextStyles.itemSubtitle(context),
),
const SizedBox(
height: 4,
),
SelectableText(
widget.walletName!,
style: STextStyles.itemSubtitle12(context),
),
const SizedBox(
height: 10,
),
CustomTextButton(
2022-11-09 19:12:41 +00:00
text: "View transaction",
onTap: () {
final coin = AppConfig.getCryptoCurrencyForTicker(
2024-05-15 21:20:45 +00:00
trade.payInCurrency,
)!;
2022-11-09 19:12:41 +00:00
if (isDesktop) {
Navigator.of(context).push(
FadePageRoute<void>(
DesktopDialog(
maxHeight:
MediaQuery.of(context).size.height - 64,
maxWidth: 580,
child: TransactionDetailsView(
coin: coin,
transaction: transactionIfSentFromStack!,
walletId: walletId!,
),
),
const RouteSettings(
name: TransactionDetailsView.routeName,
2022-08-26 08:11:35 +00:00
),
),
2022-11-09 19:12:41 +00:00
);
} else {
Navigator.of(context).pushNamed(
TransactionDetailsView.routeName,
arguments: Tuple3(
2024-05-15 21:20:45 +00:00
transactionIfSentFromStack!,
coin,
walletId!,
),
2022-11-09 19:12:41 +00:00
);
}
},
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
],
),
),
if (sentFromStack)
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
if (sentFromStack)
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${trade.exchangeName} address",
style: STextStyles.itemSubtitle(context),
),
const SizedBox(
height: 4,
),
Row(
children: [
Flexible(
child: SelectableText(
trade.payInAddress,
style: STextStyles.itemSubtitle12(context),
),
),
],
),
],
),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
if (isDesktop)
IconCopyButton(
data: trade.payInAddress,
),
],
),
),
if (!sentFromStack && !hasTx)
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
if (!sentFromStack && !hasTx)
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2022-08-26 08:11:35 +00:00
children: [
Text(
2022-11-09 19:12:41 +00:00
"Send ${trade.payInCurrency.toUpperCase()} to this address",
2022-09-22 22:17:21 +00:00
style: STextStyles.itemSubtitle(context),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
isDesktop
? IconCopyButton(
data: trade.payInAddress,
)
: GestureDetector(
onTap: () async {
final address = trade.payInAddress;
await Clipboard.setData(
ClipboardData(
text: address,
),
);
if (context.mounted) {
2023-03-06 20:01:48 +00:00
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
context: context,
),
);
}
2022-11-09 19:12:41 +00:00
},
child: Row(
children: [
SvgPicture.asset(
Assets.svg.copy,
width: 12,
height: 12,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
const SizedBox(
width: 4,
),
Text(
"Copy",
style: STextStyles.link2(context),
),
],
),
),
2022-08-26 08:11:35 +00:00
],
),
2022-11-09 19:12:41 +00:00
const SizedBox(
height: 4,
),
Row(
children: [
Expanded(
child: SelectableText(
trade.payInAddress,
style: STextStyles.itemSubtitle12(context),
),
),
],
2022-11-09 19:12:41 +00:00
),
const SizedBox(
height: 10,
),
GestureDetector(
onTap: () {
showDialog<dynamic>(
context: context,
useSafeArea: false,
barrierDismissible: true,
builder: (_) {
final width = MediaQuery.of(context).size.width / 2;
return StackDialogBase(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
2022-11-09 19:12:41 +00:00
Center(
child: Text(
"Send ${trade.payInCurrency.toUpperCase()} to this address",
style: STextStyles.pageTitleH2(context),
),
),
const SizedBox(
2022-11-09 19:12:41 +00:00
height: 12,
),
2022-11-09 19:12:41 +00:00
Center(
child: RepaintBoundary(
// key: _qrKey,
child: SizedBox(
width: width + 20,
height: width + 20,
child: QR(
2024-05-15 21:20:45 +00:00
data: trade.payInAddress,
size: width,
),
2022-11-09 19:12:41 +00:00
),
),
),
2022-11-09 19:12:41 +00:00
const SizedBox(
height: 12,
),
Center(
child: SizedBox(
width: width,
child: TextButton(
onPressed: () async {
// await _capturePng(true);
Navigator.of(context).pop();
},
style: Theme.of(context)
.extension<StackColors>()!
2023-01-24 19:29:12 +00:00
.getSecondaryEnabledButtonStyle(
2024-05-15 21:20:45 +00:00
context,
),
2022-08-26 08:11:35 +00:00
child: Text(
2022-11-09 19:12:41 +00:00
"Cancel",
style: STextStyles.button(context)
.copyWith(
2024-05-15 21:20:45 +00:00
color: Theme.of(context)
.extension<StackColors>()!
.accentColorDark,
),
2022-08-26 08:11:35 +00:00
),
),
2022-11-09 19:12:41 +00:00
),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
],
),
2022-08-26 08:11:35 +00:00
);
},
2022-11-09 19:12:41 +00:00
);
},
child: Row(
2022-08-26 08:11:35 +00:00
children: [
2022-11-09 19:12:41 +00:00
SvgPicture.asset(
Assets.svg.qrcode,
width: 12,
height: 12,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
const SizedBox(
width: 4,
),
Text(
"Show QR code",
style: STextStyles.link2(context),
2022-08-26 08:11:35 +00:00
),
],
),
2022-11-09 19:12:41 +00:00
),
],
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
),
isDesktop
? const _Divider()
: const SizedBox(
2022-08-26 08:11:35 +00:00
height: 12,
),
if (trade.payInExtraId.isNotEmpty && !sentFromStack && !hasTx)
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Memo",
style: STextStyles.itemSubtitle(context),
),
isDesktop
? IconCopyButton(
data: trade.payInExtraId,
)
: GestureDetector(
onTap: () async {
final address = trade.payInExtraId;
await Clipboard.setData(
ClipboardData(
text: address,
),
);
if (context.mounted) {
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
context: context,
),
);
}
},
child: Row(
children: [
SvgPicture.asset(
Assets.svg.copy,
width: 12,
height: 12,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
const SizedBox(
width: 4,
),
Text(
"Copy",
style: STextStyles.link2(context),
),
],
),
),
],
),
const SizedBox(
height: 4,
),
SelectableText(
trade.payInExtraId,
style: STextStyles.itemSubtitle12(context),
),
],
),
),
if (trade.payInExtraId.isNotEmpty && !sentFromStack && !hasTx)
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
2022-11-09 19:12:41 +00:00
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Trade note",
style: STextStyles.itemSubtitle(context),
),
isDesktop
? IconPencilButton(
onPressed: () {
showDialog<void>(
context: context,
builder: (context) {
return DesktopDialog(
maxWidth: 580,
maxHeight: 360,
child: EditTradeNoteView(
tradeId: tradeId,
2023-11-09 17:39:12 +00:00
note: ref
.read(tradeNoteServiceProvider)
.getNote(tradeId: tradeId),
2022-11-09 19:12:41 +00:00
),
);
},
);
},
)
: GestureDetector(
2022-08-26 08:11:35 +00:00
onTap: () {
Navigator.of(context).pushNamed(
2022-11-09 19:12:41 +00:00
EditTradeNoteView.routeName,
arguments: Tuple2(
tradeId,
ref
.read(tradeNoteServiceProvider)
.getNote(tradeId: tradeId),
2022-08-26 08:11:35 +00:00
),
);
},
child: Row(
children: [
SvgPicture.asset(
Assets.svg.pencil,
width: 10,
height: 10,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
2022-08-26 08:11:35 +00:00
),
const SizedBox(
width: 4,
),
Text(
"Edit",
2022-09-22 22:17:21 +00:00
style: STextStyles.link2(context),
2022-08-26 08:11:35 +00:00
),
],
),
),
2022-11-09 19:12:41 +00:00
],
),
const SizedBox(
height: 4,
),
SelectableText(
2024-05-15 21:20:45 +00:00
ref.watch(
tradeNoteServiceProvider
.select((value) => value.getNote(tradeId: tradeId)),
),
2022-11-09 19:12:41 +00:00
style: STextStyles.itemSubtitle12(context),
),
],
),
),
if (sentFromStack)
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
if (sentFromStack)
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Transaction note",
style: STextStyles.itemSubtitle(context),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
isDesktop
? IconPencilButton(
onPressed: () {
showDialog<void>(
context: context,
builder: (context) {
return DesktopDialog(
maxWidth: 580,
maxHeight: 360,
child: EditNoteView(
txid:
transactionIfSentFromStack!.txid,
walletId: walletId!,
),
);
},
);
},
)
: GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
EditNoteView.routeName,
2023-11-09 17:39:12 +00:00
arguments: Tuple2(
2022-11-09 19:12:41 +00:00
transactionIfSentFromStack!.txid,
2023-11-09 17:39:12 +00:00
walletId,
2022-11-09 19:12:41 +00:00
),
);
},
child: Row(
children: [
SvgPicture.asset(
Assets.svg.pencil,
width: 10,
height: 10,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
const SizedBox(
width: 4,
),
Text(
"Edit",
style: STextStyles.link2(context),
),
],
),
),
2022-08-26 08:11:35 +00:00
],
),
2022-11-09 19:12:41 +00:00
const SizedBox(
height: 4,
),
2023-11-09 17:39:12 +00:00
SelectableText(
ref
.watch(
pTransactionNote(
(
txid: transactionIfSentFromStack!.txid,
walletId: walletId!,
),
),
)
?.value ??
"",
style: STextStyles.itemSubtitle12(context),
2022-11-09 19:12:41 +00:00
),
],
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
),
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
2022-08-26 08:11:35 +00:00
children: [
Text(
"Date",
2022-09-22 22:17:21 +00:00
style: STextStyles.itemSubtitle(context),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
if (isDesktop)
const SizedBox(
height: 2,
),
if (isDesktop)
SelectableText(
Format.extractDateFrom(
2024-05-15 21:20:45 +00:00
trade.timestamp.millisecondsSinceEpoch ~/ 1000,
),
2022-11-09 19:12:41 +00:00
style: STextStyles.desktopTextExtraExtraSmall(context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
),
2022-08-26 08:11:35 +00:00
],
),
2022-11-09 19:12:41 +00:00
if (!isDesktop)
SelectableText(
Format.extractDateFrom(
2024-05-15 21:20:45 +00:00
trade.timestamp.millisecondsSinceEpoch ~/ 1000,
),
2022-11-09 19:12:41 +00:00
style: STextStyles.itemSubtitle12(context),
),
if (isDesktop)
IconCopyButton(
data: Format.extractDateFrom(
2024-05-15 21:20:45 +00:00
trade.timestamp.millisecondsSinceEpoch ~/ 1000,
),
2022-11-09 19:12:41 +00:00
),
],
),
),
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
2022-08-26 08:11:35 +00:00
children: [
Text(
2023-03-10 22:01:34 +00:00
"Swap service",
2022-09-22 22:17:21 +00:00
style: STextStyles.itemSubtitle(context),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
if (isDesktop)
const SizedBox(
height: 2,
),
if (isDesktop)
SelectableText(
trade.exchangeName,
style: STextStyles.itemSubtitle12(context),
),
2022-08-26 08:11:35 +00:00
],
),
2022-11-09 19:12:41 +00:00
if (isDesktop)
IconCopyButton(
data: trade.exchangeName,
),
if (!isDesktop)
SelectableText(
trade.exchangeName,
style: STextStyles.itemSubtitle12(context),
),
],
),
),
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
2022-08-26 08:11:35 +00:00
children: [
Text(
"Trade ID",
2022-09-22 22:17:21 +00:00
style: STextStyles.itemSubtitle(context),
2022-08-26 08:11:35 +00:00
),
2022-11-09 19:12:41 +00:00
if (isDesktop)
const SizedBox(
height: 2,
),
if (isDesktop)
Text(
trade.tradeId,
style: STextStyles.itemSubtitle12(context),
),
2022-08-26 08:11:35 +00:00
],
),
2022-11-09 19:12:41 +00:00
if (isDesktop)
IconCopyButton(
data: trade.tradeId,
),
if (!isDesktop)
Row(
children: [
Text(
trade.tradeId,
style: STextStyles.itemSubtitle12(context),
),
const SizedBox(
width: 10,
),
GestureDetector(
onTap: () async {
final data = ClipboardData(text: trade.tradeId);
await clipboard.setData(data);
if (context.mounted) {
2023-03-06 20:01:48 +00:00
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
context: context,
),
);
}
},
2022-11-09 19:12:41 +00:00
child: SvgPicture.asset(
Assets.svg.copy,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
width: 12,
),
2024-05-15 21:20:45 +00:00
),
2022-11-09 19:12:41 +00:00
],
),
],
),
),
isDesktop
? const _Divider()
: const SizedBox(
height: 12,
),
RoundedWhiteContainer(
padding: isDesktop
? const EdgeInsets.all(16)
: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Tracking",
style: STextStyles.itemSubtitle(context),
),
const SizedBox(
height: 4,
),
Builder(
builder: (context) {
late final String url;
switch (trade.exchangeName) {
case ChangeNowExchange.exchangeName:
url =
"https://changenow.io/exchange/txs/${trade.tradeId}";
break;
case SimpleSwapExchange.exchangeName:
url =
"https://simpleswap.io/exchange?id=${trade.tradeId}";
break;
2023-02-08 15:34:59 +00:00
case MajesticBankExchange.exchangeName:
url =
"https://majesticbank.sc/track?trx=${trade.tradeId}";
break;
2024-07-01 19:02:08 +00:00
case NanswapExchange.exchangeName:
url =
"https://nanswap.com/transaction/${trade.tradeId}";
break;
2023-04-28 20:31:26 +00:00
default:
if (trade.exchangeName
.startsWith(TrocadorExchange.exchangeName)) {
url =
2023-05-19 14:44:15 +00:00
"https://trocador.app/en/checkout/${trade.tradeId}";
2023-04-28 20:31:26 +00:00
}
}
return ConditionalParent(
condition: isDesktop,
builder: (child) => MouseRegion(
cursor: SystemMouseCursors.click,
child: child,
),
child: GestureDetector(
onTap: () {
launchUrl(
Uri.parse(url),
mode: LaunchMode.externalApplication,
);
},
child: Text(
url,
style: STextStyles.link2(context),
),
),
);
},
),
2022-11-09 19:12:41 +00:00
],
),
),
2022-11-22 14:07:22 +00:00
if (!isDesktop)
const SizedBox(
height: 12,
),
if (!isDesktop &&
!hasTx &&
AppConfig.isStackCoin(trade.payInCurrency) &&
2022-11-09 19:12:41 +00:00
(trade.status == "New" ||
trade.status == "new" ||
trade.status == "waiting" ||
trade.status == "Waiting"))
SecondaryButton(
label: "Send from Stack",
onPressed: () {
2024-05-15 21:20:45 +00:00
CryptoCurrency coin;
try {
coin = AppConfig.getCryptoCurrencyForTicker(
2024-05-15 21:20:45 +00:00
trade.payInCurrency,
)!;
} catch (_) {
coin = AppConfig.getCryptoCurrencyByPrettyName(
2024-05-15 21:20:45 +00:00
trade.payInCurrency,
);
}
2023-12-10 18:42:37 +00:00
final amount = Amount.fromDecimal(
sendAmount,
2024-05-15 21:20:45 +00:00
fractionDigits: coin.fractionDigits,
2023-12-10 18:42:37 +00:00
);
2022-11-09 19:12:41 +00:00
final address = trade.payInAddress;
2022-09-30 21:21:10 +00:00
2022-11-09 19:12:41 +00:00
Navigator.of(context).pushNamed(
SendFromView.routeName,
arguments: Tuple4(
coin,
amount,
address,
trade,
),
);
},
),
],
2022-08-26 08:11:35 +00:00
),
),
);
}
}
2022-11-09 19:12:41 +00:00
class _Divider extends StatelessWidget {
const _Divider({super.key});
2022-11-09 19:12:41 +00:00
@override
Widget build(BuildContext context) {
return Container(
height: 1,
2022-11-29 19:45:19 +00:00
color: Theme.of(context).extension<StackColors>()!.backgroundAppBar,
2022-11-09 19:12:41 +00:00
);
}
}