From 8ef4610db3ace79ec5d3223a3d9c7ac335ecf8c7 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Fri, 7 Dec 2018 16:10:08 -0600 Subject: [PATCH] - Update graphenej reference to use a new method included to Broadcast a Transaction using the NetworkService's centralized node connection. - Make use of the described new method in Graphenej's NetworkService to actually broadcast a Bitsy transaction to the blockchain. If the transaction is successful then all SendTransactionActivity fields are cleaned, the Send button hiden and a Toast showing that the transaction was successful. If the transaction fails then a Toast shows the error received from the Blockchain explaining the reason for the failure. --- .../fragments/ReceiveTransactionFragment.kt | 6 +++++ .../fragments/SendTransactionFragment.kt | 25 +++++++++++++++++++ graphenejlib | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt index c812567..d19829e 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt @@ -194,4 +194,10 @@ class ReceiveTransactionFragment : Fragment() { tvPleasePay.text = txtAmount tvTo.text = txtAccount } + + override fun onDestroy() { + super.onDestroy() + + if (!mDisposables.isDisposed) mDisposables.dispose() + } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt index 6ac81b9..0bc7c24 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt @@ -34,6 +34,7 @@ import cy.agorise.graphenej.* import cy.agorise.graphenej.api.ConnectionStatusUpdate import cy.agorise.graphenej.api.android.NetworkService import cy.agorise.graphenej.api.android.RxBus +import cy.agorise.graphenej.api.calls.BroadcastTransaction import cy.agorise.graphenej.api.calls.GetAccountByName import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties import cy.agorise.graphenej.api.calls.GetRequiredFees @@ -66,6 +67,7 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv private val RESPONSE_GET_ACCOUNT_BY_NAME = 1 private val RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS = 2 private val RESPONSE_GET_REQUIRED_FEES = 3 + private val RESPONSE_BROADCAST_TRANSACTION = 4 private var isCameraPreviewVisible = false private var isToAccountCorrect = false @@ -213,6 +215,7 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv RESPONSE_GET_ACCOUNT_BY_NAME -> handleAccountName(message.result) RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS -> handleDynamicGlobalProperties(message.result) RESPONSE_GET_REQUIRED_FEES -> handleRequiredFees(message.result) + RESPONSE_BROADCAST_TRANSACTION -> handleBroadcastTransaction(message) } responseMap.remove(message.id) } @@ -262,11 +265,32 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv if (result is List<*> && result[0] is AssetAmount) { Log.d(TAG, "GetRequiredFees: " + transaction.toString()) transaction!!.setFees(result as List) // TODO find how to remove this warning + + val id = mNetworkService!!.sendMessage(BroadcastTransaction(transaction), BroadcastTransaction.REQUIRED_API) + responseMap[id] = RESPONSE_BROADCAST_TRANSACTION } else { // TODO unableToSendTransactionError() } } + private fun handleBroadcastTransaction(message: JsonRpcResponse<*>) { + if (message.result == null && message.error == null) { + // TODO extract string resources + Toast.makeText(context!!, "Transaction sent!", Toast.LENGTH_SHORT).show() + + // Remove information from the text fields and disable send button + tietTo.setText("") + tietAmount.setText("") + tietMemo.setText("") + isToAccountCorrect = false + isAmountCorrect = false + enableDisableSendFAB() + } else { + // TODO extract error messages to show a better explanation to the user + Toast.makeText(context!!, message.error.message, Toast.LENGTH_LONG).show() + } + } + private fun verifyCameraPermission() { if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { @@ -351,6 +375,7 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv val currentAmount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble()) if (currentAmount < amount) { + // TODO extract string resource tilAmount.error = "Not enough funds" isAmountCorrect = false } else { diff --git a/graphenejlib b/graphenejlib index 39afcd2..0cba6a9 160000 --- a/graphenejlib +++ b/graphenejlib @@ -1 +1 @@ -Subproject commit 39afcd26c2cd11e524956417f6ea1c1f87b60af2 +Subproject commit 0cba6a9f8df574bea33b414245d0cc38846d0c4a