diff options
author | Marc Stibane <marc@taler.net> | 2023-10-24 16:43:57 +0200 |
---|---|---|
committer | Marc Stibane <marc@taler.net> | 2023-10-24 16:43:57 +0200 |
commit | f941fe2a945fbed3e8cfb7675bcb229c0d8ba0dc (patch) | |
tree | 538a647b4abfca216d410f1206c8a2f7542f3617 | |
parent | cc6b3bcfb112104bbff0b83ad12ff761f9fa21cf (diff) | |
download | taler-ios-f941fe2a945fbed3e8cfb7675bcb229c0d8ba0dc.tar.gz taler-ios-f941fe2a945fbed3e8cfb7675bcb229c0d8ba0dc.tar.bz2 taler-ios-f941fe2a945fbed3e8cfb7675bcb229c0d8ba0dc.zip |
ExchangeRowView
-rw-r--r-- | TalerWallet.xcodeproj/project.pbxproj | 6 | ||||
-rw-r--r-- | TalerWallet1/Views/Exchange/ExchangeRowView.swift | 107 | ||||
-rw-r--r-- | TalerWallet1/Views/Exchange/ExchangeSectionView.swift | 69 |
3 files changed, 115 insertions, 67 deletions
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj index cbefbd1..341df5d 100644 --- a/TalerWallet.xcodeproj/project.pbxproj +++ b/TalerWallet.xcodeproj/project.pbxproj @@ -233,6 +233,8 @@ 4EBA82AD2A3F580500E5F39A /* QuiteSomeCoins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EBA82AC2A3F580500E5F39A /* QuiteSomeCoins.swift */; }; 4EC400892AE3E7E800DF72C7 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EC400882AE3E7E800DF72C7 /* AboutView.swift */; }; 4EC4008A2AE3E7E800DF72C7 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EC400882AE3E7E800DF72C7 /* AboutView.swift */; }; + 4EC4008F2AE8019700DF72C7 /* ExchangeRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EC4008E2AE8019700DF72C7 /* ExchangeRowView.swift */; }; + 4EC400902AE8019700DF72C7 /* ExchangeRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EC4008E2AE8019700DF72C7 /* ExchangeRowView.swift */; }; 4EC90C782A1B528B0071DC58 /* ExchangeSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EC90C772A1B528B0071DC58 /* ExchangeSectionView.swift */; }; 4ECB62802A0BA6DF004ABBB7 /* Model+P2P.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ECB627F2A0BA6DF004ABBB7 /* Model+P2P.swift */; }; 4ECB62822A0BB01D004ABBB7 /* SelectDays.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ECB62812A0BB01D004ABBB7 /* SelectDays.swift */; }; @@ -402,6 +404,7 @@ 4EBA82AA2A3EB2CA00E5F39A /* TransactionButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionButton.swift; sourceTree = "<group>"; }; 4EBA82AC2A3F580500E5F39A /* QuiteSomeCoins.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuiteSomeCoins.swift; sourceTree = "<group>"; }; 4EC400882AE3E7E800DF72C7 /* AboutView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; }; + 4EC4008E2AE8019700DF72C7 /* ExchangeRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExchangeRowView.swift; sourceTree = "<group>"; }; 4EC90C772A1B528B0071DC58 /* ExchangeSectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExchangeSectionView.swift; sourceTree = "<group>"; }; 4ECB627F2A0BA6DF004ABBB7 /* Model+P2P.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Model+P2P.swift"; sourceTree = "<group>"; }; 4ECB62812A0BB01D004ABBB7 /* SelectDays.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectDays.swift; sourceTree = "<group>"; }; @@ -658,6 +661,7 @@ children = ( 4EB095292989CBFE0043A8A1 /* ExchangeListView.swift */, 4EC90C772A1B528B0071DC58 /* ExchangeSectionView.swift */, + 4EC4008E2AE8019700DF72C7 /* ExchangeRowView.swift */, 4E50B34F2A1BEE8000F9F01C /* ManualWithdraw.swift */, 4EBA82AC2A3F580500E5F39A /* QuiteSomeCoins.swift */, 4EB431662A1E55C700C5690E /* ManualWithdrawDone.swift */, @@ -1080,6 +1084,7 @@ 4E3EAE492A990778009F1BE8 /* ManualWithdrawDone.swift in Sources */, 4E3EAE4A2A990778009F1BE8 /* PaymentPurpose.swift in Sources */, 4E3EAE4B2A990778009F1BE8 /* ShareSheet.swift in Sources */, + 4EC4008F2AE8019700DF72C7 /* ExchangeRowView.swift in Sources */, 4E3EAE4C2A990778009F1BE8 /* AmountView.swift in Sources */, 4E605DBA2AB05FB6002FB9A7 /* BarGraph.swift in Sources */, 4E3EAE4D2A990778009F1BE8 /* P2pAcceptDone.swift in Sources */, @@ -1186,6 +1191,7 @@ 4EB431672A1E55C700C5690E /* ManualWithdrawDone.swift in Sources */, 4E9320472A164BC700A87B0E /* PaymentPurpose.swift in Sources */, 4E753A082A0B6A5F002D9328 /* ShareSheet.swift in Sources */, + 4EC400902AE8019700DF72C7 /* ExchangeRowView.swift in Sources */, 4EB0956C2989CBFE0043A8A1 /* AmountView.swift in Sources */, 4E605DBB2AB05FB6002FB9A7 /* BarGraph.swift in Sources */, 4E3B4BC32A42252300CC88B8 /* P2pAcceptDone.swift in Sources */, diff --git a/TalerWallet1/Views/Exchange/ExchangeRowView.swift b/TalerWallet1/Views/Exchange/ExchangeRowView.swift new file mode 100644 index 0000000..fa08d80 --- /dev/null +++ b/TalerWallet1/Views/Exchange/ExchangeRowView.swift @@ -0,0 +1,107 @@ +/* + * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * See LICENSE.md + */ +import SwiftUI +import taler_swift + +struct ExchangeRowView: View { + let stack: CallStack + let exchange: Exchange +// let amount: Amount + let currency: String + @Binding var centsToTransfer: UInt64 + + @Environment(\.sizeCategory) var sizeCategory + @State private var buttonSelected: Int? = nil + + func selectAndUpdate(_ button: Int) { + buttonSelected = button // will trigger NavigationLink + // TODO: while navigation animation runs, contact Exchange to update Fees +// Task { // runs on MainActor +// do { +// try await model.updateExchange(scopeInfo: balance.scopeInfo) +// } catch { // TODO: error handling - couldn't updateExchange +// // symLog.log("error: \(error)") +// } +// } + } + + let depositTitle = String(localized: "Deposit", comment: "Top of button <Deposit (currency)>") + let withdrawTitle = String(localized: "Withdraw", comment: "Top of button <Withdraw (currency)>") + + var body: some View { + let baseURL = exchange.exchangeBaseUrl + + HStack(spacing: 0) { // can't use the built in Label because it adds the accessory arrow + Text(baseURL.trimURL()) + .accessibilityFont(.body) + + NavigationLink(destination: LazyView { + EmptyView() // TODO: Deposit + }, tag: 1, selection: $buttonSelected + ) { EmptyView() }.frame(width: 0).opacity(0) + NavigationLink(destination: LazyView { + ManualWithdraw(stack: stack.push(), + exchange: exchange, + centsToTransfer: $centsToTransfer) + }, tag: 2, selection: $buttonSelected + ) { EmptyView() }.frame(width: 0).opacity(0) + }.listRowSeparator(.hidden) + + SingleAxisGeometryReader { width in + Group { + let uiFont = TalerFont.uiFont(.title3) + let titles = [(depositTitle, uiFont), (withdrawTitle, uiFont), (currency, uiFont)] + let sendTitle = depositTitle + "\n" + currency // TODO: amount.currencyStr + let recvTitle = withdrawTitle + "\n" + currency // TODO: amount.currencyStr + let twoRowButtons = TwoRowButtons(sendTitle: sendTitle, recvTitle: recvTitle, + lineLimit: 5, sendDisabled: true, // TODO: amount.isZero + sendAction: { selectAndUpdate(1) }, + recvAction: { selectAndUpdate(2) }) + if Self.needVStack(titles, width: width, spacing: HSPACING + 4, currency: currency) { + VStack { twoRowButtons } + } else { + HStack(spacing: HSPACING) { twoRowButtons } + } + } + } + } +} + +// MARK: - +#if DEBUG +fileprivate struct ExchangeRow_Container : View { + @State private var centsToTransfer: UInt64 = 100 + +// let amount = try! Amount(fromString: LONGCURRENCY + ":1234.56") + var body: some View { + let exchange1 = Exchange(exchangeBaseUrl: ARS_AGE_EXCHANGE, + currency: LONGCURRENCY, + paytoUris: [], + tosStatus: .pending, + exchangeEntryStatus: .preset, + exchangeUpdateStatus: .initial, + ageRestrictionOptions: [12,16]) + let exchange2 = Exchange(exchangeBaseUrl: ARS_EXP_EXCHANGE, + currency: LONGCURRENCY, + paytoUris: [], + tosStatus: .proposed, + exchangeEntryStatus: .ephemeral, + exchangeUpdateStatus: .ready, + ageRestrictionOptions: []) + ExchangeRowView(stack: CallStack("Preview"), + exchange: exchange1, + currency: LONGCURRENCY, + centsToTransfer: $centsToTransfer) + } +} + +fileprivate struct ExchangeRow_Previews: PreviewProvider { + static var previews: some View { + List { + ExchangeRow_Container() + } + } +} +#endif diff --git a/TalerWallet1/Views/Exchange/ExchangeSectionView.swift b/TalerWallet1/Views/Exchange/ExchangeSectionView.swift index 73e8dbf..e13ebc1 100644 --- a/TalerWallet1/Views/Exchange/ExchangeSectionView.swift +++ b/TalerWallet1/Views/Exchange/ExchangeSectionView.swift @@ -5,71 +5,6 @@ import SwiftUI import taler_swift -struct ExchangeRowView: View { - let stack: CallStack - let exchange: Exchange -// let amount: Amount - let currency: String - @Binding var centsToTransfer: UInt64 - - @Environment(\.sizeCategory) var sizeCategory - @State private var buttonSelected: Int? = nil - - func selectAndUpdate(_ button: Int) { - buttonSelected = button // will trigger NavigationLink - // while navigation animation runs, contact Exchange to update Fees -// Task { // runs on MainActor -// do { -// try await model.updateExchange(scopeInfo: balance.scopeInfo) -// } catch { // TODO: error handling - couldn't updateExchange -// // symLog.log("error: \(error)") -// } -// } - } - - let depositTitle = String(localized: "Deposit", comment: "Top of button <Deposit (currency)>") - let withdrawTitle = String(localized: "Withdraw", comment: "Top of button <Withdraw (currency)>") - - var body: some View { - let baseURL = exchange.exchangeBaseUrl - - HStack(spacing: 0) { // can't use the built in Label because it adds the accessory arrow - Text(baseURL.trimURL()) - .accessibilityFont(.body) - - NavigationLink(destination: LazyView { - EmptyView() // TODO: Deposit - }, tag: 1, selection: $buttonSelected - ) { EmptyView() }.frame(width: 0).opacity(0) - NavigationLink(destination: LazyView { - ManualWithdraw(stack: stack.push(), - exchange: exchange, - centsToTransfer: $centsToTransfer) - }, tag: 2, selection: $buttonSelected - ) { EmptyView() }.frame(width: 0).opacity(0) - }.listRowSeparator(.hidden) - - SingleAxisGeometryReader { width in - Group { - let uiFont = TalerFont.uiFont(.title3) - let titles = [(depositTitle, uiFont), (withdrawTitle, uiFont), (currency, uiFont)] - let sendTitle = depositTitle + "\n" + currency // TODO: amount.currencyStr - let recvTitle = withdrawTitle + "\n" + currency // TODO: amount.currencyStr - let twoRowButtons = TwoRowButtons(sendTitle: sendTitle, recvTitle: recvTitle, - lineLimit: 5, sendDisabled: true, // TODO: amount.isZero - sendAction: { selectAndUpdate(1) }, - recvAction: { selectAndUpdate(2) }) - let spacing = CGFloat(10) // space between the two buttons - if Self.needVStack(titles, width: width, spacing: spacing) { - VStack { twoRowButtons } - } else { - HStack(spacing: spacing) { twoRowButtons } - } - } - } - } -} -// MARK: - /// This view shows the currency name in an exchange section /// currency /// [Deposit Coins] [Withdraw Coins] @@ -101,7 +36,7 @@ struct ExchangeSectionView: View { } // MARK: - #if DEBUG -struct ExchangeRow_Container : View { +fileprivate struct ExchangeRow_Container : View { @State private var centsToTransfer: UInt64 = 100 // let amount = try! Amount(fromString: LONGCURRENCY + ":1234.56") @@ -126,7 +61,7 @@ struct ExchangeRow_Container : View { } } -struct ExchangeRow_Previews: PreviewProvider { +fileprivate struct ExchangeSection_Previews: PreviewProvider { static var previews: some View { List { ExchangeRow_Container() |