Updated on 2026-08-14

This commit is contained in:
Tangem 2023-11-21 15:05:17 +04:00
parent 9a8ff1830d
commit a0798cfef2
252 changed files with 247 additions and 5857 deletions

View file

@ -1,35 +0,0 @@
package com.tangem.datasource.api.oneinch
import com.squareup.moshi.Moshi
import com.tangem.datasource.api.oneinch.errors.OneIncResponseException
import com.tangem.datasource.api.oneinch.models.SwapErrorDto
import com.tangem.datasource.di.NetworkMoshi
import retrofit2.HttpException
import retrofit2.Response
import javax.inject.Inject
class OneInchErrorsHandler @Inject constructor(@NetworkMoshi moshi: Moshi) {
private val errorMoshiAdapter = moshi.adapter(SwapErrorDto::class.java)
@Throws(OneIncResponseException::class)
fun <T> handleOneInchResponse(response: Response<T>): T {
return if (response.isSuccessful) {
response.body() ?: error("response body is null")
} else {
when (response.code()) {
HTTP_CODE_400 -> {
val swapErrorDto = errorMoshiAdapter.fromJson(response.errorBody()?.string() ?: "")
throw OneIncResponseException(swapErrorDto ?: throw HttpException(response))
}
else -> {
throw HttpException(response)
}
}
}
}
companion object {
private const val HTTP_CODE_400 = 400
}
}

View file

@ -1,13 +0,0 @@
package com.tangem.datasource.api.oneinch.models
import com.squareup.moshi.Json
/**
* Path view dto
*/
data class PathViewDto(
@Json(name = "name") val name: String,
@Json(name = "part") val part: Int,
@Json(name = "fromTokenAddress") val fromTokenAddress: String,
@Json(name = "toTokenAddress") val toTokenAddress: String,
)

View file

@ -1,15 +0,0 @@
package com.tangem.datasource.api.paymentology.models.request
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
data class CheckRegistrationRequests(
@Json(name = "requests") val requests: List<Item>,
) {
@JsonClass(generateAdapter = true)
data class Item(
@Json(name = "CID") val cardId: String = "",
@Json(name = "publicKey") val publicKey: String = "",
)
}

View file

@ -1,33 +0,0 @@
package com.tangem.datasource.api.paymentology.models.request
import com.squareup.moshi.Json
import com.tangem.common.extensions.calculateHashCode
data class RegisterKYCRequest(
@Json(name = "CID") val cardId: String,
@Json(name = "publicKey") val publicKey: ByteArray,
@Json(name = "kycProvider") val kycProvider: String,
@Json(name = "kycRefId") val kycRefId: String,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as RegisterKYCRequest
if (cardId != other.cardId) return false
if (!publicKey.contentEquals(other.publicKey)) return false
if (kycProvider != other.kycProvider) return false
if (kycRefId != other.kycRefId) return false
return true
}
override fun hashCode(): Int = calculateHashCode(
cardId.hashCode(),
publicKey.contentHashCode(),
kycProvider.hashCode(),
kycRefId.hashCode(),
)
}

View file

@ -1,44 +0,0 @@
package com.tangem.datasource.api.paymentology.models.request
import com.squareup.moshi.Json
import com.tangem.common.extensions.calculateHashCode
data class RegisterWalletRequest(
@Json(name = "CID") val cardId: String,
@Json(name = "publicKey") val publicKey: ByteArray,
@Json(name = "walletPublicKey") val walletPublicKey: ByteArray,
@Json(name = "walletSalt") val walletSalt: ByteArray,
@Json(name = "walletSignature") val walletSignature: ByteArray,
@Json(name = "cardSalt") val cardSalt: ByteArray,
@Json(name = "cardSignature") val cardSignature: ByteArray,
@Json(name = "PIN") val pin: String,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as RegisterWalletRequest
if (cardId != other.cardId) return false
if (!publicKey.contentEquals(other.publicKey)) return false
if (!walletPublicKey.contentEquals(other.walletPublicKey)) return false
if (!walletSalt.contentEquals(other.walletSalt)) return false
if (!walletSignature.contentEquals(other.walletSignature)) return false
if (!cardSalt.contentEquals(other.cardSalt)) return false
if (!cardSignature.contentEquals(other.cardSignature)) return false
if (pin != other.pin) return false
return true
}
override fun hashCode(): Int = calculateHashCode(
cardId.hashCode(),
publicKey.contentHashCode(),
walletPublicKey.contentHashCode(),
walletSalt.contentHashCode(),
walletSignature.contentHashCode(),
cardSalt.contentHashCode(),
cardSignature.contentHashCode(),
pin.hashCode(),
)
}

View file

@ -1,33 +0,0 @@
package com.tangem.datasource.api.paymentology.models.response
import com.squareup.moshi.Json
import com.tangem.common.extensions.calculateHashCode
data class AttestationResponse(
@Json(name = "challenge") val challenge: ByteArray?,
@Json(name = "success") override val success: Boolean,
@Json(name = "error") override val error: String?,
@Json(name = "errorCode") override val errorCode: Int?,
) : ResponseError {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as AttestationResponse
if (!challenge.contentEquals(other.challenge)) return false
if (success != other.success) return false
if (error != other.error) return false
if (errorCode != other.errorCode) return false
return true
}
override fun hashCode(): Int = calculateHashCode(
challenge.contentHashCode(),
success.hashCode(),
error.hashCode(),
errorCode.hashCode(),
)
}

View file

@ -1,10 +0,0 @@
package com.tangem.datasource.api.paymentology.models.response
enum class KYCStatus {
NOT_STARTED,
STARTED,
WAITING_FOR_APPROVAL,
CORRECTION_REQUESTED,
REJECTED,
APPROVED,
}

View file

@ -1,9 +0,0 @@
package com.tangem.datasource.api.paymentology.models.response
import com.squareup.moshi.Json
data class RegisterWalletResponse(
@Json(name = "success") override val success: Boolean,
@Json(name = "error") override val error: String?,
@Json(name = "errorCode") override val errorCode: Int?,
) : ResponseError

View file

@ -1,25 +0,0 @@
package com.tangem.datasource.api.paymentology.models.response
import com.squareup.moshi.Json
data class RegistrationResponse(
@Json(name = "results") val results: List<Item> = listOf(),
@Json(name = "success") override val success: Boolean,
@Json(name = "error") override val error: String?,
@Json(name = "errorCode") override val errorCode: Int?,
) : ResponseError {
data class Item(
@Json(name = "CID") val cardId: String,
@Json(name = "passed") val passed: Boolean?,
@Json(name = "active") val active: Boolean?,
@Json(name = "pin_set") val pinSet: Boolean?,
@Json(name = "blockchain_init") val blockchainInit: Boolean?,
@Json(name = "kyc_passed") val kycPassed: Boolean?,
@Json(name = "kyc_provider") val kycProvider: String?,
@Json(name = "kyc_date") val kycDate: String?,
@Json(name = "kyc_status") val kycStatus: KYCStatus?,
@Json(name = "disabled_by_admin") val disabledByAdmin: Boolean?,
@Json(name = "error") val error: String?,
)
}

View file

@ -1,16 +0,0 @@
package com.tangem.datasource.api.paymentology.models.response
import com.tangem.common.services.Result
interface ResponseError {
val success: Boolean
val error: String?
val errorCode: Int?
fun makeErrorMessage(): String = error ?: "unknown error"
}
inline fun <reified T> ResponseError.tryExtractError(): Result<T> = when (success) {
true -> Result.Success(this as T)
else -> Result.Failure(Throwable(makeErrorMessage()))
}

View file

@ -1,21 +0,0 @@
package com.tangem.datasource.local.datastore.core
internal abstract class KeylessDataStoreDecorator<Value : Any>(
wrappedDataStore: StringKeyDataStore<Value>,
private val key: String = DEFAULT_STRING_KEY,
) : StringKeyDataStoreDecorator<String, Value>(wrappedDataStore) {
override fun provideStringKey(key: String) = key
open fun get() = get(key)
open suspend fun getSyncOrNull() = getSyncOrNull(key)
open suspend fun store(item: Value) = store(key, item)
override suspend fun isEmpty(): Boolean = getSyncOrNull() == null
private companion object {
const val DEFAULT_STRING_KEY = "key"
}
}