From 723ec64354cf1116b9c8ab5b45792a8303a5d6e4 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 11 Apr 2023 14:25:13 -0600 Subject: [PATCH] eth fixes --- .../send_view/confirm_transaction_view.dart | 133 ++++++++++-------- .../coins/ethereum/ethereum_wallet.dart | 2 +- lib/services/ethereum/ethereum_api.dart | 6 +- 3 files changed, 78 insertions(+), 63 deletions(-) diff --git a/lib/pages/send_view/confirm_transaction_view.dart b/lib/pages/send_view/confirm_transaction_view.dart index ba4c14b2f..a46f86666 100644 --- a/lib/pages/send_view/confirm_transaction_view.dart +++ b/lib/pages/send_view/confirm_transaction_view.dart @@ -552,10 +552,22 @@ class _ConfirmTransactionViewState String fiatAmount = "N/A"; if (externalCalls) { - final price = ref - .read(priceAnd24hChangeNotifierProvider) - .getPrice(coin) - .item1; + final price = widget.isTokenTx + ? ref + .read( + priceAnd24hChangeNotifierProvider) + .getTokenPrice( + ref + .read(tokenServiceProvider)! + .tokenContract + .address, + ) + .item1 + : ref + .read( + priceAnd24hChangeNotifierProvider) + .getPrice(coin) + .item1; if (price > Decimal.zero) { fiatAmount = (amount.decimal * price) .toAmount(fractionDigits: 2) @@ -883,58 +895,28 @@ class _ConfirmTransactionViewState SizedBox( height: isDesktop ? 23 : 12, ), - Padding( - padding: isDesktop - ? const EdgeInsets.symmetric( - horizontal: 32, - ) - : const EdgeInsets.all(0), - child: RoundedContainer( + if (!widget.isTokenTx) + Padding( padding: isDesktop ? const EdgeInsets.symmetric( - horizontal: 16, - vertical: 18, + horizontal: 32, ) - : const EdgeInsets.all(12), - color: Theme.of(context) - .extension()! - .snackBarBackSuccess, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - isDesktop ? "Total amount to send" : "Total amount", - style: isDesktop - ? STextStyles.desktopTextExtraExtraSmall(context) - .copyWith( - color: Theme.of(context) - .extension()! - .textConfirmTotalAmount, - ) - : STextStyles.titleBold12(context).copyWith( - color: Theme.of(context) - .extension()! - .textConfirmTotalAmount, - ), - ), - Builder(builder: (context) { - final coin = ref.watch(walletsChangeNotifierProvider - .select((value) => value.getManager(walletId).coin)); - 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), - ); - final amount = transactionInfo["recipientAmt"] as Amount; - return Text( - "${(amount + fee).localizedStringAsFixed( - locale: locale, - )} ${ref.watch( - managerProvider.select((value) => value.coin), - ).ticker}", + : const EdgeInsets.all(0), + child: RoundedContainer( + padding: isDesktop + ? const EdgeInsets.symmetric( + horizontal: 16, + vertical: 18, + ) + : const EdgeInsets.all(12), + color: Theme.of(context) + .extension()! + .snackBarBackSuccess, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + isDesktop ? "Total amount to send" : "Total amount", style: isDesktop ? STextStyles.desktopTextExtraExtraSmall(context) .copyWith( @@ -942,18 +924,51 @@ class _ConfirmTransactionViewState .extension()! .textConfirmTotalAmount, ) - : STextStyles.itemSubtitle12(context).copyWith( + : STextStyles.titleBold12(context).copyWith( color: Theme.of(context) .extension()! .textConfirmTotalAmount, ), - textAlign: TextAlign.right, - ); - }), - ], + ), + Builder(builder: (context) { + final coin = ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(walletId).coin)); + 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), + ); + final amount = + transactionInfo["recipientAmt"] as Amount; + return Text( + "${(amount + fee).localizedStringAsFixed( + locale: locale, + )} ${ref.watch( + managerProvider.select((value) => value.coin), + ).ticker}", + style: isDesktop + ? STextStyles.desktopTextExtraExtraSmall(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textConfirmTotalAmount, + ) + : STextStyles.itemSubtitle12(context).copyWith( + color: Theme.of(context) + .extension()! + .textConfirmTotalAmount, + ), + textAlign: TextAlign.right, + ); + }), + ], + ), ), ), - ), SizedBox( height: isDesktop ? 28 : 16, ), diff --git a/lib/services/coins/ethereum/ethereum_wallet.dart b/lib/services/coins/ethereum/ethereum_wallet.dart index 797388f67..184b67cdb 100644 --- a/lib/services/coins/ethereum/ethereum_wallet.dart +++ b/lib/services/coins/ethereum/ethereum_wallet.dart @@ -923,7 +923,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB { // precision may be lost here hence the following amountString amount: (txData["recipientAmt"] as Amount).raw.toInt(), amountString: (txData["recipientAmt"] as Amount).toJsonString(), - fee: txData["fee"] as int, + fee: (txData["fee"] as Amount).raw.toInt(), height: null, isCancelled: false, isLelantus: false, diff --git a/lib/services/ethereum/ethereum_api.dart b/lib/services/ethereum/ethereum_api.dart index d31bcfd40..09f190eb0 100644 --- a/lib/services/ethereum/ethereum_api.dart +++ b/lib/services/ethereum/ethereum_api.dart @@ -449,7 +449,7 @@ abstract class EthereumAPI { }) async { try { final uri = Uri.parse( - "$stackBaseServer/state?addrs=$address&parts=nonce", + "$stackBaseServer/state?addrs=$address&parts=all", ); final response = await get(uri); @@ -469,7 +469,7 @@ abstract class EthereumAPI { } } else { throw EthApiException( - "getWalletTokenBalance($address) failed with status code: " + "getAddressNonce($address) failed with status code: " "${response.statusCode}", ); } @@ -480,7 +480,7 @@ abstract class EthereumAPI { ); } catch (e, s) { Logging.instance.log( - "getWalletTokenBalance(): $e\n$s", + "getAddressNonce(): $e\n$s", level: LogLevel.Error, ); return EthereumResponse(