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

Hotfix for delete account with hidden assets only #1414

Merged
merged 3 commits into from
Dec 12, 2024
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
2 changes: 1 addition & 1 deletion Aux/Config/Common.xcconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// MARK: - Custom flags

/// Application version shared across all targets and flavours
APP_VERSION = 1.11.0
APP_VERSION = 1.11.1

/// App Icon base name
APP_ICON = AppIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ extension AccountPortfoliosClient {

return modified
}

/// Returns if the original account (which doesn't remove the hidden resources) contains any asset
var containsAnyAsset: Bool {
originalAccount.containsAnyAsset
}
}

/// Internal state that holds all loaded portfolios.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct DeleteAccountConfirmation: Sendable, FeatureReducer {

@CasePathable
enum InternalAction: Sendable, Equatable {
case fetchAccountPortfolioResult(TaskResult<OnLedgerEntity.OnLedgerAccount>)
case fetchAccountPortfolioResult(TaskResult<AccountPortfoliosClient.AccountPortfolio>)
case fetchReceivingAccounts
case fetchReceivingAccountsResult(TaskResult<[State.ReceivingAccountCandidate]>)
}
Expand Down Expand Up @@ -44,7 +44,7 @@ struct DeleteAccountConfirmation: Sendable, FeatureReducer {
state.footerButtonState = .loading(.local)
return .run { [address = state.account.address] send in
let result = await TaskResult {
try await accountPortfoliosClient.fetchAccountPortfolio(address, true).account
try await accountPortfoliosClient.fetchAccountPortfolio(address, true)
}
await send(.internal(.fetchAccountPortfolioResult(result)))
}
Expand All @@ -53,9 +53,9 @@ struct DeleteAccountConfirmation: Sendable, FeatureReducer {

func reduce(into state: inout State, internalAction: InternalAction) -> Effect<Action> {
switch internalAction {
case let .fetchAccountPortfolioResult(.success(account)):
case let .fetchAccountPortfolioResult(.success(portfolio)):
state.footerButtonState = .enabled
return account.containsAnyAsset ? .send(.internal(.fetchReceivingAccounts)) : .send(.delegate(.deleteAccount))
return portfolio.containsAnyAsset ? .send(.internal(.fetchReceivingAccounts)) : .send(.delegate(.deleteAccount))

case .fetchReceivingAccounts:
return .run { send in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import SwiftUI
struct CreateAccountConfig: Sendable, Hashable {
let specificNetworkID: NetworkID?
let isFirstAccount: Bool
let isNewProfile: Bool
let navigationButtonCTA: CreateAccountNavigationButtonCTA

fileprivate init(
isFirstAccount: Bool,
isNewProfile: Bool = false,
navigationButtonCTA: CreateAccountNavigationButtonCTA,
specificNetworkID: NetworkID? = nil
) {
self.specificNetworkID = specificNetworkID
self.isFirstAccount = isFirstAccount
self.isNewProfile = isNewProfile
self.navigationButtonCTA = navigationButtonCTA
}
}
Expand All @@ -31,6 +34,7 @@ extension CreateAccountConfig {
case .firstAccountForNewProfile:
self.init(
isFirstAccount: true,
isNewProfile: true,
navigationButtonCTA: .goHome
)
case let .firstAccountOnNewNetwork(specificNetworkID):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct CreateAccountCoordinator: Sendable, FeatureReducer {
let config: CreateAccountConfig
var name: NonEmptyString?

fileprivate var createdProfile = false

init(
root: Path.State? = nil,
config: CreateAccountConfig
Expand Down Expand Up @@ -92,6 +94,7 @@ struct CreateAccountCoordinator: Sendable, FeatureReducer {
enum InternalAction: Sendable, Equatable {
case createAccountResult(TaskResult<Account>)
case handleAccountCreated(TaskResult<Account>)
case handleProfileCreated(factorSourceOption: DerivePublicKeys.State.FactorSourceOption)
}

enum DelegateAction: Sendable, Equatable {
Expand All @@ -103,6 +106,7 @@ struct CreateAccountCoordinator: Sendable, FeatureReducer {
@Dependency(\.factorSourcesClient) var factorSourcesClient
@Dependency(\.accountsClient) var accountsClient
@Dependency(\.onLedgerEntitiesClient) var onLedgerEntitiesClient
@Dependency(\.onboardingClient) var onboardingClient
@Dependency(\.errorQueue) var errorQueue
@Dependency(\.isPresented) var isPresented
@Dependency(\.dismiss) var dismiss
Expand Down Expand Up @@ -146,11 +150,11 @@ extension CreateAccountCoordinator {
state.path.append(.selectLedger(.init(context: .createHardwareAccount)))
return .none
} else {
return derivePublicKey(state: &state, factorSourceOption: .device)
return createProfileIfNecessaryThenDerivePublicKey(state: &state, factorSourceOption: .device)
}

case let .path(.element(_, action: .selectLedger(.delegate(.choseLedger(ledger))))):
return derivePublicKey(
return createProfileIfNecessaryThenDerivePublicKey(
state: &state,
factorSourceOption: .specific(
ledger.asGeneral
Expand Down Expand Up @@ -194,6 +198,10 @@ extension CreateAccountCoordinator {
config: state.config
)))
return .send(.delegate(.accountCreated))

case let .handleProfileCreated(factorSourceOption):
state.createdProfile = true
return derivePublicKey(state: &state, factorSourceOption: factorSourceOption)
}
}

Expand Down Expand Up @@ -253,6 +261,21 @@ extension CreateAccountCoordinator {
}
}

private func createProfileIfNecessaryThenDerivePublicKey(state: inout State, factorSourceOption: DerivePublicKeys.State.FactorSourceOption) -> Effect<Action> {
if state.config.isNewProfile, !state.createdProfile {
// We need to create the Profile before deriving the public key
.run { send in
try await onboardingClient.createNewProfile()
await send(.internal(.handleProfileCreated(factorSourceOption: factorSourceOption)))
} catch: { error, _ in
errorQueue.schedule(error)
}
} else {
// We can derive the public key since the Profile has been created already
derivePublicKey(state: &state, factorSourceOption: factorSourceOption)
}
}

private func derivePublicKey(state: inout State, factorSourceOption: DerivePublicKeys.State.FactorSourceOption) -> Effect<Action> {
state.destination = .derivePublicKey(
.init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ struct OnboardingCoordinator: Sendable, FeatureReducer {
}
}

public enum InternalAction: Sendable, Equatable {
case newProfileCreated
}

@CasePathable
enum ChildAction: Sendable, Equatable {
case startup(OnboardingStartup.Action)
Expand Down Expand Up @@ -45,7 +41,6 @@ struct OnboardingCoordinator: Sendable, FeatureReducer {
}
}

@Dependency(\.onboardingClient) var onboardingClient
@Dependency(\.radixConnectClient) var radixConnectClient
@Dependency(\.appEventsClient) var appEventsClient
@Dependency(\.errorQueue) var errorQueue
Expand All @@ -65,27 +60,15 @@ struct OnboardingCoordinator: Sendable, FeatureReducer {

private let destinationPath: WritableKeyPath<State, PresentationState<Destination.State>> = \.$destination

func reduce(into state: inout State, internalAction: InternalAction) -> Effect<Action> {
switch internalAction {
case .newProfileCreated:
func reduce(into state: inout State, childAction: ChildAction) -> Effect<Action> {
switch childAction {
case .startup(.delegate(.setupNewUser)):
state.destination = .createAccount(
.init(
config: .init(purpose: .firstAccountForNewProfile)
)
)
return .none
}
}

func reduce(into state: inout State, childAction: ChildAction) -> Effect<Action> {
switch childAction {
case .startup(.delegate(.setupNewUser)):
return .run { send in
try await onboardingClient.createNewProfile()
await send(.internal(.newProfileCreated))
} catch: { error, _ in
errorQueue.schedule(error)
}

case .startup(.delegate(.profileCreatedFromImportedBDFS)):
appEventsClient.handleEvent(.walletRestored)
Expand Down
Loading