orbis1-sdk-rn 0.2.4 → 0.2.6

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.
@@ -384,7 +384,13 @@ class RgbModule(reactContext: ReactApplicationContext) :
384
384
 
385
385
  fun deleteRuntimeLockFile(masterFingerprint: String) {
386
386
  try {
387
- val runtimeLockPath = AppConstants.rgbDir
387
+ val rgbDir = AppConstants.rgbDir
388
+ if (rgbDir == null) {
389
+ Log.i("RGB", "RGB directory is not initialized. Skipping runtime lock deletion.")
390
+ return
391
+ }
392
+
393
+ val runtimeLockPath = rgbDir
388
394
  .resolve(masterFingerprint)
389
395
  .resolve("rgb_runtime.lock")
390
396
  if (!runtimeLockPath.exists()) {
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.4",
3
+ "version": "0.2.6",
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",