Skip to content

Commit

Permalink
Refactor BlockchainSettings module to SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Sep 8, 2023
1 parent ab44345 commit ed07b7e
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 294 deletions.
30 changes: 12 additions & 18 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import MarketKit

extension Blockchain {

var shortName: String {
switch type {
case .binanceSmartChain: return "BSC"
Expand All @@ -17,5 +16,10 @@ extension Blockchain {

return explorerUrl.replacingOccurrences(of: "$ref", with: reference)
}
}

extension Blockchain: Identifiable {
public var id: String {
uid
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SwiftUI
import Combine

class BtcBlockchainSettingsViewModel: ObservableObject {
private let service: BtcBlockchainSettingsService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import UIKit
import SwiftUI

struct BlockchainSettingsModule {

static func viewController() -> UIViewController {
let service = BlockchainSettingsService(
btcBlockchainManager: App.shared.btcBlockchainManager,
evmBlockchainManager: App.shared.evmBlockchainManager,
evmSyncSourceManager: App.shared.evmSyncSourceManager
static func view() -> some View {
let viewModel = BlockchainSettingsViewModel(
btcBlockchainManager: App.shared.btcBlockchainManager,
evmBlockchainManager: App.shared.evmBlockchainManager,
evmSyncSourceManager: App.shared.evmSyncSourceManager
)
let viewModel = BlockchainSettingsViewModel(service: service)
return BlockchainSettingsViewController(viewModel: viewModel)
return BlockchainSettingsView(viewModel: viewModel)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import MarketKit
import SDWebImageSwiftUI
import SwiftUI

struct BlockchainSettingsView: View {
@ObservedObject var viewModel: BlockchainSettingsViewModel

@State private var btcSheetBlockchain: Blockchain?
@State private var evmSheetBlockchain: Blockchain?

var body: some View {
ScrollableThemeView {
VStack(spacing: .margin32) {
ListSection {
ForEach(viewModel.btcItems, id: \.blockchain.uid) { item in
ClickableRow(action: {
btcSheetBlockchain = item.blockchain
}) {
ItemView(
blockchain: item.blockchain,
value: item.restoreMode.title
)
}
}
.sheet(item: $btcSheetBlockchain) { blockchain in
ThemeNavigationView { BtcBlockchainSettingsModule.view(blockchain: blockchain) }
}
}

ListSection {
ForEach(viewModel.evmItems, id: \.blockchain.uid) { item in
ClickableRow(action: {
evmSheetBlockchain = item.blockchain
}) {
ItemView(
blockchain: item.blockchain,
value: item.syncSource.name
)
}
}
.sheet(item: $evmSheetBlockchain) { _ in
Text("TODO")
}
}
}
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin32, trailing: .margin16))
}
.navigationTitle("blockchain_settings.title".localized)
}

struct ItemView: View {
let blockchain: Blockchain
let value: String

var body: some View {
WebImage(url: URL(string: blockchain.type.imageUrl))
.resizable()
.scaledToFit()
.frame(width: .iconSize32, height: .iconSize32)

VStack(spacing: 1) {
Text(blockchain.name).themeBody()
Text(value).themeSubhead2()
}

Image.disclosureIcon
}
}
}

This file was deleted.

Loading

0 comments on commit ed07b7e

Please sign in to comment.