From cd6c057f8c6055a885bbb83129d8709b32f3ff35 Mon Sep 17 00:00:00 2001
From: julian <julian@cypherstack.com>
Date: Tue, 11 Apr 2023 13:14:34 -0600
Subject: [PATCH] dynamic fee type checks

---
 .../confirm_change_now_send.dart              | 55 +++++++++++--------
 .../send_view/confirm_transaction_view.dart   | 46 +++++++++-------
 .../sub_widgets/desktop_token_send.dart       |  2 +-
 3 files changed, 59 insertions(+), 44 deletions(-)

diff --git a/lib/pages/exchange_view/confirm_change_now_send.dart b/lib/pages/exchange_view/confirm_change_now_send.dart
index 5d9ed25c7..a3544ade4 100644
--- a/lib/pages/exchange_view/confirm_change_now_send.dart
+++ b/lib/pages/exchange_view/confirm_change_now_send.dart
@@ -359,10 +359,16 @@ class _ConfirmChangeNowSendViewState
                         mainAxisAlignment: MainAxisAlignment.end,
                         children: [
                           Text(
-                            "${(transactionInfo["fee"] as int).toAmountAsRaw(
-                              fractionDigits: ref.watch(
-                                managerProvider
-                                    .select((value) => value.coin.decimals),
+                            "${(transactionInfo["fee"] is Amount ? transactionInfo["fee"] as Amount : (transactionInfo["fee"] as int).toAmountAsRaw(
+                                fractionDigits: ref.watch(
+                                  managerProvider
+                                      .select((value) => value.coin.decimals),
+                                ),
+                              )).localizedStringAsFixed(
+                              locale: ref.watch(
+                                localeServiceChangeNotifierProvider.select(
+                                  (value) => value.locale,
+                                ),
                               ),
                             )} ${ref.watch(
                                   managerProvider.select((value) => value.coin),
@@ -401,10 +407,12 @@ class _ConfirmChangeNowSendViewState
                               final coin = ref.watch(
                                 managerProvider.select((value) => value.coin),
                               );
-                              final fee =
-                                  (transactionInfo["fee"] as int).toAmountAsRaw(
-                                fractionDigits: coin.decimals,
-                              );
+                              final fee = transactionInfo["fee"] is Amount
+                                  ? transactionInfo["fee"] as Amount
+                                  : (transactionInfo["fee"] as int)
+                                      .toAmountAsRaw(
+                                      fractionDigits: coin.decimals,
+                                    );
                               final amount =
                                   transactionInfo["recipientAmt"] as Amount;
                               final total = amount + fee;
@@ -637,17 +645,17 @@ class _ConfirmChangeNowSendViewState
                     style: STextStyles.smallMed12(context),
                   ),
                   Text(
-                    "${(transactionInfo["fee"] as int).toAmountAsRaw(fractionDigits: ref.watch(
-                          managerProvider.select(
-                            (value) => value.coin.decimals,
-                          ),
-                        )).localizedStringAsFixed(
-                          locale: ref.watch(
-                            localeServiceChangeNotifierProvider.select(
-                              (value) => value.locale,
-                            ),
-                          ),
-                        )} ${ref.watch(
+                    "${(transactionInfo["fee"] is Amount ? transactionInfo["fee"] as Amount : (transactionInfo["fee"] as int).toAmountAsRaw(fractionDigits: ref.watch(
+                        managerProvider.select(
+                          (value) => value.coin.decimals,
+                        ),
+                      ))).localizedStringAsFixed(
+                      locale: ref.watch(
+                        localeServiceChangeNotifierProvider.select(
+                          (value) => value.locale,
+                        ),
+                      ),
+                    )} ${ref.watch(
                           managerProvider.select((value) => value.coin),
                         ).ticker}",
                     style: STextStyles.itemSubtitle12(context),
@@ -733,10 +741,11 @@ class _ConfirmChangeNowSendViewState
                         final coin = ref.watch(
                           managerProvider.select((value) => value.coin),
                         );
