Updated on 2026-08-14
This commit is contained in:
parent
1c82ef2c7b
commit
fd23ba7da7
5 changed files with 95 additions and 25 deletions
|
|
@ -20,7 +20,7 @@ public enum Blockchain {
|
|||
Rootstock("RSK", "RBTC", 1.0, R.drawable.tangem2, "RSK"),
|
||||
RootstockToken("RskToken", "RBTC", 1.0, R.drawable.tangem2, "RSK"),
|
||||
Cardano("CARDANO", "ADA", 1000000.0, R.drawable.tangem2, "Cardano"),
|
||||
Ripple("XRP", "XRP", 1000000.0, R.drawable.ic_logo_xrp, "XRP"),
|
||||
Ripple("XRP", "XRP", 1000000.0, R.drawable.ic_logo_xrp, "XRP Ledger"),
|
||||
Binance("BINANCE", "BNB", 100000000.0, R.drawable.ic_logo_binance, "Binance"),
|
||||
BinanceTestNet("BINANCE/test", "BNB", 100000000.0, R.drawable.ic_logo_binance, "Binance Testnet"),
|
||||
BinanceAsset("BinanceAsset", "BNB", 100000000.0, R.drawable.ic_logo_binance, "Binance"),
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import com.tangem.App
|
|||
import com.tangem.Constant
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.dp.PrefsManager
|
||||
import com.tangem.server_android.PayIdResponse
|
||||
import com.tangem.server_android.Result
|
||||
import com.tangem.server_android.ServerApiTangem
|
||||
import com.tangem.server_android.model.CardVerifyAndGetInfo
|
||||
|
|
@ -67,6 +66,7 @@ class LoadedWalletFragment : BaseFragment(), NavigationResultListener, NfcAdapte
|
|||
companion object {
|
||||
val TAG: String = LoadedWalletFragment::class.java.simpleName
|
||||
const val PAY_ID_TANGEM = "\$payid.tangem.com"
|
||||
val payIdSupported = setOf(Blockchain.Ripple, Blockchain.Ethereum, Blockchain.Bitcoin)
|
||||
}
|
||||
|
||||
override val layoutId = R.layout.fr_loaded_wallet
|
||||
|
|
@ -149,21 +149,26 @@ class LoadedWalletFragment : BaseFragment(), NavigationResultListener, NfcAdapte
|
|||
btnExtract.backgroundTintList = inactiveColor
|
||||
|
||||
tvWallet.text = ctx.coinData.wallet
|
||||
btnLoadItems = mutableListOf<CharSequence>(
|
||||
|
||||
btnLoadItems = mutableListOf(
|
||||
getString(R.string.loaded_wallet_load_via_app),
|
||||
getString(R.string.loaded_wallet_load_via_share_address),
|
||||
getString(R.string.loaded_wallet_load_via_qr)
|
||||
)
|
||||
if (ctx.blockchain == Blockchain.Ripple) {
|
||||
|
||||
if (payIdSupported.contains(ctx.blockchain)) {
|
||||
ivPayId.visibility = View.VISIBLE
|
||||
ivPayId.imageAlpha = 100
|
||||
ivPayId.setOnClickListener { createPayIdDialog() }
|
||||
|
||||
viewModel.getPayId(
|
||||
Util.byteArrayToHexString(ctx.card?.cid!!),
|
||||
Util.byteArrayToHexString(ctx.card?.cardPublicKey!!))
|
||||
Util.byteArrayToHexString(ctx.card.cid!!),
|
||||
Util.byteArrayToHexString(ctx.card.cardPublicKey!!))
|
||||
.observe(
|
||||
viewLifecycleOwner, Observer<Result<PayIdResponse>> { result ->
|
||||
viewLifecycleOwner, Observer { result ->
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
payId = result.data.payId
|
||||
btnLoadItems.add(result.data.payId)
|
||||
onPayIdFound(result.data.payId)
|
||||
}
|
||||
is Result.Failure -> {
|
||||
(result.error as? HttpException)?.let {
|
||||
|
|
@ -365,21 +370,21 @@ class LoadedWalletFragment : BaseFragment(), NavigationResultListener, NfcAdapte
|
|||
}
|
||||
|
||||
private fun createPayId(payId: String) {
|
||||
val network = if (ctx.blockchain == Blockchain.Ripple) "XRPL" else ctx.blockchain.id
|
||||
viewModel.setPayId(
|
||||
Util.byteArrayToHexString(ctx.card!!.cid!!),
|
||||
Util.byteArrayToHexString(ctx.card!!.cardPublicKey!!),
|
||||
payId,
|
||||
ctx.coinData.wallet,
|
||||
ctx.blockchain.id
|
||||
network
|
||||
)
|
||||
.observe(viewLifecycleOwner, Observer { result ->
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
this.payId = payId
|
||||
if (btnLoadItems.last() == getString(R.string.loaded_wallet_create_pay_id)) {
|
||||
btnLoadItems.removeAt(btnLoadItems.lastIndex)
|
||||
}
|
||||
btnLoadItems.add(payId)
|
||||
onPayIdFound(payId)
|
||||
Toast.makeText(context, getString(R.string.create_pay_id_success), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
is Result.Failure -> {
|
||||
|
|
@ -389,6 +394,13 @@ class LoadedWalletFragment : BaseFragment(), NavigationResultListener, NfcAdapte
|
|||
})
|
||||
}
|
||||
|
||||
private fun onPayIdFound(payId: String) {
|
||||
ivPayId.imageAlpha = 255
|
||||
this.payId = payId
|
||||
btnLoadItems.add(payId)
|
||||
ivPayId.setOnClickListener { copyText(payId) }
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (timerHideErrorAndMessage != null) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.tangem.server_android.PayIdService
|
|||
import com.tangem.server_android.Result
|
||||
import com.tangem.server_android.SetPayIdResponse
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
|
||||
class LoadedWalletViewModel : ViewModel() {
|
||||
private val serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
|
|
@ -20,7 +21,9 @@ class LoadedWalletViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
private val payId: LiveData<Result<PayIdResponse>> = MutableLiveData()
|
||||
private val scope = viewModelScope.coroutineContext + CoroutineExceptionHandler { _, ex ->
|
||||
throw ex
|
||||
}
|
||||
|
||||
fun getRateInfo(): LiveData<Float> {
|
||||
return rate
|
||||
|
|
@ -62,7 +65,7 @@ class LoadedWalletViewModel : ViewModel() {
|
|||
address: String,
|
||||
network: String
|
||||
): LiveData<Result<SetPayIdResponse>> {
|
||||
return liveData(viewModelScope.coroutineContext) {
|
||||
return liveData(scope) {
|
||||
emit(
|
||||
payIdService.setPayId(
|
||||
cardId, publicKey, payId, address, network
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue