Skip to content

Commit

Permalink
Localize custom node view
Browse files Browse the repository at this point in the history
  • Loading branch information
acorscadden committed Aug 18, 2017
1 parent f5eb1ce commit 4c7bc05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 12 additions & 0 deletions breadwallet/src/Constants/Strings.swift
Expand Up @@ -536,4 +536,16 @@ enum S {
static let hashCopiedMessage = NSLocalizedString("BCH.hashCopiedMessage", value: "Transaction ID copied", comment: "Transaction ID copied message")
static let genericError = NSLocalizedString("BCH.genericError", value: "Your account does not contain any BCH, or you received BCH after the fork.", comment: "Generic bch erorr message")
}

enum NodeSelector {
static let manualButton = NSLocalizedString("NodeSelector.manualButton", value: "Switch to Manual Mode", comment: "Switch to manual mode button label")
static let automaticButton = NSLocalizedString("NodeSelector.automaticButton", value: "Switch to Automatic Mode", comment: "Switch to automatic mode button label")
static let title = NSLocalizedString("NodeSelector.title", value: "Bitcoin Nodes", comment: "Node Selector view title")
static let nodeLabel = NSLocalizedString("NodeSelector.nodeLabel", value: "Current Primary Node", comment: "Node address label")
static let statusLabel = NSLocalizedString("NodeSelector.statusLabel", value: "Node Connection Status", comment: "Node status label")
static let connected = NSLocalizedString("NodeSelector.connected", value: "Connected", comment: "Node is connected label")
static let notConnected = NSLocalizedString("NodeSelector.notConnected", value: "Not Connected", comment: "Node is not connected label")
static let enterTitle = NSLocalizedString("NodeSelector.enterTitle", value: "Enter Node", comment: "Enter Node ip address view title")
static let enterBody = NSLocalizedString("NodeSelector.enterBody", value: "Enter Node IP address and port (optional)", comment: "Enter node ip address view body")
}
}
22 changes: 9 additions & 13 deletions breadwallet/src/ViewControllers/NodeSelectorViewController.swift
Expand Up @@ -24,9 +24,9 @@ class NodeSelectorViewController : UIViewController {
init(walletManager: WalletManager) {
self.walletManager = walletManager
if UserDefaults.customNodeIP == nil {
button = ShadowButton(title: "Switch to Manual Mode", type: .primary)
button = ShadowButton(title: S.NodeSelector.manualButton, type: .primary)
} else {
button = ShadowButton(title: "Switch to Automatic Mode", type: .primary)
button = ShadowButton(title: S.NodeSelector.automaticButton, type: .primary)
}
super.init(nibName: nil, bundle: nil)
}
Expand Down Expand Up @@ -61,9 +61,9 @@ class NodeSelectorViewController : UIViewController {

private func setInitialData() {
view.backgroundColor = .whiteTint
titleLabel.text = "Bitcoin Nodes"
nodeLabel.text = "Current Primary Node"
statusLabel.text = "Node Connection Status"
titleLabel.text = S.NodeSelector.title
nodeLabel.text = S.NodeSelector.nodeLabel
statusLabel.text = S.NodeSelector.statusLabel
button.tap = strongify(self) { myself in
if UserDefaults.customNodeIP == nil {
myself.switchToManual()
Expand All @@ -77,9 +77,7 @@ class NodeSelectorViewController : UIViewController {

@objc private func setStatusText() {
if let peerManager = walletManager.peerManager {
status.text = peerManager.isConnected ? "Connected" : "Not Connected"
} else {
print("No peer manager")
status.text = peerManager.isConnected ? S.NodeSelector.connected : S.NodeSelector.notConnected
}
node.text = walletManager.peerManager?.downloadPeerName
}
Expand All @@ -88,14 +86,14 @@ class NodeSelectorViewController : UIViewController {
guard UserDefaults.customNodeIP != nil else { return } //noop if custom node is already nil
UserDefaults.customNodeIP = nil
UserDefaults.customNodePort = nil
button.title = "Switch to Manual Mode"
button.title = S.NodeSelector.manualButton
DispatchQueue.walletQueue.async {
self.walletManager.peerManager?.connect()
}
}

private func switchToManual() {
let alert = UIAlertController(title: "Enter Node", message: "Enter Node ip address and port", preferredStyle: .alert)
let alert = UIAlertController(title: S.NodeSelector.enterTitle, message: S.NodeSelector.enterBody, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: S.Button.cancel, style: .cancel, handler: nil))
let okAction = UIAlertAction(title: S.Button.ok, style: .default, handler: { action in
guard let ip = alert.textFields?.first, let port = alert.textFields?.last else { return }
Expand All @@ -109,7 +107,7 @@ class NodeSelectorViewController : UIViewController {
DispatchQueue.walletQueue.async {
self.walletManager.peerManager?.connect()
}
self.button.title = "Switch to Automatic Mode"
self.button.title = S.NodeSelector.automaticButton
}
})
self.okAction = okAction
Expand All @@ -132,8 +130,6 @@ class NodeSelectorViewController : UIViewController {
if var customNode = UserDefaults.customNodeIP {
if let buf = addr2ascii(AF_INET, &customNode, Int32(MemoryLayout<in_addr_t>.size), nil) {
node.text = String(cString: buf)
} else {
node.text = "failed"
}
}
}
Expand Down

0 comments on commit 4c7bc05

Please sign in to comment.