-                        final fee =
-                            (transactionInfo["fee"] as int).toAmountAsRaw(
-                          fractionDigits: coin.decimals,
-                        );
+                        final fee = transactionInfo["fee"] is Amount
+                            ? transactionInfo["fee"] as Amount
+                            : (transactionInfo["fee"] as int).toAmountAsRaw(
+                                fractionDigits: coin.decimals,
+                              );
                         final amount =
                             transactionInfo["recipientAmt"] as Amount;
                         final total = amount + fee;
diff --git a/lib/pages/send_view/confirm_transaction_view.dart b/lib/pages/send_view/confirm_transaction_view.dart
index bb5c5b71c..ba4c14b2f 100644
--- a/lib/pages/send_view/confirm_transaction_view.dart
+++ b/lib/pages/send_view/confirm_transaction_view.dart
@@ -427,18 +427,18 @@ class _ConfirmTransactionViewState
                           style: STextStyles.smallMed12(context),
                         ),
                         Text(
-                          "${(transactionInfo["fee"] as int).toAmountAsRaw(
-                                fractionDigits: ref.watch(
-                                  managerProvider.select(
-                                    (value) => value.coin.decimals,
-                                  ),
+                          "${(transactionInfo["fee"] is Amount ? transactionInfo["fee"] as Amount : (transactionInfo["fee"] as int).toAmountAsRaw(
+                              fractionDigits: ref.watch(
+                                managerProvider.select(
+                                  (value) => value.coin.decimals,
                                 ),
-                              ).localizedStringAsFixed(
-                                locale: ref.watch(
-                                  localeServiceChangeNotifierProvider
-                                      .select((value) => value.locale),
-                                ),
-                              )} ${ref.watch(
+                              ),
+                            )).localizedStringAsFixed(
+                            locale: ref.watch(
+                              localeServiceChangeNotifierProvider
+                                  .select((value) => value.locale),
+                            ),
+                          )} ${ref.watch(
                                 managerProvider.select((value) => value.coin),
                               ).ticker}",
                           style: STextStyles.itemSubtitle12(context),
@@ -678,10 +678,12 @@ class _ConfirmTransactionViewState
                                               value.getManager(walletId)))
                                       .coin;
 
-                                  final fee = (transactionInfo["fee"] as int)
-                                      .toAmountAsRaw(
-                                    fractionDigits: coin.decimals,
-                                  );
+                                  final fee = transactionInfo["fee"] is Amount
+                                      ? transactionInfo["fee"] as Amount
+                                      : (transactionInfo["fee"] as int)
+                                          .toAmountAsRaw(
+                                          fractionDigits: coin.decimals,
+                                        );
 
                                   return Text(
                                     "${fee.localizedStringAsFixed(
@@ -857,9 +859,11 @@ class _ConfirmTransactionViewState
                               .select((value) => value.getManager(walletId)))
                           .coin;
 
-                      final fee = (transactionInfo["fee"] as int).toAmountAsRaw(
-                        fractionDigits: coin.decimals,
-                      );
+                      final fee = transactionInfo["fee"] is Amount
+                          ? transactionInfo["fee"] as Amount
+                          : (transactionInfo["fee"] as int).toAmountAsRaw(
+                              fractionDigits: coin.decimals,
+                            );
 
                       return Text(
                         "${fee.localizedStringAsFixed(
@@ -916,8 +920,10 @@ class _ConfirmTransactionViewState
                     Builder(builder: (context) {
                       final coin = ref.watch(walletsChangeNotifierProvider
                           .select((value) => value.getManager(walletId).coin));
-                      final fee = (transactionInfo["fee"] as int)
-                          .toAmountAsRaw(fractionDigits: coin.decimals);
+                      final fee = transactionInfo["fee"] is Amount
+                          ? transactionInfo["fee"] as Amount
+                          : (transactionInfo["fee"] as int)
+                              .toAmountAsRaw(fractionDigits: coin.decimals);
                       final locale = ref.watch(
                         localeServiceChangeNotifierProvider
                             .select((value) => value.locale),
diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart
index b239223a7..b00960aab 100644
--- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart
+++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart
@@ -305,7 +305,7 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
                         padding: const EdgeInsets.only(
                           right: 32,
                         ),
-                        child: Text(
+                        child: SelectableText(
                           e.toString(),
                           textAlign: TextAlign.left,
                           style: STextStyles.desktopTextExtraExtraSmall(context)