-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BtcBlockchainSettings module to SwiftUI
- Loading branch information
Showing
17 changed files
with
265 additions
and
245 deletions.
There are no files selected for viewing
65 changes: 57 additions & 8 deletions
65
UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
6 changes: 5 additions & 1 deletion
6
UnstoppableWallet/UnstoppableWallet/Models/BtcRestoreMode.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...eWallet/UnstoppableWallet/Modules/BtcBlockchainSettings/BtcBlockchainSettingsModule.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import SwiftUI | ||
import UIKit | ||
import ThemeKit | ||
import MarketKit | ||
|
||
struct BtcBlockchainSettingsModule { | ||
|
||
static func viewController(blockchain: Blockchain) -> UIViewController { | ||
let service = BtcBlockchainSettingsService(blockchain: blockchain, btcBlockchainManager: App.shared.btcBlockchainManager) | ||
let viewModel = BtcBlockchainSettingsViewModel(service: service) | ||
let viewController = BtcBlockchainSettingsViewController(viewModel: viewModel) | ||
let view = BtcBlockchainSettingsView(viewModel: viewModel) | ||
|
||
return ThemeNavigationController(rootViewController: viewController) | ||
return UIHostingController(rootView: view) | ||
} | ||
|
||
} |
29 changes: 4 additions & 25 deletions
29
...Wallet/UnstoppableWallet/Modules/BtcBlockchainSettings/BtcBlockchainSettingsService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,24 @@ | ||
import RxSwift | ||
import RxRelay | ||
import MarketKit | ||
|
||
class BtcBlockchainSettingsService { | ||
let blockchain: Blockchain | ||
private let btcBlockchainManager: BtcBlockchainManager | ||
private let disposeBag = DisposeBag() | ||
|
||
var restoreMode: BtcRestoreMode { | ||
didSet { | ||
syncHasChanges() | ||
} | ||
} | ||
|
||
private let hasChangesRelay = BehaviorRelay<Bool>(value: false) | ||
let currentRestoreMode: BtcRestoreMode | ||
|
||
init(blockchain: Blockchain, btcBlockchainManager: BtcBlockchainManager) { | ||
self.blockchain = blockchain | ||
self.btcBlockchainManager = btcBlockchainManager | ||
|
||
restoreMode = btcBlockchainManager.restoreMode(blockchainType: blockchain.type) | ||
} | ||
|
||
private func syncHasChanges() { | ||
let initialRestoreMode = btcBlockchainManager.restoreMode(blockchainType: blockchain.type) | ||
|
||
hasChangesRelay.accept(restoreMode != initialRestoreMode) | ||
currentRestoreMode = btcBlockchainManager.restoreMode(blockchainType: blockchain.type) | ||
} | ||
|
||
} | ||
|
||
extension BtcBlockchainSettingsService { | ||
|
||
var hasChangesObservable: Observable<Bool> { | ||
hasChangesRelay.asObservable() | ||
} | ||
|
||
func save() { | ||
if restoreMode != btcBlockchainManager.restoreMode(blockchainType: blockchain.type) { | ||
btcBlockchainManager.save(restoreMode: restoreMode, blockchainType: blockchain.type) | ||
} | ||
func save(restoreMode: BtcRestoreMode) { | ||
btcBlockchainManager.save(restoreMode: restoreMode, blockchainType: blockchain.type) | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
...bleWallet/UnstoppableWallet/Modules/BtcBlockchainSettings/BtcBlockchainSettingsView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import SwiftUI | ||
import SDWebImageSwiftUI | ||
|
||
struct BtcBlockchainSettingsView: View { | ||
@ObservedObject var viewModel: BtcBlockchainSettingsViewModel | ||
|
||
@Environment(\.presentationMode) var presentationMode | ||
@State var infoPresented = false | ||
|
||
var body: some View { | ||
ThemeNavigationView { | ||
ThemeView { | ||
VStack(spacing: 0) { | ||
ScrollView { | ||
VStack(spacing: .margin24) { | ||
HighlightedTextView(text: "btc_blockchain_settings.restore_source.alert".localized(viewModel.title)) | ||
|
||
VStack(spacing: 0) { | ||
ListSectionInfoHeader(text: "btc_blockchain_settings.restore_source".localized) { | ||
infoPresented = true | ||
} | ||
.sheet(isPresented: $infoPresented) { | ||
InfoModule.restoreSourceInfo | ||
} | ||
|
||
ListSection { | ||
ForEach(viewModel.restoreModes) { restoreMode in | ||
ClickableRow(action: { | ||
viewModel.selectedRestoreMode = restoreMode | ||
}) { | ||
VStack(spacing: 1) { | ||
Text(restoreMode.title).themeBody() | ||
Text(restoreMode.description).themeSubhead2() | ||
} | ||
|
||
if restoreMode == viewModel.selectedRestoreMode { | ||
Image("check_1_20").themeIcon(color: .themeJacob) | ||
} | ||
} | ||
} | ||
} | ||
|
||
ListSectionFooter(text: "btc_blockchain_settings.restore_source.description".localized) | ||
} | ||
} | ||
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin32, trailing: .margin16)) | ||
} | ||
|
||
Button(action: { | ||
viewModel.onTapSave() | ||
presentationMode.wrappedValue.dismiss() | ||
}) { | ||
Text("Save") | ||
} | ||
.disabled(!viewModel.saveEnabled) | ||
} | ||
} | ||
.navigationBarTitle(viewModel.title) | ||
.toolbar { | ||
ToolbarItem(placement: .navigationBarLeading) { | ||
WebImage(url: URL(string: viewModel.iconUrl)) | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: .iconSize24, height: .iconSize24) | ||
} | ||
|
||
ToolbarItem(placement: .navigationBarTrailing) { | ||
Button("button.cancel".localized) { | ||
presentationMode.wrappedValue.dismiss() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
141 changes: 0 additions & 141 deletions
141
...UnstoppableWallet/Modules/BtcBlockchainSettings/BtcBlockchainSettingsViewController.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.