Skip to content
Snippets Groups Projects
Commit 647933c2 authored by vjrj's avatar vjrj
Browse files

Notifications with comments

parent efffa545
No related branches found
No related tags found
No related merge requests found
......@@ -158,11 +158,6 @@ class MultiWalletTransactionCubit
appCubit.setUd(newParsedState.currentUd!);
}
logger(
'Last received notification: ${newParsedState.latestReceivedNotification.toIso8601String()})}');
logger(
'Last sent notification: ${newParsedState.latestSentNotification.toIso8601String()})}');
// Check pending transactions
final TransactionState newState =
_checkPendingTx(cursor, newParsedState, pubKey, node);
......@@ -170,6 +165,11 @@ class MultiWalletTransactionCubit
TransactionState currentModifiedState = newState;
logger(
'Last received notification: ${currentModifiedState.latestReceivedNotification.toIso8601String()})}');
logger(
'Last sent notification: ${currentModifiedState.latestSentNotification.toIso8601String()})}');
for (final Transaction tx in currentModifiedState.transactions.reversed) {
bool stateModified = false;
......@@ -181,6 +181,7 @@ class MultiWalletTransactionCubit
tx.time.millisecondsSinceEpoch.toString(),
amount: tx.amount,
currentUd: appCubit.currentUd,
comment: tx.comment,
from: from.title,
isG1: isG1);
currentModifiedState = currentModifiedState.copyWith(
......@@ -196,6 +197,7 @@ class MultiWalletTransactionCubit
tx.time.millisecondsSinceEpoch.toString(),
amount: -tx.amount,
currentUd: appCubit.currentUd,
comment: tx.comment,
to: to.title,
isG1: isG1);
currentModifiedState =
......
......@@ -144,31 +144,19 @@ class NotificationController {
{required double amount,
String? to,
String? from,
String? description = '',
String? comment = '',
required bool isG1,
required double currentUd}) async {
final String title = from != null
? tr('notification_new_payment_title')
: tr('notification_new_sent_title');
final String desc = from != null
? '${tr('notification_new_payment_desc', namedArgs: <String, String>{
'amount': formatKAmountInViewWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
currentUd: currentUd,
useSymbol: true),
'from': from,
})} ($description)'
: '${tr('notification_new_sent_desc', namedArgs: <String, String>{
'amount': formatKAmountInViewWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
currentUd: currentUd,
useSymbol: true),
'to': to!,
})} ($description)';
final String title = buildTxNotifTitle(from);
final String desc = buildTxNotifDescription(
from: from,
to: to,
comment: comment,
localeLanguageCode: locale.languageCode,
amount: amount,
isG1: isG1,
currentUd: currentUd,
);
await notify(title: title, desc: desc, id: id);
}
......
......@@ -97,29 +97,17 @@ class NotificationController {
String? description = '',
required double currentUd,
required bool isG1}) async {
// FIXME: DUP CODE!!
final String title = from != null
? tr('notification_new_payment_title')
: tr('notification_new_sent_title');
final String desc = from != null
? '${tr('notification_new_payment_desc', namedArgs: <String, String>{
'amount': formatKAmountInViewWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
currentUd: currentUd,
useSymbol: true),
'from': from,
})} ($description)'
: '${tr('notification_new_sent_desc', namedArgs: <String, String>{
'amount': formatKAmountInViewWithLocale(
locale: locale.languageCode,
amount: amount,
isG1: isG1,
currentUd: currentUd,
useSymbol: true),
'to': to!
})} ($description)';
final String title = buildTxNotifTitle(from);
final String desc = buildTxNotifDescription(
from: from,
to: to,
comment: description,
localeLanguageCode: locale.languageCode,
amount: amount,
isG1: isG1,
currentUd: currentUd,
);
await notify(title: title, desc: desc, id: '');
}
......
......@@ -655,3 +655,37 @@ Future<void> hydratedInit() async {
await HydratedStorage.build(storageDirectory: tmpDir);
}
}
String buildTxNotifTitle(String? from) {
final String title = from != null
? tr('notification_new_payment_title')
: tr('notification_new_sent_title');
return title;
}
String buildTxNotifDescription({
required String? from,
required String? to,
required String? comment,
required String localeLanguageCode,
required double amount,
required bool isG1,
required double currentUd,
}) {
final String formattedAmount = formatKAmountInViewWithLocale(
locale: localeLanguageCode,
amount: amount,
isG1: isG1,
currentUd: currentUd,
useSymbol: true,
);
final String desc = from != null
? tr('notification_new_payment_desc', namedArgs: <String, String>{
'amount': formattedAmount,
'from': from,
})
: tr('notification_new_sent_desc',
namedArgs: <String, String>{'amount': formattedAmount, 'to': to!});
return comment != null && comment.isNotEmpty ? '$desc ($comment)' : desc;
}
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