-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Investment Portfolio Screen with Stream Tokens
- Loading branch information
1 parent
68df72c
commit f23fc76
Showing
15 changed files
with
391 additions
and
33 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
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
8 changes: 8 additions & 0 deletions
8
...d/app-newm/src/main/java/io/newm/screens/investment/portfolio/InvestmentPortfolioEvent.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.newm.screens.investment.portfolio | ||
|
||
import com.slack.circuit.runtime.CircuitUiEvent | ||
|
||
|
||
sealed interface InvestmentPortfolioEvent : CircuitUiEvent { | ||
data object OnBack : InvestmentPortfolioEvent | ||
} |
68 changes: 68 additions & 0 deletions
68
...p-newm/src/main/java/io/newm/screens/investment/portfolio/InvestmentPortfolioPresenter.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,68 @@ | ||
package io.newm.screens.investment.portfolio | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import com.slack.circuit.retained.collectAsRetainedState | ||
import com.slack.circuit.runtime.Navigator | ||
import com.slack.circuit.runtime.presenter.Presenter | ||
import io.newm.shared.public.usecases.HasWalletConnectionsUseCase | ||
import io.newm.shared.public.usecases.SyncWalletConnectionsUseCase | ||
import io.newm.shared.public.usecases.WalletNFTTracksUseCase | ||
import kotlinx.coroutines.flow.flowOf | ||
|
||
class InvestmentPortfolioPresenter( | ||
private val navigator: Navigator, | ||
private val syncWalletConnectionsUseCase: SyncWalletConnectionsUseCase, | ||
private val hasWalletConnectionsUseCase: HasWalletConnectionsUseCase, | ||
private val walletNFTTracksUseCase: WalletNFTTracksUseCase, | ||
) : Presenter<InvestmentPortfolioState> { | ||
@Composable | ||
override fun present(): InvestmentPortfolioState { | ||
|
||
LaunchedEffect(Unit) { | ||
syncWalletConnectionsUseCase.syncWalletConnectionsFromNetworkToDevice() | ||
} | ||
|
||
val isWalletConnected: Boolean? by remember { hasWalletConnectionsUseCase.hasWalletConnectionsFlow() }.collectAsRetainedState( | ||
null | ||
) | ||
val isWalletSynced by remember { walletNFTTracksUseCase.walletSynced }.collectAsState( | ||
false | ||
) | ||
|
||
val streamTokes by remember(isWalletConnected) { | ||
if (isWalletConnected == true) { | ||
walletNFTTracksUseCase.getAllStreamTokensFlow() | ||
} else { | ||
flowOf() | ||
} | ||
}.collectAsRetainedState(initial = emptyList()) | ||
|
||
return when { | ||
streamTokes.isNotEmpty() -> { | ||
InvestmentPortfolioState.Content( | ||
streamTokens = streamTokes, | ||
eventSink = { event -> | ||
when (event) { | ||
InvestmentPortfolioEvent.OnBack -> { | ||
navigator.pop() | ||
} | ||
} | ||
} | ||
) | ||
} | ||
isWalletConnected == true && isWalletSynced -> { | ||
InvestmentPortfolioState.ZeroState | ||
} | ||
else -> { | ||
InvestmentPortfolioState.Error | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...d/app-newm/src/main/java/io/newm/screens/investment/portfolio/InvestmentPortfolioState.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,17 @@ | ||
package io.newm.screens.investment.portfolio | ||
|
||
import com.slack.circuit.runtime.CircuitUiState | ||
import io.newm.shared.public.models.NFTTrack | ||
|
||
sealed class InvestmentPortfolioState : CircuitUiState { | ||
data class Content( | ||
val streamTokens: List<NFTTrack>, | ||
val eventSink: (InvestmentPortfolioEvent) -> Unit | ||
) : InvestmentPortfolioState() | ||
|
||
data object Loading : InvestmentPortfolioState() | ||
|
||
data object Error : InvestmentPortfolioState() | ||
|
||
data object ZeroState : InvestmentPortfolioState() | ||
} |
Oops, something went wrong.