Updated on 2026-08-14
This commit is contained in:
commit
5ea3c46a37
6 changed files with 46 additions and 14 deletions
|
|
@ -32,6 +32,7 @@ import kotlinx.coroutines.flow.*
|
|||
import kotlinx.coroutines.launch
|
||||
import org.rekotlin.Action
|
||||
import org.rekotlin.Middleware
|
||||
import timber.log.Timber
|
||||
import java.util.Locale
|
||||
|
||||
object GlobalMiddleware {
|
||||
|
|
@ -190,6 +191,7 @@ private fun handleAction(action: Action, appState: () -> AppState?) {
|
|||
.getAll(userWallet.walletId)
|
||||
.distinctUntilChanged()
|
||||
.onEach(infoHolder::setWalletsInfo)
|
||||
.catch { Timber.e(it) }
|
||||
.launchIn(mainScope)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,12 @@ class WalletConnectSdkHelper {
|
|||
SimpleResult.Success -> {
|
||||
val sentFrom = AnalyticsParam.TxSentFrom.WalletConnect
|
||||
Analytics.send(Basic.TransactionSent(sentFrom = sentFrom, memoType = MemoType.Null))
|
||||
HEX_PREFIX + data.walletManager.wallet.recentTransactions.last().hash
|
||||
val hash = data.walletManager.wallet.recentTransactions.last().hash
|
||||
if (hash?.startsWith(HEX_PREFIX) == true) {
|
||||
hash
|
||||
} else {
|
||||
HEX_PREFIX + hash
|
||||
}
|
||||
}
|
||||
is SimpleResult.Failure -> {
|
||||
Timber.e(result.error as BlockchainSdkError)
|
||||
|
|
@ -202,12 +207,17 @@ class WalletConnectSdkHelper {
|
|||
val result = tangemSdkManager.runTaskAsync(command, initialMessage = Message(), cardId = cardId)
|
||||
return when (result) {
|
||||
is CompletionResult.Success -> {
|
||||
HEX_PREFIX + EthereumUtils.prepareTransactionToSend(
|
||||
val hash = EthereumUtils.prepareTransactionToSend(
|
||||
signature = result.data.signature,
|
||||
transactionToSign = dataToSign,
|
||||
walletPublicKey = data.walletManager.wallet.publicKey,
|
||||
blockchain = data.walletManager.wallet.blockchain,
|
||||
).toHexString()
|
||||
if (hash.startsWith(HEX_PREFIX)) {
|
||||
hash
|
||||
} else {
|
||||
HEX_PREFIX + hash
|
||||
}
|
||||
}
|
||||
is CompletionResult.Failure -> {
|
||||
Timber.e(result.error.customMessage)
|
||||
|
|
|
|||
|
|
@ -13,9 +13,8 @@ internal class AddressValidator {
|
|||
suspend fun validateAddress(walletManager: WalletManager, address: String): AddressVerifyAction.Error? {
|
||||
val blockchain = walletManager.wallet.blockchain
|
||||
val wallet = walletManager.wallet
|
||||
return if ((blockchain == Blockchain.Near || blockchain == Blockchain.NearTestnet) &&
|
||||
address.length != NEAR_IMPLICIT_ADDRESS_LENGTH
|
||||
) {
|
||||
|
||||
return if (blockchain.isNear()) {
|
||||
validateNearAddress(walletManager, address)
|
||||
} else {
|
||||
validateAddress(wallet, address)
|
||||
|
|
@ -26,12 +25,28 @@ internal class AddressValidator {
|
|||
walletManager: WalletManager,
|
||||
address: String,
|
||||
): AddressVerifyAction.Error? {
|
||||
val result = (walletManager as? NearWalletManager)?.getAccount(address)
|
||||
return if (result is Result.Success && result.data is NearAccount.Full) {
|
||||
null
|
||||
} else {
|
||||
AddressVerifyAction.Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN
|
||||
// implicit address validation
|
||||
if (address.length == NEAR_IMPLICIT_ADDRESS_LENGTH && hexRegex.matches(address)) {
|
||||
return validateAddress(walletManager.wallet, address)
|
||||
}
|
||||
|
||||
// named address validation
|
||||
if (address.length in NEAR_MIN_ADDRESS_LENGTH until NEAR_IMPLICIT_ADDRESS_LENGTH &&
|
||||
nearAddressRegex.matches(address)
|
||||
) {
|
||||
val result = (walletManager as? NearWalletManager)?.getAccount(address)
|
||||
return if (result is Result.Success && result.data is NearAccount.Full) {
|
||||
null
|
||||
} else {
|
||||
AddressVerifyAction.Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN
|
||||
}
|
||||
}
|
||||
|
||||
return AddressVerifyAction.Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN
|
||||
}
|
||||
|
||||
private fun Blockchain.isNear(): Boolean {
|
||||
return this == Blockchain.Near || this == Blockchain.NearTestnet
|
||||
}
|
||||
|
||||
private fun validateAddress(wallet: Wallet, address: String): AddressVerifyAction.Error? {
|
||||
|
|
@ -47,6 +62,9 @@ internal class AddressValidator {
|
|||
}
|
||||
|
||||
companion object {
|
||||
private const val NEAR_MIN_ADDRESS_LENGTH = 2
|
||||
private const val NEAR_IMPLICIT_ADDRESS_LENGTH = 64
|
||||
private val hexRegex = Regex("^[0-9a-f]+$")
|
||||
private val nearAddressRegex = Regex("^(([a-z\\d]+[\\-_])*[a-z\\d]+\\.)*([a-z\\d]+[\\-_])*[a-z\\d]+\$")
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.tangem.datasource.files
|
|||
|
||||
import android.content.Context
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import okio.use
|
||||
import javax.inject.Inject
|
||||
|
||||
class AndroidFileReader @Inject constructor(@ApplicationContext private val context: Context) : FileReader {
|
||||
|
|
@ -16,7 +17,10 @@ class AndroidFileReader @Inject constructor(@ApplicationContext private val cont
|
|||
|
||||
override fun rewriteFile(content: String, fileName: String) {
|
||||
context.openFileOutput(fileName, Context.MODE_PRIVATE).use { stream ->
|
||||
stream.write(content.toByteArray(), 0, content.length)
|
||||
stream.writer().use { writer ->
|
||||
// warning: don't write byteArray as json, its break cyrillic encoding
|
||||
writer.write(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -226,6 +226,4 @@ private val excludedBlockchains = listOf(
|
|||
Blockchain.Ducatus,
|
||||
Blockchain.Telos,
|
||||
Blockchain.TelosTestnet,
|
||||
Blockchain.Near,
|
||||
Blockchain.NearTestnet,
|
||||
)
|
||||
|
|
@ -82,7 +82,7 @@ spr-client = "3.6.2"
|
|||
# endregion Other libraries
|
||||
|
||||
# region Tangem
|
||||
tangemBlockchainSdk = "develop-377"
|
||||
tangemBlockchainSdk = "develop-380"
|
||||
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
|
||||
tangemCardSdk = "develop-310"
|
||||
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue