react-native-rgb 0.2.2 → 0.2.3

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.
@@ -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