Skip to content

Commit 5133283

Browse files
committed
chore: unify menu item model in all setting screens
1 parent 8dc7f2e commit 5133283

45 files changed

Lines changed: 237 additions & 278 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MainMenuViewController: UIViewController {
2525

2626
weak var delegate: DWWipeDelegate?
2727

28-
private var hostingController: UIHostingController<MianMenuScreen>!
28+
private var hostingController: UIHostingController<MainMenuScreen>!
2929

3030
#if DASHPAY
3131
private let receiveModel: DWReceiveModelProtocol?
@@ -85,7 +85,7 @@ class MainMenuViewController: UIViewController {
8585

8686
private func setupSwiftUIView() {
8787
#if DASHPAY
88-
let swiftUIView = MianMenuScreen(
88+
let swiftUIView = MainMenuScreen(
8989
vc: navigationController!,
9090
delegate: delegate as? MainMenuViewControllerDelegate,
9191
wipeDelegate: delegate,
@@ -130,7 +130,7 @@ extension MainMenuViewController: MFMailComposeViewControllerDelegate {
130130
}
131131
}
132132

133-
struct MianMenuScreen: View {
133+
struct MainMenuScreen: View {
134134
private let vc: UINavigationController
135135
private let delegateInternal: DelegateInternal
136136
private let onContactSupport: () -> ()
@@ -224,12 +224,49 @@ struct MianMenuScreen: View {
224224
}
225225
#endif
226226

227-
// Menu sections
228-
ForEach(Array(viewModel.menuSections.enumerated()), id: \.offset) { index, section in
229-
MenuSectionView(section: section) { menuItem in
230-
viewModel.handleMenuAction(menuItem)
227+
// Menu items grouped in sections
228+
VStack(spacing: 16) {
229+
// First group - main services (first 2 items)
230+
if viewModel.items.count >= 2 {
231+
VStack(spacing: 0) {
232+
ForEach(viewModel.items.prefix(2)) { item in
233+
MenuItem(
234+
title: item.title,
235+
subtitle: item.subtitle,
236+
icon: item.icon,
237+
showChevron: false,
238+
action: item.action
239+
)
240+
.frame(minHeight: 60)
241+
}
242+
}
243+
.padding(.vertical, 5)
244+
.background(Color.secondaryBackground)
245+
.cornerRadius(12)
246+
.shadow(color: Color.shadow, radius: 20, x: 0, y: 5)
247+
}
248+
249+
// Second group - settings items (remaining items)
250+
if viewModel.items.count > 2 {
251+
VStack(spacing: 0) {
252+
ForEach(viewModel.items.dropFirst(2)) { item in
253+
MenuItem(
254+
title: item.title,
255+
subtitle: item.subtitle,
256+
icon: item.icon,
257+
showChevron: false,
258+
action: item.action
259+
)
260+
.frame(minHeight: 60)
261+
}
262+
}
263+
.padding(.vertical, 5)
264+
.background(Color.secondaryBackground)
265+
.cornerRadius(12)
266+
.shadow(color: Color.shadow, radius: 20, x: 0, y: 5)
231267
}
232268
}
269+
.padding(.horizontal, 20)
233270

234271
Spacer(minLength: 60)
235272
}
@@ -471,42 +508,8 @@ struct MianMenuScreen: View {
471508
#endif
472509
}
473510

474-
struct MenuSectionView: View {
475-
let section: MenuSection
476-
let onMenuItemTap: (MenuItemType) -> Void
477-
478-
var body: some View {
479-
VStack(spacing: 0) {
480-
ForEach(section.items, id: \.self) { item in
481-
MenuItemView(item: item) {
482-
onMenuItemTap(item)
483-
}
484-
}
485-
}
486-
.padding(.vertical, 5)
487-
.background(Color.secondaryBackground)
488-
.cornerRadius(12)
489-
.shadow(color: Color.shadow, radius: 20, x: 0, y: 5)
490-
.padding(.horizontal, 20)
491-
}
492-
}
493-
494-
struct MenuItemView: View {
495-
let item: MenuItemType
496-
let action: () -> Void
497-
498-
var body: some View {
499-
MenuItem(
500-
title: item.title,
501-
subtitle: nil,
502-
icon: item.iconName,
503-
showChevron: false,
504-
action: action
505-
)
506-
}
507-
}
508511

509-
extension MianMenuScreen {
512+
extension MainMenuScreen {
510513
class DelegateInternal: NSObject, RootEditProfileViewControllerDelegate, ExploreViewControllerDelegate {
511514
private weak var delegate: MainMenuViewControllerDelegate?
512515
private weak var wipeDelegate: DWWipeDelegate?

DashWallet/Sources/UI/Menu/Main/MainMenuViewModel.swift

Lines changed: 63 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protocol MainMenuViewModelDelegate: AnyObject {
4141
@MainActor
4242
class MainMenuViewModel: ObservableObject {
4343

44-
@Published var menuSections: [MenuSection] = []
44+
@Published var items: [MenuItemModel] = []
4545
@Published var navigationDestination: MainMenuNavigationDestination?
4646
@Published var showCreditsWarning: Bool = false
4747
@Published var creditsWarningHeading: String = ""
@@ -73,57 +73,79 @@ class MainMenuViewModel: ObservableObject {
7373
// MARK: - Menu Building
7474

7575
func buildMenuSections() {
76-
var sections: [MenuSection] = []
76+
var allItems: [MenuItemModel] = []
7777

78-
// Main services section
79-
sections.append(MenuSection(items: [
80-
.buySellDash,
81-
.explore
82-
]))
78+
// Buy & Sell Dash
79+
allItems.append(MenuItemModel(
80+
title: NSLocalizedString("Buy & sell Dash", comment: ""),
81+
icon: .custom("image.buy.and.sell", maxHeight: 22),
82+
action: { [weak self] in
83+
self?.handleBuySellDash()
84+
}
85+
))
86+
87+
// Explore
88+
allItems.append(MenuItemModel(
89+
title: NSLocalizedString("Explore", comment: ""),
90+
icon: .custom("image.explore", maxHeight: 22),
91+
action: { [weak self] in
92+
self?.navigationDestination = .explore
93+
}
94+
))
8395

84-
// Settings section
85-
var settingsItems: [MenuItemType] = [
86-
.security,
87-
.settings,
88-
.tools,
89-
.support
90-
]
96+
// Security
97+
allItems.append(MenuItemModel(
98+
title: NSLocalizedString("Security", comment: ""),
99+
icon: .custom("image.security", maxHeight: 22),
100+
action: { [weak self] in
101+
self?.navigationDestination = .security
102+
}
103+
))
104+
105+
// Settings
106+
allItems.append(MenuItemModel(
107+
title: NSLocalizedString("Settings", comment: ""),
108+
icon: .custom("image.settings", maxHeight: 22),
109+
action: { [weak self] in
110+
self?.navigationDestination = .settings
111+
}
112+
))
113+
114+
// Tools
115+
allItems.append(MenuItemModel(
116+
title: NSLocalizedString("Tools", comment: ""),
117+
icon: .custom("image.tools", maxHeight: 22),
118+
action: { [weak self] in
119+
self?.navigationDestination = .tools
120+
}
121+
))
122+
123+
// Support
124+
allItems.append(MenuItemModel(
125+
title: NSLocalizedString("Support", comment: ""),
126+
icon: .custom("image.support", maxHeight: 22),
127+
action: { [weak self] in
128+
self?.navigationDestination = .support
129+
}
130+
))
91131

92132
#if DASHPAY
133+
// Voting
93134
if VotingPrefs.shared.votingEnabled {
94-
settingsItems.append(.voting)
135+
allItems.append(MenuItemModel(
136+
title: NSLocalizedString("Voting", comment: ""),
137+
icon: .custom("menu_voting", maxHeight: 22),
138+
action: { [weak self] in
139+
self?.navigationDestination = .voting
140+
}
141+
))
95142
}
96143
#endif
97144

98-
sections.append(MenuSection(items: settingsItems))
99-
100-
self.menuSections = sections
145+
self.items = allItems
101146
}
102147

103148
// MARK: - Actions
104-
105-
func handleMenuAction(_ item: MenuItemType) {
106-
switch item {
107-
case .buySellDash:
108-
handleBuySellDash()
109-
case .explore:
110-
navigationDestination = .explore
111-
case .security:
112-
navigationDestination = .security
113-
case .settings:
114-
navigationDestination = .settings
115-
case .tools:
116-
navigationDestination = .tools
117-
case .support:
118-
navigationDestination = .support
119-
#if DASHPAY
120-
case .invite:
121-
navigationDestination = .invite
122-
case .voting:
123-
navigationDestination = .voting
124-
#endif
125-
}
126-
}
127149

128150
private func handleBuySellDash() {
129151
DSAuthenticationManager.sharedInstance().authenticate(
@@ -147,69 +169,3 @@ class MainMenuViewModel: ObservableObject {
147169
showCreditsWarning = true
148170
}
149171
}
150-
151-
// MARK: - Data Models
152-
153-
struct MenuSection {
154-
let items: [MenuItemType]
155-
}
156-
157-
enum MenuItemType: CaseIterable {
158-
case buySellDash
159-
case explore
160-
case security
161-
case settings
162-
case tools
163-
case support
164-
#if DASHPAY
165-
case invite
166-
case voting
167-
#endif
168-
169-
var title: String {
170-
switch self {
171-
case .buySellDash:
172-
return NSLocalizedString("Buy & sell Dash", comment: "")
173-
case .explore:
174-
return NSLocalizedString("Explore", comment: "")
175-
case .security:
176-
return NSLocalizedString("Security", comment: "")
177-
case .settings:
178-
return NSLocalizedString("Settings", comment: "")
179-
case .tools:
180-
return NSLocalizedString("Tools", comment: "")
181-
case .support:
182-
return NSLocalizedString("Support", comment: "")
183-
#if DASHPAY
184-
case .invite:
185-
return NSLocalizedString("Invite", comment: "")
186-
case .voting:
187-
return NSLocalizedString("Voting", comment: "")
188-
#endif
189-
}
190-
}
191-
192-
var iconName: IconName {
193-
switch self {
194-
case .buySellDash:
195-
return .custom("image.buy.and.sell", maxHeight: 22)
196-
case .explore:
197-
return .custom("image.explore", maxHeight: 22)
198-
case .security:
199-
return .custom("image.security", maxHeight: 22)
200-
case .settings:
201-
return .custom("image.settings", maxHeight: 22)
202-
case .tools:
203-
return .custom("image.tools", maxHeight: 22)
204-
case .support:
205-
return .custom("image.support", maxHeight: 22)
206-
#if DASHPAY
207-
case .invite:
208-
return .custom("menu_invite", maxHeight: 22)
209-
case .voting:
210-
return .custom("menu_voting", maxHeight: 22)
211-
#endif
212-
}
213-
}
214-
}
215-

DashWallet/ar.lproj/Localizable.strings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,6 @@
592592
/* Usernames */
593593
"Create a username" = "Create a username";
594594

595-
/* No comment provided by engineer. */
596-
"Create a username and say goodbye to numerical addresses" = "Create a username and say goodbye to numerical addresses";
597-
598595
/* CrowdNode */
599596
"Create Account" = "إنشاء حساب";
600597

@@ -2371,6 +2368,9 @@
23712368
/* Voting */
23722369
"Submit" = "Submit";
23732370

2371+
/* No comment provided by engineer. */
2372+
"Successful purchase" = "Successful purchase";
2373+
23742374
/* No comment provided by engineer. */
23752375
"Support" = "Support";
23762376

DashWallet/bg.lproj/Localizable.strings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,6 @@
592592
/* Usernames */
593593
"Create a username" = "Create a username";
594594

595-
/* No comment provided by engineer. */
596-
"Create a username and say goodbye to numerical addresses" = "Create a username and say goodbye to numerical addresses";
597-
598595
/* CrowdNode */
599596
"Create Account" = "Create Account";
600597

@@ -2371,6 +2368,9 @@
23712368
/* Voting */
23722369
"Submit" = "Submit";
23732370

2371+
/* No comment provided by engineer. */
2372+
"Successful purchase" = "Successful purchase";
2373+
23742374
/* No comment provided by engineer. */
23752375
"Support" = "Support";
23762376

DashWallet/ca.lproj/Localizable.strings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,6 @@
592592
/* Usernames */
593593
"Create a username" = "Create a username";
594594

595-
/* No comment provided by engineer. */
596-
"Create a username and say goodbye to numerical addresses" = "Create a username and say goodbye to numerical addresses";
597-
598595
/* CrowdNode */
599596
"Create Account" = "Create Account";
600597

@@ -2371,6 +2368,9 @@
23712368
/* Voting */
23722369
"Submit" = "Submit";
23732370

2371+
/* No comment provided by engineer. */
2372+
"Successful purchase" = "Successful purchase";
2373+
23742374
/* No comment provided by engineer. */
23752375
"Support" = "Support";
23762376

0 commit comments

Comments
 (0)