From 6439b55c6904c877a245f6bdaa1217022c69066a Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Mon, 25 Feb 2019 09:01:45 -0600 Subject: [PATCH] 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. --- .../fragments/SettingsFragment.kt | 30 +++++++++++++++---- app/src/main/res/values-es/strings.xml | 4 +++ app/src/main/res/values/strings.xml | 4 +++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt index e863a56..10a36da 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt @@ -9,7 +9,6 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Toast import androidx.lifecycle.ViewModelProviders import com.afollestad.materialdialogs.MaterialDialog 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.utils.Constants import cy.agorise.bitsybitshareswallet.utils.CryptoUtils -import cy.agorise.bitsybitshareswallet.utils.toast import cy.agorise.bitsybitshareswallet.viewmodels.SettingsFragmentViewModel import cy.agorise.graphenej.* import cy.agorise.graphenej.api.ConnectionStatusUpdate 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.models.DynamicGlobalProperties import cy.agorise.graphenej.models.JsonRpcResponse @@ -219,16 +218,35 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter val id = mNetworkService?.sendMessage(BroadcastTransaction(ltmTransaction), BroadcastTransaction.REQUIRED_API) 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 - * or not and acts accordingly */ + /** Handles the result of the [BroadcastTransaction] api call to find out if the Transaction to upgrade the + * current account to LTM was successful or not */ private fun handleBroadcastTransaction(message: JsonRpcResponse<*>) { 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) { - 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) + } + } } } diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index fe67365..2400bee 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -137,6 +137,10 @@ 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. Ascender a LTM 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? + Cuenta Actualizada + ¡Felicidades! Tu cuenta ahora se ha actualizado a la membresía de por vida (LTM). + Error al intentar actualizar la cuenta + Por favor, asegúrate de que tu cuenta tenga un balance suficiente para cubrir los costos. Errores o Ideas? Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise Bloque: %1$s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a9b27ea..4a11ce1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -138,6 +138,10 @@ Upgrade to LifeTime Membership (LTM). Bitshares\' LTM accounts pay near-zero fees, get 80% cashback and bonuses for referrals. Upgrade to LTM 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? + Account Upgraded + Congratulations! Your account has now been upgraded to the Lifetime Membership. + Error while trying to upgrade account + Please make sure your account has enough balance to cover the costs. Bugs or Ideas? Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise Block: %1$s