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-2378] Set current gateway to mainnet after import #812

Merged
merged 1 commit into from
Sep 29, 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
1 change: 1 addition & 0 deletions Sources/Clients/ProfileStore/ProfileStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ extension ProfileStore {
// Changes the currently used ProfileSnapshot, usually to one from a backup or to one just created.
func changeProfileSnapshot(to profileSnapshot: ProfileSnapshot) async throws {
var profileSnapshot = profileSnapshot
profileSnapshot.changeCurrentToMainnetIfNeeded()
try await claimProfileSnapshot(&profileSnapshot)
updateHeader(&profileSnapshot)

Expand Down
6 changes: 6 additions & 0 deletions Sources/Profile/AppPreferences/AppPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public struct AppPreferences:
public static let `default`: Self = .init()
}

extension AppPreferences {
public mutating func changeCurrentToMainnetIfNeeded() {
gateways.changeCurrentToMainnetIfNeeded()
}
}

extension AppPreferences {
public var customDumpMirror: Mirror {
.init(
Expand Down
5 changes: 5 additions & 0 deletions Sources/Profile/AppPreferences/Gateways/Gateways.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ extension Gateways {
current = newCurrent
}

public mutating func changeCurrentToMainnetIfNeeded() {
if current == .mainnet { return }
try? changeCurrent(to: .mainnet)
}

/// Adds `newOther` to `other` (if indeed new).
fileprivate mutating func add(_ newOther: Radix.Gateway) {
other.append(newOther)
Expand Down
8 changes: 7 additions & 1 deletion Sources/Profile/Snapshot/ProfileSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct ProfileSnapshot:

/// Settings for this profile in the app, contains default security configs
/// as well as display settings.
public let appPreferences: AppPreferences
public private(set) var appPreferences: AppPreferences
Copy link
Contributor Author

@CyonAlexRDX CyonAlexRDX Sep 29, 2023

Choose a reason for hiding this comment

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

Preferably we want the Snapshot to be immutable, but in this case it would just be a hassle to "roundtrip" through Profile in ProfileStore's function changeProfileSnapshot:to, thus we allow this, but still make the setter private, having to go through changeCurrentToMainnetIfNeeded.


/// Effectivly **per network**: a list of accounts, personas and connected dApps.
public let networks: Profile.Networks
Expand All @@ -40,6 +40,12 @@ public struct ProfileSnapshot:
}
}

extension ProfileSnapshot {
public mutating func changeCurrentToMainnetIfNeeded() {
appPreferences.changeCurrentToMainnetIfNeeded()
}
}

// MARK: Take Snapshot
extension Profile {
public func snapshot() -> ProfileSnapshot {
Expand Down
Loading