Updated on 2026-08-14
This commit is contained in:
parent
e79bbf29ad
commit
ee69ff5fb3
2 changed files with 45 additions and 37 deletions
|
|
@ -4,31 +4,32 @@ import com.tangem.blockchain.common.Blockchain
|
|||
import com.tangem.blockchainsdk.utils.fromNetworkId
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.utils.converter.Converter
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class BlockAidChainNameConverter @Inject constructor() : Converter<Network, String> {
|
||||
internal object BlockAidChainNameConverter : Converter<Network, String?> {
|
||||
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
override fun convert(value: Network): String {
|
||||
override fun convert(value: Network): String? {
|
||||
return when (Blockchain.fromNetworkId(value.backendId)) {
|
||||
Blockchain.Arbitrum -> "arbitrum"
|
||||
Blockchain.Avalanche -> "avalanche"
|
||||
Blockchain.AvalancheTestnet -> "avalanche-fuji"
|
||||
Blockchain.Binance, Blockchain.BSC -> "bsc"
|
||||
Blockchain.Ethereum -> "ethereum"
|
||||
Blockchain.EthereumTestnet -> "ethereum-sepolia"
|
||||
Blockchain.Polygon -> "polygon"
|
||||
Blockchain.Solana -> "mainnet"
|
||||
Blockchain.Gnosis -> "gnosis"
|
||||
Blockchain.Optimism -> "optimism"
|
||||
Blockchain.ZkSyncEra -> "zksync"
|
||||
Blockchain.ZkSyncEraTestnet -> "zksync-sepolia"
|
||||
Blockchain.Base -> "base"
|
||||
Blockchain.BaseTestnet -> "base-sepolia"
|
||||
Blockchain.Binance, Blockchain.BSC -> "bsc"
|
||||
Blockchain.Ethereum -> "ethereum"
|
||||
Blockchain.Optimism -> "optimism"
|
||||
Blockchain.Polygon -> "polygon"
|
||||
Blockchain.ZkSyncEra -> "zksync"
|
||||
Blockchain.ZkSyncEraTestnet -> "zksync-sepolia"
|
||||
Blockchain.Blast, Blockchain.BlastTestnet -> "blast"
|
||||
Blockchain.ApeChain, Blockchain.ApeChainTestnet -> "apechain"
|
||||
Blockchain.Scroll -> "scroll"
|
||||
else -> value.name
|
||||
Blockchain.EthereumTestnet -> "ethereum-sepolia"
|
||||
Blockchain.Gnosis -> "gnosis"
|
||||
Blockchain.ApeChain, Blockchain.ApeChainTestnet -> "apechain"
|
||||
|
||||
Blockchain.Solana -> "mainnet"
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,6 @@ import javax.inject.Inject
|
|||
|
||||
internal class BlockAidVerificationDelegate @Inject constructor(
|
||||
private val blockAidVerifier: BlockAidVerifier,
|
||||
private val blockAidChainNameConverter: BlockAidChainNameConverter,
|
||||
) {
|
||||
|
||||
fun getSecurityStatus(
|
||||
|
|
@ -27,7 +26,6 @@ internal class BlockAidVerificationDelegate @Inject constructor(
|
|||
session: WcSession,
|
||||
accountAddress: String?,
|
||||
): LceFlow<Throwable, CheckTransactionResult> = flow {
|
||||
emit(Lce.Loading(partialContent = null))
|
||||
val failedResult = CheckTransactionResult(
|
||||
validation = ValidationResult.FAILED_TO_VALIDATE,
|
||||
simulation = SimulationResult.FailedToSimulate,
|
||||
|
|
@ -36,7 +34,13 @@ internal class BlockAidVerificationDelegate @Inject constructor(
|
|||
emit(Lce.Content(failedResult))
|
||||
return@flow
|
||||
}
|
||||
when (method) {
|
||||
val chain = BlockAidChainNameConverter.convert(network)
|
||||
if (chain == null) {
|
||||
emit(Lce.Content(failedResult))
|
||||
return@flow
|
||||
}
|
||||
emit(Lce.Loading(partialContent = null))
|
||||
val params = when (method) {
|
||||
is WcEthMethod -> TransactionParams.Evm(rawSdkRequest.request.params)
|
||||
is WcSolanaMethod.SignAllTransaction -> TransactionParams.Solana(method.transaction)
|
||||
is WcSolanaMethod.SignTransaction -> TransactionParams.Solana(listOf(method.transaction))
|
||||
|
|
@ -45,25 +49,28 @@ internal class BlockAidVerificationDelegate @Inject constructor(
|
|||
emit(Lce.Content(failedResult))
|
||||
return@flow
|
||||
}
|
||||
else -> null
|
||||
}?.let { params ->
|
||||
blockAidVerifier.verifyTransaction(
|
||||
TransactionData(
|
||||
chain = blockAidChainNameConverter.convert(network),
|
||||
accountAddress = accountAddress,
|
||||
method = rawSdkRequest.request.method,
|
||||
domainUrl = session.sdkModel.appMetaData.url,
|
||||
params = params,
|
||||
),
|
||||
).fold(
|
||||
ifLeft = {
|
||||
Timber.e("Failed to verify transaction: ${it.localizedMessage}")
|
||||
emit(Lce.Error(it))
|
||||
},
|
||||
ifRight = {
|
||||
emit(Lce.Content(it))
|
||||
},
|
||||
)
|
||||
} ?: emit(Lce.Content(failedResult))
|
||||
else -> {
|
||||
emit(Lce.Content(failedResult))
|
||||
return@flow
|
||||
}
|
||||
}
|
||||
|
||||
blockAidVerifier.verifyTransaction(
|
||||
data = TransactionData(
|
||||
chain = chain,
|
||||
accountAddress = accountAddress,
|
||||
method = rawSdkRequest.request.method,
|
||||
domainUrl = session.sdkModel.appMetaData.url,
|
||||
params = params,
|
||||
),
|
||||
).fold(
|
||||
ifLeft = {
|
||||
Timber.e("Failed to verify transaction: ${it.localizedMessage}")
|
||||
emit(Lce.Error(it))
|
||||
},
|
||||
ifRight = {
|
||||
emit(Lce.Content(it))
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue