-
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
Debug Only: Inspect FactorInstancesCache
#1391
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,13 @@ extension ProfileStore { | |
|
||
extension ProfileStore { | ||
func createNewProfile() async throws { | ||
try await SargonOS.shared.newWallet() | ||
let shouldPrederiveInstances: Bool | ||
#if DEBUG | ||
shouldPrederiveInstances = true | ||
#else | ||
shouldPrederiveInstances = false | ||
#endif | ||
return try await SargonOS.shared.newWallet(shouldPrederiveInstances: shouldPrederiveInstances) | ||
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. @micbakos-rdx breaking change for Android, you need to pass |
||
} | ||
|
||
func finishOnboarding( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,6 +273,8 @@ extension InteractionReview.Sections { | |
accountDepositSetting: accountDepositSetting, | ||
accountDepositExceptions: accountDepositExceptions | ||
) | ||
case .some(.deleteAccounts(accountAddresses: let accountAddresses)): | ||
fatalError() | ||
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. will go away when #1389 is merged and I rebase to |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Sargon | ||
import SwiftUI | ||
|
||
// MARK: - DebugFactorInstancesCacheContents.View | ||
extension DebugFactorInstancesCacheContents { | ||
struct View: SwiftUI.View { | ||
let store: StoreOf<DebugFactorInstancesCacheContents> | ||
|
||
var body: some SwiftUI.View { | ||
WithPerceptionTracking { | ||
VStack(spacing: .small2) { | ||
Button("Delete Cache File") { | ||
store.send(.view(.deleteButtonTapped)) | ||
} | ||
.buttonStyle(.primaryRectangular(isDestructive: true)) | ||
loadable(store.factorInstances) { | ||
ProgressView() | ||
} successContent: { instances in | ||
content(instances: instances) | ||
} | ||
} | ||
.padding() | ||
.navigationTitle("FactorInstances cache") | ||
}.task { | ||
store.send(.view(.task)) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private func content(instances: Instances) -> some SwiftUI.View { | ||
ScrollView { | ||
VStack(alignment: .leading) { | ||
ForEach(Array(instances.keys), id: \.self) { (key: FactorSourceIDFromHash) in | ||
Section { | ||
let listOfList: [[FactorInstanceForDebugPurposes]] = instances[key]! | ||
ForEach(listOfList, id: \.self) { (instancesForFactorForPath: [FactorInstanceForDebugPurposes]) in | ||
if let firstInstance = instancesForFactorForPath.first { | ||
Section { | ||
ForEach(instancesForFactorForPath, id: \.self) { (instance: FactorInstanceForDebugPurposes) in | ||
VStack(alignment: .leading) { | ||
Text("Index `\(instance.derivationEntityIndex)`") | ||
|
||
Text("PublicKey `\(String(reflecting: instance.publicKeyHex.prefix(8)))`") | ||
} | ||
.frame(maxWidth: .infinity) | ||
.padding(.horizontal, .medium3) | ||
.padding(.vertical, .small2) | ||
.border(Color.gray, width: 1) | ||
} | ||
} header: { | ||
VStack { | ||
Text("Agnostic `\(firstInstance.indexAgnosticDerivationPath)`").font(.title) | ||
Text("#\(instancesForFactorForPath.count) instances") | ||
} | ||
.padding() | ||
} | ||
} | ||
} | ||
} header: { | ||
Text("Source `\(key.idPrefix())`") | ||
.font(.largeTitle) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension FactorSourceIDFromHash { | ||
fileprivate func idPrefix() -> String { | ||
String(toString().prefix(10)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Sargon | ||
|
||
public typealias Instances = [FactorSourceIDFromHash: [[FactorInstanceForDebugPurposes]]] | ||
|
||
// MARK: - DebugFactorInstancesCacheContents | ||
@Reducer | ||
struct DebugFactorInstancesCacheContents: Sendable, FeatureReducer { | ||
@ObservableState | ||
struct State: Sendable, Hashable { | ||
var factorInstances: Loadable<Instances> = .idle | ||
init() {} | ||
} | ||
|
||
typealias Action = FeatureAction<Self> | ||
|
||
enum ViewAction: Sendable, Equatable { | ||
case task | ||
case deleteButtonTapped | ||
} | ||
|
||
enum InternalAction: Sendable, Equatable { | ||
case loadedInstances(Instances) | ||
case failedToDelete(String) | ||
} | ||
|
||
var body: some ReducerOf<Self> { | ||
Reduce(core) | ||
} | ||
|
||
func reduce(into state: inout State, internalAction: InternalAction) -> Effect<Action> { | ||
switch internalAction { | ||
case let .failedToDelete(error): | ||
struct Err: LocalizedError { | ||
let localizedDescription: String | ||
} | ||
state.factorInstances = .failure(Err(localizedDescription: error)) | ||
return .none | ||
case let .loadedInstances(instances): | ||
state.factorInstances = .success(instances) | ||
return .none | ||
} | ||
} | ||
|
||
func reduce(into state: inout State, viewAction: ViewAction) -> Effect<Action> { | ||
switch viewAction { | ||
case .deleteButtonTapped: | ||
return .run { send in | ||
try await FileSystem.shared.deleteFactorInstancesCache() | ||
await send(.internal(.loadedInstances([:]))) | ||
} catch: { error, send in | ||
await send(.internal(.failedToDelete(error.localizedDescription))) | ||
} | ||
case .task: | ||
state.factorInstances = .loading | ||
return .run { send in | ||
let instances = await SargonOS.shared.debugFactorInstancesInCache() | ||
await send(.internal(.loadedInstances(instances))) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,11 @@ extension Account { | |
} | ||
|
||
mutating func hide() { | ||
flags.append(.deletedByUser) | ||
flags.append(.hiddenByUser) | ||
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. will go away once rebased on main with changes from #1389 |
||
} | ||
|
||
mutating func unhide() { | ||
entityFlags.remove(.deletedByUser) | ||
entityFlags.remove(.hiddenByUser) | ||
} | ||
} | ||
|
||
|
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.
should be reverted ofc... and updated to use Sargon once the needed branch is merged.