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-2347 ] Post mainnet live, default to mainnet, stop checking if mainnet is live #796

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ extension AuthorizedDappsClient {
if updatedAuthedDapp != authorizedDapp {
// Write back `updatedAuthedDapp` to Profile only if changes were needed
try await updateAuthorizedDapp(updatedAuthedDapp)
} else {
loggerGlobal.feature("nothing to do... skipped updating authorizedDapp")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public struct GatewayAPIClient: Sendable, DependencyKey {
public static var rdxClientVersion: String?

// MARK: Request
public var isMainnetLive: IsMainnetLive
public var getNetworkName: GetNetworkName
public var getEpoch: GetEpoch

Expand All @@ -34,8 +33,6 @@ public struct GatewayAPIClient: Sendable, DependencyKey {
}

extension GatewayAPIClient {
public typealias IsMainnetLive = @Sendable () async -> Bool

public typealias GetNetworkName = @Sendable (URL) async throws -> Radix.Network.Name
public typealias GetEpoch = @Sendable () async throws -> Epoch

Expand All @@ -59,14 +56,6 @@ extension GatewayAPIClient {
public typealias TransactionPreview = @Sendable (GatewayAPI.TransactionPreviewRequest) async throws -> GatewayAPI.TransactionPreviewResponse
}

// MARK: - IsMainnetLiveResponse
public struct IsMainnetLiveResponse: Decodable, Sendable, Hashable {
public let isMainnetLive: Bool
public init(isMainnetLive: Bool) {
self.isMainnetLive = isMainnetLive
}
}

extension GatewayAPIClient {
@Sendable
public func getSingleEntityDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,6 @@ extension GatewayAPIClient {
}

return GatewayAPIClient(
isMainnetLive: {
do {
return try await makeRequest(
responseType: IsMainnetLiveResponse.self,
baseURL: URL(string: "https://mainnet-status.extratools.works")!,
timeoutInterval: 1
) {
$0
}.isMainnetLive
} catch {
loggerGlobal.notice("Failed to get mainnet is online status, error: \(error)")
return false
}
},
getNetworkName: { baseURL in
let response = try await makeRequest(
responseType: GatewayAPI.GatewayStatusResponse.self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extension GatewayAPIClient: TestDependencyKey {
public static let previewValue = Self.mock()

public static let testValue = Self(
isMainnetLive: unimplemented("\(Self.self).isMainnetLive"),
getNetworkName: unimplemented("\(Self.self).getNetworkName"),
getEpoch: unimplemented("\(Self.self).getEpoch"),
getEntityDetails: unimplemented("\(Self.self).getEntityDetails"),
Expand All @@ -31,7 +30,6 @@ extension GatewayAPIClient: TestDependencyKey {
txStatus: GatewayAPI.TransactionStatus? = nil
) -> Self {
.init(
isMainnetLive: { true },
getNetworkName: { _ in .init("Nebunet") },
getEpoch: { .init(rawValue: 123) },
getEntityDetails: unimplemented("\(self).getEntityDetails"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import ClientPrelude

// MARK: - NetworkSwitchingClient
public struct NetworkSwitchingClient: Sendable, DependencyKey {
public var hasMainnetEverBeenLive: HasMainnetEverBeenLive
public var validateGatewayURL: ValidateGatewayURL
public var hasAccountOnNetwork: HasAccountOnNetwork
public var switchTo: SwitchTo
}

extension NetworkSwitchingClient {
public typealias HasMainnetEverBeenLive = @Sendable () async -> Bool
public typealias ValidateGatewayURL = @Sendable (URL) async throws -> Radix.Gateway?
public typealias HasAccountOnNetwork = @Sendable (Radix.Gateway) async throws -> Bool
public typealias SwitchTo = @Sendable (Radix.Gateway) async throws -> Radix.Gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@ extension NetworkSwitchingClient {
}

return Self(
hasMainnetEverBeenLive: {
if userDefaultsClient.hasMainnetEverBeenLive {
loggerGlobal.debug("Mainnet has been live before..")
return true
}
loggerGlobal.debug("Mainnet has never been live before, checking if it is live now")
let isLive = await gatewayAPIClient.isMainnetLive()
if isLive {
loggerGlobal.notice("Mainnet is live, saving that is has been seen to be live...")
await userDefaultsClient.setMainnetIsLive()
} else {
loggerGlobal.notice("Mainnet is not live")
}
return isLive
},
validateGatewayURL: validateGatewayURL,
hasAccountOnNetwork: hasAccountOnNetwork,
switchTo: switchTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ClientPrelude
#if DEBUG
extension NetworkSwitchingClient: TestDependencyKey {
public static let testValue: Self = .init(
hasMainnetEverBeenLive: unimplemented("\(Self.self).hasMainnetEverBeenLive"),
validateGatewayURL: unimplemented("\(Self.self).validateGatewayURL"),
hasAccountOnNetwork: unimplemented("\(Self.self).hasAccountOnNetwork"),
switchTo: unimplemented("\(Self.self).switchTo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ extension OnboardingClient {
public typealias LoadProfile = @Sendable () async -> LoadProfileOutcome

/// Returns `true` iff Profile contains any mainnet accounts
public typealias CommitEphemeral = @Sendable () async throws -> Bool
public typealias CommitEphemeral = @Sendable () async throws -> Prelude.Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ extension OnboardingClient: TestDependencyKey {

public static let noop = Self(
loadProfile: { .newUser },
commitEphemeral: { false }
commitEphemeral: { Prelude.Unit.instance }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extension OnboardingClient: DependencyKey {
},
commitEphemeral: {
try await getProfileStore().commitEphemeral()
return Prelude.Unit.instance
}
)
}
Expand Down
8 changes: 3 additions & 5 deletions Sources/Clients/ProfileStore/ProfileStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extension ProfileStore {
public func getLoadProfileOutcome() async -> LoadProfileOutcome {
switch self.profileStateSubject.value {
case let .persisted(profile):
return .existingProfile(hasMainnetAccounts: profile.hasMainnetAccounts)
return .existingProfile
case let .ephemeral(ephemeral):
if let error = ephemeral.loadFailure {
return .usersExistingProfileCouldNotBeLoaded(failure: error)
Expand Down Expand Up @@ -184,11 +184,9 @@ extension ProfileStore {
}
}

/// Returns `true` iff Profile contains any mainnet accounts
public func commitEphemeral() async throws -> Bool {
public func commitEphemeral() async throws {
let ephemeral = try assertProfileStateIsEphemeral()
try await changeProfileSnapshot(to: ephemeral.profile.snapshot())
return ephemeral.profile.hasMainnetAccounts
}

/// If persisted: updates the in-memory across-the-app-used Profile and also
Expand Down Expand Up @@ -552,7 +550,7 @@ extension ProfileStore {
contentHint: .init() // Empty initially
)

loggerGlobal.debug("Created new ephemeral profile with ID: \(header.id), and device factorSourceID: \(factorSource.id)")
loggerGlobal.trace("Created new ephemeral profile with ID: \(header.id), and device factorSourceID: \(factorSource.id)")

return Profile(header: header, deviceFactorSource: factorSource)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public struct AccountDetails: Sendable, FeatureReducer {
}

public enum InternalAction: Sendable, Equatable {
case transfer(hasMainnetEverBeenLive: Bool)

case markBackupNeeded
case accountUpdated(Profile.Network.Account)
case portfolioLoaded(AccountPortfolio)
Expand Down Expand Up @@ -195,10 +193,10 @@ public struct AccountDetails: Sendable, FeatureReducer {
return .none

case .transferButtonTapped:
return .run { send in
let hasMainnetEverBeenLive = await networkSwitchingClient.hasMainnetEverBeenLive()
await send(.internal(.transfer(hasMainnetEverBeenLive: hasMainnetEverBeenLive)))
}
state.destination = .transfer(.init(
from: state.account
))
return .none

case .exportMnemonicButtonTapped:
return loadMnemonic(state: state)
Expand Down Expand Up @@ -244,7 +242,6 @@ public struct AccountDetails: Sendable, FeatureReducer {
return checkAccountSecurityPromptStatus(state: &state)

case .destination(.dismiss):
loggerGlobal.feature("Dismissed child")
return checkAccountSecurityPromptStatus(state: &state)

default:
Expand All @@ -254,13 +251,6 @@ public struct AccountDetails: Sendable, FeatureReducer {

public func reduce(into state: inout State, internalAction: InternalAction) -> Effect<Action> {
switch internalAction {
case let .transfer(hasMainnetEverBeenLive):
state.destination = .transfer(.init(
from: state.account,
hasMainnetEverBeenLive: hasMainnetEverBeenLive
))
return .none

case .markBackupNeeded:
state.exportMnemonicPrompt = .init(needed: true)
return .none
Expand All @@ -272,7 +262,7 @@ public struct AccountDetails: Sendable, FeatureReducer {
return loadImport()

case let .loadMnemonicResult(.success(mnemonicWithPassphraseAndFactorSourceInfo)):
loggerGlobal.feature("Successfully loaded mnemonic to export")
loggerGlobal.trace("Successfully loaded mnemonic to export")
state.destination = .exportMnemonic(.init(
warning: L10n.RevealSeedPhrase.warning,
mnemonicWithPassphrase: mnemonicWithPassphraseAndFactorSourceInfo.mnemonicWithPassphrase,
Expand Down Expand Up @@ -306,7 +296,6 @@ public struct AccountDetails: Sendable, FeatureReducer {
}

private func loadMnemonic(state: State) -> Effect<Action> {
loggerGlobal.feature("implement export")
let factorInstance = state.deviceControlledFactorInstance
let factorSourceID = factorInstance.factorSourceID
return .run { send in
Expand Down
Loading
Loading