From bda2299cb5dd0dfcb161e9a41ed32b1919240d2b Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Tue, 15 Jan 2019 17:06:00 -0600 Subject: [PATCH] Create a list of IDs of BTS and all the SmartCoins in the Constants class, so that we can easily decide whether sending the agorise fee or not. If the Asset ID is contained into the list then the fee is sent. --- .../fragments/SendTransactionFragment.kt | 39 +++++-------------- .../bitsybitshareswallet/utils/Constants.kt | 28 ++++++++++++- 2 files changed, 35 insertions(+), 32 deletions(-) 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 320c580..bb572e1 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt @@ -80,8 +80,6 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand /** Keeps track of the asset's symbol selected in the Asset spinner */ private var selectedAssetSymbol = "" - private var selectedAssetToBTSExchangeRatio = 1.0 - /** Current user account */ private var mUserAccount: UserAccount? = null @@ -199,30 +197,19 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand ) } - /** Handles the selection of items in the Asset spinner, to keep track of the selectedAssetSymbol, show the - * current user's balance of the selected asset and make a call to obtain the Asset <-> BTS exchange rate in case - * Asset != BTS, this latest item is needed to correctly calculate and send the fee to Agorise. */ + /** Handles the selection of items in the Asset spinner, to keep track of the selectedAssetSymbol and show the + * current user's balance of the selected asset. */ private val assetItemSelectedListener = object : AdapterView.OnItemSelectedListener{ override fun onNothingSelected(parent: AdapterView<*>?) { } override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { val balance = mBalancesDetailsAdapter!!.getItem(position)!! selectedAssetSymbol = balance.symbol - val asset = Asset(balance.id) val amount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble()) tvAvailableAssetAmount.text = String.format("%." + Math.min(balance.precision, 8) + "f %s", amount, balance.symbol) - - // Obtain current selected asset to BTS exchange rate - if (balance.symbol == "BTS") - selectedAssetToBTSExchangeRatio = 1.0 - else { - // TODO obtain exchange ratio when selected asset is not BTS -// var id = mNetworkService?.sendMessage(GetRequiredFees(exchangeOperation, asset), -// GetRequiredFees.REQUIRED_API) - } } } @@ -474,6 +461,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand transaction = Transaction(privateKey, null, operations) + // Start the send transaction procedure which includes a series of calls val id = mNetworkService?.sendMessage(GetDynamicGlobalProperties(), GetDynamicGlobalProperties.REQUIRED_API) if (id != null ) responseMap[id] = RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS @@ -482,20 +470,12 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand } /** - * Obtains the correct [TransferOperation] object to send the fee to Agorise. This operation has to always send - * BTS so, depending on the Asset selected there are three possible options: - * a) The Asset is BTS, this is the easiest case because we only need to calculate the fee as a percentage - * of transferOperation's AssetAmount - * b) The Asset is other than BTS and the user has enough BTS to pay the fee, in this case we need to calculate - * the fee in BTS taking into account the Asset <-> BTS exchange rate. - * c) The Asset is other than BTS but the user has not enough BTS to pay the fee, this is the most complex - * scenario because we first need to calculate the fee in BTS taking into account the Asset <-> BTS exchange - * rate, then create an exchange operation to obtain that amount of BTS and finally send that BTS as a fee to - * Agorise. + * Obtains the correct [TransferOperation] object to send the fee to Agorise. A fee is only sent if the Asset is + * BTS or a SmartCoin. */ private fun getAgoriseFeeOperation(transferOperation: TransferOperation): TransferOperation? { - if (transferOperation.assetAmount?.asset?.equals(Constants.BTS) == true) { - // The transfer operation is already in BTS so the fee amount can be easily calculated + // Verify that the current Asset is either BTS or a SmartCoin + if (Constants.assetsWhichSendFeeToAgorise.contains(transferOperation.assetAmount?.asset?.objectId ?: "")) { val fee = transferOperation.assetAmount?.multiplyBy(Constants.FEE_PERCENTAGE) ?: return null return TransferOperationBuilder() @@ -503,9 +483,8 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand .setDestination(Constants.AGORISE_ACCOUNT) .setTransferAmount(fee) .build() - } - // TODO obtain fee amount when the asset to transfer is not BTS - return null + } else + return null } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt index cb32103..4d5ae12 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt @@ -32,8 +32,32 @@ object Constants { /** The account used to send the fees */ val AGORISE_ACCOUNT = UserAccount("1.2.390320", "agorise") - /** Core BTS token */ - val BTS = Asset("1.3.0") + /** List of assets symbols that send fee to Agorise when sending a transaction (BTS and smartcoins only) */ + val assetsWhichSendFeeToAgorise = setOf( + "1.3.0", // BTS + "1.3.113", // CNY + "1.3.121", // USD + "1.3.1325", // RUBLE + "1.3.120", // EUR + "1.3.103", // BTC + "1.3.109", // HKD + "1.3.119", // JPY + "1.3.102", // KRW + "1.3.106", // GOLD + "1.3.105", // SILVER + "1.3.118", // GBP + "1.3.115", // CAD + "1.3.1017", // ARS + "1.3.114", // MXN + "1.3.111", // SEK + "1.3.117", // AUD + "1.3.116", // CHF + "1.3.112", // NZD + "1.3.110", // RUB + "1.3.2650", // XCD + "1.3.107", // TRY + "1.3.108" // SGD + ) /** * LTM accounts come with an expiration date expressed as this string.