Updated on 2026-08-14
This commit is contained in:
parent
64626bbcbc
commit
3e2de9fd6b
12 changed files with 812 additions and 0 deletions
|
|
@ -0,0 +1,62 @@
|
|||
package com.tangem.domain.swap.models
|
||||
|
||||
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import org.joda.time.DateTime
|
||||
|
||||
/**
|
||||
* Swapped status model
|
||||
*/
|
||||
data class SwapStatusModel(
|
||||
val providerId: String,
|
||||
val status: SwapStatus? = null,
|
||||
val txId: String? = null,
|
||||
val txExternalUrl: String? = null,
|
||||
val txExternalId: String? = null,
|
||||
val refundNetwork: String? = null,
|
||||
val refundContractAddress: String? = null,
|
||||
val refundTokensResponse: UserTokensResponse.Token? = null,
|
||||
val refundCurrency: CryptoCurrency? = null,
|
||||
val createdAt: DateTime? = null,
|
||||
val averageDuration: Int? = null,
|
||||
) {
|
||||
val hasLongTime: Boolean
|
||||
get() = if (createdAt != null && averageDuration != null) {
|
||||
DateTime.now().minusSeconds(averageDuration * 5) > createdAt
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
enum class SwapStatus {
|
||||
New,
|
||||
Waiting,
|
||||
WaitingTxHash,
|
||||
Confirming,
|
||||
Verifying,
|
||||
Exchanging,
|
||||
Failed,
|
||||
Sending,
|
||||
Finished,
|
||||
Refunded,
|
||||
Cancelled,
|
||||
TxFailed,
|
||||
Unknown,
|
||||
Paused,
|
||||
;
|
||||
|
||||
val isTerminal: Boolean
|
||||
get() = this == Refunded ||
|
||||
this == Finished ||
|
||||
this == Cancelled ||
|
||||
this == TxFailed ||
|
||||
this == Paused ||
|
||||
this == Unknown
|
||||
|
||||
val isAutoDisposable: Boolean
|
||||
get() = this == Finished
|
||||
|
||||
companion object {
|
||||
fun SwapStatus?.isFailed(): Boolean = this == Failed || this == TxFailed
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.tangem.domain.swap.models
|
||||
|
||||
import com.tangem.domain.express.models.ExpressProvider
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import java.math.BigDecimal
|
||||
|
||||
/**
|
||||
* List of saved swap transactions
|
||||
*/
|
||||
data class SwapTransactionListModel(
|
||||
val userWalletId: String,
|
||||
val fromCryptoCurrencyId: String,
|
||||
val toCryptoCurrencyId: String,
|
||||
val fromCryptoCurrency: CryptoCurrency,
|
||||
val toCryptoCurrency: CryptoCurrency,
|
||||
val transactions: List<SwapTransactionModel>,
|
||||
)
|
||||
|
||||
/**
|
||||
* Saved swap transactions
|
||||
*/
|
||||
data class SwapTransactionModel(
|
||||
val txId: String,
|
||||
val timestamp: Long,
|
||||
val fromCryptoAmount: BigDecimal,
|
||||
val toCryptoAmount: BigDecimal,
|
||||
val provider: ExpressProvider,
|
||||
val status: SwapStatusModel? = null,
|
||||
)
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.tangem.domain.swap
|
||||
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.swap.models.SwapStatusModel
|
||||
import com.tangem.domain.swap.models.SwapTransactionListModel
|
||||
import com.tangem.domain.swap.models.SwapTransactionModel
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Swap repository for statuses
|
||||
*/
|
||||
interface SwapTransactionRepository {
|
||||
|
||||
/**
|
||||
* Store new swap transaction
|
||||
*
|
||||
* @param userWalletId selected user wallet id
|
||||
* @param fromCryptoCurrency currency swap from
|
||||
* @param toCryptoCurrency currency swap to
|
||||
* @param transaction swap transaction
|
||||
*/
|
||||
suspend fun storeTransaction(
|
||||
userWalletId: UserWalletId,
|
||||
fromCryptoCurrency: CryptoCurrency,
|
||||
toCryptoCurrency: CryptoCurrency,
|
||||
transaction: SwapTransactionModel,
|
||||
)
|
||||
|
||||
/**
|
||||
* Get list of swap transactions
|
||||
*
|
||||
* @param userWallet selected user wallet
|
||||
* @param cryptoCurrencyId transactions for specific crypto currency
|
||||
*/
|
||||
suspend fun getTransactions(
|
||||
userWallet: UserWallet,
|
||||
cryptoCurrencyId: CryptoCurrency.ID,
|
||||
): Flow<List<SwapTransactionListModel>?>
|
||||
|
||||
/**
|
||||
* Remove stores swap transaction
|
||||
*
|
||||
* @param userWalletId selected user wallet id
|
||||
* @param fromCryptoCurrency currency swap from
|
||||
* @param toCryptoCurrency currency swap to
|
||||
* @param txId transaction id to remove
|
||||
*/
|
||||
suspend fun removeTransaction(
|
||||
userWalletId: UserWalletId,
|
||||
fromCryptoCurrency: CryptoCurrency,
|
||||
toCryptoCurrency: CryptoCurrency,
|
||||
txId: String,
|
||||
)
|
||||
|
||||
/**
|
||||
* Update swap transaction
|
||||
*
|
||||
* @param txId transaction id to update
|
||||
* @param status new transaction status
|
||||
* @param refundTokenCurrency refund token
|
||||
*/
|
||||
suspend fun storeTransactionState(txId: String, status: SwapStatusModel, refundTokenCurrency: CryptoCurrency?)
|
||||
|
||||
/**
|
||||
* Save last swapped crypto currency token
|
||||
*
|
||||
* @param userWalletId selected user wallet id
|
||||
* @param cryptoCurrencyId last swapped currency id
|
||||
*/
|
||||
suspend fun storeLastSwappedCryptoCurrencyId(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID)
|
||||
|
||||
/**
|
||||
* Get last swapped crypto currency token
|
||||
*
|
||||
* @param userWalletId selected user wallet id
|
||||
*/
|
||||
suspend fun getLastSwappedCryptoCurrencyId(userWalletId: UserWalletId): String?
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue