Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ABW-2743] Create basic UI for bottom sheet to access factor sources #750

Merged
merged 42 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3ffca05
make currentNetwork not nullable and default to default network
giannis-rdx Jan 15, 2024
6a8d421
removed unnecessary ExperimentalAnimationApi
giannis-rdx Jan 15, 2024
998b223
added access factor source feature package in presentation which
giannis-rdx Jan 15, 2024
2767c95
added accessFactorSourceBottomSheet in NavigationHost
giannis-rdx Jan 15, 2024
1744b6c
added app events to trigger bottom sheet
giannis-rdx Jan 15, 2024
f993bd6
added icon create account
giannis-rdx Jan 15, 2024
19ded08
reverted nullable currentNetwork from profile extensions
giannis-rdx Jan 21, 2024
59c9483
removed all ExperimentalAnimationApi
giannis-rdx Jan 21, 2024
fe840c4
renamed every AccessFactorSource to AccessFactorSources
giannis-rdx Jan 24, 2024
feed700
fixed detekt
giannis-rdx Feb 5, 2024
96af5cc
make LedgerHardwareWalletFactorSource and DeviceFactorSource able to
giannis-rdx Jan 23, 2024
849f61d
added CreateAccountExtensions and replaced them in use cases of
giannis-rdx Jan 23, 2024
28ba9f3
added AccessFactorSourceProvider that provides access to factor sources
giannis-rdx Jan 23, 2024
c2cb59d
added new CreateAccountUseCase which takes a CreateEntity factor source
giannis-rdx Jan 23, 2024
53bf3c8
updated ChooseLedgerScreen to only return the selected ledger and
giannis-rdx Jan 23, 2024
db5d211
added AccessFactorSourceProxyContract
giannis-rdx Jan 23, 2024
46d8378
added implementation of AccessFactorSourceProxy
giannis-rdx Jan 23, 2024
cb41e6e
refactored CreateAccount screen to use the AccessFactorSourceProxy and
giannis-rdx Jan 23, 2024
e44f280
implemented logic for AccessFactorSourceBottomSheet and its viewmodel
giannis-rdx Jan 23, 2024
3867ecb
removed old use cases to create account
giannis-rdx Jan 23, 2024
248935a
removed wrong interface from AccessFactorSourceProxyImpl
giannis-rdx Jan 24, 2024
820d84e
renamed ViewModule to UiModule
giannis-rdx Jan 24, 2024
94a4293
renamed every AccessFactorSource to AccessFactorSources
giannis-rdx Jan 24, 2024
167c2d6
fixed detekt
giannis-rdx Feb 5, 2024
86d2010
fixed unit test ChooseLedgerViewModelTest
giannis-rdx Feb 5, 2024
1e6eab7
renamed app event ToCreateAccount to DeriveAccountPublicKeys
giannis-rdx Feb 5, 2024
f26f3f3
refactored AccessFactorSourcesProxyContract to return failure
giannis-rdx Feb 5, 2024
725dfa0
renamed LedgerSelectionPurpose CreateAccount to DerivePublicKey
giannis-rdx Feb 5, 2024
8df6a48
do not ensureBabylonFactorSourceExistUseCase in ChooseLedgerViewModel
giannis-rdx Feb 5, 2024
41783dd
ensureBabylonFactorSourceExistUseCase when derive public key in
giannis-rdx Feb 5, 2024
ff2236e
one off event for biometric prompt in AccessFactorSourcesViewModel
giannis-rdx Feb 5, 2024
373fb44
next line
giannis-rdx Feb 5, 2024
253abe0
better naming
giannis-rdx Feb 6, 2024
fb12bc4
fixed naming
giannis-rdx Feb 6, 2024
e03ef9d
removed unnecessary val ledger in DeriveAccountPublicKey app event
giannis-rdx Feb 12, 2024
c7dbac7
better names for AccessFactorSources functions
giannis-rdx Feb 12, 2024
73924e5
minor
giannis-rdx Feb 12, 2024
7fc3927
fixed detekt
giannis-rdx Feb 13, 2024
70b53d7
removed unnecessary public reset
giannis-rdx Feb 13, 2024
115fc02
Merge pull request #761 from radixdlt/feature/ABW-2744-access-factor-…
giannis-rdx Feb 13, 2024
570c5df
updated AccessFactorSourcesDialog UI
giannis-rdx Feb 14, 2024
7de83ed
fixed detekt
giannis-rdx Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions app/src/main/java/com/babylon/wallet/android/WalletApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.babylon.wallet.android.domain.model.MessageFromDataChannel
import com.babylon.wallet.android.domain.userFriendlyMessage
import com.babylon.wallet.android.presentation.accessfactorsources.accessFactorSources
import com.babylon.wallet.android.presentation.dapp.authorized.login.dAppLoginAuthorized
import com.babylon.wallet.android.presentation.dapp.unauthorized.login.dAppLoginUnauthorized
import com.babylon.wallet.android.presentation.main.MAIN_ROUTE
Expand All @@ -43,7 +44,6 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
import kotlinx.coroutines.flow.Flow

