Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABW-1715 Simplify Ledger Screen Variants #588

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct CreationOfAccount: Sendable, FeatureReducer {
self.isCreatingLedgerAccount = isCreatingLedgerAccount

if isCreatingLedgerAccount {
self.step = .step0_chooseLedger(.init(allowSelection: true, context: .ledgerSelection))
self.step = .step0_chooseLedger(.init(context: .createHardwareAccount))
} else {
self.step = .step1_derivePublicKeys(
.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension CreationOfAccount {

public var body: some SwiftUI.View {
ZStack {
SwitchStore(store.scope(state: \.step)) {
SwitchStore(store.scope(state: \.step, action: { $0 })) {
CaseLet(
state: /CreationOfAccount.State.Step.step0_chooseLedger,
action: { CreationOfAccount.Action.child(.step0_chooseLedger($0)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct ImportOlympiaLedgerAccountsAndFactorSources: Sendable, FeatureRedu
let accountsValidation = OlympiaAccountsValidation(validated: [], unvalidated: Set(hardwareAccounts.elements))
self.networkID = networkID
self.unmigrated = accountsValidation
self.chooseLedger = .init(allowSelection: true, context: .ledgerSelection, showHeaders: false)
self.chooseLedger = .init(context: .importOlympia)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ public struct LedgerHardwareDevices: Sendable, FeatureReducer {
// MARK: - State

public struct State: Sendable, Hashable {
public enum Context {
public enum Context: Sendable, Hashable {
case settings
case ledgerSelection
case importOlympia
case createHardwareAccount
}

public let allowSelection: Bool
public let showHeaders: Bool
public let context: Context

public var hasAConnectorExtension: Bool = false
Expand All @@ -37,10 +36,8 @@ public struct LedgerHardwareDevices: Sendable, FeatureReducer {

var pendingAction: ActionRequiringP2P? = nil

public init(allowSelection: Bool, context: Context, showHeaders: Bool = true) {
self.allowSelection = allowSelection
public init(context: Context) {
self.context = context
self.showHeaders = showHeaders
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ extension LedgerHardwareDevices.State {
// MARK: - LedgerHardwareDevice.View
extension LedgerHardwareDevices {
public struct ViewState: Equatable {
let allowSelection: Bool
let showHeaders: Bool
var allowSelection: Bool { context != .settings }
var showHeaders: Bool { context != .importOlympia }
var showIcon: Bool { context != .settings }

let ledgers: Loadable<IdentifiedArrayOf<LedgerHardwareWalletFactorSource>>
let selectedLedgerID: FactorSourceID.FromHash?
let selectedLedgerControlRequirements: SelectedLedgerControlRequirements?
let context: State.Context

init(state: LedgerHardwareDevices.State) {
self.allowSelection = state.allowSelection
self.showHeaders = state.showHeaders
self.ledgers = state.$ledgers
self.selectedLedgerID = state.selectedLedgerID
self.context = state.context

if let id = state.selectedLedgerID, let selectedLedger = state.ledgers?[id: id] {
self.selectedLedgerControlRequirements = .init(selectedLedger: selectedLedger)
} else {
self.selectedLedgerControlRequirements = nil
}
self.context = state.context
}

var ledgersArray: [LedgerHardwareWalletFactorSource]? { .init(ledgers.wrappedValue ?? []) }
Expand Down Expand Up @@ -74,12 +74,7 @@ extension LedgerHardwareDevices {
ScrollView {
VStack(spacing: 0) {
Group {
if viewStore.context == .settings {
Text(L10n.LedgerHardwareDevices.subtitleAllLedgers)
.textStyle(.body1HighImportance)
.foregroundColor(.app.gray2)
.padding(.vertical, .medium1)
} else {
if viewStore.allowSelection {
Image(asset: AssetResource.iconHardwareLedger)
.frame(.medium)
.padding(.vertical, .medium2)
Expand All @@ -88,6 +83,11 @@ extension LedgerHardwareDevices {
.textStyle(.sheetTitle)
.foregroundColor(.app.gray1)
.padding(.bottom, .medium1)
} else {
Text(L10n.LedgerHardwareDevices.subtitleAllLedgers)
.textStyle(.body1HighImportance)
.foregroundColor(.app.gray2)
.padding(.vertical, .medium1)
}

if viewStore.showHeaders {
Expand Down Expand Up @@ -120,10 +120,7 @@ extension LedgerHardwareDevices {
Spacer(minLength: 0)
}
}
.frame(
minWidth: 0,
maxWidth: .infinity
)
.frame(minWidth: 0, maxWidth: .infinity)
.footer(visible: viewStore.allowSelection) {
WithControlRequirements(
viewStore.selectedLedgerControlRequirements,
Expand Down
3 changes: 1 addition & 2 deletions Sources/Features/SettingsFeature/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ public struct AppSettings: Sendable, FeatureReducer {
return .none

case .personasButtonTapped:
// TODO: implement
state.destination = .personas(.init())
return .none

Expand All @@ -203,7 +202,7 @@ public struct AppSettings: Sendable, FeatureReducer {
return .none

case .ledgerHardwareWalletsButtonTapped:
state.destination = .ledgerHardwareWallets(.init(allowSelection: false, context: .settings, showHeaders: true))
state.destination = .ledgerHardwareWallets(.init(context: .settings))
return .none

case .mnemonicsButtonTapped:
Expand Down