mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2025-12-21 16:04:27 +01:00
* Add Swift notification plugin * Hash the metadata * Validate min sendable amount * Remove initializer as base class, UNNotificationServiceExtension, has no default initializer * Set the PaymentMethod * Handle PaymentDetails in SwapUpdated * Improve payment text
51 lines
1.8 KiB
Swift
51 lines
1.8 KiB
Swift
import Foundation
|
|
import os.log
|
|
|
|
#if DEBUG && true
|
|
fileprivate var logger = OSLog(
|
|
subsystem: Bundle.main.bundleIdentifier!,
|
|
category: "BreezSDKLiquidConnector"
|
|
)
|
|
#else
|
|
fileprivate var logger = OSLog.disabled
|
|
#endif
|
|
|
|
class BreezSDKLiquidConnector {
|
|
private static var liquidSDK: BindingLiquidSdk? = nil
|
|
fileprivate static var queue = DispatchQueue(label: "BreezSDKLiquidConnector")
|
|
fileprivate static var sdkListener: EventListener? = nil
|
|
|
|
static func register(connectRequest: ConnectRequest, listener: EventListener) throws -> BindingLiquidSdk? {
|
|
try BreezSDKLiquidConnector.queue.sync { [] in
|
|
BreezSDKLiquidConnector.sdkListener = listener
|
|
if BreezSDKLiquidConnector.liquidSDK == nil {
|
|
BreezSDKLiquidConnector.liquidSDK = try BreezSDKLiquidConnector.connectSDK(connectRequest: connectRequest)
|
|
}
|
|
return BreezSDKLiquidConnector.liquidSDK
|
|
}
|
|
}
|
|
|
|
static func unregister() {
|
|
BreezSDKLiquidConnector.queue.sync { [] in
|
|
BreezSDKLiquidConnector.sdkListener = nil
|
|
}
|
|
}
|
|
|
|
static func connectSDK(connectRequest: ConnectRequest) throws -> BindingLiquidSdk? {
|
|
// Connect to the Breez Liquid SDK make it ready for use
|
|
os_log("Connecting to Breez Liquid SDK", log: logger, type: .debug)
|
|
let liquidSDK = try connect(req: connectRequest)
|
|
os_log("Connected to Breez Liquid SDK", log: logger, type: .debug)
|
|
let _ = try liquidSDK.addEventListener(listener: BreezSDKEventListener())
|
|
return liquidSDK
|
|
}
|
|
}
|
|
|
|
class BreezSDKEventListener: EventListener {
|
|
func onEvent(e: SdkEvent) {
|
|
BreezSDKLiquidConnector.queue.async { [] in
|
|
BreezSDKLiquidConnector.sdkListener?.onEvent(e: e)
|
|
}
|
|
}
|
|
}
|