Skip to content

Commit

Permalink
Account hiding crash fix (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
kugel3 committed Nov 6, 2023
1 parent cd2c653 commit 5ca1d5c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ public struct AccountDetails: Sendable, FeatureReducer {
}

case .destination(.presented(.preferences(.delegate(.accountHidden)))):
state.destination = nil
return .send(.delegate(.dismiss))

case .destination(.dismiss):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ extension AccountDetails.State {
displayName: account.displayName.rawValue,
needToImportMnemonicForThisAccount: importMnemonicPrompt.needed,
needToBackupMnemonicForThisAccount: exportMnemonicPrompt.needed,
isLedgerAccount: account.isLedgerAccount
isLedgerAccount: account.isLedgerAccount,
showToolbar: destination == nil
)
}
}
Expand All @@ -22,6 +23,7 @@ extension AccountDetails {
let needToImportMnemonicForThisAccount: Bool
let needToBackupMnemonicForThisAccount: Bool
let isLedgerAccount: Bool
let showToolbar: Bool
}

@MainActor
Expand All @@ -43,9 +45,9 @@ extension AccountDetails {
Group {
// Mutally exclusive to prompt user to recover and backup mnemonic.
if viewStore.needToImportMnemonicForThisAccount {
recoverMnemonicsPromptView(viewStore)
importMnemonicPromptView { viewStore.send(.recoverMnemonicsButtonTapped) }
} else if viewStore.needToBackupMnemonicForThisAccount {
exportMnemonicPromptView(viewStore)
backupMnemonicPromptView { viewStore.send(.exportMnemonicButtonTapped) }
}
}
.padding(.medium1)
Expand All @@ -70,71 +72,60 @@ extension AccountDetails {
.task {
viewStore.send(.task)
}
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(viewStore.displayName)
.navigationBarTitleColor(.white)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
BackButton {
viewStore.send(.backButtonTapped)
if viewStore.showToolbar {
ToolbarItem(placement: .navigationBarLeading) {
BackButton {
viewStore.send(.backButtonTapped)
}
.foregroundColor(.app.white)
}
.foregroundColor(.app.white)
}
ToolbarItem(placement: .principal) {
Text(viewStore.displayName)
.textStyle(.secondaryHeader)

ToolbarItem(placement: .navigationBarTrailing) {
Button(asset: AssetResource.ellipsis) {
viewStore.send(.preferencesButtonTapped)
}
.frame(.small)
.foregroundColor(.app.white)
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(asset: AssetResource.ellipsis) {
viewStore.send(.preferencesButtonTapped)
}
.frame(.small)
.foregroundColor(.app.white)
}
}
.navigationDestination(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.preferences,
action: AccountDetails.Destinations.Action.preferences,
destination: { AccountPreferences.View(store: $0) }
)
.fullScreenCover(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.transfer,
action: AccountDetails.Destinations.Action.transfer,
content: { AssetTransfer.SheetView(store: $0) }
)
.fullScreenCover( /* Full Screen cover to not be able to use iOS dismiss gestures */
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.exportMnemonic,
action: AccountDetails.Destinations.Action.exportMnemonic,
content: { childStore in
NavigationView {
ImportMnemonic.View(store: childStore)
.navigationTitle(L10n.ImportMnemonic.navigationTitleBackup)
}
}
)
.sheet(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.importMnemonics,
action: AccountDetails.Destinations.Action.importMnemonics,
content: { ImportMnemonicsFlowCoordinator.View(store: $0) }
)
}
.navigationDestination(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.preferences,
action: AccountDetails.Destinations.Action.preferences,
destination: { AccountPreferences.View(store: $0) }
)
.fullScreenCover(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.transfer,
action: AccountDetails.Destinations.Action.transfer,
content: { AssetTransfer.SheetView(store: $0) }
)
.fullScreenCover( /* Full Screen cover to prevent iOS dismiss gestures */
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.exportMnemonic,
action: AccountDetails.Destinations.Action.exportMnemonic,
content: { childStore in
NavigationView {
ImportMnemonic.View(store: childStore)
.navigationTitle(L10n.ImportMnemonic.navigationTitleBackup)
}
}
)
.sheet(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /AccountDetails.Destinations.State.importMnemonics,
action: AccountDetails.Destinations.Action.importMnemonics,
content: { ImportMnemonicsFlowCoordinator.View(store: $0) }
)
}
}
}

