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.
- package/android/src/main/java/com/rgb/RgbModule.kt +62 -44
- package/ios/AppConstants.swift +36 -50
- package/ios/Rgb.mm +249 -220
- package/ios/Rgb.swift +24 -7
- package/lib/module/NativeRgb.js.map +1 -1
- package/lib/module/index.js +14 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/docs/docusaurus.config.d.ts +4 -0
- package/lib/typescript/docs/docusaurus.config.d.ts.map +1 -0
- package/lib/typescript/docs/sidebars.d.ts +14 -0
- package/lib/typescript/docs/sidebars.d.ts.map +1 -0
- package/lib/typescript/docs/src/components/HomepageFeatures/index.d.ts +3 -0
- package/lib/typescript/docs/src/components/HomepageFeatures/index.d.ts.map +1 -0
- package/lib/typescript/docs/src/pages/index.d.ts +2 -0
- package/lib/typescript/docs/src/pages/index.d.ts.map +1 -0
- package/lib/typescript/src/NativeRgb.d.ts +1 -0
- package/lib/typescript/src/NativeRgb.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/NativeRgb.ts +1 -0
- package/src/index.tsx +17 -0
|
@@ -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
|
}
|
package/ios/AppConstants.swift
CHANGED
|
@@ -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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|