orbis1-sdk-rn 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -335,14 +335,43 @@ class RgbModule(reactContext: ReactApplicationContext) :
335
335
  val session = WalletStore.get(walletId.toInt())
336
336
  ?: throw IllegalStateException("Wallet with id $walletId not found")
337
337
 
338
- val online = session.wallet.goOnline(
339
- skipConsistencyCheck = skipConsistencyCheck,
340
- indexerUrl = indexerUrl
341
- )
342
- WalletStore.setOnline(walletId.toInt(), online)
338
+ val masterFingerprint = session.wallet.getWalletData().masterFingerprint
339
+
340
+ suspend fun runOnline(): Pair<Boolean, String>? {
341
+ return try {
342
+ val online = session.wallet.goOnline(
343
+ skipConsistencyCheck = skipConsistencyCheck,
344
+ indexerUrl = indexerUrl
345
+ )
346
+ WalletStore.setOnline(walletId.toInt(), online)
347
+ Pair(true, "")
348
+ } catch (e: Exception) {
349
+ Pair(false, parseErrorMessage(e.message))
350
+ }
351
+ }
343
352
 
344
- withContext(Dispatchers.Main) {
345
- promise.resolve(null)
353
+ val result = runOnline()
354
+
355
+ withContext(Dispatchers.Main) {
356
+ if (result != null) {
357
+ val (status, error) = result
358
+ if (status) {
359
+ val map = Arguments.createMap()
360
+ map.putBoolean("status", status)
361
+ map.putString("error", error)
362
+ promise.resolve(map)
363
+ } else {
364
+ deleteRuntimeLockFile(masterFingerprint)
365
+ val retryResult = runOnline()
366
+ if (retryResult != null) {
367
+ val (retryStatus, retryError) = retryResult
368
+ val map = Arguments.createMap()
369
+ map.putBoolean("status", retryStatus)
370
+ map.putString("error", retryError)
371
+ promise.resolve(map)
372
+ }
373
+ }
374
+ }
346
375
  }
347
376
  } catch (e: Exception) {
348
377
  Log.e(TAG, "goOnline error: ${e.message}", e)
@@ -353,6 +382,26 @@ class RgbModule(reactContext: ReactApplicationContext) :
353
382
  }
354
383
  }
355
384
 
385
+ fun deleteRuntimeLockFile(masterFingerprint: String) {
386
+ try {
387
+ val runtimeLockPath = AppConstants.rgbDir
388
+ .resolve(masterFingerprint)
389
+ .resolve("rgb_runtime.lock")
390
+ if (!runtimeLockPath.exists()) {
391
+ Log.i("RGB", "No runtime lock file exists at path: ${runtimeLockPath.path}")
392
+ return
393
+ }
394
+ Log.i("RGB", "Deleting runtime lock at: ${runtimeLockPath.path}")
395
+ if (runtimeLockPath.delete()) {
396
+ Log.i("RGB", "Runtime lock deleted successfully.")
397
+ } else {
398
+ Log.e("RGB", "Failed to delete runtime lock.")
399
+ }
400
+ } catch (e: Exception) {
401
+ Log.e("RGB", "Failed to delete runtime lock: ${e.message}", e)
402
+ }
403
+ }
404
+
356
405
  override fun getBtcBalance(
357
406
  walletId: Double,
358
407
  skipSync: Boolean,
package/ios/Rgb.swift CHANGED
@@ -137,6 +137,30 @@ public class RgbSwiftHelper: NSObject {
137
137
  try fileManager.removeItem(at: URL(fileURLWithPath: targetPath))
138
138
  }
139
139
 
140
+ private static func deleteRuntimeLockFile(masterFingerprint: String) {
141
+ let constants = AppConstants.shared
142
+ constants.ensureInitialized()
143
+
144
+ guard let rgbDir = constants.rgbDir else {
145
+ return
146
+ }
147
+
148
+ let runtimeLockURL = rgbDir
149
+ .appendingPathComponent(masterFingerprint, isDirectory: true)
150
+ .appendingPathComponent("rgb_runtime.lock", isDirectory: false)
151
+
152
+ let fileManager = FileManager.default
153
+ guard fileManager.fileExists(atPath: runtimeLockURL.path) else {
154
+ return
155
+ }
156
+
157
+ do {
158
+ try fileManager.removeItem(at: runtimeLockURL)
159
+ } catch {
160
+ NSLog("RNRgb: Failed to delete runtime lock file: \(error.localizedDescription)")
161
+ }
162
+ }
163
+
140
164
  private static func getNetwork(_ network: String) -> BitcoinNetwork {
141
165
  switch network.uppercased() {
142
166
  case "MAINNET":
@@ -343,20 +367,45 @@ public class RgbSwiftHelper: NSObject {
343
367
  return ["error": "Wallet with id \(walletId) not found"] as NSDictionary
344
368
  }
345
369
 
346
- do {
347
- let online = try session.wallet.goOnline(
348
- skipConsistencyCheck: skipConsistencyCheck,
349
- indexerUrl: indexerUrl
350
- )
351
- WalletStore.shared.setOnline(id: walletId.intValue, online: online)
352
- return [:] as NSDictionary
353
- } catch {
354
- let errorData = [
355
- "error": parseErrorMessage(error),
356
- "errorCode": getErrorClassName(error)
357
- ] as NSDictionary
358
- return errorData
370
+ let masterFingerprint = session.wallet.getWalletData().masterFingerprint
371
+
372
+ func runOnline() -> (Bool, String)? {
373
+ do {
374
+ let online = try session.wallet.goOnline(
375
+ skipConsistencyCheck: skipConsistencyCheck,
376
+ indexerUrl: indexerUrl
377
+ )
378
+ WalletStore.shared.setOnline(id: walletId.intValue, online: online)
379
+ return (true, "")
380
+ } catch {
381
+ return (false, parseErrorMessage(error))
382
+ }
359
383
  }
384
+
385
+ if let result = runOnline() {
386
+ let (status, errorMessage) = result
387
+ if status {
388
+ return [
389
+ "status": NSNumber(value: status),
390
+ "error": errorMessage
391
+ ] as NSDictionary
392
+ }
393
+
394
+ deleteRuntimeLockFile(masterFingerprint: masterFingerprint)
395
+
396
+ if let retryResult = runOnline() {
397
+ let (retryStatus, retryError) = retryResult
398
+ return [
399
+ "status": NSNumber(value: retryStatus),
400
+ "error": retryError
401
+ ] as NSDictionary
402
+ }
403
+ }
404
+
405
+ return [
406
+ "status": NSNumber(value: false),
407
+ "error": "Failed to go online"
408
+ ] as NSDictionary
360
409
  }
361
410
 
362
411
  @objc(_getBtcBalance:skipSync:)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orbis1-sdk-rn",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Orbis1 SDK for React Native with RGB core, Watch Tower, and Gas-Free transfers.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",