diff --git a/android/app/build.gradle b/android/app/build.gradle index 0bd16c62..90856f87 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -78,7 +78,7 @@ android { } } - ndkVersion 25.1.8937393 + ndkVersion "25.1.8937393" } flutter { diff --git a/lib/appstate_container.dart b/lib/appstate_container.dart index 52245844..e1e4a027 100644 --- a/lib/appstate_container.dart +++ b/lib/appstate_container.dart @@ -704,9 +704,6 @@ class StateContainerState extends State { uuid: uuid, fcmToken: fcmToken, notificationEnabled: notificationsEnabled)); - sl - .get() - .queueRequest(AccountHistoryRequest(account: wallet.address)); sl.get().processQueue(); // Request account history diff --git a/lib/main.dart b/lib/main.dart index 7c27e23c..f3219e08 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -79,14 +79,14 @@ class _AppState extends State { debugShowCheckedModeBanner: false, title: 'Natrium', theme: ThemeData( - dialogBackgroundColor: - StateContainer.of(context).curTheme.backgroundDark, - primaryColor: StateContainer.of(context).curTheme.primary, - accentColor: StateContainer.of(context).curTheme.primary10, - backgroundColor: StateContainer.of(context).curTheme.backgroundDark, - fontFamily: 'NunitoSans', - brightness: Brightness.dark, - ), + dialogBackgroundColor: + StateContainer.of(context).curTheme.backgroundDark, + primaryColor: StateContainer.of(context).curTheme.primary, + accentColor: StateContainer.of(context).curTheme.primary10, + backgroundColor: StateContainer.of(context).curTheme.backgroundDark, + fontFamily: 'NunitoSans', + brightness: Brightness.dark, + useMaterial3: true), localizationsDelegates: [ AppLocalizationsDelegate(StateContainer.of(context).curLanguage), GlobalMaterialLocalizations.delegate, diff --git a/lib/model/wallet.dart b/lib/model/wallet.dart index 1f70d4b9..3a921c53 100644 --- a/lib/model/wallet.dart +++ b/lib/model/wallet.dart @@ -6,10 +6,12 @@ import 'package:natrium_wallet_flutter/util/numberutil.dart'; /// Main wallet object that's passed around the app via state class AppWallet { - static const String defaultRepresentative = 'nano_1natrium1o3z5519ifou7xii8crpxpk8y65qmkih8e8bpsjri651oza8imdd'; + static const String defaultRepresentative = + 'nano_1natrium1o3z5519ifou7xii8crpxpk8y65qmkih8e8bpsjri651oza8imdd'; bool _loading; // Whether or not app is initially loading - bool _historyLoading; // Whether or not we have received initial account history response + bool + _historyLoading; // Whether or not we have received initial account history response String _address; BigInt _accountBalance; String _frontier; @@ -22,10 +24,20 @@ class AppWallet { int confirmationHeight; List _history; - - AppWallet({String address, BigInt accountBalance, String frontier, String openBlock, String representativeBlock, - String representative, String localCurrencyPrice,String btcPrice, int blockCount, - List history, bool loading, bool historyLoading, this.confirmationHeight = -1}) { + AppWallet( + {String address, + BigInt accountBalance, + String frontier, + String openBlock, + String representativeBlock, + String representative, + String localCurrencyPrice, + String btcPrice, + int blockCount, + List history, + bool loading, + bool historyLoading, + this.confirmationHeight = -1}) { this._address = address; this._accountBalance = accountBalance ?? BigInt.zero; this._frontier = frontier; @@ -37,7 +49,7 @@ class AppWallet { this._blockCount = blockCount ?? 0; this._history = history ?? new List(); this._loading = loading ?? true; - this._historyLoading = historyLoading ?? true; + this._historyLoading = historyLoading ?? true; } String get address => _address; @@ -54,16 +66,24 @@ class AppWallet { // Get pretty account balance version String getAccountBalanceDisplay() { - if (accountBalance == null) { - return "0"; + try { + return NumberUtil.getRawAsUsableString(_accountBalance.toString()); + } catch (e) { + return "N/A"; } - return NumberUtil.getRawAsUsableString(_accountBalance.toString()); } - - String getLocalCurrencyPrice(AvailableCurrency currency, {String locale = "en_US"}) { - Decimal converted = Decimal.parse(_localCurrencyPrice) * NumberUtil.getRawAsUsableDecimal(_accountBalance.toString()); - return NumberFormat.currency(locale:locale, symbol: currency.getCurrencySymbol()).format(converted.toDouble()); + String getLocalCurrencyPrice(AvailableCurrency currency, + {String locale = "en_US"}) { + try { + Decimal converted = Decimal.parse(_localCurrencyPrice) * + NumberUtil.getRawAsUsableDecimal(_accountBalance.toString()); + return NumberFormat.currency( + locale: locale, symbol: currency.getCurrencySymbol()) + .format(converted.toDouble()); + } catch (e) { + return "N/A"; + } } set localCurrencyPrice(String value) { @@ -75,12 +95,19 @@ class AppWallet { } String get btcPrice { - Decimal converted = Decimal.parse(_btcPrice) * NumberUtil.getRawAsUsableDecimal(_accountBalance.toString()); - // Show 4 decimal places for BTC price if its >= 0.0001 BTC, otherwise 6 decimals - if (converted >= Decimal.parse("0.0001")) { - return new NumberFormat("#,##0.0000", "en_US").format(converted.toDouble()); - } else { - return new NumberFormat("#,##0.000000", "en_US").format(converted.toDouble()); + try { + Decimal converted = Decimal.parse(_btcPrice) * + NumberUtil.getRawAsUsableDecimal(_accountBalance.toString()); + // Show 4 decimal places for BTC price if its >= 0.0001 BTC, otherwise 6 decimals + if (converted >= Decimal.parse("0.0001")) { + return new NumberFormat("#,##0.0000", "en_US") + .format(converted.toDouble()); + } else { + return new NumberFormat("#,##0.000000", "en_US") + .format(converted.toDouble()); + } + } catch (e) { + return "N/A"; } } @@ -89,7 +116,7 @@ class AppWallet { } String get representative { - return _representative ?? defaultRepresentative; + return _representative ?? defaultRepresentative; } set representative(String value) { @@ -137,4 +164,4 @@ class AppWallet { set historyLoading(bool value) { _historyLoading = value; } -} \ No newline at end of file +} diff --git a/lib/network/account_service.dart b/lib/network/account_service.dart index 4eaf5b53..e50fb1f4 100644 --- a/lib/network/account_service.dart +++ b/lib/network/account_service.dart @@ -350,14 +350,15 @@ class AccountService { http.Response response = await http.post(Uri.parse(_SERVER_ADDRESS_HTTP), headers: {'Content-type': 'application/json'}, body: json.encode(request.toJson())); - if (response.statusCode != 200) { - return null; - } - Map decoded = json.decode(response.body); - if (decoded.containsKey("error")) { - return ErrorResponse.fromJson(decoded); + try { + Map decoded = json.decode(response.body); + if (decoded.containsKey("error")) { + return ErrorResponse.fromJson(decoded); + } + return decoded; + } catch (e) { + return ErrorResponse(error: "Invalid response from server"); } - return decoded; } Future getAccountInfo(String account) async {