Skip to content

Commit

Permalink
feat: coinjoin menu item UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Syn-McJ committed Sep 1, 2024
1 parent be7bc3b commit 1354fdf
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "image.coinjoin.menu.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion DashWallet/Sources/UI/Menu/MenuItemModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import SwiftUI

struct MenuItemModel: Identifiable, Equatable {
class MenuItemModel: Identifiable, Equatable {
let id = UUID()

var title: String
Expand All @@ -30,7 +30,30 @@ struct MenuItemModel: Identifiable, Equatable {
@State var isToggled: Bool = false
var action: (() -> Void)? = nil

init(title: String, subtitle: String? = nil, details: String? = nil, icon: IconName? = nil, showInfo: Bool = false, showChevron: Bool = false, showToggle: Bool = false, isToggled: Bool = false, action: (() -> Void)? = nil) {
self.title = title
self.subtitle = subtitle
self.details = details
self.icon = icon
self.showInfo = showInfo
self.showChevron = showChevron
self.showToggle = showToggle
self.isToggled = isToggled
self.action = action
}

static func == (lhs: MenuItemModel, rhs: MenuItemModel) -> Bool {
lhs.id == rhs.id
}
}

class CoinJoinMenuItemModel: MenuItemModel {
var mixingPercentage: String
var dashAmount: String

init(title: String, mixingPercentage: String, dashAmount: String, action: (() -> Void)? = nil) {
self.mixingPercentage = mixingPercentage
self.dashAmount = dashAmount
super.init(title: title, action: action)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ class SettingsMenuViewController: UIViewController, DWLocalCurrencyViewControlle

#if DASHPAY
items.append(contentsOf: [
MenuItemModel(
CoinJoinMenuItemModel(
title: NSLocalizedString("CoinJoin", comment: ""),
showChevron: true,
mixingPercentage: "70%",
dashAmount: "0.085 of 0.199",
action: { [weak self] in
self?.showCoinJoinController()
}
Expand Down Expand Up @@ -270,17 +271,28 @@ struct SettingsMenuContent: View {

var body: some View {
List(items) { item in
MenuItem(
title: item.title,
subtitle: item.subtitle,
details: item.details,
icon: item.icon,
showInfo: item.showInfo,
showChevron: item.showChevron,
showToggle: item.showToggle,
isToggled: item.isToggled,
action: item.action
)
Group {
if let cjItem = item as? CoinJoinMenuItemModel {
MenuItem(
title: cjItem.title,
subtitleView: AnyView(CoinJoinSubtitle(cjItem.mixingPercentage, cjItem.dashAmount)),
icon: .custom("image.coinjoin.menu"),
action: cjItem.action
)
} else {
MenuItem(
title: item.title,
subtitle: item.subtitle,
details: item.details,
icon: item.icon,
showInfo: item.showInfo,
showChevron: item.showChevron,
showToggle: item.showToggle,
isToggled: item.isToggled,
action: item.action
)
}
}
.background(Color.secondaryBackground)
.cornerRadius(8)
.shadow(color: .shadow, radius: 10, x: 0, y: 5)
Expand All @@ -290,4 +302,31 @@ struct SettingsMenuContent: View {
.listStyle(.plain)
.background(Color.clear)
}

@ViewBuilder
private func CoinJoinSubtitle(_ mixingPercentage: String, _ dashAmount: String) -> some View {
HStack(spacing: 0) {
SwiftUI.ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .dashBlue))
.scaleEffect(0.5)
Text(NSLocalizedString("Mixing ·", comment: "CoinJoin"))
.font(.caption)
.foregroundColor(.tertiaryText)
.padding(.leading, 2)
Text(mixingPercentage)
.font(.caption)
.foregroundColor(.tertiaryText)
.padding(.leading, 4)
Spacer()
Text(dashAmount)
.font(.caption)
.foregroundColor(.tertiaryText)
Image("icon_dash_currency")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 12, height: 12)
.padding(.leading, 2)
.foregroundColor(.tertiaryText)
}
}
}

0 comments on commit 1354fdf

Please sign in to comment.