Properly handle the response from the node when trying to upgrade the current account to LTM. When it is successful the app shows a dialog explaining just that and also sends a request to the node to update the account info, to update the account with the LTM property set as true. When it is not successful, the app shows a dialog explaining that there was an error due maybe to an insuficient balance.

This commit is contained in:
Severiano Jaramillo 2019-02-25 09:01:45 -06:00
parent 0330588885
commit 6439b55c69
3 changed files with 32 additions and 6 deletions

View file

@ -9,7 +9,6 @@ import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProviders
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss import com.afollestad.materialdialogs.callbacks.onDismiss
@ -24,11 +23,11 @@ import cy.agorise.bitsybitshareswallet.adapters.FullNodesAdapter
import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository
import cy.agorise.bitsybitshareswallet.utils.Constants import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.utils.CryptoUtils import cy.agorise.bitsybitshareswallet.utils.CryptoUtils
import cy.agorise.bitsybitshareswallet.utils.toast
import cy.agorise.bitsybitshareswallet.viewmodels.SettingsFragmentViewModel import cy.agorise.bitsybitshareswallet.viewmodels.SettingsFragmentViewModel
import cy.agorise.graphenej.* import cy.agorise.graphenej.*
import cy.agorise.graphenej.api.ConnectionStatusUpdate import cy.agorise.graphenej.api.ConnectionStatusUpdate
import cy.agorise.graphenej.api.calls.BroadcastTransaction import cy.agorise.graphenej.api.calls.BroadcastTransaction
import cy.agorise.graphenej.api.calls.GetAccounts
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties
import cy.agorise.graphenej.models.DynamicGlobalProperties import cy.agorise.graphenej.models.DynamicGlobalProperties
import cy.agorise.graphenej.models.JsonRpcResponse import cy.agorise.graphenej.models.JsonRpcResponse
@ -219,16 +218,35 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
val id = mNetworkService?.sendMessage(BroadcastTransaction(ltmTransaction), BroadcastTransaction.REQUIRED_API) val id = mNetworkService?.sendMessage(BroadcastTransaction(ltmTransaction), BroadcastTransaction.REQUIRED_API)
if (id != null) responseMap[id] = RESPONSE_BROADCAST_TRANSACTION if (id != null) responseMap[id] = RESPONSE_BROADCAST_TRANSACTION
// TODO use an indicator to show that a transaction is in progress
} }
} }
/** Handles the result of the [BroadcastTransaction] api call to find out if the Transaction was sent successfully /** Handles the result of the [BroadcastTransaction] api call to find out if the Transaction to upgrade the
* or not and acts accordingly */ * current account to LTM was successful or not */
private fun handleBroadcastTransaction(message: JsonRpcResponse<*>) { private fun handleBroadcastTransaction(message: JsonRpcResponse<*>) {
if (message.result == null && message.error == null) { if (message.result == null && message.error == null) {
// TODO test on the testnet the actual LTM upgrade // Looks like the upgrade to LTM was successful, we need to update the current account information from
// the blockchain and show a success dialog
mNetworkService?.sendMessage(GetAccounts(mUserAccount), GetAccounts.REQUIRED_API)
context?.let { context ->
MaterialDialog(context).show {
title(R.string.title__account_upgraded)
message(R.string.msg__account_upgraded)
positiveButton(android.R.string.ok)
}
}
} else if (message.error != null) { } else if (message.error != null) {
context?.toast(message.error.message, Toast.LENGTH_LONG) // The upgrade to LTM wasn't successful, show a dialog to the user explaining the situation
context?.let { context ->
MaterialDialog(context).show {
title(R.string.title__upgrade_account_error)
message(R.string.msg__upgrade_account_error)
positiveButton(android.R.string.ok)
}
}
} }
} }

View file

@ -137,6 +137,10 @@
<string name="msg__upgrade_to_ltm">Actualiza a la membresía de por vida (LTM). Las cuentas LTM de Bitshares pagan las tarifas más bajas, obtienen un 80% de devolución de dinero y bonificaciones por referencias.</string> <string name="msg__upgrade_to_ltm">Actualiza a la membresía de por vida (LTM). Las cuentas LTM de Bitshares pagan las tarifas más bajas, obtienen un 80% de devolución de dinero y bonificaciones por referencias.</string>
<string name="button__upgrade_to_ltm">Ascender a LTM</string> <string name="button__upgrade_to_ltm">Ascender a LTM</string>
<string name="msg__account_upgrade_dialog">La membresía de por vida te permite operar con tarifas de red muy reducidas.\n\nTendrá efecto en la cuenta actual "%1$s"\n\nSin embargo, tiene un costo de alrededor de 100 USD pagados en Bitshares.\n\n¿Estás seguro de que deseas continuar?</string> <string name="msg__account_upgrade_dialog">La membresía de por vida te permite operar con tarifas de red muy reducidas.\n\nTendrá efecto en la cuenta actual "%1$s"\n\nSin embargo, tiene un costo de alrededor de 100 USD pagados en Bitshares.\n\n¿Estás seguro de que deseas continuar?</string>
<string name="title__account_upgraded">Cuenta Actualizada</string>
<string name="msg__account_upgraded">¡Felicidades! Tu cuenta ahora se ha actualizado a la membresía de por vida (LTM).</string>
<string name="title__upgrade_account_error">Error al intentar actualizar la cuenta</string>
<string name="msg__upgrade_account_error">Por favor, asegúrate de que tu cuenta tenga un balance suficiente para cubrir los costos.</string>
<string name="title__bugs_or_ideas">Errores o Ideas?</string> <string name="title__bugs_or_ideas">Errores o Ideas?</string>
<string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string> <string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string>
<string name="title__bitshares_nodes_dialog">Bloque: %1$s</string> <string name="title__bitshares_nodes_dialog">Bloque: %1$s</string>

View file

@ -138,6 +138,10 @@
<string name="msg__upgrade_to_ltm">Upgrade to LifeTime Membership (LTM). Bitshares\' LTM accounts pay near-zero fees, get 80% cashback and bonuses for referrals.</string> <string name="msg__upgrade_to_ltm">Upgrade to LifeTime Membership (LTM). Bitshares\' LTM accounts pay near-zero fees, get 80% cashback and bonuses for referrals.</string>
<string name="button__upgrade_to_ltm">Upgrade to LTM</string> <string name="button__upgrade_to_ltm">Upgrade to LTM</string>
<string name="msg__account_upgrade_dialog">The Life Time Membership allows you to trade with a reduced set of network fees.\n\nIt will take effect to the current account "%1$s"\n\nIt does however come with a cost of around 100 USD paid in Bitshares.\n\nAre you sure you want to proceed?</string> <string name="msg__account_upgrade_dialog">The Life Time Membership allows you to trade with a reduced set of network fees.\n\nIt will take effect to the current account "%1$s"\n\nIt does however come with a cost of around 100 USD paid in Bitshares.\n\nAre you sure you want to proceed?</string>
<string name="title__account_upgraded">Account Upgraded</string>
<string name="msg__account_upgraded">Congratulations! Your account has now been upgraded to the Lifetime Membership.</string>
<string name="title__upgrade_account_error">Error while trying to upgrade account</string>
<string name="msg__upgrade_account_error">Please make sure your account has enough balance to cover the costs.</string>
<string name="title__bugs_or_ideas">Bugs or Ideas?</string> <string name="title__bugs_or_ideas">Bugs or Ideas?</string>
<string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string> <string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string>
<string name="title__bitshares_nodes_dialog">Block: %1$s</string> <string name="title__bitshares_nodes_dialog">Block: %1$s</string>