Skip to content

Commit

Permalink
material 3 and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bbedward committed Sep 1, 2022
1 parent 696c8c8 commit 68e834a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 41 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ android {
}
}

ndkVersion 25.1.8937393
ndkVersion "25.1.8937393"
}

flutter {
Expand Down
3 changes: 0 additions & 3 deletions lib/appstate_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,6 @@ class StateContainerState extends State<StateContainer> {
uuid: uuid,
fcmToken: fcmToken,
notificationEnabled: notificationsEnabled));
sl
.get<AccountService>()
.queueRequest(AccountHistoryRequest(account: wallet.address));
sl.get<AccountService>().processQueue();
// Request account history

Expand Down
16 changes: 8 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ class _AppState extends State<App> {
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,
Expand Down
71 changes: 49 additions & 22 deletions lib/model/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,10 +24,20 @@ class AppWallet {
int confirmationHeight;
List<AccountHistoryResponseItem> _history;


AppWallet({String address, BigInt accountBalance, String frontier, String openBlock, String representativeBlock,
String representative, String localCurrencyPrice,String btcPrice, int blockCount,
List<AccountHistoryResponseItem> 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<AccountHistoryResponseItem> history,
bool loading,
bool historyLoading,
this.confirmationHeight = -1}) {
this._address = address;
this._accountBalance = accountBalance ?? BigInt.zero;
this._frontier = frontier;
Expand All @@ -37,7 +49,7 @@ class AppWallet {
this._blockCount = blockCount ?? 0;
this._history = history ?? new List<AccountHistoryResponseItem>();
this._loading = loading ?? true;
this._historyLoading = historyLoading ?? true;
this._historyLoading = historyLoading ?? true;
}

String get address => _address;
Expand All @@ -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) {
Expand All @@ -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";
}
}

Expand All @@ -89,7 +116,7 @@ class AppWallet {
}

String get representative {
return _representative ?? defaultRepresentative;
return _representative ?? defaultRepresentative;
}

set representative(String value) {
Expand Down Expand Up @@ -137,4 +164,4 @@ class AppWallet {
set historyLoading(bool value) {
_historyLoading = value;
}
}
}
15 changes: 8 additions & 7 deletions lib/network/account_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountInfoResponse> getAccountInfo(String account) async {
Expand Down

0 comments on commit 68e834a

Please sign in to comment.