Skip to content

Commit 22f1542

Browse files
authored
feat(ui): add balance action toasts (#258)
1 parent 1471783 commit 22f1542

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

Bitkit/Components/MoneyStack.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct MoneyStack: View {
88
var showEyeIcon: Bool = false
99
var enableSwipeGesture: Bool = false
1010

11+
@EnvironmentObject var app: AppViewModel
1112
@EnvironmentObject var currency: CurrencyViewModel
1213
@EnvironmentObject var settings: SettingsViewModel
1314

@@ -109,10 +110,29 @@ struct MoneyStack: View {
109110
.accessibilityIdentifier("TotalBalance")
110111
.contentShape(Rectangle())
111112
.onTapGesture {
113+
let previousDisplay = currency.primaryDisplay
114+
112115
withAnimation(springAnimation) {
113116
currency.togglePrimaryDisplay()
114117
}
115118
Haptics.play(.medium)
119+
120+
// Show toast on first switch
121+
if !settings.ignoresSwitchUnitToast {
122+
let newDisplay = currency.primaryDisplay
123+
let toUnitText = getUnitText(for: newDisplay)
124+
let fromUnitText = getUnitText(for: previousDisplay)
125+
126+
app.toast(
127+
type: .info,
128+
title: t("wallet__balance_unit_switched_title", variables: ["unit": toUnitText]),
129+
description: t("wallet__balance_unit_switched_message", variables: ["unit": fromUnitText]),
130+
visibilityTime: 5.0,
131+
accessibilityIdentifier: "BalanceUnitSwitchedToast"
132+
)
133+
134+
settings.ignoresSwitchUnitToast = true
135+
}
116136
}
117137
.animation(springAnimation, value: currency.primaryDisplay)
118138
.conditionalGesture(enableSwipeGesture) {
@@ -123,10 +143,24 @@ struct MoneyStack: View {
123143

124144
// Only trigger if horizontal swipe is more significant than vertical
125145
if abs(horizontalAmount) > abs(verticalAmount) {
146+
let wasHidden = settings.hideBalance
126147
withAnimation(springAnimation) {
127148
settings.hideBalance.toggle()
128149
}
129150
Haptics.play(.medium)
151+
152+
// Show toast on first hide (when balance becomes hidden)
153+
if !wasHidden && settings.hideBalance && !settings.ignoresHideBalanceToast {
154+
app.toast(
155+
type: .info,
156+
title: t("wallet__balance_hidden_title"),
157+
description: t("wallet__balance_hidden_message"),
158+
visibilityTime: 5.0,
159+
accessibilityIdentifier: "BalanceHiddenToast"
160+
)
161+
162+
settings.ignoresHideBalanceToast = true
163+
}
130164
}
131165
}
132166
}
@@ -158,6 +192,15 @@ private extension MoneyStack {
158192
}
159193
Haptics.play(.medium)
160194
}
195+
196+
func getUnitText(for display: PrimaryDisplay) -> String {
197+
switch display {
198+
case .bitcoin:
199+
return t("settings__general__unit_bitcoin")
200+
case .fiat:
201+
return currency.selectedCurrency
202+
}
203+
}
161204
}
162205

163206
// MARK: - Helper View Modifier

Bitkit/ViewModels/AppViewModel.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,21 @@ extension AppViewModel {
364364

365365
try await CoreService.shared.activity.insert(.lightning(ln))
366366
} else {
367-
toast(type: .lightning, title: t("lightning__channel_opened_title"), description: t("lightning__channel_opened_msg"))
367+
toast(
368+
type: .lightning,
369+
title: t("lightning__channel_opened_title"),
370+
description: t("lightning__channel_opened_msg"),
371+
visibilityTime: 5.0
372+
)
368373
}
369374
}
370375
} else {
371-
toast(type: .lightning, title: t("lightning__channel_opened_title"), description: t("lightning__channel_opened_msg"))
376+
toast(
377+
type: .lightning,
378+
title: t("lightning__channel_opened_title"),
379+
description: t("lightning__channel_opened_msg"),
380+
visibilityTime: 5.0
381+
)
372382
}
373383
case .channelClosed(channelId: _, userChannelId: _, counterpartyNodeId: _, reason: _):
374384
break

Bitkit/ViewModels/SettingsViewModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class SettingsViewModel: NSObject, ObservableObject {
9797
@AppStorage("quickpayAmount") var quickpayAmount: Double = 5
9898
@AppStorage("enableNotifications") var enableNotifications: Bool = false
9999
@AppStorage("enableNotificationsAmount") var enableNotificationsAmount: Bool = false // TODO: remove this
100+
@AppStorage("ignoresSwitchUnitToast") var ignoresSwitchUnitToast: Bool = false
101+
@AppStorage("ignoresHideBalanceToast") var ignoresHideBalanceToast: Bool = false
100102

101103
// PIN Management
102104
@Published internal(set) var pinEnabled: Bool = false

0 commit comments

Comments
 (0)