Updated on 2026-08-14
This commit is contained in:
parent
b0649c93df
commit
632b0dd663
13 changed files with 86 additions and 13 deletions
|
|
@ -15,7 +15,7 @@ private const val SUCCESS_STATUS = "Success"
|
|||
private const val DOMAIN_CHECKED_STATUS = "hit"
|
||||
private const val VALIDATION_SAFE_STATUS = "Benign"
|
||||
|
||||
internal class BlockAidMapper {
|
||||
internal object BlockAidMapper {
|
||||
|
||||
fun mapToDomain(from: DomainScanResponse): CheckDAppResult {
|
||||
return when {
|
||||
|
|
|
|||
|
|
@ -12,19 +12,19 @@ import kotlinx.coroutines.withContext
|
|||
|
||||
internal class DefaultBlockAidRepository(
|
||||
private val api: BlockAidApi,
|
||||
private val dispatcherProvider: CoroutineDispatcherProvider,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
private val mapper: BlockAidMapper,
|
||||
) : BlockAidRepository {
|
||||
|
||||
override suspend fun verifyDAppDomain(data: DAppData): CheckDAppResult {
|
||||
val response = withContext(dispatcherProvider.io) {
|
||||
val response = withContext(dispatchers.io) {
|
||||
api.scanDomain(DomainScanRequest(data.url))
|
||||
}
|
||||
return mapper.mapToDomain(response)
|
||||
}
|
||||
|
||||
override suspend fun verifyTransaction(data: TransactionData): CheckTransactionResult {
|
||||
val response = withContext(dispatcherProvider.io) {
|
||||
val response = withContext(dispatchers.io) {
|
||||
when (data.params) {
|
||||
is TransactionParams.Evm -> {
|
||||
api.scanJsonRpc(mapper.mapToEvmRequest(data))
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ internal object BlockAidDataInternalModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRepository(api: BlockAidApi, dispatcherProvider: CoroutineDispatcherProvider): BlockAidRepository {
|
||||
fun provideRepository(api: BlockAidApi, dispatchers: CoroutineDispatcherProvider): BlockAidRepository {
|
||||
return DefaultBlockAidRepository(
|
||||
api = api,
|
||||
dispatcherProvider = dispatcherProvider,
|
||||
mapper = BlockAidMapper(),
|
||||
dispatchers = dispatchers,
|
||||
mapper = BlockAidMapper,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ import java.math.BigDecimal
|
|||
|
||||
class BlockAidMapperTest {
|
||||
|
||||
private val mapper = BlockAidMapper()
|
||||
private val mapper = BlockAidMapper
|
||||
|
||||
@Test
|
||||
fun `when status hit and is malicious false then map to domain returns safe`() {
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ class DefaultBlockAidRepositoryTest {
|
|||
|
||||
private lateinit var repository: DefaultBlockAidRepository
|
||||
|
||||
private val testDispatcherProvider = TestingCoroutineDispatcherProvider()
|
||||
private val dispatchers = TestingCoroutineDispatcherProvider()
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockKAnnotations.init(this)
|
||||
repository = DefaultBlockAidRepository(api, testDispatcherProvider, mapper)
|
||||
repository = DefaultBlockAidRepository(api, dispatchers, mapper)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue