Skip to content
Snippets Groups Projects
Commit 75073bd1 authored by vjrj's avatar vjrj
Browse files

Better currency format and styles

parent e20280f1
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ extension CurrencyExtension on Currency { ...@@ -6,7 +6,7 @@ extension CurrencyExtension on Currency {
case Currency.G1: case Currency.G1:
return 'Ğ1'; return 'Ğ1';
case Currency.DU: case Currency.DU:
return 'DUğ1'; return 'DU';
} }
} }
} }
......
...@@ -150,11 +150,19 @@ class NotificationController { ...@@ -150,11 +150,19 @@ class NotificationController {
: tr('notification_new_sent_title'); : tr('notification_new_sent_title');
final String desc = from != null final String desc = from != null
? tr('notification_new_payment_desc', namedArgs: <String, String>{ ? tr('notification_new_payment_desc', namedArgs: <String, String>{
'amount': formatAmountWithLocale(locale.languageCode, amount, isG1), 'amount': formatAmountWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
useSymbol: true),
'from': from, 'from': from,
}) })
: tr('notification_new_sent_desc', namedArgs: <String, String>{ : tr('notification_new_sent_desc', namedArgs: <String, String>{
'amount': formatAmountWithLocale(locale.languageCode, amount, isG1), 'amount': formatAmountWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
useSymbol: true),
'to': to!, 'to': to!,
}); });
if (kIsWeb) { if (kIsWeb) {
......
...@@ -101,11 +101,19 @@ class NotificationController { ...@@ -101,11 +101,19 @@ class NotificationController {
: tr('notification_new_sent_title'); : tr('notification_new_sent_title');
final String desc = from != null final String desc = from != null
? tr('notification_new_payment_desc', namedArgs: <String, String>{ ? tr('notification_new_payment_desc', namedArgs: <String, String>{
'amount': formatAmountWithLocale(locale.languageCode, amount, isG1), 'amount': formatAmountWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
useSymbol: true),
'from': from, 'from': from,
}) })
: tr('notification_new_sent_desc', namedArgs: <String, String>{ : tr('notification_new_sent_desc', namedArgs: <String, String>{
'amount': formatAmountWithLocale(locale.languageCode, amount, isG1), 'amount': formatAmountWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
useSymbol: true),
'to': to!, 'to': to!,
}); });
try { try {
......
...@@ -124,25 +124,61 @@ bool bigScreen(BuildContext context) => ...@@ -124,25 +124,61 @@ bool bigScreen(BuildContext context) =>
bool smallScreen(BuildContext context) => bool smallScreen(BuildContext context) =>
MediaQuery.of(context).size.width <= smallScreenWidth; MediaQuery.of(context).size.width <= smallScreenWidth;
String formatAmount(BuildContext context, double amount, bool isG1) { String formatAmount(
{required BuildContext context,
required double amount,
required bool isG1,
required bool useSymbol}) {
return formatAmountWithLocale( return formatAmountWithLocale(
Localizations.localeOf(context).toString(), amount, isG1); locale: currentLocale(context),
amount: amount,
isG1: isG1,
useSymbol: useSymbol);
} }
String formatAmountWithLocale(String locale, double amount, bool isG1) { String currentLocale(BuildContext context) =>
Localizations.localeOf(context).toString();
String formatAmountWithLocale(
{required String locale,
required double amount,
required bool isG1,
required bool useSymbol}) {
final NumberFormat currencyFormatter =
currentNumberFormat(isG1: isG1, locale: locale, useSymbol: useSymbol);
return currencyFormatter.format(amount);
}
NumberFormat currentNumberFormat(
{required bool useSymbol, required bool isG1, required String locale}) {
final NumberFormat currencyFormatter = NumberFormat.currency( final NumberFormat currencyFormatter = NumberFormat.currency(
// in English $10 is G110 ... confusing // in English $10 is G110 ... confusing
symbol: isG1 ? '${Currency.G1.name()} ' : '${Currency.DU.name()} ', symbol: useSymbol ? currentCurrency(isG1) : '',
locale: locale, locale: locale,
decimalDigits: isG1 ? 2 : 4, decimalDigits: isG1 ? 2 : 4,
); );
return currencyFormatter.format(amount); return currencyFormatter;
}
String currentCurrency(bool isG1) {
return isG1 ? '${Currency.G1.name()} ' : '${Currency.DU.name()} ';
}
String currentCurrencyTrimmed(bool isG1) {
return currentCurrency(isG1).trim();
} }
String formatKAmount( String formatKAmount(
BuildContext context, double amount, bool isG1, double currentUd) => {required BuildContext context,
required double amount,
required bool isG1,
required double currentUd,
required bool useSymbol}) =>
formatAmount( formatAmount(
context, isG1 ? amount / 100 : ((amount / 100) / currentUd), isG1); context: context,
amount: isG1 ? amount / 100 : ((amount / 100) / currentUd),
isG1: isG1,
useSymbol: useSymbol);
double parseToDoubleLocalized( double parseToDoubleLocalized(
{required String locale, required String number}) => {required String locale, required String number}) =>
...@@ -361,3 +397,14 @@ final GlobalKey<ScaffoldMessengerState> globalMessengerKey = ...@@ -361,3 +397,14 @@ final GlobalKey<ScaffoldMessengerState> globalMessengerKey =
GlobalKey<ScaffoldMessengerState>(); GlobalKey<ScaffoldMessengerState>();
const Color deleteColor = Color(0xFFFE4A49); const Color deleteColor = Color(0xFFFE4A49);
bool isSymbolPlacementBefore(String pattern) {
final int symbolIndex = pattern.indexOf('\u00A4');
final int numberIndex = pattern.indexOf('#');
if (symbolIndex < numberIndex) {
return true;
} else {
return false;
}
}
...@@ -23,6 +23,8 @@ class TransactionListItem extends StatelessWidget { ...@@ -23,6 +23,8 @@ class TransactionListItem extends StatelessWidget {
required this.index, required this.index,
required this.isG1, required this.isG1,
required this.currentUd, required this.currentUd,
required this.currentSymbol,
required this.isCurrencyBefore,
this.afterCancel, this.afterCancel,
this.afterRetry}); this.afterRetry});
...@@ -31,6 +33,8 @@ class TransactionListItem extends StatelessWidget { ...@@ -31,6 +33,8 @@ class TransactionListItem extends StatelessWidget {
final int index; final int index;
final bool isG1; final bool isG1;
final double currentUd; final double currentUd;
final String currentSymbol;
final bool isCurrencyBefore;
final VoidCallback? afterCancel; final VoidCallback? afterCancel;
final VoidCallback? afterRetry; final VoidCallback? afterRetry;
...@@ -49,10 +53,15 @@ class TransactionListItem extends StatelessWidget { ...@@ -49,10 +53,15 @@ class TransactionListItem extends StatelessWidget {
Color? iconColor; Color? iconColor;
String statusText; String statusText;
final amountWithSymbol = final String amountWithSymbol = formatKAmount(
formatKAmount(context, transaction.amount, isG1, currentUd); context: context,
amount: transaction.amount,
isG1: isG1,
currentUd: currentUd,
useSymbol: false);
final String amountS = final String amountS =
'${transaction.amount < 0 ? "" : "+"}${amountWithSymbol}'; '${transaction.amount < 0 ? "" : "+"}$amountWithSymbol';
statusText = tr('transaction_${transaction.type.name}'); statusText = tr('transaction_${transaction.type.name}');
switch (transaction.type) { switch (transaction.type) {
case TransactionType.pending: case TransactionType.pending:
...@@ -219,16 +228,26 @@ class TransactionListItem extends StatelessWidget { ...@@ -219,16 +228,26 @@ class TransactionListItem extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[ children: <Widget>[
Text( Text.rich(TextSpan(
amountS, children: <InlineSpan>[
style: TextStyle( if (isCurrencyBefore)
// fontWeight: FontWeight.bold, currencyBalanceWidget(isG1, currentSymbol),
color: transaction.type == TransactionType.received || if (isCurrencyBefore) separatorSpan(),
transaction.type == TransactionType.receiving TextSpan(
? Colors.blue text: amountS,
: Colors.red, style: TextStyle(
), // fontWeight: FontWeight.bold,
), color: transaction.type == TransactionType.received ||
transaction.type == TransactionType.receiving
? Colors.blue
: Colors.red,
),
),
if (!isCurrencyBefore) separatorSpan(),
if (!isCurrencyBefore)
currencyBalanceWidget(isG1, currentSymbol),
],
)),
const SizedBox(height: 4.0), const SizedBox(height: 4.0),
Tooltip( Tooltip(
message: DateFormat.yMd(context.locale.languageCode) message: DateFormat.yMd(context.locale.languageCode)
...@@ -258,3 +277,33 @@ class TransactionListItem extends StatelessWidget { ...@@ -258,3 +277,33 @@ class TransactionListItem extends StatelessWidget {
afterRetry!(); afterRetry!();
} }
} }
WidgetSpan separatorSpan() {
return const WidgetSpan(
child: SizedBox(width: 3),
);
}
InlineSpan currencyBalanceWidget(bool isG1, String currentSymbol) {
return TextSpan(children: <InlineSpan>[
TextSpan(
text: currentSymbol,
style: const TextStyle(
color: Colors.black54,
),
),
if (!isG1)
WidgetSpan(
child: Transform.translate(
offset: const Offset(1, 4),
child: const Text(
'Ğ1',
style: TextStyle(
fontSize: 12,
// fontWeight: FontWeight.w500,
// fontFeatures: <FontFeature>[FontFeature.subscripts()],
color: Colors.black54,
),
)))
]);
}
...@@ -48,6 +48,7 @@ class _TransactionsAndBalanceWidgetState ...@@ -48,6 +48,7 @@ class _TransactionsAndBalanceWidgetState
final int _pendingPageSize = 30; final int _pendingPageSize = 30;
final Cron cron = Cron(); final Cron cron = Cron();
static const double balanceFontSize = 36.0;
@override @override
void initState() { void initState() {
...@@ -141,10 +142,17 @@ class _TransactionsAndBalanceWidgetState ...@@ -141,10 +142,17 @@ class _TransactionsAndBalanceWidgetState
final String myPubKey = SharedPreferencesHelper().getPubKey(); final String myPubKey = SharedPreferencesHelper().getPubKey();
final bool isG1 = appCubit.currency == Currency.G1; final bool isG1 = appCubit.currency == Currency.G1;
final double currentUd = appCubit.currentUd; final double currentUd = appCubit.currentUd;
final String currentSymbol = currentCurrencyTrimmed(isG1);
final NumberFormat currentNumber = currentNumberFormat(
useSymbol: true, isG1: isG1, locale: currentLocale(context));
final bool isCurrencyBefore =
isSymbolPlacementBefore(currentNumber.symbols.CURRENCY_PATTERN);
return BlocBuilder<TransactionCubit, TransactionState>( return BlocBuilder<TransactionCubit, TransactionState>(
builder: (BuildContext context, TransactionState transBalanceState) { builder: (BuildContext context, TransactionState transBalanceState) {
// final List<Transaction> transactions = transBalanceState.transactions; // final List<Transaction> transactions = transBalanceState.transactions;
final double balance = transBalanceState.balance; final double balance = transBalanceState.balance;
return BackdropScaffold( return BackdropScaffold(
appBar: BackdropAppBar( appBar: BackdropAppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary, backgroundColor: Theme.of(context).colorScheme.inversePrimary,
...@@ -190,14 +198,30 @@ class _TransactionsAndBalanceWidgetState ...@@ -190,14 +198,30 @@ class _TransactionsAndBalanceWidgetState
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0), padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Center( child: Center(
child: Text( child: Text.rich(TextSpan(
formatKAmount(context, balance, isG1, currentUd), children: <InlineSpan>[
style: TextStyle( if (isCurrencyBefore)
fontSize: 36.0, currencyBalanceWidget(isG1, currentSymbol),
color: if (isCurrencyBefore) separatorSpan(),
balance == 0 ? Colors.lightBlue : Colors.lightBlue, TextSpan(
fontWeight: FontWeight.bold), text: formatKAmount(
)), context: context,
amount: balance,
isG1: isG1,
currentUd: currentUd,
useSymbol: false),
style: TextStyle(
fontSize: balanceFontSize,
color: balance == 0
? Colors.lightBlue
: Colors.lightBlue,
fontWeight: FontWeight.bold),
),
if (!isCurrencyBefore) separatorSpan(),
if (!isCurrencyBefore)
currencyBalanceWidget(isG1, currentSymbol),
],
))),
), ),
// if (!kReleaseMode) TransactionChart(transactions: transactions) // if (!kReleaseMode) TransactionChart(transactions: transactions)
], ],
...@@ -234,7 +258,9 @@ class _TransactionsAndBalanceWidgetState ...@@ -234,7 +258,9 @@ class _TransactionsAndBalanceWidgetState
index: index, index: index,
transaction: tx, transaction: tx,
isG1: isG1, isG1: isG1,
currentSymbol: currentSymbol,
currentUd: currentUd, currentUd: currentUd,
isCurrencyBefore: isCurrencyBefore,
afterRetry: () => _refresh(), afterRetry: () => _refresh(),
afterCancel: () => _refresh()); afterCancel: () => _refresh());
}, },
...@@ -253,6 +279,8 @@ class _TransactionsAndBalanceWidgetState ...@@ -253,6 +279,8 @@ class _TransactionsAndBalanceWidgetState
pubKey: myPubKey, pubKey: myPubKey,
currentUd: currentUd, currentUd: currentUd,
isG1: isG1, isG1: isG1,
isCurrencyBefore: isCurrencyBefore,
currentSymbol: currentSymbol,
index: index + index: index +
(_pendingController.itemList != null (_pendingController.itemList != null
? _pendingController.itemList!.length ? _pendingController.itemList!.length
...@@ -269,6 +297,38 @@ class _TransactionsAndBalanceWidgetState ...@@ -269,6 +297,38 @@ class _TransactionsAndBalanceWidgetState
}); });
} }
InlineSpan separatorSpan() {
return const WidgetSpan(
child: SizedBox(width: 7),
);
}
InlineSpan currencyBalanceWidget(bool isG1, String currentSymbol) {
return TextSpan(children: <InlineSpan>[
TextSpan(
text: currentSymbol,
style: const TextStyle(
fontSize: balanceFontSize,
fontWeight: FontWeight.w500,
color: Colors.deepPurple,
),
),
if (!isG1)
WidgetSpan(
child: Transform.translate(
offset: const Offset(2, 16),
child: const Text(
'Ğ1',
style: TextStyle(
fontSize: balanceFontSize - 10,
fontWeight: FontWeight.w500,
// fontFeatures: <FontFeature>[FontFeature.subscripts()],
color: Colors.deepPurple,
),
)))
]);
}
Future<void> _refresh() { Future<void> _refresh() {
return Future<void>.sync(() { return Future<void>.sync(() {
_pagingController.refresh(); _pagingController.refresh();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment