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

Debug Only: Inspect FactorInstancesCache #1391

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
90 changes: 29 additions & 61 deletions RadixWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "7d3590b225945abb1bc0ab6c684b005c28c64bdc204afcc2d34c3e379ef8a3c8",
"originHash" : "60b889ccc513476448aa6483246b773f242561a612324e9d081205fc3041851f",
"pins" : [
{
"identity" : "anycodable",
Expand Down Expand Up @@ -109,15 +109,6 @@
"version" : "11.6.4"
}
},
{
Copy link
Contributor Author

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.

"identity" : "sargon",
"kind" : "remoteSourceControl",
"location" : "https://github.com/radixdlt/sargon",
"state" : {
"revision" : "6af408a3252888560a9c401bf3be61512dba1035",
"version" : "1.1.50"
}
},
{
"identity" : "screenshotpreventing-ios",
"kind" : "remoteSourceControl",
Expand Down
8 changes: 7 additions & 1 deletion RadixWallet/Clients/ProfileStore/ProfileStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

@CyonAlexRDX CyonAlexRDX Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@micbakos-rdx breaking change for Android, you need to pass shouldPrederiveInstances: false to newWallet once Sargon "FIP" PR is merged.

}

func finishOnboarding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ extension InteractionReview.Sections {
accountDepositSetting: accountDepositSetting,
accountDepositExceptions: accountDepositExceptions
)
case .some(.deleteAccounts(accountAddresses: let accountAddresses)):
fatalError()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will go away when #1389 is merged and I rebase to main.

}
}

Expand Down
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
Expand Up @@ -23,6 +23,7 @@ struct DebugSettingsCoordinator: Sendable, FeatureReducer {
case debugUserDefaultsContentsButtonTapped
case debugTestKeychainButtonTapped
case debugKeychainContentsButtonTapped
case debugFactorInstancesCacheContentsButtonTapped
}

enum InternalAction: Sendable, Equatable {
Expand All @@ -36,7 +37,8 @@ struct DebugSettingsCoordinator: Sendable, FeatureReducer {
case debugManageFactorSources(DebugManageFactorSources.State)
#if DEBUG
case debugKeychainTest(DebugKeychainTest.State)
case debugKeychainContents(DebugKeychainContents.State)
case debugKeychainContents(DebugKeychainContents.State)
case debugFactorInstancesCacheContents(DebugFactorInstancesCacheContents.State)
#endif // DEBUG
}

Expand All @@ -45,7 +47,8 @@ struct DebugSettingsCoordinator: Sendable, FeatureReducer {
case debugInspectProfile(DebugInspectProfile.Action)
#if DEBUG
case debugKeychainTest(DebugKeychainTest.Action)
case debugKeychainContents(DebugKeychainContents.Action)
case debugKeychainContents(DebugKeychainContents.Action)
case debugFactorInstancesCacheContents(DebugFactorInstancesCacheContents.Action)
#endif // DEBUG
case debugManageFactorSources(DebugManageFactorSources.Action)
}
Expand All @@ -64,6 +67,9 @@ struct DebugSettingsCoordinator: Sendable, FeatureReducer {
Scope(state: /State.debugKeychainContents, action: /Action.debugKeychainContents) {
DebugKeychainContents()
}
Scope(state: /State.debugFactorInstancesCacheContents, action: /Action.debugFactorInstancesCacheContents) {
DebugFactorInstancesCacheContents()
}
#endif // DEBUG
Scope(state: /State.debugManageFactorSources, action: /Action.debugManageFactorSources) {
DebugManageFactorSources()
Expand Down Expand Up @@ -110,6 +116,12 @@ struct DebugSettingsCoordinator: Sendable, FeatureReducer {
#endif // DEBUG
return .none

case .debugFactorInstancesCacheContentsButtonTapped:
#if DEBUG
state.destination = .debugFactorInstancesCacheContents(.init())
#endif // DEBUG
return .none

case .debugUserDefaultsContentsButtonTapped:
state.destination = .debugUserDefaultsContents(.init())
return .none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ extension DebugSettingsCoordinator.View {
icon: .systemImage("key"),
action: .debugKeychainContentsButtonTapped
),
// ONLY DEBUG EVER
.model(
title: "FactorInstances Cache",
icon: .systemImage("key"),
action: .debugFactorInstancesCacheContentsButtonTapped
),
]
}
}
Expand All @@ -88,7 +94,8 @@ private extension View {
.debugUserDefaultsContents(with: destinationStore)
#if DEBUG
.debugKeychainTest(with: destinationStore)
.debugKeychainContents(with: destinationStore)
.debugKeychainContents(with: destinationStore)
.debugFactorInstancesCacheContents(with: destinationStore)
#endif
.debugInspectProfile(with: destinationStore)
}
Expand Down Expand Up @@ -126,6 +133,18 @@ private extension View {
destination: { DebugKeychainContents.View(store: $0) }
)
}


private func debugFactorInstancesCacheContents(
with destinationStore: PresentationStoreOf<DebugSettingsCoordinator.Destination>
) -> some View {
navigationDestination(
store: destinationStore,
state: /DebugSettingsCoordinator.Destination.State.debugFactorInstancesCacheContents,
action: DebugSettingsCoordinator.Destination.Action.debugFactorInstancesCacheContents,
destination: { DebugFactorInstancesCacheContents.View(store: $0) }
)
}
#endif // DEBUG

private func factorSources(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ extension Account {
}

mutating func hide() {
flags.append(.deletedByUser)
flags.append(.hiddenByUser)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Sargon

extension Persona {
mutating func hide() {
entityFlags.append(.deletedByUser)
entityFlags.append(.hiddenByUser)
}

mutating func unhide() {
entityFlags.remove(.deletedByUser)
entityFlags.remove(.hiddenByUser)
}
}

Expand Down