Feature/notify mined tx (#51)

* add notification for mined transactions

* display a notification bubble when transaction is mined
This commit is contained in:
Francisco Gindre 2019-12-17 17:11:21 -03:00 committed by GitHub
parent 5930fbed6f
commit 97ab864cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 12 deletions

View File

@ -7,6 +7,7 @@ target 'ZcashLightClientSample' do
# Pods for ZcashLightClientSample
pod 'ZcashLightClientKit', :path => '../../', :testspecs => ['Tests']
pod 'PaginatedTableView'
pod 'NotificationBubbles'
target 'ZcashLightClientSampleTests' do
inherit! :search_paths
# Pods for testing

View File

@ -21,6 +21,7 @@ PODS:
- nanopb/encode (= 0.3.9011)
- nanopb/decode (0.3.9011)
- nanopb/encode (0.3.9011)
- NotificationBubbles (0.1.1)
- PaginatedTableView (0.1.0)
- SQLite.swift (0.12.2):
- SQLite.swift/standard (= 0.12.2)
@ -38,6 +39,7 @@ PODS:
DEPENDENCIES:
- KRProgressHUD
- NotificationBubbles
- PaginatedTableView
- ZcashLightClientKit (from `../../`)
- ZcashLightClientKit/Tests (from `../../`)
@ -49,6 +51,7 @@ SPEC REPOS:
- KRActivityIndicatorView
- KRProgressHUD
- nanopb
- NotificationBubbles
- PaginatedTableView
- SQLite.swift
- SwiftGRPC
@ -64,12 +67,13 @@ SPEC CHECKSUMS:
KRActivityIndicatorView: 549db10b9578d58bac73db063d8b544e8970f7f2
KRProgressHUD: c3b9a48a0ee4824ea13212ac3f1efa50dca021e3
nanopb: 18003b5e52dab79db540fe93fe9579f399bd1ccd
NotificationBubbles: 91ee10deee54f35b5d49a161e1cb3d788ab5d011
PaginatedTableView: 14025b52a9f88bb1e9a87f31765eae7986ffb192
SQLite.swift: d2b4642190917051ce6bd1d49aab565fe794eea3
SwiftGRPC: f8fcfecb547c96cc6913de619f95fa3cd09838ee
SwiftProtobuf: 4fd9645e69b72cbae6ec8da5be0cdd20ca6565dd
ZcashLightClientKit: 7c5c65f59cf49f9db5341bacd0504e4264689965
PODFILE CHECKSUM: 2e4c89ef66d003face250e6559f935e7afec3d7b
PODFILE CHECKSUM: 78798ec859cb13d41ca5227082a269eef8f45a05
COCOAPODS: 1.8.4

View File

@ -8,9 +8,10 @@
import UIKit
import ZcashLightClientKit
import NotificationBubbles
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private var wallet: Initializer?
var addresses: [String]?
@ -37,30 +38,44 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
func subscribeToMinedTxNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(txMinedNotification(_:)), name: Notification.Name.synchronizerMinedTransaction, object: nil)
}
@objc func txMinedNotification(_ notification: Notification) {
guard let tx = notification.userInfo?[SDKSynchronizer.NotificationKeys.minedTransaction] as? PendingTransactionEntity else {
print("no tx information on notification")
return
}
NotificationBubble.display(in: window!.rootViewController!.view, options: NotificationBubble.sucessOptions(animation: NotificationBubble.Animation.fade(duration: 1)), attributedText: NSAttributedString(string: "Transaction \(String(describing: tx.id))mined!")) {}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
_ = self.sharedWallet
subscribeToMinedTxNotifications()
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@ -135,3 +150,14 @@ func __spendParamsURL() throws -> URL {
func __outputParamsURL() throws -> URL {
Bundle.main.url(forResource: "sapling-output", withExtension: ".params")!
}
public extension NotificationBubble {
static func sucessOptions(animation: NotificationBubble.Animation) -> [NotificationBubble.Style] {
return [ NotificationBubble.Style.animation(animation),
NotificationBubble.Style.margins(UIEdgeInsets(top: 40, left: 0, bottom: 0, right: 0)),
NotificationBubble.Style.cornerRadius(8),
NotificationBubble.Style.duration(timeInterval: 10),
NotificationBubble.Style.backgroundColor(UIColor.green)]
}
}

View File

@ -19,7 +19,6 @@ enum TransactionManagerError: Error {
class PersistentTransactionManager: OutboundTransactionManager {
var repository: PendingTransactionRepository
var encoder: TransactionEncoder
var service: LightWalletService

View File

@ -17,6 +17,7 @@ public extension Notification.Name {
static let synchronizerStopped = Notification.Name("SDKSyncronizerStopped")
static let synchronizerDisconnected = Notification.Name("SDKSyncronizerDisconnected")
static let synchronizerSyncing = Notification.Name("SDKSyncronizerSyncing")
static let synchronizerMinedTransaction = Notification.Name("synchronizerMinedTransaction")
}
/**
@ -25,8 +26,9 @@ public extension Notification.Name {
public class SDKSynchronizer: Synchronizer {
public struct NotificationKeys {
static let progress = "SDKSynchronizer.progress"
static let blockHeight = "SDKSynchronizer.progress"
public static let progress = "SDKSynchronizer.progress"
public static let blockHeight = "SDKSynchronizer.blockHeight"
public static let minedTransaction = "SDKSynchronizer.minedTransaction"
}
public private(set) var status: Status {
@ -187,7 +189,6 @@ public class SDKSynchronizer: Synchronizer {
name: Notification.Name.blockProcessorHandledReOrg,
object: processor)
}
// MARK: Block Processor notifications
@ -389,11 +390,20 @@ public class SDKSynchronizer: Synchronizer {
guard let minedHeight = tx?.minedHeight else { return }
_ = try transactionManager.applyMinedHeight(pendingTransaction: pendingTx, minedHeight: minedHeight)
let minedTx = try transactionManager.applyMinedHeight(pendingTransaction: pendingTx, minedHeight: minedHeight)
notifyMinedTransaction(minedTx)
})
} catch {
print("error refreshing pending transactions: \(error)")
}
}
private func notifyMinedTransaction(_ tx: PendingTransactionEntity) {
DispatchQueue.main.async {
NotificationCenter.default.post(name: Notification.Name.synchronizerMinedTransaction, object: self, userInfo: [NotificationKeys.minedTransaction : tx])
}
}
}