taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit d729e1b8b2e5c99dadca4cca930cea7a84f53bc0
parent c4294a7738cfba17fd1f12c5a08ec28dec8ba9d3
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 12 Jun 2023 19:07:58 +0200

Moved AgePicker in its own file

Diffstat:
MTalerWallet.xcodeproj/project.pbxproj | 8++++++--
ATalerWallet1/Helper/AgePicker.swift | 49+++++++++++++++++++++++++++++++++++++++++++++++++
MTalerWallet1/Views/Exchange/ManualWithdraw.swift | 35++++-------------------------------
3 files changed, 59 insertions(+), 33 deletions(-)

diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ 4E9320432A14F6EA00A87B0E /* WalletColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E9320422A14F6EA00A87B0E /* WalletColors.swift */; }; 4E9320452A1645B600A87B0E /* RequestPayment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E9320442A1645B600A87B0E /* RequestPayment.swift */; }; 4E9320472A164BC700A87B0E /* ReceivePurpose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E9320462A164BC700A87B0E /* ReceivePurpose.swift */; }; + 4E9796902A3765ED006F73BC /* AgePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E97968F2A3765ED006F73BC /* AgePicker.swift */; }; 4EA1ABBE29A3833A008821EA /* PublicConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EA1ABBD29A3833A008821EA /* PublicConstants.swift */; }; 4EA551252A2C923600FEC9A8 /* CurrencyInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */; }; 4EAD117629F672FA008EDD0B /* KeyboardResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */; }; @@ -151,6 +152,7 @@ 4E9320422A14F6EA00A87B0E /* WalletColors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletColors.swift; sourceTree = "<group>"; }; 4E9320442A1645B600A87B0E /* RequestPayment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestPayment.swift; sourceTree = "<group>"; }; 4E9320462A164BC700A87B0E /* ReceivePurpose.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReceivePurpose.swift; sourceTree = "<group>"; }; + 4E97968F2A3765ED006F73BC /* AgePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgePicker.swift; sourceTree = "<group>"; }; 4EA1ABBD29A3833A008821EA /* PublicConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicConstants.swift; sourceTree = "<group>"; }; 4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyInputView.swift; sourceTree = "<group>"; }; 4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardResponder.swift; sourceTree = "<group>"; }; @@ -303,6 +305,7 @@ 4EB095052989CB7C0043A8A1 /* Helper */ = { isa = PBXGroup; children = ( + 4E97968F2A3765ED006F73BC /* AgePicker.swift */, 4E363CBD2A23CB2100D7E98C /* AnyTransition+backslide.swift */, 4E16E12229F3BB99008B9C86 /* CurrencyFormatter.swift */, 4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */, @@ -688,6 +691,7 @@ files = ( 4ECB62822A0BB01D004ABBB7 /* SelectDays.swift in Sources */, 4EB095512989CBFE0043A8A1 /* ExchangeModel.swift in Sources */, + 4E9796902A3765ED006F73BC /* AgePicker.swift in Sources */, 4EB095032989C9BC0043A8A1 /* Controller.swift in Sources */, 4EB095682989CBFE0043A8A1 /* MainView.swift in Sources */, 4EB0956A2989CBFE0043A8A1 /* Buttons.swift in Sources */, @@ -923,7 +927,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = "GNU Taler.entitlements"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_TEAM = ""; @@ -948,7 +952,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.taler-systems.talerwallet-1"; PRODUCT_NAME = "GNU Taler"; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = iOS_Distribution_230606; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = Dev230612a; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; diff --git a/TalerWallet1/Helper/AgePicker.swift b/TalerWallet1/Helper/AgePicker.swift @@ -0,0 +1,49 @@ +/* + * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * See LICENSE.md + */ +import SwiftUI + +struct AgePicker: View { + @Binding var ageMenuList: [Int] + @Binding var selectedAge: Int + + func setAges(ages: [Int]?) { + if let ages { + var zero: [Int] = [] + if ages.count > 0 { // need at least 1 value from exchange which is not 0 + if ages[0] != 0 { // ensure that the first age is "0" + zero.insert(0, at: 0) // if not, insert "0" at position 0 + } + zero += ages + if selectedAge >= zero.count { // check for out of bounds + selectedAge = 0 + } + } else { + selectedAge = 0 // first ensure that selected is not out of bounds + } + ageMenuList = zero // set State (will update view) + } + } + + var body: some View { + if ageMenuList.count > 1 { + VStack { + HStack { + Text("If this wallet belongs to a child or teenager, the generated coins should be age-restricted:") + .multilineTextAlignment(.leading) + .font(.footnote) + Spacer() + }.padding(.top) + Picker("Select age", selection: $selectedAge) { + ForEach($ageMenuList, id: \.self) { item in + let index = item.wrappedValue + Text((index == 0) ? "unrestricted" + : "\(index) years").tag(index) + } + } + } + } + } +} + diff --git a/TalerWallet1/Views/Exchange/ManualWithdraw.swift b/TalerWallet1/Views/Exchange/ManualWithdraw.swift @@ -41,6 +41,7 @@ struct ManualWithdraw: View { #endif let currency = exchange.currency! let currencyField = CurrencyField(value: $centsToTransfer, currency: currency) // becomeFirstResponder + let agePicker = AgePicker(ageMenuList: $ageMenuList, selectedAge: $selectedAge) ScrollView { Text("from \(exchange.exchangeBaseUrl.trimURL())") @@ -87,21 +88,8 @@ struct ManualWithdraw: View { .foregroundColor(quiteSome ? .red : .primary) } // warnings - if ageMenuList.count > 1 { - HStack { - Text("If this wallet belongs to a child or teenager, the generated coins should be age-restricted:") - .multilineTextAlignment(.leading) - .font(.footnote) - Spacer() - }.padding(.top) - Picker("Select age", selection: $selectedAge) { - ForEach($ageMenuList, id: \.self) { item in - let index = item.wrappedValue - Text((index == 0) ? "unlimited" - : "\(index) years").tag(index) - } - } - } + agePicker + if let tosAcc = manualWithdrawalDetails?.tosAccepted { if tosAcc { let restrictAge: Int? = (selectedAge == 0) ? nil @@ -141,22 +129,7 @@ let _ = print(selectedAge, restrictAge) let amount = Amount.amountFromCents(currency, centsToTransfer) do { manualWithdrawalDetails = try await model.loadWithdrawalDetailsForAmountM(exchange.exchangeBaseUrl, amount: amount) - if let ageRestrictions = manualWithdrawalDetails?.ageRestrictionOptions { - var ages = ageRestrictions - let nonzero = ages.count > 0 // need at least 1 value from exchange which is not 0 - if nonzero { - if ages[0] != 0 { // ensure that the first age is "0" - ages.insert(0, at: 0) // if not, insert "0" at position 0 - } - if selectedAge >= ages.count { // check for out of bounds - selectedAge = 0 - } - } else { - selectedAge = 0 // first ensure that selected is not out of bounds - } -print(ages) - ageMenuList = ages // set State (will update view) - } + agePicker.setAges(ages: manualWithdrawalDetails?.ageRestrictionOptions) } catch { // TODO: error symLog.log(error.localizedDescription) manualWithdrawalDetails = nil