Skip to content

Commit

Permalink
feat(staking): AND-6780 summary sheet pt 1 - earn module (#4132)
Browse files Browse the repository at this point in the history
  • Loading branch information
dserrano-bc committed Nov 24, 2022
1 parent e2c067c commit ba652ce
Show file tree
Hide file tree
Showing 60 changed files with 389 additions and 165 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Expand Up @@ -419,6 +419,10 @@ dependencies {
implementation project(':nfts:presentation')
implementation project(':membership:presentation')

implementation project(':earn:data')
implementation project(':earn:domain')
implementation project(':earn:presentation')

implementation Libraries.multidex
coreLibraryDesugaring Libraries.desugaring

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/blockchain/koin/KoinStarter.kt
Expand Up @@ -14,6 +14,8 @@ import com.blockchain.core.price.pricesModule
import com.blockchain.coreandroid.coreAndroidModule
import com.blockchain.deeplinking.koin.deeplinkModule
import com.blockchain.defiwalletbackup.data.koin.backupPhraseDataModule
import com.blockchain.earn.data.koin.earnDataModule
import com.blockchain.earn.koin.earnPresentationModule
import com.blockchain.home.data.koin.homeDataModule
import com.blockchain.home.presentation.koin.homePresentationModule
import com.blockchain.koin.modules.apiInterceptorsModule
Expand Down Expand Up @@ -171,6 +173,7 @@ object KoinStarter {
fraudDataModule,
nftDataModule, nftPresentationModule,
multiAppModule,
earnDataModule, earnPresentationModule
)
)
}
Expand Down
Expand Up @@ -8,7 +8,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.blockchain.coincore.CustodialStakingActivitySummaryItem
import com.blockchain.core.price.historic.HistoricRateFetcher
import com.blockchain.core.staking.domain.StakingState
import com.blockchain.earn.domain.models.StakingState
import com.blockchain.preferences.CurrencyPrefs
import com.blockchain.utils.toFormattedDate
import info.blockchain.balance.AssetInfo
Expand Down
Expand Up @@ -5,9 +5,9 @@ import com.blockchain.coincore.RecurringBuyActivitySummaryItem
import com.blockchain.commonarch.presentation.mvi.MviModel
import com.blockchain.commonarch.presentation.mvi.MviState
import com.blockchain.core.interest.domain.model.InterestState
import com.blockchain.core.staking.domain.StakingState
import com.blockchain.domain.paymentmethods.model.MobilePaymentType
import com.blockchain.domain.paymentmethods.model.PaymentMethodType
import com.blockchain.earn.domain.models.StakingState
import com.blockchain.enviroment.EnvironmentConfig
import com.blockchain.logging.RemoteLogger
import com.blockchain.nabu.datamanagers.OrderState
Expand Down
Expand Up @@ -24,8 +24,8 @@ import com.blockchain.componentlib.viewextensions.gone
import com.blockchain.componentlib.viewextensions.visible
import com.blockchain.componentlib.viewextensions.visibleIf
import com.blockchain.core.interest.domain.model.InterestState
import com.blockchain.core.staking.domain.StakingState
import com.blockchain.domain.paymentmethods.model.PaymentMethodType
import com.blockchain.earn.domain.models.StakingState
import com.blockchain.nabu.datamanagers.OrderState
import com.blockchain.nabu.datamanagers.RecurringBuyFailureReason
import com.blockchain.presentation.koin.scopedInject
Expand Down
Expand Up @@ -13,10 +13,10 @@ import com.blockchain.coincore.defaultFilter
import com.blockchain.coincore.impl.CryptoNonCustodialAccount
import com.blockchain.coincore.impl.CustodialTradingAccount
import com.blockchain.core.interest.domain.InterestService
import com.blockchain.core.staking.domain.StakingService
import com.blockchain.data.DataResource
import com.blockchain.data.combineDataResources
import com.blockchain.data.map
import com.blockchain.earn.domain.service.StakingService
import com.blockchain.preferences.CurrencyPrefs
import com.blockchain.store.flatMapData
import com.blockchain.walletmode.WalletMode
Expand Down
Expand Up @@ -131,6 +131,7 @@ class CoinViewActivityV2 :
navigateToAccountActions(
cvAccount = navigationEvent.cvAccount,
interestRate = navigationEvent.interestRate,
stakingRate = navigationEvent.stakingRate,
actions = navigationEvent.actions,
balanceCrypto = navigationEvent.cryptoBalance,
fiatBalance = navigationEvent.fiatBalance,
Expand Down Expand Up @@ -231,6 +232,9 @@ class CoinViewActivityV2 :
showBottomSheet(InterestSummarySheet.newInstance(navigationEvent.cvAccount.account as CryptoAccount))
}

