-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1106 from novasamatech/nomination_pool_base
Nomination pool base
- Loading branch information
Showing
1,078 changed files
with
23,452 additions
and
4,694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...androidTest/java/io/novafoundation/nova/NominationPoolsRewardCalculatorIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.novafoundation.nova | ||
|
||
import android.util.Log | ||
import io.novafoundation.nova.common.di.FeatureUtils | ||
import io.novafoundation.nova.common.utils.Perbill | ||
import io.novafoundation.nova.feature_staking_api.di.StakingFeatureApi | ||
import io.novafoundation.nova.feature_staking_api.domain.nominationPool.model.PoolId | ||
import io.novafoundation.nova.feature_staking_impl.data.StakingOption | ||
import io.novafoundation.nova.feature_staking_impl.data.StakingSharedState.OptionAdditionalData | ||
import io.novafoundation.nova.feature_staking_impl.di.StakingFeatureComponent | ||
import io.novafoundation.nova.feature_staking_impl.domain.nominationPools.common.rewards.NominationPoolRewardCalculator | ||
import io.novafoundation.nova.runtime.ext.utilityAsset | ||
import io.novafoundation.nova.runtime.multiNetwork.ChainWithAsset | ||
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain.Asset.StakingType | ||
import kotlinx.coroutines.flow.launchIn | ||
import org.junit.Test | ||
|
||
class NominationPoolsRewardCalculatorIntegrationTest : BaseIntegrationTest() { | ||
|
||
private val stakingFeatureComponent = FeatureUtils.getFeature<StakingFeatureComponent>(context, StakingFeatureApi::class.java) | ||
|
||
private val nominationPoolRewardCalculatorFactory = stakingFeatureComponent.nominationPoolRewardCalculatorFactory | ||
private val stakingUpdateSystem = stakingFeatureComponent.stakingUpdateSystem | ||
private val stakingSharedState = stakingFeatureComponent.stakingSharedState | ||
|
||
@Test | ||
fun testRewardCalculator() = runTest { | ||
val polkadot = chainRegistry.polkadot() | ||
val stakingOption = StakingOption( | ||
assetWithChain = ChainWithAsset(polkadot, polkadot.utilityAsset), | ||
additional = OptionAdditionalData(StakingType.NOMINATION_POOLS) | ||
) | ||
|
||
stakingSharedState.setSelectedOption(stakingOption) | ||
|
||
stakingUpdateSystem.start() | ||
.launchIn(this) | ||
|
||
val rewardCalculator = nominationPoolRewardCalculatorFactory.create(stakingOption, sharedComputationScope = this) | ||
|
||
Log.d("NominationPoolsRewardCalculatorIntegrationTest", "Max APY: ${rewardCalculator.maxAPY}") | ||
Log.d("NominationPoolsRewardCalculatorIntegrationTest", "APY for Nova Pool: ${rewardCalculator.apyFor(54)}") | ||
} | ||
|
||
private fun NominationPoolRewardCalculator.apyFor(poolId: Int): Perbill? { | ||
return apyFor(PoolId(poolId)) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...vafoundation/nova/app/di/app/navigation/staking/NominationPoolsStakingNavigationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.novafoundation.nova.app.di.app.navigation.staking | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import io.novafoundation.nova.app.root.navigation.NavigationHolder | ||
import io.novafoundation.nova.app.root.navigation.Navigator | ||
import io.novafoundation.nova.app.root.navigation.staking.nominationPools.NominationPoolsStakingNavigator | ||
import io.novafoundation.nova.common.di.scope.ApplicationScope | ||
import io.novafoundation.nova.feature_staking_impl.presentation.NominationPoolsRouter | ||
|
||
@Module | ||
class NominationPoolsStakingNavigationModule { | ||
|
||
@Provides | ||
@ApplicationScope | ||
fun provideRouter(navigationHolder: NavigationHolder, navigator: Navigator): NominationPoolsRouter { | ||
return NominationPoolsStakingNavigator(navigationHolder, navigator) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 37 additions & 2 deletions
39
...main/java/io/novafoundation/nova/app/di/app/navigation/staking/StakingNavigationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,41 @@ | ||
package io.novafoundation.nova.app.di.app.navigation.staking | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import io.novafoundation.nova.app.root.navigation.NavigationHolder | ||
import io.novafoundation.nova.app.root.navigation.Navigator | ||
import io.novafoundation.nova.app.root.navigation.staking.StakingDashboardNavigator | ||
import io.novafoundation.nova.app.root.navigation.staking.StartMultiStakingNavigator | ||
import io.novafoundation.nova.common.di.scope.ApplicationScope | ||
import io.novafoundation.nova.feature_staking_impl.presentation.StakingDashboardRouter | ||
import io.novafoundation.nova.feature_staking_impl.presentation.StartMultiStakingRouter | ||
|
||
@Module(includes = [ParachainStakingNavigationModule::class, RelayStakingNavigationModule::class]) | ||
class StakingNavigationModule | ||
@Module( | ||
includes = [ | ||
ParachainStakingNavigationModule::class, | ||
RelayStakingNavigationModule::class, | ||
NominationPoolsStakingNavigationModule::class | ||
] | ||
) | ||
class StakingNavigationModule { | ||
|
||
@Provides | ||
@ApplicationScope | ||
fun provideStakingDashboardNavigator(navigationHolder: NavigationHolder): StakingDashboardNavigator { | ||
return StakingDashboardNavigator(navigationHolder) | ||
} | ||
|
||
@Provides | ||
@ApplicationScope | ||
fun provideStakingDashboardRouter(relayStakingNavigator: StakingDashboardNavigator): StakingDashboardRouter = relayStakingNavigator | ||
|
||
@Provides | ||
@ApplicationScope | ||
fun provideStartMultiStakingRouter( | ||
navigationHolder: NavigationHolder, | ||
dashboardRouter: StakingDashboardRouter, | ||
commonNavigationHolder: Navigator | ||
): StartMultiStakingRouter { | ||
return StartMultiStakingNavigator(navigationHolder, dashboardRouter, commonNavigationHolder) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/src/main/java/io/novafoundation/nova/app/root/domain/RootInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ava/io/novafoundation/nova/app/root/navigation/delayedNavigation/BackDelayedNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.novafoundation.nova.app.root.navigation.delayedNavigation | ||
|
||
import io.novafoundation.nova.common.navigation.DelayedNavigation | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@Parcelize | ||
object BackDelayedNavigation : DelayedNavigation |
8 changes: 8 additions & 0 deletions
8
...ovafoundation/nova/app/root/navigation/delayedNavigation/NavComponentDelayedNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.novafoundation.nova.app.root.navigation.delayedNavigation | ||
|
||
import android.os.Bundle | ||
import io.novafoundation.nova.common.navigation.DelayedNavigation | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@Parcelize | ||
class NavComponentDelayedNavigation(val globalActionId: Int, val extras: Bundle? = null) : DelayedNavigation |
50 changes: 50 additions & 0 deletions
50
...main/java/io/novafoundation/nova/app/root/navigation/staking/StakingDashboardNavigator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.novafoundation.nova.app.root.navigation.staking | ||
|
||
import androidx.navigation.NavController | ||
import io.novafoundation.nova.app.R | ||
import io.novafoundation.nova.app.root.navigation.BaseNavigator | ||
import io.novafoundation.nova.app.root.navigation.NavigationHolder | ||
import io.novafoundation.nova.feature_staking_impl.presentation.StakingDashboardRouter | ||
|
||
class StakingDashboardNavigator( | ||
navigationHolder: NavigationHolder, | ||
) : BaseNavigator(navigationHolder), StakingDashboardRouter { | ||
|
||
private var stakingTabNavController: NavController? = null | ||
private var pendingAction: Int? = null | ||
|
||
fun setStakingTabNavController(navController: NavController) { | ||
stakingTabNavController = navController | ||
|
||
if (pendingAction != null) { | ||
navController.performNavigation(pendingAction!!) | ||
pendingAction = null | ||
} | ||
} | ||
|
||
fun clearStakingTabNavController() { | ||
stakingTabNavController = null | ||
} | ||
|
||
override fun openMoreStakingOptions() { | ||
stakingTabNavController?.performNavigation(R.id.action_stakingDashboardFragment_to_moreStakingOptionsFragment) | ||
} | ||
|
||
override fun backInStakingTab() { | ||
stakingTabNavController?.popBackStack() | ||
} | ||
|
||
override fun returnToStakingTabRoot() { | ||
stakingTabNavController.performNavigationOrDelay(R.id.return_to_staking_dashboard) | ||
} | ||
|
||
private fun NavController?.performNavigationOrDelay(actionId: Int) { | ||
val controller = this | ||
|
||
if (controller != null) { | ||
controller.performNavigation(actionId) | ||
} else { | ||
pendingAction = actionId | ||
} | ||
} | ||
} |
Oops, something went wrong.