Make all smartcoins to show the 'bit' prefix in all the screens that show them, but keeping the original asset symbol unmodified to be used in the places where the symbol is required.
This commit is contained in:
parent
535796b0be
commit
b628260d77
8 changed files with 35 additions and 20 deletions
|
@ -22,7 +22,7 @@ class AssetsAdapter(context: Context, resource: Int, data: List<Asset>) :
|
|||
val text: TextView = cv!!.findViewById(android.R.id.text1)
|
||||
|
||||
val asset = getItem(position)
|
||||
text.text = asset!!.symbol
|
||||
text.text = asset?.toString()
|
||||
|
||||
return cv
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class AssetsAdapter(context: Context, resource: Int, data: List<Asset>) :
|
|||
val text: TextView = v.findViewById(android.R.id.text1)
|
||||
|
||||
val asset = getItem(position)
|
||||
text.text = asset!!.symbol
|
||||
text.text = asset?.toString()
|
||||
|
||||
return v
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ class BalancesAdapter(private val context: Context) :
|
|||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||
val balance = mSortedList.get(position)
|
||||
|
||||
viewHolder.tvSymbol.text = balance.symbol
|
||||
viewHolder.tvSymbol.text = balance.toString()
|
||||
|
||||
val amount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble())
|
||||
viewHolder.tvAmount.text = String.format("%." + Math.min(balance.precision, 8) + "f", amount)
|
||||
|
|
|
@ -26,7 +26,7 @@ class BalancesDetailsAdapter(context: Context, resource: Int, data: List<Balance
|
|||
val text: TextView = cv!!.findViewById(android.R.id.text1)
|
||||
|
||||
val balanceDetail = getItem(position)
|
||||
text.text = balanceDetail!!.symbol
|
||||
text.text = balanceDetail?.toString()
|
||||
|
||||
return cv
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class BalancesDetailsAdapter(context: Context, resource: Int, data: List<Balance
|
|||
val text: TextView = v.findViewById(android.R.id.text1)
|
||||
|
||||
val balanceDetail = getItem(position)
|
||||
text.text = balanceDetail!!.symbol
|
||||
text.text = balanceDetail?.toString()
|
||||
|
||||
return v
|
||||
}
|
||||
|
|
|
@ -13,7 +13,10 @@ data class Asset(
|
|||
@ColumnInfo(name = "description") val description: String,
|
||||
@ColumnInfo(name = "issuer") val issuer: String
|
||||
) {
|
||||
// Add the bit prefix to smartcoins, ie bitUSD, bitEUR, bitMXN, etc.
|
||||
override fun toString(): String {
|
||||
if (issuer == "1.2.0")
|
||||
return "bit$symbol"
|
||||
return symbol
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,13 @@ data class BalanceDetail(
|
|||
val id: String,
|
||||
val amount: Long,
|
||||
val precision: Int,
|
||||
val symbol: String
|
||||
)
|
||||
val symbol: String,
|
||||
val issuer: String
|
||||
) {
|
||||
// Add the bit prefix to smartcoins, ie bitUSD, bitEUR, bitMXN, etc.
|
||||
override fun toString(): String {
|
||||
if (issuer == "1.2.0")
|
||||
return "bit$symbol"
|
||||
return symbol
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import androidx.room.Query
|
|||
|
||||
@Dao
|
||||
interface BalanceDetailDao {
|
||||
@Query("SELECT assets.id AS id, balances.asset_amount AS amount, assets.precision, assets.symbol " +
|
||||
@Query("SELECT assets.id AS id, balances.asset_amount AS amount, assets.precision, assets.symbol, assets.issuer " +
|
||||
"FROM balances INNER JOIN assets on balances.asset_id = assets.id WHERE balances.asset_amount > 0")
|
||||
fun getAll(): LiveData<List<BalanceDetail>>
|
||||
}
|
|
@ -71,6 +71,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
|||
|
||||
private var mAssets = ArrayList<cy.agorise.bitsybitshareswallet.database.entities.Asset>()
|
||||
|
||||
/** Keeps track of the current selected asset symbol */
|
||||
private var selectedAssetSymbol = ""
|
||||
|
||||
/** Used to avoid erasing the QR code when the user selects an item from the AutoComplete suggestions */
|
||||
|
@ -150,7 +151,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
|||
tilAsset.visibility = View.GONE
|
||||
selectedAssetSymbol = asset.symbol
|
||||
|
||||
mAsset = Asset(asset.id, asset.symbol, asset.precision)
|
||||
mAsset = Asset(asset.id, asset.toString(), asset.precision)
|
||||
}
|
||||
updateQR()
|
||||
}
|
||||
|
@ -194,7 +195,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
|||
|
||||
actvAsset.setOnItemClickListener { parent, _, position, _ ->
|
||||
val asset = parent.adapter.getItem(position) as cy.agorise.bitsybitshareswallet.database.entities.Asset
|
||||
mAsset = Asset(asset.id, asset.symbol, asset.precision)
|
||||
mAsset = Asset(asset.id, asset.toString(), asset.precision)
|
||||
selectedInAutoCompleteTextView = true
|
||||
updateQR()
|
||||
}
|
||||
|
@ -250,23 +251,26 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
|||
return
|
||||
}
|
||||
|
||||
val asset = mAsset!!
|
||||
|
||||
// Try to obtain the amount from the Amount Text Field or make it zero otherwise
|
||||
val amount: Long = try {
|
||||
val tmpAmount = tietAmount.text.toString().toDouble()
|
||||
(tmpAmount * Math.pow(10.0, mAsset!!.precision.toDouble())).toLong()
|
||||
(tmpAmount * Math.pow(10.0, asset.precision.toDouble())).toLong()
|
||||
}catch (e: Exception) {
|
||||
0
|
||||
}
|
||||
|
||||
val total = AssetAmount(UnsignedLong.valueOf(amount), mAsset!!)
|
||||
val total = AssetAmount(UnsignedLong.valueOf(amount), asset)
|
||||
val totalInDouble = Util.fromBase(total)
|
||||
val items = arrayOf(LineItem("transfer", 1, totalInDouble))
|
||||
val invoice = Invoice(mUserAccount!!.name, "", "", mAsset!!.symbol, items, "", "")
|
||||
val invoice = Invoice(mUserAccount?.name, "", "",
|
||||
asset.symbol.replaceFirst("bit", ""), items, "", "")
|
||||
Log.d(TAG, "invoice: " + invoice.toJsonString())
|
||||
try {
|
||||
val bitmap = encodeAsBitmap(Invoice.toQrCode(invoice), "#139657") // PalmPay green
|
||||
ivQR.setImageBitmap(bitmap)
|
||||
updateAmountAddressUI(total, mUserAccount!!.name)
|
||||
updateAmountAddressUI(amount, asset.symbol, asset.precision, mUserAccount!!.name)
|
||||
} catch (e: WriterException) {
|
||||
Log.e(TAG, "WriterException. Msg: " + e.message)
|
||||
}
|
||||
|
@ -323,17 +327,17 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
|||
* @param total Total Amount in crypto to be paid
|
||||
* @param account Account to pay total
|
||||
*/
|
||||
private fun updateAmountAddressUI(total: AssetAmount, account: String) {
|
||||
val txtAmount: String = if (total.amount.toLong() == 0L) {
|
||||
private fun updateAmountAddressUI(assetAmount: Long, assetSymbol: String, assetPrecision: Int, account: String) {
|
||||
val txtAmount: String = if (assetAmount == 0L) {
|
||||
getString(R.string.template__please_send, getString(R.string.text__any_amount), " ")
|
||||
} else {
|
||||
val df = DecimalFormat("####."+("#".repeat(total.asset.precision)))
|
||||
val df = DecimalFormat("####."+("#".repeat(assetPrecision)))
|
||||
df.roundingMode = RoundingMode.CEILING
|
||||
df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault())
|
||||
|
||||
val amount = total.amount.toDouble() / Math.pow(10.toDouble(), total.asset.precision.toDouble())
|
||||
val amount = assetAmount.toDouble() / Math.pow(10.toDouble(), assetPrecision.toDouble())
|
||||
val strAmount = df.format(amount)
|
||||
getString(R.string.template__please_send, strAmount, total.asset.symbol)
|
||||
getString(R.string.template__please_send, strAmount, assetSymbol)
|
||||
}
|
||||
|
||||
val txtAccount = getString(R.string.template__to, account)
|
||||
|
|
|
@ -213,7 +213,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
|||
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)
|
||||
String.format("%." + Math.min(balance.precision, 8) + "f %s", amount, balance.toString())
|
||||
|
||||
validateAmount()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue