- 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.
This commit is contained in:
parent
04b509651b
commit
8ef4610db3
3 changed files with 32 additions and 1 deletions
|
@ -194,4 +194,10 @@ class ReceiveTransactionFragment : Fragment() {
|
||||||
tvPleasePay.text = txtAmount
|
tvPleasePay.text = txtAmount
|
||||||
tvTo.text = txtAccount
|
tvTo.text = txtAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
|
||||||
|
if (!mDisposables.isDisposed) mDisposables.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -34,6 +34,7 @@ import cy.agorise.graphenej.*
|
||||||
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
||||||
import cy.agorise.graphenej.api.android.NetworkService
|
import cy.agorise.graphenej.api.android.NetworkService
|
||||||
import cy.agorise.graphenej.api.android.RxBus
|
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.GetAccountByName
|
||||||
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties
|
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties
|
||||||
import cy.agorise.graphenej.api.calls.GetRequiredFees
|
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_ACCOUNT_BY_NAME = 1
|
||||||
private val RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS = 2
|
private val RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS = 2
|
||||||
private val RESPONSE_GET_REQUIRED_FEES = 3
|
private val RESPONSE_GET_REQUIRED_FEES = 3
|
||||||
|
private val RESPONSE_BROADCAST_TRANSACTION = 4
|
||||||
|
|
||||||
private var isCameraPreviewVisible = false
|
private var isCameraPreviewVisible = false
|
||||||
private var isToAccountCorrect = 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_ACCOUNT_BY_NAME -> handleAccountName(message.result)
|
||||||
RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS -> handleDynamicGlobalProperties(message.result)
|
RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS -> handleDynamicGlobalProperties(message.result)
|
||||||
RESPONSE_GET_REQUIRED_FEES -> handleRequiredFees(message.result)
|
RESPONSE_GET_REQUIRED_FEES -> handleRequiredFees(message.result)
|
||||||
|
RESPONSE_BROADCAST_TRANSACTION -> handleBroadcastTransaction(message)
|
||||||
}
|
}
|
||||||
responseMap.remove(message.id)
|
responseMap.remove(message.id)
|
||||||
}
|
}
|
||||||
|
@ -262,11 +265,32 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
|
||||||
if (result is List<*> && result[0] is AssetAmount) {
|
if (result is List<*> && result[0] is AssetAmount) {
|
||||||
Log.d(TAG, "GetRequiredFees: " + transaction.toString())
|
Log.d(TAG, "GetRequiredFees: " + transaction.toString())
|
||||||
transaction!!.setFees(result as List<AssetAmount>) // TODO find how to remove this warning
|
transaction!!.setFees(result as List<AssetAmount>) // TODO find how to remove this warning
|
||||||
|
|
||||||
|
val id = mNetworkService!!.sendMessage(BroadcastTransaction(transaction), BroadcastTransaction.REQUIRED_API)
|
||||||
|
responseMap[id] = RESPONSE_BROADCAST_TRANSACTION
|
||||||
} else {
|
} else {
|
||||||
// TODO unableToSendTransactionError()
|
// 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() {
|
private fun verifyCameraPermission() {
|
||||||
if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.CAMERA)
|
if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.CAMERA)
|
||||||
!= PackageManager.PERMISSION_GRANTED) {
|
!= 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())
|
val currentAmount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble())
|
||||||
|
|
||||||
if (currentAmount < amount) {
|
if (currentAmount < amount) {
|
||||||
|
// TODO extract string resource
|
||||||
tilAmount.error = "Not enough funds"
|
tilAmount.error = "Not enough funds"
|
||||||
isAmountCorrect = false
|
isAmountCorrect = false
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 39afcd26c2cd11e524956417f6ea1c1f87b60af2
|
Subproject commit 0cba6a9f8df574bea33b414245d0cc38846d0c4a
|
Loading…
Reference in a new issue