diff options
Diffstat (limited to 'wallet/src/main/java/net/taler')
9 files changed, 40 insertions, 109 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt index b880036..485df73 100644 --- a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt +++ b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt @@ -34,6 +34,7 @@ import net.taler.wallet.payment.PaymentManager import net.taler.wallet.pending.PendingOperationsManager import net.taler.wallet.refund.RefundManager import net.taler.wallet.transactions.TransactionManager +import net.taler.wallet.transactions.TransactionsResult import net.taler.wallet.withdraw.WithdrawManager import org.json.JSONObject @@ -121,6 +122,14 @@ class MainViewModel(val app: Application) : AndroidViewModel(app) { val amountIncoming = Amount.fromJsonObject(jsonAmountIncoming) balanceMap[currency] = BalanceItem(amount, amountIncoming) } + // TODO remove when wallet-core supports 0 balance for pending transactions + if (balanceMap.isEmpty()) { + val transactionsResult = transactionManager.transactions.value + if (transactionsResult is TransactionsResult.Success && transactionsResult.transactions.isNotEmpty()) { + val currency = transactionsResult.transactions[0].amountRaw.currency + balanceMap[currency] = BalanceItem(Amount.zero(currency), Amount.zero(currency)) + } + } mBalances.postValue(balanceMap) showProgressBar.postValue(false) } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt index 8aaebbc..5c73d6c 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt @@ -107,11 +107,11 @@ class PaymentManager( mDetailsShown.value = !oldValue } - fun confirmPay(proposalId: String) { + fun confirmPay(proposalId: String, currency: String) { val args = JSONObject(mapOf("proposalId" to proposalId)) walletBackendApi.sendRequest("confirmPay", args) { _, _ -> - mPayStatus.postValue(PayStatus.Success) + mPayStatus.postValue(PayStatus.Success(currency)) } } @@ -157,5 +157,5 @@ sealed class PayStatus { data class InsufficientBalance(val contractTerms: ContractTerms) : PayStatus() data class AlreadyPaid(val contractTerms: ContractTerms) : PayStatus() data class Error(val error: String) : PayStatus() - object Success : PayStatus() + data class Success(val currency: String) : PayStatus() } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentSuccessfulFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentSuccessfulFragment.kt deleted file mode 100644 index 2a868b0..0000000 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentSuccessfulFragment.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of GNU Taler - * (C) 2020 Taler Systems S.A. - * - * GNU Taler is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 3, or (at your option) any later version. - * - * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -package net.taler.wallet.payment - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.navigation.fragment.findNavController -import kotlinx.android.synthetic.main.fragment_payment_successful.* -import net.taler.common.fadeIn -import net.taler.wallet.R - -/** - * Fragment that shows the success message for a payment. - */ -class PaymentSuccessfulFragment : Fragment() { - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return inflater.inflate(R.layout.fragment_payment_successful, container, false) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - successImageView.fadeIn() - successTextView.fadeIn() - backButton.setOnClickListener { - findNavController().navigateUp() - } - } - -} diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt index 6d31879..ab109bc 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt @@ -30,14 +30,16 @@ import androidx.lifecycle.observe import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import androidx.transition.TransitionManager.beginDelayedTransition +import com.google.android.material.snackbar.Snackbar +import com.google.android.material.snackbar.Snackbar.LENGTH_LONG import kotlinx.android.synthetic.main.payment_bottom_bar.* import kotlinx.android.synthetic.main.payment_details.* import net.taler.common.Amount import net.taler.common.ContractTerms import net.taler.common.fadeIn import net.taler.common.fadeOut -import net.taler.wallet.R import net.taler.wallet.MainViewModel +import net.taler.wallet.R /** * Show a payment and ask the user to accept/decline. @@ -97,7 +99,10 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { confirmButton.isEnabled = true confirmButton.setOnClickListener { model.showProgressBar.value = true - paymentManager.confirmPay(payStatus.proposalId) + paymentManager.confirmPay( + payStatus.proposalId, + payStatus.contractTerms.amount.currency + ) confirmButton.fadeOut() confirmProgressBar.fadeIn() } @@ -111,7 +116,10 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { is PayStatus.Success -> { showLoading(false) paymentManager.resetPayStatus() - findNavController().navigate(R.id.action_promptPayment_to_paymentSuccessful) + // TODO bring the user to the currency's transaction page, if there's more than one currency + model.transactionManager.selectedCurrency = payStatus.currency + findNavController().navigate(R.id.action_promptPayment_to_nav_main) + Snackbar.make(requireView(), R.string.payment_initiated, LENGTH_LONG).show() } is PayStatus.AlreadyPaid -> { showLoading(false) diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt index 81d53b9..c6c1ecd 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt @@ -45,6 +45,7 @@ class TransactionManager( var selectedCurrency: String? = null var selectedTransaction: Transaction? = null + // TODO maybe cache transactions per currency? private val mTransactions = MutableLiveData<TransactionsResult>() val transactions: LiveData<TransactionsResult> = mTransactions diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt index 7310142..7f573ef 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt @@ -73,9 +73,7 @@ class TransactionWithdrawal( val exchangeBaseUrl: String = "unknown", // TODO fix in wallet-core val confirmed: Boolean, val bankConfirmationUrl: String?, - @JsonProperty("amountEffective") // TODO remove when fixed in wallet-core amountRaw: Amount, - @JsonProperty("amountRaw") // TODO remove when fixed in wallet-core amountEffective: Amount? ) : Transaction(transactionId, timestamp, pending, amountRaw, amountEffective) { override val icon = R.drawable.transaction_withdrawal diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt index 747551b..e700f67 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt @@ -24,12 +24,14 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController +import com.google.android.material.snackbar.Snackbar +import com.google.android.material.snackbar.Snackbar.LENGTH_LONG import kotlinx.android.synthetic.main.fragment_prompt_withdraw.* import net.taler.common.Amount import net.taler.common.fadeIn import net.taler.common.fadeOut -import net.taler.wallet.R import net.taler.wallet.MainViewModel +import net.taler.wallet.R import net.taler.wallet.cleanExchange import net.taler.wallet.withdraw.WithdrawStatus.Loading import net.taler.wallet.withdraw.WithdrawStatus.TermsOfServiceReviewRequired @@ -63,7 +65,11 @@ class PromptWithdrawFragment : Fragment() { setOnClickListener { it.fadeOut() confirmProgressBar.fadeIn() - withdrawManager.acceptWithdrawal(status.talerWithdrawUri, status.exchange) + withdrawManager.acceptWithdrawal( + status.talerWithdrawUri, + status.exchange, + status.amount.currency + ) } isEnabled = true } @@ -71,7 +77,10 @@ class PromptWithdrawFragment : Fragment() { is WithdrawStatus.Success -> { model.showProgressBar.value = false withdrawManager.withdrawStatus.value = null - findNavController().navigate(R.id.action_promptWithdraw_to_withdrawSuccessful) + // TODO bring the user to the currency's transaction page, if there's more than one currency + model.transactionManager.selectedCurrency = status.currency + findNavController().navigate(R.id.action_promptWithdraw_to_nav_main) + Snackbar.make(requireView(), R.string.withdraw_initiated, LENGTH_LONG).show() } is Loading -> { model.showProgressBar.value = true diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt index 6bcd013..75e4daa 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt @@ -43,8 +43,7 @@ sealed class WithdrawStatus { ) : WithdrawStatus() data class Withdrawing(val talerWithdrawUri: String) : WithdrawStatus() - - object Success : WithdrawStatus() + data class Success(val currency: String) : WithdrawStatus() data class Error(val message: String?) : WithdrawStatus() } @@ -145,7 +144,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { } } - fun acceptWithdrawal(talerWithdrawUri: String, selectedExchange: String) { + fun acceptWithdrawal(talerWithdrawUri: String, selectedExchange: String, currency: String) { val args = JSONObject() args.put("talerWithdrawUri", talerWithdrawUri) args.put("selectedExchange", selectedExchange) @@ -154,7 +153,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { walletBackendApi.sendRequest("acceptWithdrawal", args) { isError, result -> if (isError) { - Log.v(TAG, "got acceptWithdrawal error result: ${result.toString(4)}") + Log.v(TAG, "got acceptWithdrawal error result: ${result.toString(2)}") return@sendRequest } Log.v(TAG, "got acceptWithdrawal result") @@ -163,7 +162,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) { Log.w(TAG, "ignoring acceptWithdrawal result, invalid state: $status") return@sendRequest } - withdrawStatus.postValue(WithdrawStatus.Success) + withdrawStatus.postValue(WithdrawStatus.Success(currency)) } } diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawSuccessfulFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawSuccessfulFragment.kt deleted file mode 100644 index 5daeff1..0000000 --- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawSuccessfulFragment.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of GNU Taler - * (C) 2020 Taler Systems S.A. - * - * GNU Taler is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 3, or (at your option) any later version. - * - * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - -package net.taler.wallet.withdraw - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.navigation.fragment.findNavController -import kotlinx.android.synthetic.main.fragment_withdraw_successful.* -import net.taler.wallet.R - -class WithdrawSuccessfulFragment : Fragment() { - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return inflater.inflate(R.layout.fragment_withdraw_successful, container, false) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - backButton.setOnClickListener { - findNavController().navigateUp() - } - } - -} |