extension View {
func recoverMnemonicsPromptView(_ viewStore: ViewStoreOf<AccountDetails>) -> some View {
importMnemonicPromptView { viewStore.send(.recoverMnemonicsButtonTapped) }
}

func exportMnemonicPromptView(_ viewStore: ViewStoreOf<AccountDetails>) -> some View {
backupMnemonicPromptView { viewStore.send(.exportMnemonicButtonTapped) }
}
}

#if DEBUG
import ComposableArchitecture
import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ extension AccountPreferences {
case .devPreferences:
return .none
case let .confirmHideAccount(action):
state.destinations = nil
switch action {
case .confirmTapped:
return .run { [account = state.account] send in
Expand Down
83 changes: 40 additions & 43 deletions RadixWallet/Features/HomeFeature/Coordinator/Home+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,55 @@ extension Home {

public var body: some SwiftUI.View {
WithViewStore(store, observe: \.viewState, send: { .view($0) }) { viewStore in
NavigationStack {
ScrollView {
VStack(spacing: .medium1) {
Header.View(
store: store.scope(
state: \.header,
action: { .child(.header($0)) }
)
ScrollView {
VStack(spacing: .medium1) {
Header.View(
store: store.scope(
state: \.header,
action: { .child(.header($0)) }
)
)

AccountList.View(
store: store.scope(
state: \.accountList,
action: { .child(.accountList($0)) }
)
AccountList.View(
store: store.scope(
state: \.accountList,
action: { .child(.accountList($0)) }
)
.padding(.horizontal, .medium1)
)
.padding(.horizontal, .medium1)

Button(L10n.HomePage.createNewAccount) {
viewStore.send(.createAccountButtonTapped)
}
.buttonStyle(.secondaryRectangular())
Button(L10n.HomePage.createNewAccount) {
viewStore.send(.createAccountButtonTapped)
}
.padding(.bottom, .medium1)
.buttonStyle(.secondaryRectangular())
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
SettingsButton(shouldShowNotification: viewStore.hasNotification) {
viewStore.send(.settingsButtonTapped)
}
.padding(.bottom, .medium1)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
SettingsButton(shouldShowNotification: viewStore.hasNotification) {
viewStore.send(.settingsButtonTapped)
}
}
.refreshable {
await viewStore.send(.pullToRefreshStarted).finish()
}
.task { @MainActor in
await viewStore.send(.task).finish()
}
.navigationDestination(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /Home.Destinations.State.accountDetails,
action: Home.Destinations.Action.accountDetails,
destination: { AccountDetails.View(store: $0) }
)
.sheet(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /Home.Destinations.State.createAccount,
action: Home.Destinations.Action.createAccount,
content: { CreateAccountCoordinator.View(store: $0) }
)
}
.navigationTransition(.default, interactivity: .pan)
.refreshable {
await viewStore.send(.pullToRefreshStarted).finish()
}
.task { @MainActor in
await viewStore.send(.task).finish()
}
.navigationDestination(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /Home.Destinations.State.accountDetails,
action: Home.Destinations.Action.accountDetails,
destination: { AccountDetails.View(store: $0) }
)
.sheet(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /Home.Destinations.State.createAccount,
action: Home.Destinations.Action.createAccount,
content: { CreateAccountCoordinator.View(store: $0) }
)
}
}

Expand Down
3 changes: 0 additions & 3 deletions RadixWallet/Features/MainFeature/Main+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ extension Main {
action: { .child(.home($0)) }
)
)
.navigationBarBackButtonFont(.app.backButton)
.navigationBarInlineTitleFont(.app.secondaryHeader)
.navigationBarTitleColor(.app.gray1)
.navigationDestination(
store: store.scope(state: \.$destination, action: { .child(.destination($0)) }),
state: /Main.Destinations.State.settings,
Expand Down

0 comments on commit 5ca1d5c

Please sign in to comment.