Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

Commit

Permalink
Add configurable option for showing message
Browse files Browse the repository at this point in the history
  • Loading branch information
vikmeup committed Aug 8, 2018
1 parent c7bf0d2 commit 43e0a44
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
29 changes: 25 additions & 4 deletions Trust/Core/Coordinators/StartupCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@ import Foundation
import UIKit
import Moya

struct StartupModel: Encodable {
struct StartupModel: Codable {
let deviceID: String
let networks: [Int: [String]]
let locale: String
}

struct StartupResult: Decodable {
struct StartupResult: Codable {
let showMessage: Bool
let message: StartupMessage
}

struct StartupMessage: Decodable {
struct StartupButton: Codable {
let title: String
let url: String?
}

struct StartupMessage: Codable {
let title: String
let message: String
let buttons: [StartupButton]
}

protocol StartupCoordinatorDelegate: class {
func didPressURL(url: URL)
}

class StartupCoordinator: Coordinator {
Expand All @@ -27,6 +37,8 @@ class StartupCoordinator: Coordinator {
let provider: MoyaProvider<TrustAPI>
var coordinators: [Coordinator] = []

weak var delegate: StartupCoordinatorDelegate?

init(
keystore: Keystore,
navigationController: NavigationController,
Expand Down Expand Up @@ -69,7 +81,16 @@ class StartupCoordinator: Coordinator {
preferredStyle: UIAlertControllerStyle.alert
)
controller.popoverPresentationController?.sourceView = navigationController.view
controller.addAction(UIAlertAction(title: R.string.localizable.oK(), style: .default))

for button in message.buttons {
let addAction = UIAlertAction(title: button.title, style: .default) { [weak self] _ in
guard let urlString = button.url, let url = URL(string: urlString) else { return }
guard let `self` = self else { return }
self.delegate?.didPressURL(url: url)
}
controller.addAction(addAction)
}

navigationController.present(controller, animated: true)
}
}
7 changes: 7 additions & 0 deletions Trust/InCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class InCoordinator: Coordinator {
navigationController: navigationController,
provider: TrustProviderFactory.makeProvider()
)
coordinator.delegate = self
coordinator.start()
addCoordinator(coordinator)
}
Expand Down Expand Up @@ -424,3 +425,9 @@ extension InCoordinator: WalletsCoordinatorDelegate {
// removeCoordinator(coordinator)
}
}

extension InCoordinator: StartupCoordinatorDelegate {
func didPressURL(url: URL) {
showTab(.browser(openURL: url))
}
}
2 changes: 1 addition & 1 deletion Trust/Wallet/Coordinators/WalletCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ final class WalletCoordinator: Coordinator {
private func markAsMainWallet(for wallet: WalletInfo) {
let number = keystore.wallets.filter { $0.mainWallet }.count
let initialName: String = {
if number <= 1 {
if number < 1 {
return R.string.localizable.mainWallet()
}
return R.string.localizable.mainWallet() + " \(number + 1)"
Expand Down

0 comments on commit 43e0a44

Please sign in to comment.