-
Notifications
You must be signed in to change notification settings - Fork 6
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 #750 from radixdlt/feature/ABW-2743-create-basic-u…
…i-for-bottom-sheet [ABW-2743] Create basic UI for bottom sheet to access factor sources
- Loading branch information
Showing
38 changed files
with
1,027 additions
and
639 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
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/babylon/wallet/android/di/UiModule.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,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 | ||
} |
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/babylon/wallet/android/domain/usecases/CreateAccountUseCase.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,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 | ||
} | ||
} |
78 changes: 0 additions & 78 deletions
78
...bylon/wallet/android/domain/usecases/CreateAccountWithBabylonDeviceFactorSourceUseCase.kt
This file was deleted.
Oops, something went wrong.
70 changes: 0 additions & 70 deletions
70
.../com/babylon/wallet/android/domain/usecases/CreateAccountWithLedgerFactorSourceUseCase.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
...com/babylon/wallet/android/presentation/accessfactorsources/AccessFactorSourceNavGraph.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,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 | ||
) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...abylon/wallet/android/presentation/accessfactorsources/AccessFactorSourceProxyContract.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,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 | ||
} |
Oops, something went wrong.