-
Notifications
You must be signed in to change notification settings - Fork 9
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-1472] Allow user to toggle Verbose / Summary when making ledger requests #474
Changes from all commits
add9f4e
178e990
e357de4
102da7c
f735217
7f148fe
52fcd8e
b249a2d
983f92b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import FeaturePrelude | |
extension GeneralSettings.State { | ||
var viewState: GeneralSettings.ViewState { | ||
.init( | ||
hasLedgerHardwareWalletFactorSources: hasLedgerHardwareWalletFactorSources, | ||
useVerboseLedgerDisplayMode: (preferences?.display.ledgerHQHardwareWalletSigningDisplayMode ?? .default) == .verbose, | ||
isDeveloperModeEnabled: preferences?.security.isDeveloperModeEnabled ?? false | ||
) | ||
} | ||
|
@@ -11,6 +13,11 @@ extension GeneralSettings.State { | |
// MARK: - GeneralSettings.View | ||
extension GeneralSettings { | ||
public struct ViewState: Equatable { | ||
let hasLedgerHardwareWalletFactorSources: Bool | ||
|
||
/// only to be displayed if `hasLedgerHardwareWalletFactorSources` is true | ||
let useVerboseLedgerDisplayMode: Bool | ||
|
||
let isDeveloperModeEnabled: Bool | ||
} | ||
|
||
|
@@ -36,12 +43,26 @@ extension GeneralSettings { | |
VStack(spacing: .zero) { | ||
VStack(spacing: .zero) { | ||
isDeveloperModeEnabled(with: viewStore) | ||
if viewStore.hasLedgerHardwareWalletFactorSources { | ||
isUsingVerboseLedgerMode(with: viewStore) | ||
} | ||
Separator() | ||
} | ||
.padding(.medium3) | ||
} | ||
} | ||
|
||
private func isUsingVerboseLedgerMode(with viewStore: ViewStoreOf<GeneralSettings>) -> some SwiftUI.View { | ||
ToggleView( | ||
title: "Verbose Ledger transaction signing", | ||
subtitle: "When signing with your Ledger hardware wallet, should all instructions be displayed?", | ||
isOn: viewStore.binding( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're only using the binding in here, you could create it outside and pass it in. This has no practical benefit, it's merely philosophical since this view is very unlikely to be reused... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think unnecessary variables in ResultBuilders are ugly :D matter of taste I guess... |
||
get: \.useVerboseLedgerDisplayMode, | ||
send: { .useVerboseModeToggled($0) } | ||
) | ||
) | ||
} | ||
|
||
private func isDeveloperModeEnabled(with viewStore: ViewStoreOf<GeneralSettings>) -> some SwiftUI.View { | ||
ToggleView( | ||
title: L10n.GeneralSettings.DeveloperMode.title, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
import AppPreferencesClient | ||
import FactorSourcesClient | ||
import FeaturePrelude | ||
|
||
// MARK: - GeneralSettings | ||
public struct GeneralSettings: Sendable, FeatureReducer { | ||
public struct State: Sendable, Hashable { | ||
var preferences: AppPreferences? | ||
|
||
public var preferences: AppPreferences? | ||
public var hasLedgerHardwareWalletFactorSources: Bool = false | ||
public init() {} | ||
} | ||
|
||
public enum ViewAction: Sendable, Equatable { | ||
case appeared | ||
case useVerboseModeToggled(Bool) | ||
case developerModeToggled(Bool) | ||
} | ||
|
||
public enum InternalAction: Sendable, Equatable { | ||
case loadPreferences(AppPreferences) | ||
case hasLedgerHardwareWalletFactorSourcesLoaded(Bool) | ||
} | ||
|
||
public init() {} | ||
|
||
@Dependency(\.appPreferencesClient) var appPreferencesClient | ||
@Dependency(\.factorSourcesClient) var factorSourcesClient | ||
|
||
public func reduce(into state: inout State, viewAction: ViewAction) -> EffectTask<Action> { | ||
switch viewAction { | ||
case .appeared: | ||
return .run { send in | ||
let preferences = await appPreferencesClient.getPreferences() | ||
await send(.internal(.loadPreferences(preferences))) | ||
|
||
do { | ||
let ledgers = try await factorSourcesClient.getFactorSources(ofKind: .ledgerHQHardwareWallet) | ||
await send(.internal(.hasLedgerHardwareWalletFactorSourcesLoaded(!ledgers.isEmpty))) | ||
} catch { | ||
loggerGlobal.warning("Failed to load ledgers, error: \(error)") | ||
// OK to display it... | ||
await send(.internal(.hasLedgerHardwareWalletFactorSourcesLoaded(true))) | ||
} | ||
} | ||
|
||
case let .developerModeToggled(value): | ||
|
@@ -36,6 +49,13 @@ public struct GeneralSettings: Sendable, FeatureReducer { | |
return .fireAndForget { | ||
try await appPreferencesClient.updatePreferences(preferences) | ||
} | ||
|
||
case let .useVerboseModeToggled(useVerboseMode): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we just put the mode here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the problem with bindings and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes if it's the one that goes into the binding then sure, bool makes more sense |
||
state.preferences?.display.ledgerHQHardwareWalletSigningDisplayMode = useVerboseMode ? .verbose : .summary | ||
guard let preferences = state.preferences else { return .none } | ||
return .fireAndForget { | ||
try await appPreferencesClient.updatePreferences(preferences) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -44,6 +64,9 @@ public struct GeneralSettings: Sendable, FeatureReducer { | |
case let .loadPreferences(preferences): | ||
state.preferences = preferences | ||
return .none | ||
case let .hasLedgerHardwareWalletFactorSourcesLoaded(hasLedgerHardwareWalletFactorSources): | ||
state.hasLedgerHardwareWalletFactorSources = hasLedgerHardwareWalletFactorSources | ||
return .none | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import AppPreferencesClient | ||
import EngineToolkit | ||
import FactorSourcesClient | ||
import FeaturePrelude | ||
|
@@ -21,6 +22,7 @@ public struct SignWithFactorSourcesOfKindLedger: SignWithFactorSourcesOfKindRedu | |
} | ||
|
||
@Dependency(\.ledgerHardwareWalletClient) var ledgerHardwareWalletClient | ||
@Dependency(\.appPreferencesClient) var appPreferencesClient | ||
public init() {} | ||
|
||
public func reduce(into state: inout State, viewAction: ViewAction) -> EffectTask<Action> { | ||
|
@@ -48,11 +50,22 @@ public struct SignWithFactorSourcesOfKindLedger: SignWithFactorSourcesOfKindRedu | |
} catch { | ||
loggerGlobal.critical("Failed to hash: \(error)") | ||
} | ||
let ledgerTXDisplayMode: FactorSource.LedgerHardwareWallet.SigningDisplayMode = await appPreferencesClient.getPreferences().display.ledgerHQHardwareWalletSigningDisplayMode | ||
return try await ledgerHardwareWalletClient.sign(.init( | ||
signingFactor: signingFactor, | ||
unhashedDataToSign: state.dataToSign, | ||
ledgerTXDisplayMode: .verbose, | ||
ledgerTXDisplayMode: ledgerTXDisplayMode.mode, | ||
displayHashOnLedgerDisplay: true | ||
)) | ||
} | ||
} | ||
|
||
extension FactorSource.LedgerHardwareWallet.SigningDisplayMode { | ||
// seperation so that we do not accidentally break profile or RadixConnect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separation in the sense that we have two identical enums? |
||
var mode: P2P.ConnectorExtension.Request.LedgerHardwareWallet.Request.SignTransaction.Mode { | ||
switch self { | ||
case .verbose: return .verbose | ||
case .summary: return .summary | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we are inside the init of
Self
andgetFactorSource:ofKind
is a non static func, I myself silly enough tried to call it, which ofc does not work, since we are in the process of init Self :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one could complicate matters with
static func
but deemed it not worth it.