Updated on 2026-08-14
This commit is contained in:
parent
8966e28e29
commit
799a38655e
9 changed files with 733 additions and 67 deletions
|
|
@ -1,10 +1,12 @@
|
|||
package com.tangem.data.dynamicaddresses
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.blockchain.common.AmountType
|
||||
import com.tangem.blockchain.common.DynamicAddressesManager
|
||||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.blockchain.common.WalletManager
|
||||
import com.tangem.blockchain.common.transaction.Fee
|
||||
import com.tangem.blockchain.common.transaction.TransactionFee
|
||||
import com.tangem.blockchain.extensions.Result
|
||||
import com.tangem.domain.dynamicaddresses.repository.ConsolidationRepository
|
||||
import com.tangem.domain.models.network.Network
|
||||
|
|
@ -33,13 +35,25 @@ internal class DefaultConsolidationRepository(
|
|||
|
||||
when (val result = dynamicAddressesManager.createConsolidationTransaction(fee)) {
|
||||
is Result.Success -> result.data
|
||||
is Result.Failure -> error("Failed to create consolidation tx: ${result.error}")
|
||||
is Result.Failure -> throw result.error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UnusedParameter")
|
||||
private fun getNormalFee(walletManager: WalletManager): Fee {
|
||||
TODO("Fee calculation for consolidation from multiple addresses is not yet implemented")
|
||||
private suspend fun getNormalFee(walletManager: WalletManager): Fee {
|
||||
val coinAmount = walletManager.wallet.amounts[AmountType.Coin]
|
||||
?: error("Coin amount not found")
|
||||
val feeResult = walletManager.getFee(
|
||||
amount = coinAmount,
|
||||
destination = walletManager.wallet.address,
|
||||
)
|
||||
|
||||
return when (feeResult) {
|
||||
is Result.Success -> when (val txFee = feeResult.data) {
|
||||
is TransactionFee.Single -> txFee.normal
|
||||
is TransactionFee.Choosable -> txFee.normal
|
||||
}
|
||||
is Result.Failure -> throw feeResult.error
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue