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.
This commit is contained in:
parent
529d5db41d
commit
bda2299cb5
2 changed files with 35 additions and 32 deletions
|
@ -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,8 +483,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
|||
.setDestination(Constants.AGORISE_ACCOUNT)
|
||||
.setTransferAmount(fee)
|
||||
.build()
|
||||
}
|
||||
// TODO obtain fee amount when the asset to transfer is not BTS
|
||||
} else
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue