Updated on 2026-08-14
This commit is contained in:
parent
f6ac775120
commit
fc1591532c
24 changed files with 219 additions and 34 deletions
|
|
@ -75,4 +75,11 @@ interface TangemTechApi {
|
|||
|
||||
@GET("promotion")
|
||||
suspend fun getPromotionInfo(@Query("programName") name: String): ApiResponse<PromotionInfoResponse>
|
||||
|
||||
@POST("user-network-account")
|
||||
suspend fun createUserNetworkAccount(
|
||||
@Header("card_public_key") cardPublicKey: String,
|
||||
@Header("card_id") cardId: String,
|
||||
@Body body: CreateUserNetworkAccountBody,
|
||||
): ApiResponse<CreateUserNetworkAccountResponse>
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.datasource.api.tangemTech.models
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class CreateUserNetworkAccountBody(
|
||||
@Json(name = "networkId") val networkId: String,
|
||||
@Json(name = "publicWalletKey") val publicWalletKey: String,
|
||||
)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.tangem.datasource.api.tangemTech.models
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class CreateUserNetworkAccountResponse(
|
||||
@Json(name = "status") val status: String,
|
||||
@Json(name = "data") val data: AccountCreated,
|
||||
) {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class AccountCreated(
|
||||
@Json(name = "accountId") val accountId: String,
|
||||
@Json(name = "publicWalletKey") val publicWalletKey: String,
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.tangem.datasource.di
|
||||
|
||||
import com.tangem.blockchain.common.AccountCreator
|
||||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.local.blockchain.DefaultAccountCreator
|
||||
import com.tangem.lib.auth.AuthProvider
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object AccountCreatorModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAccountCreator(authProvider: AuthProvider, @DevTangemApi tangemTechApi: TangemTechApi): AccountCreator {
|
||||
return DefaultAccountCreator(authProvider, tangemTechApi)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.tangem.datasource.local.blockchain
|
||||
|
||||
import com.tangem.blockchain.common.AccountCreator
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.BlockchainSdkError
|
||||
import com.tangem.blockchain.extensions.Result
|
||||
import com.tangem.common.extensions.toHexString
|
||||
import com.tangem.datasource.api.common.response.getOrThrow
|
||||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.api.tangemTech.models.CreateUserNetworkAccountBody
|
||||
import com.tangem.lib.auth.AuthProvider
|
||||
|
||||
internal class DefaultAccountCreator(
|
||||
private val authProvider: AuthProvider,
|
||||
private val tangemTechApi: TangemTechApi,
|
||||
) : AccountCreator {
|
||||
|
||||
override suspend fun createAccount(blockchain: Blockchain, walletPublicKey: ByteArray): Result<String> {
|
||||
val request = CreateUserNetworkAccountBody(blockchain.id.removeSuffix("/test"), walletPublicKey.toHexString())
|
||||
return try {
|
||||
val response = tangemTechApi.createUserNetworkAccount(
|
||||
cardPublicKey = authProvider.getCardPublicKey(),
|
||||
cardId = authProvider.getCardId(),
|
||||
body = request,
|
||||
).getOrThrow()
|
||||
Result.Success(response.data.accountId)
|
||||
} catch (e: Exception) {
|
||||
Result.Failure(BlockchainSdkError.FailedToCreateAccount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -51,6 +51,7 @@ fun getActiveIconRes(blockchainId: String): Int {
|
|||
"aptos", "aptos/test" -> R.drawable.img_aptos_22
|
||||
"shibarium", "shibarium/test" -> R.drawable.img_shibarium_22
|
||||
"algorand", "algorand/test" -> R.drawable.img_algorand_22
|
||||
"hedera", "hedera/test" -> R.drawable.img_hedera_22
|
||||
else -> R.drawable.ic_alert_24
|
||||
}
|
||||
}
|
||||
|
|
@ -103,6 +104,7 @@ fun getActiveIconResByNetworkId(networkId: String): Int {
|
|||
"aptos", "aptos/test" -> R.drawable.img_aptos_22
|
||||
"shibarium", "shibarium/test" -> R.drawable.img_shibarium_22
|
||||
"algorand", "algorand/test" -> R.drawable.img_algorand_22
|
||||
"hedera", "hedera/test" -> R.drawable.img_hedera_22
|
||||
else -> R.drawable.ic_alert_24
|
||||
}
|
||||
}
|
||||
|
|
@ -152,6 +154,7 @@ fun getActiveIconResByCoinId(coinId: String): Int {
|
|||
"aptos" -> R.drawable.img_aptos_22
|
||||
"shibarium" -> R.drawable.img_shibarium_22
|
||||
"algorand" -> R.drawable.img_algorand_22
|
||||
"hedera" -> R.drawable.img_hedera_22
|
||||
else -> R.drawable.ic_alert_24
|
||||
}
|
||||
}
|
||||
|
|
@ -204,6 +207,7 @@ fun getGreyedOutIconRes(blockchainId: String): Int {
|
|||
"aptos", "aptos/test" -> R.drawable.ic_aptos_22
|
||||
"shibarium", "shibarium/test" -> R.drawable.ic_shibarium_22
|
||||
"algorand", "algorand/test" -> R.drawable.ic_algorand_22
|
||||
"hedera", "hedera/test" -> R.drawable.ic_hedera_22
|
||||
else -> R.drawable.ic_alert_24
|
||||
}
|
||||
}
|
||||
|
|
@ -256,6 +260,7 @@ fun getGreyedOutIconResByNetworkId(networkId: String): Int {
|
|||
"aptos", "aptos/test" -> R.drawable.ic_aptos_22
|
||||
"shibarium", "shibarium/test" -> R.drawable.ic_shibarium_22
|
||||
"algorand", "algorand/test" -> R.drawable.ic_algorand_22
|
||||
"hedera", "hedera/test" -> R.drawable.ic_hedera_22
|
||||
else -> R.drawable.ic_alert_24
|
||||
}
|
||||
}
|
||||
16
core/ui/src/main/res/drawable/ic_hedera_22.xml
Normal file
16
core/ui/src/main/res/drawable/ic_hedera_22.xml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="22dp"
|
||||
android:height="22dp"
|
||||
android:viewportWidth="22"
|
||||
android:viewportHeight="22">
|
||||
<group>
|
||||
<clip-path
|
||||
android:pathData="M11,0L11,0A11,11 0,0 1,22 11L22,11A11,11 0,0 1,11 22L11,22A11,11 0,0 1,0 11L0,11A11,11 0,0 1,11 0z"/>
|
||||
<path
|
||||
android:pathData="M7.876,6H6.5V16H7.876V6Z"
|
||||
android:fillColor="#000000"/>
|
||||
<path
|
||||
android:pathData="M15.5,6H14.123V9.118H7.877V10.194H14.123V11.806H7.877V12.882H14.123V16H15.5V6Z"
|
||||
android:fillColor="#000000"/>
|
||||
</group>
|
||||
</vector>
|
||||
19
core/ui/src/main/res/drawable/img_hedera_22.xml
Normal file
19
core/ui/src/main/res/drawable/img_hedera_22.xml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="22dp"
|
||||
android:height="22dp"
|
||||
android:viewportWidth="22"
|
||||
android:viewportHeight="22">
|
||||
<group>
|
||||
<clip-path
|
||||
android:pathData="M11,0L11,0A11,11 0,0 1,22 11L22,11A11,11 0,0 1,11 22L11,22A11,11 0,0 1,0 11L0,11A11,11 0,0 1,11 0z"/>
|
||||
<path
|
||||
android:pathData="M11,0L11,0A11,11 0,0 1,22 11L22,11A11,11 0,0 1,11 22L11,22A11,11 0,0 1,0 11L0,11A11,11 0,0 1,11 0z"
|
||||
android:fillColor="#000000"/>
|
||||
<path
|
||||
android:pathData="M7.876,6H6.5V16H7.876V6Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
<path
|
||||
android:pathData="M15.5,6H14.123V9.118H7.877V10.194H14.123V11.806H7.877V12.882H14.123V16H15.5V6Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</group>
|
||||
</vector>
|
||||
Loading…
Add table
Add a link
Reference in a new issue