Skip to content

Commit

Permalink
Merge branch 'notifications' into staging
Browse files Browse the repository at this point in the history
# Conflicts:
#	pubspec.lock
  • Loading branch information
marco committed Apr 2, 2022
2 parents d7868c0 + 91ef29f commit 4b79d18
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 0 deletions.
7 changes: 7 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ android {
ndk {
debugSymbolLevel 'FULL'
}

proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Gson rules
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keep class com.dexterous.** { *; }

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}


# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
Binary file added android/app/src/main/app_icon-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions android/app/src/main/res/raw/keep.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/*,@mipmap/*" />
Binary file added assets/icon/app_icon_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ PODS:
- devicelocale (0.0.1):
- Flutter
- Flutter (1.0.0)
- flutter_local_notifications (0.0.1):
- Flutter
- flutter_secure_storage (3.3.1):
- Flutter
- lelantus (0.0.1):
Expand All @@ -30,6 +32,7 @@ DEPENDENCIES:
- barcode_scan2 (from `.symlinks/plugins/barcode_scan2/ios`)
- devicelocale (from `.symlinks/plugins/devicelocale/ios`)
- Flutter (from `Flutter`)
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- lelantus (from `.symlinks/plugins/lelantus/ios`)
- local_auth (from `.symlinks/plugins/local_auth/ios`)
Expand All @@ -52,6 +55,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/devicelocale/ios"
Flutter:
:path: Flutter
flutter_local_notifications:
:path: ".symlinks/plugins/flutter_local_notifications/ios"
flutter_secure_storage:
:path: ".symlinks/plugins/flutter_secure_storage/ios"
lelantus:
Expand All @@ -72,6 +77,7 @@ SPEC CHECKSUMS:
barcode_scan2: 0af2bb63c81b4565aab6cd78278e4c0fa136dbb0
devicelocale: b22617f40038496deffba44747101255cee005b0
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec
lelantus: 97ab4ecc648423278f807e499b3a717dea9268f8
local_auth: ef62030a2731330b95df7ef1331bd15f6a64b8a6
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
"${BUILT_PRODUCTS_DIR}/app_settings/app_settings.framework",
"${BUILT_PRODUCTS_DIR}/barcode_scan2/barcode_scan2.framework",
"${BUILT_PRODUCTS_DIR}/devicelocale/devicelocale.framework",
"${BUILT_PRODUCTS_DIR}/flutter_local_notifications/flutter_local_notifications.framework",
"${BUILT_PRODUCTS_DIR}/flutter_secure_storage/flutter_secure_storage.framework",
"${BUILT_PRODUCTS_DIR}/lelantus/lelantus.framework",
"${BUILT_PRODUCTS_DIR}/local_auth/local_auth.framework",
Expand All @@ -238,6 +239,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/app_settings.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/barcode_scan2.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/devicelocale.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_local_notifications.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_secure_storage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/lelantus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/local_auth.framework",
Expand Down
3 changes: 3 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import Flutter
UIApplication.shared.isStatusBarHidden = false

GeneratedPluginRegistrant.register(with: self)
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:paymint/services/address_book_service.dart';
import 'package:paymint/services/coins/manager.dart';
import 'package:paymint/services/node_service.dart';
import 'package:paymint/services/notes_service.dart';
import 'package:paymint/services/notifications_api.dart';
import 'package:paymint/services/wallets_service.dart';
import 'package:paymint/utilities/cfcolors.dart';
import 'package:paymint/utilities/logger.dart';
Expand Down Expand Up @@ -48,6 +49,7 @@ void main() async {

SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: [SystemUiOverlay.bottom]);
await NotificationApi.init();

runApp(MyApp());
}
Expand Down
1 change: 1 addition & 0 deletions lib/pages/wallet_selection_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:paymint/widgets/custom_buttons/gradient_button.dart';
import 'package:paymint/widgets/custom_buttons/simple_button.dart';
import 'package:provider/provider.dart';

import '../services/notifications_api.dart';
import 'lockscreen2.dart';
import 'onboarding_view/helpers/builders.dart';
import 'onboarding_view/helpers/create_wallet_type.dart';
Expand Down
64 changes: 64 additions & 0 deletions lib/services/coins/firo/firo_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import 'package:paymint/utilities/misc_global_constants.dart';
import 'package:paymint/utilities/shared_utilities.dart';

import '../../globals.dart';
import '../../notifications_api.dart';

const JMINT_INDEX = 5;
const MINT_INDEX = 2;
Expand Down Expand Up @@ -767,6 +768,7 @@ class FiroWallet extends CoinServiceAPI {
FiroNetworkType get networkType => _networkType;

Set<String> unconfirmedTxs = {};
Set<String> pastUnconfirmedTxs = {};

NetworkType get _network {
switch (networkType) {
Expand Down Expand Up @@ -1054,6 +1056,9 @@ class FiroWallet extends CoinServiceAPI {
try {
bool needsRefresh = false;
Logger.print("unonconfirmeds $unconfirmedTxs");
for (String txid in unconfirmedTxs) {
pastUnconfirmedTxs.add(txid);
}
for (String txid in unconfirmedTxs) {
final txn = await electrumXClient.getTransaction(tx_hash: txid);
var confirmations = txn["confirmations"];
Expand Down Expand Up @@ -1095,9 +1100,15 @@ class FiroWallet extends CoinServiceAPI {
Logger.print(txData.txChunks);
Logger.print(lTxData.txChunks);
Set<String> needRefresh = {};
Map<String, String> txsTypes = {};
Map<String, bool> txsStatus = {};
Map<String, int> txsAmounts = {};

for (models.TransactionChunk chunk in txData.txChunks) {
for (models.Transaction tx in chunk.transactions) {
txsTypes[tx.txid] = tx.subType == null ? tx.txType : tx.subType;
txsStatus[tx.txid] = tx.confirmedStatus;
txsAmounts[tx.txid] = tx.amount;
models.Transaction lTx = lTxData.findTransaction(tx.txid);
if (!tx.confirmedStatus) {
// Get all normal txs that are at 0 confirmations
Expand Down Expand Up @@ -1125,6 +1136,11 @@ class FiroWallet extends CoinServiceAPI {
for (models.TransactionChunk chunk in lTxData.txChunks) {
for (models.Transaction lTX in chunk.transactions) {
models.Transaction tx = txData.findTransaction(lTX.txid);
if (tx == null) {
txsTypes[lTX.txid] = lTX.subType;
txsStatus[lTX.txid] = lTX.confirmedStatus;
txsAmounts[lTX.txid] = lTX.amount;
}
if (!lTX.confirmedStatus && tx == null) {
// if this is a ltx transaction that is unconfirmed and not represented in the normal transaction set.
needRefresh.add(lTX.txid);
Expand All @@ -1133,6 +1149,54 @@ class FiroWallet extends CoinServiceAPI {
}
}
Logger.print("needRefresh $needRefresh");
Logger.print("txsTypes \n $txsTypes");
Logger.print("txsStatuses \n $txsStatus");
Logger.print("pastUnconfirmedTxs \n $pastUnconfirmedTxs");
Set<String> notified = {};
for (String tx in needRefresh) {
switch (txsTypes[tx]) {
case "Received":
if (txsStatus[tx]) {
notified.add(tx);
NotificationApi.showNotification(
id: 1,
title: "Receiving Payment",
body: "${txsAmounts[tx] / 100000000.0} $coinName",
payload: null);
}
break;
default:
break;
}
}
for (String tx in pastUnconfirmedTxs) {
if (!needRefresh.contains(tx)) {
switch (txsTypes[tx]) {
case "mint":
notified.add(tx);
NotificationApi.showNotification(
id: 2,
title: "New Funds Available",
body: "${txsAmounts[tx] / 100000000.0} $coinName",
payload: null);
break;
case "join":
notified.add(tx);
NotificationApi.showNotification(
id: 3,
title: "Payment Sent",
body: "${txsAmounts[tx] / 100000000.0} $coinName",
payload: null);
break;
default:
break;
}
}
}

for (String tx in notified) {
pastUnconfirmedTxs.remove(tx);
}
unconfirmedTxs = needRefresh;
}

Expand Down
48 changes: 48 additions & 0 deletions lib/services/notifications_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:rxdart/rxdart.dart';

class NotificationApi {
static final _notifications = FlutterLocalNotificationsPlugin();
static final onNotifications = BehaviorSubject<String>();

static Future _notificationDetails() async {
return NotificationDetails(
android: AndroidNotificationDetails('channel id', 'channel name',
channelDescription: 'channel description',
// importance: Importance.max,
priority: Priority.high,
ticker: 'ticker'),
iOS: IOSNotificationDetails(),
);
}

static Future init({bool initScheduled = false}) async {
final android = AndroidInitializationSettings('app_icon_alpha');
final iOS = IOSInitializationSettings();
final settings = InitializationSettings(android: android, iOS: iOS);
await _notifications.initialize(
settings,
onSelectNotification: (payload) async {
onNotifications.add(payload);
},
);
}

static Future clearNotifications() async => _notifications.cancelAll();

static Future clearNotification(int id) async => _notifications.cancel(id);

static Future showNotification({
int id = 0,
String title,
String body,
String payload,
}) async =>
_notifications.show(
id,
title,
body,
await _notificationDetails(),
payload: payload,
);
}
49 changes: 49 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.8"
decimal:
dependency: "direct main"
description:
Expand Down Expand Up @@ -316,6 +323,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.2"
flutter_local_notifications:
dependency: "direct main"
description:
name: flutter_local_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "9.4.0"
flutter_local_notifications_linux:
dependency: transitive
description:
name: flutter_local_notifications_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1+1"
flutter_local_notifications_platform_interface:
dependency: transitive
description:
name: flutter_local_notifications_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
flutter_native_splash:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -564,6 +592,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -816,6 +851,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
rxdart:
dependency: "direct main"
description:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.27.3"
shelf:
dependency: transitive
description:
Expand Down Expand Up @@ -940,6 +982,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
timezone:
dependency: transitive
description:
name: timezone
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.0"
timing:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ dependencies:
http: ^0.13.4
local_auth: ^1.1.10
permission_handler: ^8.3.0
flutter_local_notifications: ^9.4.0
rxdart: ^0.27.3

# Bitcoin plugins
bip39: ^1.0.3
Expand Down

0 comments on commit 4b79d18

Please sign in to comment.