@Composable
@Suppress("ModifierMissing")
fun WalletApp(
modifier: Modifier = Modifier,
mainViewModel: MainViewModel,
Expand Down Expand Up @@ -103,6 +103,10 @@ fun WalletApp(
)
}
}
HandleAccessFactorSourcesEvents(
navController = navController,
accessFactorSourcesEvents = mainViewModel.accessFactorSourcesEvents
)
HandleStatusEvents(
navController = navController,
statusEvents = mainViewModel.statusEvents
Expand Down Expand Up @@ -175,7 +179,26 @@ private fun SyncStatusBarWithScreenChanges(navController: NavHostController) {
}

@Composable
fun HandleStatusEvents(navController: NavController, statusEvents: Flow<AppEvent.Status>) {
private fun HandleAccessFactorSourcesEvents(
navController: NavController,
accessFactorSourcesEvents: Flow<AppEvent.AccessFactorSources.DeriveAccountPublicKey>
) {
LaunchedEffect(Unit) {
accessFactorSourcesEvents.collect { event ->
when (event) {
is AppEvent.AccessFactorSources -> {
navController.accessFactorSources()
}
}
}
}
}

@Composable
private fun HandleStatusEvents(
navController: NavController,
statusEvents: Flow<AppEvent.Status>
) {
LaunchedEffect(Unit) {
statusEvents.collect { event ->
when (event) {
Expand All @@ -192,7 +215,7 @@ fun HandleStatusEvents(navController: NavController, statusEvents: Flow<AppEvent
}

@Composable
fun ObserveHighPriorityScreens(
private fun ObserveHighPriorityScreens(
navController: NavController,
onLowPriorityScreen: () -> Unit,
onHighPriorityScreen: () -> Unit
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/babylon/wallet/android/di/UiModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.babylon.wallet.android.di

import com.babylon.wallet.android.presentation.accessfactorsources.AccessFactorSourcesProxy
import com.babylon.wallet.android.presentation.accessfactorsources.AccessFactorSourcesProxyImpl
import com.babylon.wallet.android.presentation.accessfactorsources.AccessFactorSourcesUiProxy
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityRetainedComponent

@Module
@InstallIn(ActivityRetainedComponent::class)
interface UiModule {

@Binds
fun bindAccessFactorSourcesUiProxy(
accessFactorSourcesProxyImpl: AccessFactorSourcesProxyImpl
): AccessFactorSourcesUiProxy

@Binds
fun bindAccessFactorSourcesProxy(
accessFactorSourcesProxyImpl: AccessFactorSourcesProxyImpl
): AccessFactorSourcesProxy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.babylon.wallet.android.domain.usecases

import com.babylon.wallet.android.data.repository.ResolveAccountsLedgerStateRepository
import com.babylon.wallet.android.presentation.accessfactorsources.AccessFactorSourcesOutput
import kotlinx.coroutines.flow.first
import rdx.works.profile.data.model.apppreferences.Radix
import rdx.works.profile.data.model.currentNetwork
import rdx.works.profile.data.model.extensions.createAccount
import rdx.works.profile.data.model.factorsources.FactorSource
import rdx.works.profile.data.model.pernetwork.Network
import rdx.works.profile.data.model.pernetwork.addAccounts
import rdx.works.profile.data.repository.ProfileRepository
import rdx.works.profile.data.repository.profile
import rdx.works.profile.derivation.model.NetworkId
import javax.inject.Inject

class CreateAccountUseCase @Inject constructor(
private val profileRepository: ProfileRepository,
private val resolveAccountsLedgerStateRepository: ResolveAccountsLedgerStateRepository
) {

suspend operator fun invoke(
displayName: String,
factorSource: FactorSource.CreatingEntity,
publicKeyAndDerivationPath: AccessFactorSourcesOutput.PublicKeyAndDerivationPath,
onNetworkId: NetworkId?
): Network.Account {
val currentProfile = profileRepository.profile.first()
val networkId = onNetworkId ?: currentProfile.currentNetwork?.knownNetworkId ?: Radix.Gateway.default.network.networkId()

val newAccount = currentProfile.createAccount(
displayName = displayName,
onNetworkId = networkId,
factorSource = factorSource,
derivationPath = publicKeyAndDerivationPath.derivationPath,
compressedPublicKey = publicKeyAndDerivationPath.compressedPublicKey,
onLedgerSettings = Network.Account.OnLedgerSettings.init()
)

val accountWithOnLedgerStatusResult = resolveAccountsLedgerStateRepository(listOf(newAccount))

val accountToAdd = if (accountWithOnLedgerStatusResult.isSuccess) {
accountWithOnLedgerStatusResult.getOrThrow().first().account
} else {
newAccount
}

val updatedProfile = currentProfile.addAccounts(
accounts = listOf(accountToAdd),
onNetwork = networkId
)
// Save updated profile
profileRepository.saveProfile(updatedProfile)
// Return new account
return accountToAdd
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.babylon.wallet.android.presentation.accessfactorsources

import androidx.compose.ui.window.DialogProperties
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.dialog

fun NavController.accessFactorSources() {
navigate("access_factor_source_bottom_sheet")
}

fun NavGraphBuilder.accessFactorSources(
onDismiss: () -> Unit
) {
dialog(
route = "access_factor_source_bottom_sheet",
dialogProperties = DialogProperties(usePlatformDefaultWidth = false)
) {
AccessFactorSourcesDialog(
viewModel = hiltViewModel(),
onDismiss = onDismiss
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.babylon.wallet.android.presentation.accessfactorsources

import rdx.works.profile.data.model.factorsources.FactorSource
import rdx.works.profile.data.model.pernetwork.DerivationPath
import rdx.works.profile.derivation.model.NetworkId

// interface for clients that need access to factor sources
interface AccessFactorSourcesProxy {

suspend fun getPublicKeyAndDerivationPathForFactorSource(
accessFactorSourcesInput: AccessFactorSourcesInput.ToDerivePublicKey
): Result<AccessFactorSourcesOutput.PublicKeyAndDerivationPath>
}

// interface for the AccessFactorSourceViewModel that works as a mediator between the clients
// and the AccessFactorSourcesProvider
interface AccessFactorSourcesUiProxy {

fun getInput(): AccessFactorSourcesInput

suspend fun setOutput(output: AccessFactorSourcesOutput)
}

// ----- Models for input/output ----- //

sealed interface AccessFactorSourcesInput {

data class ToDerivePublicKey(
val forNetworkId: NetworkId,
val factorSource: FactorSource.CreatingEntity? = null
) : AccessFactorSourcesInput

// just for demonstration - will change in next PR
data class ToSign(
val someData: List<Int>
) : AccessFactorSourcesInput

data object Init : AccessFactorSourcesInput
}

sealed interface AccessFactorSourcesOutput {

data class PublicKeyAndDerivationPath(
val compressedPublicKey: ByteArray,
val derivationPath: DerivationPath
) : AccessFactorSourcesOutput

// just for demonstration - will change in next PR
data class Signers(
val someData: List<String>
) : AccessFactorSourcesOutput

data class Failure(
val error: Throwable
) : AccessFactorSourcesOutput

data object Init : AccessFactorSourcesOutput
}
Loading
Loading