-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathSharedDefaults.swift
33 lines (25 loc) · 1.21 KB
/
SharedDefaults.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// ∅ 2025 lil org
import Foundation
struct SharedDefaults {
#if os(macOS)
static let defaults = UserDefaults(suiteName: "8DXC3N7E7P.group.org.lil.wallet")
#else
static let defaults = UserDefaults(suiteName: "group.org.lil.wallet")
#endif
private static let customEthereumNetworksKey = "customEthereumNetworks"
private static let customEthereumNetworkNodeKeyPrefix = "customEthereumNetworkNode_"
static func addNetwork(_ network: EthereumNetworkFromDapp) {
guard let chainId = Int(hexString: network.chainId) else { return }
let updated = getCustomNetworks() + [network]
defaults?.setCodable(updated, forKey: customEthereumNetworksKey)
let nodeKey = customEthereumNetworkNodeKeyPrefix + String(chainId)
defaults?.set(network.defaultRpcUrl, forKey: nodeKey)
}
static func getCustomNetworks() -> [EthereumNetworkFromDapp] {
return defaults?.codableValue(type: [EthereumNetworkFromDapp].self, forKey: customEthereumNetworksKey) ?? []
}
static func getCustomNetworkNode(chainId: Int) -> String? {
let key = customEthereumNetworkNodeKeyPrefix + String(chainId)
return defaults?.string(forKey: key)
}
}