summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-12-07 00:14:22 +0100
committerMarc Stibane <marc@taler.net>2023-12-07 00:14:22 +0100
commitb38c0d54de538b7ae46775e77aeab0ef4c5816ae (patch)
treebdd168ef11a8972188109d93f08c3d0031269b15
parente306950a195eaa278a43f03c7f0ca3f890c329d3 (diff)
downloadtaler-ios-b38c0d54de538b7ae46775e77aeab0ef4c5816ae.tar.gz
taler-ios-b38c0d54de538b7ae46775e77aeab0ef4c5816ae.tar.bz2
taler-ios-b38c0d54de538b7ae46775e77aeab0ef4c5816ae.zip
tosAccepted -> tosStatus
-rw-r--r--TalerWallet1/Views/Exchange/ExchangeRowView.swift3
-rw-r--r--TalerWallet1/Views/Exchange/ManualWithdraw.swift178
-rw-r--r--TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift12
-rw-r--r--TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift33
4 files changed, 106 insertions, 120 deletions
diff --git a/TalerWallet1/Views/Exchange/ExchangeRowView.swift b/TalerWallet1/Views/Exchange/ExchangeRowView.swift
index 15e9c2a..aa93dff 100644
--- a/TalerWallet1/Views/Exchange/ExchangeRowView.swift
+++ b/TalerWallet1/Views/Exchange/ExchangeRowView.swift
@@ -56,8 +56,7 @@ struct ExchangeRowView: View {
}
let manualWithdraw = LazyView {
ManualWithdraw(stack: stack.push(),
-// url: nil,
- exchange: exchange,
+ exchangeBaseUrl: baseURL,
amountToTransfer: $amountToTransfer)
}
let showToS = LazyView {
diff --git a/TalerWallet1/Views/Exchange/ManualWithdraw.swift b/TalerWallet1/Views/Exchange/ManualWithdraw.swift
index 0ad86f6..9cf3534 100644
--- a/TalerWallet1/Views/Exchange/ManualWithdraw.swift
+++ b/TalerWallet1/Views/Exchange/ManualWithdraw.swift
@@ -10,18 +10,15 @@ import SymLog
struct ManualWithdraw: View {
private let symLog = SymLogV(0)
let stack: CallStack
-
-// let url: URL?
-// let exchange: Exchange?
- let exchange: Exchange
+ let exchangeBaseUrl: String
@Binding var amountToTransfer: Amount
@EnvironmentObject private var controller: Controller
@EnvironmentObject private var model: WalletModel
@AppStorage("iconOnly") var iconOnly: Bool = false
- @State var tosAccepted = false
- @State var withdrawalAmountDetails: WithdrawalAmountDetails? = nil
+ @State private var withdrawalAmountDetails: WithdrawalAmountDetails? = nil
+ @State private var exchange: Exchange? = nil
// @State var ageMenuList: [Int] = []
// @State var selectedAge = 0
@@ -30,77 +27,84 @@ struct ManualWithdraw: View {
let _ = Self._printChanges()
let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear
#endif
- let currency = exchange.scopeInfo?.currency ?? exchange.currency ?? String(localized: "Unknown", comment: "unknown currency")
- let currencyInfo = controller.info(for: currency, controller.currencyTicker)
- let navTitle = String(localized: "NavTitle_Withdraw (currency)", defaultValue: "Withdraw \(currency)")
-// let agePicker = AgePicker(ageMenuList: $ageMenuList, selectedAge: $selectedAge)
+ Group {
+ if let exchange {
+ let currency = exchange.scopeInfo?.currency
+ ?? exchange.currency
+ ?? String(localized: "Unknown", comment: "unknown currency")
+ let currencyInfo = controller.info(for: currency, controller.currencyTicker)
+ let navTitle = String(localized: "NavTitle_Withdraw (currency)", defaultValue: "Withdraw \(currency)")
+// let agePicker = AgePicker(ageMenuList: $ageMenuList, selectedAge: $selectedAge)
- let someCoins = SomeCoins(details: withdrawalAmountDetails)
-// let restrictAge: Int? = (selectedAge == 0) ? nil
-// : selectedAge
+ let someCoins = SomeCoins(details: withdrawalAmountDetails)
+// let restrictAge: Int? = (selectedAge == 0) ? nil
+// : selectedAge
// let _ = print(selectedAge, restrictAge)
- let destination = LazyView {
- ManualWithdrawDone(stack: stack.push(),
- exchange: exchange,
- amountToTransfer: amountToTransfer)
-// restrictAge: restrictAge)
- }
- let disabled = amountToTransfer.isZero || someCoins.invalid || someCoins.tooMany
- ScrollView { VStack(alignment: .trailing) {
- Text("via \(exchange.exchangeBaseUrl.trimURL())")
- .multilineTextAlignment(.center)
- .accessibilityFont(.body)
- CurrencyInputView(amount: $amountToTransfer,
- available: nil,
- title: iconOnly ? String(localized: "Amount:")
- : String(localized: "Amount to withdraw:"),
- shortcutAction: nil)
- .padding(.top)
- QuiteSomeCoins(someCoins: someCoins,
- shouldShowFee: true, // TODO: set to false if we never charge withdrawal fees
- currency: currency,
- currencyInfo: currencyInfo,
- amountEffective: withdrawalAmountDetails?.amountEffective)
-// agePicker
- if tosAccepted {
- NavigationLink(destination: destination) {
- Text("Confirm Withdrawal") // VIEW_WITHDRAW_ACCEPT
+ let destination = LazyView {
+ ManualWithdrawDone(stack: stack.push(),
+ exchange: exchange,
+ amountToTransfer: amountToTransfer)
+// restrictAge: restrictAge)
+ }
+ let disabled = amountToTransfer.isZero || someCoins.invalid || someCoins.tooMany
+ ScrollView { VStack(alignment: .trailing) {
+ Text("via \(exchange.exchangeBaseUrl.trimURL())")
+ .multilineTextAlignment(.center)
+ .accessibilityFont(.body)
+ CurrencyInputView(amount: $amountToTransfer,
+ available: nil,
+ title: iconOnly ? String(localized: "Amount:")
+ : String(localized: "Amount to withdraw:"),
+ shortcutAction: nil)
+ .padding(.top)
+ QuiteSomeCoins(someCoins: someCoins,
+ shouldShowFee: true, // TODO: set to false if we never charge withdrawal fees
+ currency: currency,
+ currencyInfo: currencyInfo,
+ amountEffective: withdrawalAmountDetails?.amountEffective)
+// agePicker
+ if exchange.tosStatus == .accepted {
+ NavigationLink(destination: destination) {
+ Text("Confirm Withdrawal") // VIEW_WITHDRAW_ACCEPT
+ }
+ .buttonStyle(TalerButtonStyle(type: .prominent))
+ .disabled(disabled)
+ .padding(.top)
+ } else {
+ ToSButtonView(stack: stack.push(),
+ exchangeBaseUrl: exchange.exchangeBaseUrl,
+ viewID: VIEW_WITHDRAW_TOS, // TODO: YIKES might be withdraw-exchange
+ p2p: false)
+ .padding(.top)
}
- .buttonStyle(TalerButtonStyle(type: .prominent))
- .disabled(disabled)
- .padding(.top)
- } else {
- ToSButtonView(stack: stack.push(),
- exchangeBaseUrl: exchange.exchangeBaseUrl,
- viewID: VIEW_WITHDRAW_TOS,
- p2p: false)
- .padding(.top)
+ } } // ScrollVStack
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(.horizontal)
+ .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
+ .navigationTitle(navTitle)
+ .onAppear {
+ DebugViewC.shared.setViewID(VIEW_WITHDRAWAL, stack: stack.push())
+ symLog.log("❗️ \(navTitle) onAppear")
}
- } } // ScrollVStack
- .frame(maxWidth: .infinity, alignment: .leading)
- .padding(.horizontal)
- .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
- .navigationTitle(navTitle)
- .onAppear {
- DebugViewC.shared.setViewID(VIEW_WITHDRAWAL, stack: stack.push())
- symLog.log("❗️ \(navTitle) onAppear")
- }
- .onDisappear {
- symLog.log("❗️ \(navTitle) onDisappear")
+ .onDisappear {
+ symLog.log("❗️ \(navTitle) onDisappear")
+ }
+ } else {
+ WithdrawProgressView(message: exchangeBaseUrl.trimURL())
+ .navigationTitle("Contacting Exchange")
}
- .task(id: amountToTransfer.value) { // re-run this whenever amountToTransfer changes
+ } .task(id: amountToTransfer.value) { // re-run this whenever amountToTransfer changes
+ symLog.log("getExchangeByUrl(\(exchangeBaseUrl))")
do {
- let amount = amountToTransfer.isZero ? Amount(currency: currency, cent: 100)
- : amountToTransfer
-// if amountToTransfer.isZero {
-// tosAccepted = GetTosStatus(exchange.exchangeBaseUrl)
-// } else {
- let details = try await model.loadWithdrawalDetailsForAmountM(exchange.exchangeBaseUrl,
- amount: amount)
- tosAccepted = details.tosAccepted
- withdrawalAmountDetails = amountToTransfer.isZero ? nil : details
-// agePicker.setAges(ages: withdrawalAmountDetails?.ageRestrictionOptions)
-// }
+ if let exc = await model.getExchangeByUrl(url: exchangeBaseUrl) {
+ exchange = exc
+ if !amountToTransfer.isZero {
+ let details = try await model.loadWithdrawalDetailsForAmountM(exchangeBaseUrl,
+ amount: amountToTransfer)
+ withdrawalAmountDetails = details
+// agePicker.setAges(ages: withdrawalAmountDetails?.ageRestrictionOptions)
+ }
+ }
} catch { // TODO: error
symLog.log(error.localizedDescription)
withdrawalAmountDetails = nil
@@ -111,33 +115,15 @@ struct ManualWithdraw: View {
// MARK: -
#if DEBUG
struct ManualWithdraw_Previews: PreviewProvider {
- struct StateContainer : View {
- @State private var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 510)
+ struct StateContainer : View {
+ @State private var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 510)
- var body: some View {
- let scopeInfo = ScopeInfo(type: ScopeInfo.ScopeInfoType.exchange, url: DEMOEXCHANGE, currency: LONGCURRENCY)
- let exchange = Exchange(exchangeBaseUrl: DEMOEXCHANGE,
- currency: LONGCURRENCY,
- paytoUris: [],
- tosStatus: .pending,
- exchangeEntryStatus: .preset,
- exchangeUpdateStatus: .initial,
- ageRestrictionOptions: [])
- let details = WithdrawalAmountDetails(tosAccepted: false,
- amountRaw: Amount(currency: LONGCURRENCY, cent: 510),
- amountEffective: Amount(currency: LONGCURRENCY, cent: 500),
- numCoins: 6,
-// paytoUris: [],
- withdrawalAccountsList: [],
- ageRestrictionOptions: [],
- scopeInfo: scopeInfo)
- ManualWithdraw(stack: CallStack("Preview"),
-// url: nil,
- exchange: exchange,
- amountToTransfer: $amountToTransfer,
- withdrawalAmountDetails: details)
+ var body: some View {
+ ManualWithdraw(stack: CallStack("Preview"),
+ exchangeBaseUrl: DEMOEXCHANGE,
+ amountToTransfer: $amountToTransfer)
+ }
}
- }
static var previews: some View {
StateContainer()
diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
index 4a39eca..05da8fb 100644
--- a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
+++ b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
@@ -19,7 +19,8 @@ struct P2pReceiveURIView: View {
@EnvironmentObject private var model: WalletModel
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
- @State private var peerPushCreditResponse: PreparePeerPushCreditResponse?
+ @State private var peerPushCreditResponse: PreparePeerPushCreditResponse? = nil
+ @State private var exchange: Exchange? = nil
var body: some View {
let badURL = "Error in URL: \(url)"
@@ -41,7 +42,7 @@ struct P2pReceiveURIView: View {
}
.listStyle(myListStyle.style).anyView
.navigationTitle(navTitle)
- let tosAccepted = true // TODO: https://bugs.gnunet.org/view.php?id=7869
+ let tosAccepted = exchange?.tosStatus == .accepted
if tosAccepted {
NavigationLink(destination: LazyView {
P2pAcceptDone(stack: stack.push(),
@@ -54,7 +55,7 @@ struct P2pReceiveURIView: View {
.padding(.horizontal)
} else {
ToSButtonView(stack: stack.push(),
- exchangeBaseUrl: nil,
+ exchangeBaseUrl: peerPushCreditResponse.exchangeBaseUrl,
viewID: SHEET_RCV_P2P_TOS,
p2p: true)
}
@@ -71,8 +72,9 @@ struct P2pReceiveURIView: View {
.task {
do { // TODO: cancelled
symLog.log(".task")
- let ppCreditResponse = try await model.preparePeerPushCreditM(url.absoluteString)
- peerPushCreditResponse = ppCreditResponse
+ let ppResponse = try await model.preparePeerPushCreditM(url.absoluteString)
+ exchange = await model.getExchangeByUrl(url: ppResponse.exchangeBaseUrl)
+ peerPushCreditResponse = ppResponse
} catch { // TODO: error
symLog.log(error.localizedDescription)
peerPushCreditResponse = nil
diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift
index 56773b4..9ae8592 100644
--- a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift
+++ b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift
@@ -21,14 +21,13 @@ struct WithdrawURIView: View {
@EnvironmentObject private var model: WalletModel
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
- // the exchange used for this withdrawal.
- @State private var exchangeBaseUrl: String? = nil
- @State private var withdrawalAmountDetails: WithdrawalAmountDetails?
+ @State private var withdrawalAmountDetails: WithdrawalAmountDetails? = nil
+ @State private var exchange: Exchange? = nil
var body: some View {
let badURL = "Error in URL: \(url)"
VStack {
- if let withdrawalAmountDetails, let exchangeBaseUrl {
+ if let withdrawalAmountDetails, let exchange {
List {
let raw = withdrawalAmountDetails.amountRaw
let effective = withdrawalAmountDetails.amountEffective
@@ -45,7 +44,7 @@ struct WithdrawURIView: View {
bottomAbbrev: String(localized: "Effective:"),
bottomAmount: effective,
large: false, pending: false, incoming: true,
- baseURL: exchangeBaseUrl)
+ baseURL: exchange.exchangeBaseUrl)
let someCoins = SomeCoins(details: withdrawalAmountDetails)
QuiteSomeCoins(someCoins: someCoins,
shouldShowFee: true, // TODO: set to false if we never charge withdrawal fees
@@ -55,11 +54,10 @@ struct WithdrawURIView: View {
}
.listStyle(myListStyle.style).anyView
.navigationTitle(navTitle)
- let tosAccepted = withdrawalAmountDetails.tosAccepted
- if tosAccepted {
+ if exchange.tosStatus == .accepted {
NavigationLink(destination: LazyView {
WithdrawAcceptDone(stack: stack.push(),
- exchangeBaseUrl: exchangeBaseUrl,
+ exchangeBaseUrl: exchange.exchangeBaseUrl,
url: url)
}) {
Text("Confirm Withdrawal") // SHEET_WITHDRAW_ACCEPT
@@ -68,12 +66,12 @@ struct WithdrawURIView: View {
.padding(.horizontal)
} else {
ToSButtonView(stack: stack.push(),
- exchangeBaseUrl: exchangeBaseUrl,
+ exchangeBaseUrl: exchange.exchangeBaseUrl,
viewID: SHEET_WITHDRAW_TOS,
p2p: false)
}
} else {
- // Yikes no details or no baseURL
+ // Yikes no details or no exchange
WithdrawProgressView(message: url.host ?? badURL)
.navigationTitle("Contacting Exchange")
}
@@ -86,15 +84,16 @@ struct WithdrawURIView: View {
do { // TODO: cancelled
symLog.log(".task")
let withdrawUriInfo = try await model.loadWithdrawalDetailsForUriM(url.absoluteString)
- exchangeBaseUrl = withdrawUriInfo.defaultExchangeBaseUrl ??
- withdrawUriInfo.possibleExchanges.first?.exchangeBaseUrl
- if let exchangeBaseUrl {
- let amount = withdrawUriInfo.amount
- let details = try await model.loadWithdrawalDetailsForAmountM(exchangeBaseUrl, amount: amount)
+ let amount = withdrawUriInfo.amount
+ let baseUrl = withdrawUriInfo.defaultExchangeBaseUrl
+ ?? withdrawUriInfo.possibleExchanges.first?.exchangeBaseUrl
+ if let baseUrl, let exc = await model.getExchangeByUrl(url: baseUrl) {
+ exchange = exc
+ let details = try await model.loadWithdrawalDetailsForAmountM(baseUrl, amount: amount)
withdrawalAmountDetails = details
-// agePicker.setAges(ages: details?.ageRestrictionOptions)
+// agePicker.setAges(ages: details?.ageRestrictionOptions)
} else { // TODO: error
- symLog.log("no exchangeBaseUrl")
+ symLog.log("no exchangeBaseUrl or no exchange")
withdrawalAmountDetails = nil
}
} catch { // TODO: error