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-1536 Show Ledgers from Settings #514

Merged
merged 8 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
10 changes: 9 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ package.addModules([
],
tests: .no
),
.feature(
name: "LedgerHardwareWalletsFeature",
kugel3 marked this conversation as resolved.
Show resolved Hide resolved
dependencies: [
"AddLedgerFactorSourceFeature",
"FactorSourcesClient",
],
tests: .no
),
.feature(
name: "MainFeature",
dependencies: [
Expand All @@ -230,7 +238,6 @@ package.addModules([
],
tests: .yes()
),

.feature(
name: "NewConnectionFeature",
dependencies: [
Expand Down Expand Up @@ -305,6 +312,7 @@ package.addModules([
"GeneralSettings",
"ImportLegacyWalletClient",
"InspectProfileFeature",
"LedgerHardwareWalletsFeature",
"MnemonicClient",
"P2PLinksFeature",
"PersonasFeature",
Expand Down
23 changes: 23 additions & 0 deletions Sources/Core/DesignSystem/Styles/InfoButtonStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Resources
import SwiftUI

// MARK: - InfoButtonStyle

extension ButtonStyle where Self == InfoButtonStyle {
public static var info: InfoButtonStyle { .init() }
}

// MARK: - InfoButtonStyle
public struct InfoButtonStyle: ButtonStyle {
public func makeBody(configuration: Configuration) -> some View {
Label {
configuration.label
.textStyle(.body1StandaloneLink)
} icon: {
Image(asset: AssetResource.info)
}
.labelStyle(.titleAndIcon)
.foregroundColor(.app.blue2)
.opacity(configuration.isPressed ? 0.2 : 1)
}
}
65 changes: 65 additions & 0 deletions Sources/Core/FeaturePrelude/LedgerRowView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import SwiftUI

// MARK: - LedgerRowView
@MainActor
public struct LedgerRowView: View {
public struct ViewState: Equatable {
let description: String
let addedOn: String
let lastUsedOn: String

public init(factorSource: LedgerFactorSource) {
self.description = "\(factorSource.label.rawValue) (\(factorSource.description.rawValue))"
self.addedOn = factorSource.addedOn.ISO8601Format(.iso8601Date(timeZone: .current))
self.lastUsedOn = factorSource.lastUsedOn.ISO8601Format(.iso8601Date(timeZone: .current))
}
}

private let viewState: ViewState
private let isSelected: Bool?
private let action: () -> Void

/// Initialises a plain LedgerRowView
public init(viewState: ViewState) {
self.viewState = viewState
self.isSelected = nil
self.action = {}
}

/// Initialises a selectable LedgerRowView
public init(viewState: ViewState, isSelected: Bool, action: @escaping () -> Void) {
self.viewState = viewState
self.isSelected = isSelected
self.action = action
}

public var body: some View {
Button(action: action) {
HStack {
VStack(alignment: .leading, spacing: 0) {
Text(viewState.description)
.textStyle(.body1Header)

HPair(label: L10n.CreateEntity.Ledger.usedHeading, item: viewState.lastUsedOn)

HPair(label: L10n.CreateEntity.Ledger.addedHeading, item: viewState.addedOn)
}

Spacer()

if let isSelected {
RadioButton(
appearance: .light,
state: isSelected ? .selected : .unselected
)
}
}
.foregroundColor(.app.white)
.padding(.medium1)
.background(.black)
.brightness(isSelected == true ? -0.1 : 0)
.cornerRadius(.small1)
}
.buttonStyle(.inert)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,40 @@ extension ChooseLedgerHardwareDevice {

public var body: some SwiftUI.View {
WithViewStore(store, observe: \.viewState, send: { .view($0) }) { viewStore in
VStack {
if viewStore.ledgers.isEmpty {
Text(L10n.CreateEntity.Ledger.subtitleNoLedgers)
} else {
Text(L10n.CreateEntity.Ledger.subtitleSelectLedger)

ScrollView {
VStack(spacing: .small1) {
Selection(
viewStore.binding(
get: \.ledgersArray,
send: { .selectedLedger(id: $0?.first?.id) }
),
from: viewStore.ledgers,
requiring: .exactly(1)
) { item in
SelectLedgerRow.View(
viewState: .init(factorSource: item.value),
isSelected: item.isSelected,
action: item.action
)
}
ScrollView {
VStack(spacing: .small1) {
if viewStore.ledgers.isEmpty {
Text(L10n.CreateEntity.Ledger.subtitleNoLedgers)
} else {
Text(L10n.CreateEntity.Ledger.subtitleSelectLedger)

Selection(
viewStore.binding(
get: \.ledgersArray,
send: { .selectedLedger(id: $0?.first?.id) }
),
from: viewStore.ledgers,
requiring: .exactly(1)
) { item in
LedgerRowView(
viewState: .init(factorSource: item.value),
isSelected: item.isSelected,
action: item.action
)
.padding(.horizontal, .large2)
}

.padding(.horizontal, .medium1)
.padding(.bottom, .medium2)
}
}

Spacer()

Spacer(minLength: 0)
}
.padding(.top, .small1)
}
.footer {
Button(L10n.CreateEntity.Ledger.addNewLedger) {
viewStore.send(.addNewLedgerButtonTapped)
}
.buttonStyle(.secondaryRectangular(shouldExpand: true))
}
.padding(.horizontal, .small1)
.footer {

WithControlRequirements(
viewStore.selectedLedgerControlRequirements,
forAction: { viewStore.send(.confirmedLedger($0.selectedLedger)) }
Expand All @@ -92,59 +88,9 @@ extension ChooseLedgerHardwareDevice {
content: { AddLedgerFactorSource.View(store: $0) }
)
.onFirstTask { @MainActor in
ViewStore(store.stateless).send(.view(.onFirstTask))
}
}
}
}
}

// MARK: - SelectLedgerRow
enum SelectLedgerRow {
struct ViewState: Equatable {
let description: String
let addedOn: String
let lastUsedOn: String

init(factorSource: LedgerFactorSource) {
self.description = "\(factorSource.label.rawValue) (\(factorSource.description.rawValue))"
self.addedOn = factorSource.addedOn.ISO8601Format(.iso8601Date(timeZone: .current))
self.lastUsedOn = factorSource.lastUsedOn.ISO8601Format(.iso8601Date(timeZone: .current))
}
}

@MainActor
struct View: SwiftUI.View {
let viewState: ViewState
let isSelected: Bool
let action: () -> Void

var body: some SwiftUI.View {
Button(action: action) {
HStack {
VStack(alignment: .leading, spacing: 0) {
Text(viewState.description)
.textStyle(.body1Header)

HPair(label: L10n.CreateEntity.Ledger.usedHeading, item: viewState.lastUsedOn)

HPair(label: L10n.CreateEntity.Ledger.addedHeading, item: viewState.addedOn)
}

Spacer()

RadioButton(
appearance: .light,
state: isSelected ? .selected : .unselected
)
viewStore.send(.onFirstTask)
}
.foregroundColor(.app.white)
.padding(.medium1)
.background(.black)
.brightness(isSelected ? -0.1 : 0)
.cornerRadius(.small1)
}
.buttonStyle(.inert)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ extension CreationOfAccount {
}
}
.navigationTitle(L10n.CreateEntity.Ledger.createAccount)
.onFirstTask { @MainActor in
ViewStore(store.stateless).send(.view(.onFirstTask))
}
#if os(iOS)
.navigationBarTitleColor(.app.gray1)
.navigationBarTitleDisplayMode(.inline)
.navigationBarInlineTitleFont(.app.secondaryHeader)
#endif
.onFirstTask { @MainActor in
ViewStore(store.stateless).send(.view(.onFirstTask))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,10 @@ extension IntroductionToPersonas {
.foregroundColor(.app.gray1)
.textStyle(.sheetTitle)

Button {
Button(L10n.CreatePersona.Introduction.learnAboutPersonas) {
viewStore.send(.showTutorial)
} label: {
Label {
Text(L10n.CreatePersona.Introduction.learnAboutPersonas).textStyle(.body1StandaloneLink)
} icon: {
Image(asset: AssetResource.info)
}
.tint(.app.blue2)
}
.buttonStyle(.info)

Text(L10n.CreatePersona.Introduction.subtitle1)
.font(.app.body1Regular)
Expand Down
24 changes: 6 additions & 18 deletions Sources/Features/GatewaySettingsFeature/GatewaySettings+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ extension GatewaySettings {

private func coreView(with viewStore: ViewStoreOf<GatewaySettings>) -> some SwiftUI.View {
VStack(spacing: .zero) {
VStack(spacing: .small2) {
VStack(alignment: .leading, spacing: .small2) {
subtitle

whatIsAGatewayButton(with: viewStore)
.flushedLeft
.padding(.vertical, .medium2)
Button(L10n.Gateways.whatIsAGateway) {
viewStore.send(.popoverButtonTapped)
}
.buttonStyle(.info)
.padding(.vertical, .medium2)

Separator()
}
Expand All @@ -91,7 +93,6 @@ extension GatewaySettings {
Text(L10n.Gateways.subtitle)
.foregroundColor(.app.gray2)
.textStyle(.body1HighImportance)
.flushedLeft
}

private var gatewayList: some SwiftUI.View {
Expand All @@ -102,19 +103,6 @@ extension GatewaySettings {
)
)
}

private func whatIsAGatewayButton(with viewStore: ViewStoreOf<GatewaySettings>) -> some SwiftUI.View {
Button {
viewStore.send(.popoverButtonTapped)
} label: {
HStack {
Image(asset: AssetResource.info)
Text(L10n.Gateways.whatIsAGateway)
.textStyle(.body1StandaloneLink)
}
.tint(.app.blue2)
}
}
}
}

Expand Down
Loading