[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 20/204: Balances uses ScopePicker, Transactions uses s
From: |
gnunet |
Subject: |
[taler-taler-ios] 20/204: Balances uses ScopePicker, Transactions uses static text |
Date: |
Thu, 05 Dec 2024 23:49:48 +0100 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit 1410e3d878da65ef23889f8c8c941eb506f7c244
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Sep 13 10:48:06 2024 +0200
Balances uses ScopePicker, Transactions uses static text
---
.../Views/Actions/Peer2peer/SendAmount.swift | 108 +++++++++++++++------
TalerWallet1/Views/HelperViews/ScopePicker.swift | 20 ++--
2 files changed, 93 insertions(+), 35 deletions(-)
diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmount.swift
b/TalerWallet1/Views/Actions/Peer2peer/SendAmount.swift
index 559d3c5..5955ad7 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/SendAmount.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/SendAmount.swift
@@ -20,6 +20,76 @@ struct SendAmount: View {
let scopeInfo: ScopeInfo
let cameraAction: () -> Void
+ @State private var balanceIndex = 0
+ @State private var nonZeroBalances: [Balance] = []
+ @State private var balance: Balance? = nil
+
+ var body: some View {
+#if PRINT_CHANGES
+ let _ = Self._printChanges()
+#endif
+// nonZeroBalances.count > 0
+// let balance = selectedBalance ?? nonZeroBalances[balanceIndex]
+ let sendAmountView = ScrollView {
+ let count = nonZeroBalances.count
+ if let selectedBalance {
+ let urlOrCurrency = selectedBalance.scopeInfo.url?.trimURL()
+ ?? selectedBalance.scopeInfo.currency
+ let amount = selectedBalance.available
+ let formattedAmount = amount.formatted(isNegative: false,
useISO: false)
+ let label = String("\(urlOrCurrency):\t\(formattedAmount.nbs)")
+ Text(label)
+// .padding(.leading)
+ .talerFont(.title3)
+ } else if count > 0 {
+ ScopePicker(value: $balanceIndex, balances: nonZeroBalances) {
index in
+ balanceIndex = index
+ balance = nonZeroBalances[index]
+ }
+ }
+ SendAmountContent(stack: stack.push(),
+ balance: $balance,
+ balanceIndex: $balanceIndex,
+ amountToTransfer: $amountToTransfer,
+ summary: $summary,
+ cameraAction: cameraAction)
+ } // ScrollView
+
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
+// .scrollBounceBehavior(.basedOnSize) needs iOS 16.4
+ .task {
+ if selectedBalance == nil {
+ nonZeroBalances = Balance.nonZeroBalances(balances)
+ let count = nonZeroBalances.count
+ if balanceIndex >= count {
+ balanceIndex = 0
+ }
+ if count > 0 {
+ balance = nonZeroBalances[balanceIndex]
+ } else {
+ balance = nil
+ }
+ } else {
+ balance = selectedBalance
+ }
+ }
+
+ if #available(iOS 16.0, *) {
+ sendAmountView.toolbar(.hidden, for: .tabBar)
+ } else {
+ sendAmountView
+ }
+ }
+}
+// MARK: -
+struct SendAmountContent: View {
+ private let symLog = SymLogV()
+ let stack: CallStack
+ @Binding var balance: Balance?
+ @Binding var balanceIndex: Int
+ @Binding var amountToTransfer: Amount
+ @Binding var summary: String
+ let cameraAction: () -> Void
+
// TODO: call getMaxPeerPushDebitAmountM
@EnvironmentObject private var controller: Controller
@@ -39,7 +109,6 @@ struct SendAmount: View {
@State private var amountAvailable = Amount.zero(currency: EMPTYSTRING)
// GetMaxPeerPushAmount
@State private var exchange: Exchange? = nil
// wg. noFees
- @State private var balanceIndex = 0
@State private var currencyInfo = CurrencyInfo.zero(UNKNOWN)
@State private var currencyName = UNKNOWN
@State private var currencySymbol = UNKNOWN
@@ -123,12 +192,6 @@ struct SendAmount: View {
let _ = Self._printChanges()
let _ = symLog.vlog() // just to get the # to compare it with
.onAppear & onDisappear
#endif
- let nonZeroBalances = Balance.nonZeroBalances(balances)
- let count = nonZeroBalances.count
- let index = balanceIndex < count ? balanceIndex : 0
- let balance = nonZeroBalances[index]
- let scopeInfo = balance.scopeInfo
- let currency = scopeInfo.currency
let navTitle = String(localized: "NavTitle_Send",
defaultValue: "Send",
comment: "NavTitle: Send")
@@ -159,9 +222,7 @@ struct SendAmount: View {
expireDays: $expireDays)
}
- let sendAmountView = ScrollView {
- ScopePicker(stack: stack.push(), balances: nonZeroBalances,
selected: $balanceIndex)
-
+ Group {
let amountLabel = minimalistic ? String(localized: "Amount:")
: String(localized: "Amount to
send:")
AmountInputV(stack: stack.push(),
@@ -181,9 +242,8 @@ struct SendAmount: View {
.background(NavigationLink(destination: inputDestination,
isActive: $buttonSelected)
{ EmptyView() }.frame(width: 0).opacity(0).hidden()
) // inputDestination
- } // ScrollView
+ }
.frame(maxWidth: .infinity, alignment: .leading)
-// .scrollBounceBehavior(.basedOnSize) needs iOS 16.4
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
.navigationTitle(navTitle)
.task {
@@ -205,14 +265,15 @@ struct SendAmount: View {
}
.navigationBarItems(trailing: QRButton(action: cameraAction))
.task(id: balanceIndex + (1000 * controller.currencyTicker)) {
- let balance = nonZeroBalances[index]
- let scopeInfo = balance.scopeInfo
- let currency = scopeInfo.currency
- amountAvailable = balance.available
- amountToTransfer.setCurrency(currency)
- currencyInfo = controller.info(for: currency,
controller.currencyTicker)
- currencyName = currencyInfo.scope.currency
- currencySymbol = currencyInfo.altUnitSymbol ??
currencyInfo.specs.name
+ if let balance {
+ let scopeInfo = balance.scopeInfo
+ let currency = scopeInfo.currency
+ amountAvailable = balance.available
+ amountToTransfer.setCurrency(currency)
+ currencyInfo = controller.info(for: currency,
controller.currencyTicker)
+ currencyName = currencyInfo.scope.currency
+ currencySymbol = currencyInfo.altUnitSymbol ??
currencyInfo.specs.name
+ }
}
// .task(id: amountToTransfer.value) {
// if exchange == nil {
@@ -249,13 +310,6 @@ struct SendAmount: View {
// }
// }
// }
-
- if #available(iOS 16.0, *) {
- sendAmountView.toolbar(.hidden, for: .tabBar)
- } else {
- sendAmountView
- }
-
}
}
// MARK: -
diff --git a/TalerWallet1/Views/HelperViews/ScopePicker.swift
b/TalerWallet1/Views/HelperViews/ScopePicker.swift
index e4c2a08..8d66090 100644
--- a/TalerWallet1/Views/HelperViews/ScopePicker.swift
+++ b/TalerWallet1/Views/HelperViews/ScopePicker.swift
@@ -8,11 +8,11 @@
import SwiftUI
struct ScopePicker: View {
- let stack: CallStack
+ @Binding var value: Int
let balances: [Balance]
+ let action: (Int) -> Void
- @Binding var selected: Int
-// @State private var selected = 0
+ @State private var selected = 0
func formattedAmount(_ balance: Balance) -> String {
let amount = balance.available
@@ -27,18 +27,22 @@ struct ScopePicker: View {
var body: some View {
HStack {
- Text("From: ")
+ Text("Use: ", comment: "ScopePicker")
Spacer()
- if (balances.count > 1) {
+ if (balances.count > 0) {
Picker(EMPTYSTRING, selection: $selected) {
ForEach(0..<balances.count, id: \.self) { index in
Text(label(balance: balances[index]))
.tag(index)
}
}
- } else { // only 1 choice, no need for a picker
- Text(label(balance: balances[0]))
- .tag(0)
+ .pickerStyle(.menu)
+ .onAppear() {
+ withAnimation { selected = value }
+ }
+ .onChange(of: selected) { newValue in
+ action(newValue)
+ }
}
}
.padding(.leading)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 10/204: SendAmount with Picker, (continued)
- [taler-taler-ios] 10/204: SendAmount with Picker, gnunet, 2024/12/05
- [taler-taler-ios] 16/204: GetMaxDepositAmount, gnunet, 2024/12/05
- [taler-taler-ios] 12/204: cleanup project, gnunet, 2024/12/05
- [taler-taler-ios] 14/204: PaymentInsufficientBalanceDetails, gnunet, 2024/12/05
- [taler-taler-ios] 22/204: Sheet drop bar, gnunet, 2024/12/05
- [taler-taler-ios] 13/204: balances & selectedBalance, move action navigation to MainView, gnunet, 2024/12/05
- [taler-taler-ios] 24/204: @State ScopeInfo.zero, gnunet, 2024/12/05
- [taler-taler-ios] 15/204: GetMaxPeerPushDebitAmount, gnunet, 2024/12/05
- [taler-taler-ios] 17/204: "Transactions" -> currency, gnunet, 2024/12/05
- [taler-taler-ios] 23/204: KeyboardShowingEnvironment, gnunet, 2024/12/05
- [taler-taler-ios] 20/204: Balances uses ScopePicker, Transactions uses static text,
gnunet <=
- [taler-taler-ios] 19/204: cleanup, debug, gnunet, 2024/12/05
- [taler-taler-ios] 21/204: SendAmountV, gnunet, 2024/12/05
- [taler-taler-ios] 31/204: a11y, gnunet, 2024/12/05
- [taler-taler-ios] 33/204: BarGraph 15, trust GetTransactionsV2, gnunet, 2024/12/05
- [taler-taler-ios] 32/204: cleanup, gnunet, 2024/12/05
- [taler-taler-ios] 37/204: debugging, gnunet, 2024/12/05
- [taler-taler-ios] 44/204: cleanup, gnunet, 2024/12/05
- [taler-taler-ios] 50/204: amountLastUsed, gnunet, 2024/12/05
- [taler-taler-ios] 18/204: Unsuccessfull trial to fix TX-Detailview jump onAppear, gnunet, 2024/12/05
- [taler-taler-ios] 26/204: hide TabBarView, gnunet, 2024/12/05