is CoinviewNavigationEvent.NavigateToStakingStatement ->
showBottomSheet(InterestSummarySheet.newInstance(navigationEvent.cvAccount.account as CryptoAccount))

is CoinviewNavigationEvent.NavigateToInterestDeposit -> {
goToInterestDeposit(navigationEvent.cvAccount.account)
}
Expand Down Expand Up @@ -312,6 +316,7 @@ class CoinViewActivityV2 :
private fun navigateToAccountActions(
cvAccount: CoinviewAccount,
interestRate: Double,
stakingRate: Double,
fiatBalance: Money,
balanceCrypto: Money,
actions: List<StateAwareAction>
Expand All @@ -322,6 +327,7 @@ class CoinViewActivityV2 :
balanceFiat = fiatBalance,
balanceCrypto = balanceCrypto,
interestRate = interestRate,
stakingRate = stakingRate,
stateAwareActions = actions.toTypedArray()
)
)
Expand Down
Expand Up @@ -19,6 +19,7 @@ sealed interface CoinviewNavigationEvent : NavigationEvent {
data class ShowAccountActions(
val cvAccount: CoinviewAccount,
val interestRate: Double,
val stakingRate: Double,
val fiatBalance: Money,
val cryptoBalance: Money,
val actions: List<StateAwareAction>
Expand Down Expand Up @@ -54,6 +55,10 @@ sealed interface CoinviewNavigationEvent : NavigationEvent {
val cvAccount: CoinviewAccount
) : CoinviewNavigationEvent

data class NavigateToStakingStatement(
val cvAccount: CoinviewAccount
) : CoinviewNavigationEvent

data class NavigateToInterestDeposit(
val cvAccount: CoinviewAccount
) : CoinviewNavigationEvent
Expand Down
Expand Up @@ -49,6 +49,8 @@ import piuk.blockchain.android.ui.coinview.domain.model.CoinviewAssetPriceHistor
import piuk.blockchain.android.ui.coinview.domain.model.CoinviewAssetTotalBalance
import piuk.blockchain.android.ui.coinview.domain.model.CoinviewQuickAction
import piuk.blockchain.android.ui.coinview.domain.model.CoinviewQuickActions
import piuk.blockchain.android.ui.coinview.domain.model.isInterestAccount
import piuk.blockchain.android.ui.coinview.domain.model.isStakingAccount
import piuk.blockchain.android.ui.coinview.presentation.CoinviewAccountsState.Data.CoinviewAccountState.Available
import piuk.blockchain.android.ui.coinview.presentation.CoinviewAccountsState.Data.CoinviewAccountState.Unavailable
import piuk.blockchain.android.ui.coinview.presentation.CoinviewAccountsState.Data.CoinviewAccountsHeaderState
Expand Down Expand Up @@ -89,7 +91,6 @@ class CoinviewViewModel(
private var loadQuickActionsJob: Job? = null
private var loadRecurringBuyJob: Job? = null
private var loadAssetInfoJob: Job? = null
private var loadAccountActionsJob: Job? = null
private var snackbarMessageJob: Job? = null

private val fiatCurrency: FiatCurrency
Expand Down Expand Up @@ -870,6 +871,7 @@ class CoinviewViewModel(
CoinviewNavigationEvent.ShowAccountActions(
cvAccount = cvAccount,
interestRate = cvAccount.interestRate(),
stakingRate = cvAccount.stakingRate(),
actions = intent.actions,
cryptoBalance = balance.data,
fiatBalance = fiatBalance.data,
Expand Down Expand Up @@ -1212,6 +1214,7 @@ class CoinviewViewModel(
CoinviewNavigationEvent.ShowAccountActions(
cvAccount = account,
interestRate = account.interestRate(),
stakingRate = account.stakingRate(),
actions = actions,
cryptoBalance = (account.cryptoBalance as DataResource.Data).data,
fiatBalance = (account.fiatBalance as DataResource.Data).data
Expand Down Expand Up @@ -1313,9 +1316,19 @@ class CoinviewViewModel(
)

AssetAction.ViewStatement -> navigate(
CoinviewNavigationEvent.NavigateToInterestStatement(
cvAccount = account
)
when {
account.isInterestAccount() -> {
CoinviewNavigationEvent.NavigateToInterestStatement(
cvAccount = account
)
}
account.isStakingAccount() -> {
CoinviewNavigationEvent.NavigateToInterestStatement(
cvAccount = account
)
}
else -> throw IllegalStateException("ViewStatement is not supported for account $account")
}
)

AssetAction.InterestDeposit -> navigate(
Expand All @@ -1330,12 +1343,11 @@ class CoinviewViewModel(
)
)

AssetAction.StakingDeposit ->
navigate(
CoinviewNavigationEvent.NavigateToStakingDeposit(
cvAccount = account
)
AssetAction.StakingDeposit -> navigate(
CoinviewNavigationEvent.NavigateToStakingDeposit(
cvAccount = account
)
)

else -> throw IllegalStateException("Action $action is not supported in this flow")
}
Expand Down
Expand Up @@ -531,6 +531,7 @@ class CoinViewActivity :
balanceFiat = fiatBalance,
balanceCrypto = balance,
interestRate = interestRate,
stakingRate = stakingRate,
stateAwareActions = state.actions
)
)
Expand Down
Expand Up @@ -12,6 +12,7 @@ import com.blockchain.coincore.InterestAccount
import com.blockchain.coincore.NonCustodialAccount
import com.blockchain.coincore.NullCryptoAccount
import com.blockchain.coincore.SingleAccountList
import com.blockchain.coincore.StakingAccount
import com.blockchain.coincore.StateAwareAction
import com.blockchain.coincore.TradingAccount
import com.blockchain.coincore.defaultFilter
Expand Down Expand Up @@ -303,8 +304,9 @@ class CoinViewInteractor(
accounts,
load24hPriceDelta(asset),
asset.interestRate(),
asset.stakingRate(),
watchlistDataManager.isAssetInWatchlist(asset.currency)
) { accounts, prices, interestRate, isAddedToWatchlist ->
) { accounts, prices, interestRate, stakingRate, isAddedToWatchlist ->
// while we wait for a BE flag on whether an asset is tradeable or not, we can check the
// available accounts to see if we support custodial or PK balances as a guideline to asset support
val tradeableAsset = accounts.any {
Expand All @@ -318,7 +320,7 @@ class CoinViewInteractor(
)
} else {
val accountsList = mapAccounts(
accounts, prices.currentRate, interestRate
accounts, prices.currentRate, interestRate, stakingRate
)
var totalCryptoMoneyAll = Money.zero(asset.currency)
val totalCryptoBalance = hashMapOf<AssetFilter, Money>()
Expand Down Expand Up @@ -358,7 +360,8 @@ class CoinViewInteractor(
private fun mapAccounts(
accounts: List<DetailsItem>,
exchangeRate: ExchangeRate,
interestRate: Double = Double.NaN
interestRate: Double = Double.NaN,
stakingRate: Double = Double.NaN
): List<AssetDisplayInfo> {

val accountComparator = object : Comparator<DetailsItem> {
Expand All @@ -371,7 +374,8 @@ class CoinViewInteractor(
detailItem.account is NonCustodialAccount && detailItem.isDefault -> 0
detailItem.account is TradingAccount -> 1
detailItem.account is InterestAccount -> 2
detailItem.account is NonCustodialAccount && detailItem.isDefault.not() -> 3
detailItem.account is StakingAccount -> 3
detailItem.account is NonCustodialAccount && detailItem.isDefault.not() -> 4
else -> Int.MAX_VALUE
}
}
Expand All @@ -388,6 +392,7 @@ class CoinViewInteractor(
filter = when (it.account) {
is TradingAccount -> AssetFilter.Trading
is InterestAccount -> AssetFilter.Interest
is StakingAccount -> AssetFilter.Staking
// todo (othman) should be removed once universal mode is removed
is NonCustodialAccount -> AssetFilter.NonCustodial
else -> error("account type not supported")
Expand All @@ -398,7 +403,8 @@ class CoinViewInteractor(
actions = it.actions.filter { action ->
action.action != AssetAction.InterestDeposit
}.toSet(),
interestRate = interestRate
interestRate = interestRate,
stakingRate = stakingRate
)
}
WalletMode.NON_CUSTODIAL_ONLY -> {
Expand Down
Expand Up @@ -65,6 +65,7 @@ sealed class AssetDisplayInfo(
open val fiatValue: Money,
open val actions: Set<StateAwareAction>,
open val interestRate: Double,
open val stakingRate: Double,
open val filter: AssetFilter
) {
data class BrokerageDisplayInfo(
Expand All @@ -74,9 +75,10 @@ sealed class AssetDisplayInfo(
override val fiatValue: Money,
override val actions: Set<StateAwareAction>,
override val interestRate: Double,
override val stakingRate: Double,
override val filter: AssetFilter
) : AssetDisplayInfo(
account, amount, pendingAmount, fiatValue, actions, interestRate, filter
account, amount, pendingAmount, fiatValue, actions, interestRate, stakingRate, filter
)

data class DefiDisplayInfo(
Expand All @@ -86,7 +88,7 @@ sealed class AssetDisplayInfo(
override val fiatValue: Money,
override val actions: Set<StateAwareAction>,
) : AssetDisplayInfo(
account, amount, pendingAmount, fiatValue, actions, Double.NaN, AssetFilter.NonCustodial
account, amount, pendingAmount, fiatValue, actions, Double.NaN, Double.NaN, AssetFilter.NonCustodial
)
}

Expand Down
Expand Up @@ -76,7 +76,8 @@ sealed interface AssetDetailsItem {
open val balance: Money,
open val fiatBalance: Money,
open val actions: Set<StateAwareAction>,
open val interestRate: Double
open val interestRate: Double,
open val stakingRate: Double
) : AssetDetailsItem

/**
Expand All @@ -88,13 +89,15 @@ sealed interface AssetDetailsItem {
override val balance: Money,
override val fiatBalance: Money,
override val actions: Set<StateAwareAction>,
override val interestRate: Double = Double.NaN
override val interestRate: Double = Double.NaN,
override val stakingRate: Double = Double.NaN
) : CryptoDetailsInfo(
account = account,
balance = balance,
fiatBalance = fiatBalance,
actions = actions,
interestRate = interestRate
interestRate = interestRate,
stakingRate = stakingRate
)

/**
Expand All @@ -110,7 +113,8 @@ sealed interface AssetDetailsItem {
balance = balance,
fiatBalance = fiatBalance,
actions = actions,
interestRate = Double.NaN
interestRate = Double.NaN,
stakingRate = Double.NaN
)

data class CentralCta(
Expand Down

0 comments on commit ba652ce

Please sign in to comment.