react-native-rgb 0.2.2 → 0.2.4

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.
@@ -123,6 +123,68 @@ class RgbModule(reactContext: ReactApplicationContext) :
123
123
  }
124
124
  }
125
125
 
126
+ override fun restoreBackup(path: String, password: String, promise: Promise) {
127
+ coroutineScope.launch(Dispatchers.IO) {
128
+ try {
129
+ val rgbDir = AppConstants.rgbDir
130
+ ?: throw IllegalStateException("RGB directory not initialized.")
131
+ org.rgbtools.restoreBackup(path, password, rgbDir.absolutePath)
132
+
133
+ withContext(Dispatchers.Main) {
134
+ promise.resolve(null)
135
+ }
136
+ } catch (e: Exception) {
137
+ Log.e(TAG, "restoreBackup error: ${e.message}", e)
138
+ withContext(Dispatchers.Main) {
139
+ promise.reject(getErrorClassName(e), parseErrorMessage(e.message), e)
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ override fun decodeInvoice(invoice: String, promise: Promise) {
146
+ coroutineScope.launch(Dispatchers.IO) {
147
+ try {
148
+ val invoiceData = Invoice(invoiceString = invoice).invoiceData()
149
+ val map = Arguments.createMap()
150
+ map.putString("invoice", invoice)
151
+ map.putString("recipientId", invoiceData.recipientId)
152
+ invoiceData.assetSchema?.let { schema ->
153
+ val assetSchemaString = when (schema) {
154
+ AssetSchema.NIA -> "NIA"
155
+ AssetSchema.UDA -> "UDA"
156
+ AssetSchema.CFA -> "CFA"
157
+ AssetSchema.IFA -> "IFA"
158
+ }
159
+ map.putString("assetSchema", assetSchemaString)
160
+ }
161
+ map.putString("assetId", invoiceData.assetId)
162
+ map.putMap("assignment", assignmentToMap(invoiceData.assignment))
163
+ map.putString("assignmentName", invoiceData.assignmentName)
164
+ map.putString("network", invoiceData.network.toString())
165
+ val transportEndpointsArray = Arguments.createArray()
166
+ invoiceData.transportEndpoints.forEach {
167
+ transportEndpointsArray.pushString(it)
168
+ }
169
+ map.putArray("transportEndpoints", transportEndpointsArray)
170
+
171
+ invoiceData.expirationTimestamp?.let {
172
+ map.putDouble("expirationTimestamp", it.toDouble())
173
+ } ?: run {
174
+ map.putNull("expirationTimestamp")
175
+ }
176
+ withContext(Dispatchers.Main) {
177
+ promise.resolve(map)
178
+ }
179
+ } catch (e: Exception) {
180
+ Log.e(TAG, "decodeInvoice error: ${e.message}", e)
181
+ withContext(Dispatchers.Main) {
182
+ promise.reject(getErrorClassName(e), parseErrorMessage(e.message), e)
183
+ }
184
+ }
185
+ }
186
+ }
187
+
126
188
  private fun getNetwork(network: String): BitcoinNetwork {
127
189
  return when (network) {
128
190
  "MAINNET" -> BitcoinNetwork.MAINNET
@@ -2003,48 +2065,4 @@ class RgbModule(reactContext: ReactApplicationContext) :
2003
2065
  }
2004
2066
  }
2005
2067
 
2006
- override fun decodeInvoice(invoice: String, promise: Promise) {
2007
- coroutineScope.launch(Dispatchers.IO) {
2008
- try {
2009
- val invoiceData = Invoice(invoiceString = invoice).invoiceData()
2010
- val map = Arguments.createMap()
2011
- map.putString("invoice", invoice)
2012
- map.putString("recipientId", invoiceData.recipientId)
2013
- invoiceData.assetSchema?.let { schema ->
2014
- val assetSchemaString = when (schema) {
2015
- AssetSchema.NIA -> "NIA"
2016
- AssetSchema.UDA -> "UDA"
2017
- AssetSchema.CFA -> "CFA"
2018
- AssetSchema.IFA -> "IFA"
2019
- }
2020
- map.putString("assetSchema", assetSchemaString)
2021
- }
2022
- map.putString("assetId", invoiceData.assetId)
2023
- map.putMap("assignment", assignmentToMap(invoiceData.assignment))
2024
- map.putString("assignmentName", invoiceData.assignmentName)
2025
- map.putString("network", invoiceData.network.toString())
2026
- val transportEndpointsArray = Arguments.createArray()
2027
- invoiceData.transportEndpoints.forEach {
2028
- transportEndpointsArray.pushString(it)
2029
- }
2030
- map.putArray("transportEndpoints", transportEndpointsArray)
2031
-
2032
- invoiceData.expirationTimestamp?.let {
2033
- map.putDouble("expirationTimestamp", it.toDouble())
2034
- } ?: run {
2035
- map.putNull("expirationTimestamp")
2036
- }
2037
-
2038
- withContext(Dispatchers.Main) {
2039
- promise.resolve(map)
2040
- }
2041
- } catch (e: Exception) {
2042
- Log.e(TAG, "decodeInvoice error: ${e.message}", e)
2043
- withContext(Dispatchers.Main) {
2044
- promise.reject(getErrorClassName(e), parseErrorMessage(e.message), e)
2045
- }
2046
- }
2047
- }
2048
- }
2049
-
2050
2068
  }
@@ -5,67 +5,53 @@ import Foundation
5
5
  public class AppConstants: NSObject {
6
6
  @objc public static let shared = AppConstants()
7
7
 
8
- let rgbDirName = ""
9
- var appContext: Any? = nil
10
- var rgbDir: URL? = nil
11
- let backupName = "%s.rgb_backup"
12
-
13
- let testnetElectrumURL = "ssl://electrum.iriswallet.com:50013"
14
- let testnet4ElectrumURL = "ssl://electrum.iriswallet.com:50053"
15
-
16
- let regtestElectrumURL = "electrum.rgbtools.org:50041"
17
- let mainnetElectrumUrl = "ssl://electrum.iriswallet.com:50003"
18
-
19
- let proxyConsignmentEndpoint = "rpcs://proxy.iriswallet.com/0.2/json-rpc"
20
- let rgbDefaultPrecision: UInt8 = 0
21
- let defaultFeeRate: Float = 50.0
22
-
23
- private let mainnetUrls = [
24
- "ssl://electrum.iriswallet.com:50003",
25
- "https://blockstream.info/api"
26
- ]
27
- private var callCount = 0
8
+ private let rgbDirName = ""
9
+ private var _rgbDir: URL? = nil
10
+ private let queue = DispatchQueue(label: "com.rgb.appconstants")
11
+
12
+ var rgbDir: URL? {
13
+ get {
14
+ return queue.sync {
15
+ return _rgbDir
16
+ }
17
+ }
18
+ set {
19
+ queue.sync {
20
+ self._rgbDir = newValue
21
+ }
22
+ }
23
+ }
28
24
 
29
25
  private override init() {
30
26
  super.init()
31
27
  }
32
28
 
33
29
  @objc public func initContext() {
34
- let fileManager = FileManager.default
35
- let documentsPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
36
- rgbDir = documentsPath.appendingPathComponent(rgbDirName)
37
-
38
- // Create directory if it doesn't exist
39
- if let rgbDir = rgbDir {
40
- try? fileManager.createDirectory(at: rgbDir, withIntermediateDirectories: true, attributes: nil)
30
+ queue.sync {
31
+ let fileManager = FileManager.default
32
+ let documentsPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
33
+ _rgbDir = documentsPath.appendingPathComponent(rgbDirName)
34
+
35
+ // Create directory if it doesn't exist
36
+ if let rgbDir = _rgbDir {
37
+ try? fileManager.createDirectory(at: rgbDir, withIntermediateDirectories: true, attributes: nil)
38
+ }
41
39
  }
42
40
  }
43
41
 
44
42
  @objc public func ensureInitialized() {
45
- if rgbDir == nil {
46
- initContext()
47
- }
48
- }
49
-
50
- @objc public func getElectrumUrl(network: String) -> String {
51
- switch network.uppercased() {
52
- case "TESTNET":
53
- return testnetElectrumURL
54
- case "TESTNET4":
55
- return testnet4ElectrumURL
56
- case "REGTEST":
57
- return regtestElectrumURL
58
- case "MAINNET":
59
- return getNextMainnetUrl()
60
- default:
61
- return testnetElectrumURL
43
+ queue.sync {
44
+ if _rgbDir == nil {
45
+ let fileManager = FileManager.default
46
+ let documentsPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
47
+ _rgbDir = documentsPath.appendingPathComponent(rgbDirName)
48
+
49
+ // Create directory if it doesn't exist
50
+ if let rgbDir = _rgbDir {
51
+ try? fileManager.createDirectory(at: rgbDir, withIntermediateDirectories: true, attributes: nil)
52
+ }
53
+ }
62
54
  }
63
55
  }
64
-
65
- private func getNextMainnetUrl() -> String {
66
- let url = mainnetUrls[callCount % mainnetUrls.count]
67
- callCount += 1
68
- return url
69
- }
70
56
  }
71
57