mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-16 12:34:22 +01:00
Add option to specify backup path (#228)
* feat: add backup_path to backup method * Re-generate bindings with flutter_rust_bridge`@ 2.0.0-dev.35 * Rebased on main * Update backup path description --------- Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,37 @@ import breez_liquid_sdk.*
|
||||
import com.facebook.react.bridge.*
|
||||
import java.util.*
|
||||
|
||||
fun asBackupRequest(backupRequest: ReadableMap): BackupRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
backupRequest,
|
||||
arrayOf(),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val backupPath = if (hasNonNullKey(backupRequest, "backupPath")) backupRequest.getString("backupPath") else null
|
||||
return BackupRequest(
|
||||
backupPath,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(backupRequest: BackupRequest): ReadableMap {
|
||||
return readableMapOf(
|
||||
"backupPath" to backupRequest.backupPath,
|
||||
)
|
||||
}
|
||||
|
||||
fun asBackupRequestList(arr: ReadableArray): List<BackupRequest> {
|
||||
val list = ArrayList<BackupRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asBackupRequest(value)!!)
|
||||
else -> throw LiquidSdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asConnectRequest(connectRequest: ReadableMap): ConnectRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
connectRequest,
|
||||
|
||||
@@ -218,10 +218,17 @@ class BreezLiquidSDKModule(reactContext: ReactApplicationContext) : ReactContext
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun backup(promise: Promise) {
|
||||
fun backup(
|
||||
req: ReadableMap,
|
||||
promise: Promise,
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
getBindingLiquidSdk().backup()
|
||||
val backupRequest =
|
||||
asBackupRequest(
|
||||
req,
|
||||
) ?: run { throw LiquidSdkException.Generic(errMissingMandatoryField("req", "BackupRequest")) }
|
||||
getBindingLiquidSdk().backup(backupRequest)
|
||||
promise.resolve(readableMapOf("status" to "ok"))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
|
||||
Reference in New Issue
Block a user