Skip to content

Commit

Permalink
PERA-1159 :: Handle account selection automatically in ARC-78 flow (#101
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yasin-ce authored Jan 10, 2025
1 parent 59bac46 commit 8f3bfed
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 222 deletions.
6 changes: 5 additions & 1 deletion app/src/main/java/com/algorand/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ class MainActivity :
xnote = deepLink.xnote
)

nav(HomeNavigationDirections.actionGlobalConfirmKeyRegAccountSelectionFragment(txnDetail))
if (qrScannerViewModel.hasAccountAuthority(deepLink.senderAddress)) {
nav(HomeNavigationDirections.actionGlobalKeyRegTransactionFragment(txnDetail))
} else {
showGlobalError(getString(R.string.you_dont_have_any, deepLink.senderAddress), tag = activityTag)
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/algorand/android/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.algorand.android.models.AssetOperationResult
import com.algorand.android.models.Node
import com.algorand.android.models.SignedTransactionDetail
import com.algorand.android.models.TransactionData
import com.algorand.android.modules.accountstatehelper.domain.usecase.AccountStateHelperUseCase
import com.algorand.android.modules.appopencount.domain.usecase.IncreaseAppOpeningCountUseCase
import com.algorand.android.modules.autolockmanager.ui.usecase.AutoLockManagerUseCase
import com.algorand.android.modules.deeplink.ui.DeeplinkHandler
Expand All @@ -36,7 +37,6 @@ import com.algorand.android.network.IndexerInterceptor
import com.algorand.android.network.MobileHeaderInterceptor
import com.algorand.android.repository.NodeRepository
import com.algorand.android.usecase.AccountCacheStatusUseCase
import com.algorand.android.usecase.AccountDetailUseCase
import com.algorand.android.usecase.SendSignedTransactionUseCase
import com.algorand.android.utils.AccountCacheManager
import com.algorand.android.utils.AssetName
Expand Down Expand Up @@ -75,11 +75,11 @@ class MainViewModel @Inject constructor(
private val tutorialUseCase: TutorialUseCase,
private val swapNavigationDestinationHelper: SwapNavigationDestinationHelper,
private val sendSignedTransactionUseCase: SendSignedTransactionUseCase,
private val accountDetailUseCase: AccountDetailUseCase,
private val accountDetailCacheManager: AccountDetailCacheManager,
private val nodeRepository: NodeRepository,
accountCacheStatusUseCase: AccountCacheStatusUseCase,
private val autoLockManagerUseCase: AutoLockManagerUseCase
private val autoLockManagerUseCase: AutoLockManagerUseCase,
private val accountStateHelperUseCase: AccountStateHelperUseCase
) : BaseViewModel() {

// TODO: Replace this with Flow whenever have time
Expand Down Expand Up @@ -295,4 +295,8 @@ class MainViewModel @Inject constructor(
}
}
}

fun hasAccountAuthority(accountAddress: String): Boolean {
return accountStateHelperUseCase.hasAccountAuthority(accountAddress)
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class KeyRegTransactionViewModel @Inject constructor(
savedStateHandle: SavedStateHandle
) : ViewModel() {

private var signingAccountAddress = savedStateHandle.getOrThrow<String>(
SIGNING_ACCOUNT_ADDRSS
)
private var keyRegTransactionDetail = savedStateHandle.getOrThrow<KeyRegTransactionDetail>(
KEY_REG_DETAIL
)
Expand All @@ -55,7 +52,7 @@ class KeyRegTransactionViewModel @Inject constructor(
get() = _previewState.asStateFlow()

fun initUi() {
_previewState.value = previewMapper.createInitialPreview(keyRegTransactionDetail, signingAccountAddress)
_previewState.value = previewMapper.createInitialPreview(keyRegTransactionDetail)
}

fun confirmTransaction() {
Expand Down Expand Up @@ -97,7 +94,6 @@ class KeyRegTransactionViewModel @Inject constructor(
}

companion object {
const val SIGNING_ACCOUNT_ADDRSS = "signingAccountAddress"
const val KEY_REG_DETAIL = "keyRegTransactionDetail"
const val TAG = "KeyRegTransactionViewModel"
const val TRANSACTION_ERROR = "transaction_error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ fun keyRegTable(
"Last Valid Round" to keyRegTransactionDetail.lastValid,
"xNote" to keyRegTransactionDetail.xNote,
"Note" to keyRegTransactionDetail.note,
"Signing Address" to keyRegTransactionDetail.signingAddress,
)

val fabHeight by remember {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class KeyRegTransactionPreviewMapper @Inject constructor() {

fun createInitialPreview(
detail: KeyRegTransactionDetail,
signingAddress: String
): KeyRegTransactionPreview {
return KeyRegTransactionPreview(
isLoadingVisible = false,
Expand All @@ -35,7 +34,6 @@ class KeyRegTransactionPreviewMapper @Inject constructor() {
lastValid = detail.voteLastRound.orEmpty(),
xNote = detail.xnote,
note = detail.note,
signingAddress = signingAddress,
signTransactionEvent = null,
showErrorEvent = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ data class KeyRegTransactionPreview(
val lastValid: String,
val xNote: String?,
val note: String?,
val signingAddress: String,
val signTransactionEvent: Event<KeyRegTransaction>?,
val showErrorEvent: Event<Unit>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ abstract class BaseQrScannerFragment(
xnote = deepLink.xnote
)

nav(HomeNavigationDirections.actionGlobalConfirmKeyRegAccountSelectionFragment(txnDetail))

if (qrScannerViewModel.hasAccountAuthority(deepLink.senderAddress)) {
nav(HomeNavigationDirections.actionGlobalKeyRegTransactionFragment(txnDetail))
} else {
showGlobalError(getString(R.string.you_dont_have_any, deepLink.senderAddress))
}
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package com.algorand.android.modules.qrscanning

import androidx.lifecycle.viewModelScope
import com.algorand.android.core.BaseViewModel
import com.algorand.android.modules.accountstatehelper.domain.usecase.AccountStateHelperUseCase
import com.algorand.android.modules.deeplink.ui.DeeplinkHandler
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
Expand All @@ -23,7 +24,8 @@ import kotlinx.coroutines.launch

@HiltViewModel
class QrScannerViewModel @Inject constructor(
private val deeplinkHandler: DeeplinkHandler
private val deeplinkHandler: DeeplinkHandler,
private val accountStateHelperUseCase: AccountStateHelperUseCase,
) : BaseViewModel() {

private val _isQrCodeInProgressFlow = MutableSharedFlow<Boolean>()
Expand All @@ -46,4 +48,8 @@ class QrScannerViewModel @Inject constructor(
fun removeDeeplinkHandlerListener() {
deeplinkHandler.setListener(null)
}

fun hasAccountAuthority(accountAddress: String): Boolean {
return accountStateHelperUseCase.hasAccountAuthority(accountAddress)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import kotlinx.coroutines.flow.MutableStateFlow

class GetLocalAccountsUseCase @Inject constructor(
private val accountManager: AccountManager,
private val accountDetailUseCase: AccountDetailUseCase,
private val accountStateHelperUseCase: AccountStateHelperUseCase
) {
fun getLocalAccountsFromAccountManagerCache(): List<Account> {
Expand Down
31 changes: 2 additions & 29 deletions app/src/main/res/navigation/home_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,8 @@
</action>

<action
android:id="@+id/action_global_confirmKeyRegAccountSelectionFragment"
app:destination="@id/keyRegAccountSelectionFragment">
<argument
android:name="keyRegTransactionDetail"
app:argType="com.algorand.android.modules.keyreg.ui.model.KeyRegTransactionDetail" />
</action>
android:id="@+id/action_global_keyRegTransactionFragment"
app:destination="@id/keyRegTransactionFragment" />

<action
android:id="@+id/action_global_assetInboxOneAccountNavigation"
Expand All @@ -342,26 +338,6 @@
android:id="@+id/action_global_accountDetailFragment"
app:destination="@id/accountDetailFragment" />

<fragment
android:id="@+id/keyRegAccountSelectionFragment"
android:name="com.algorand.android.modules.keyreg.ui.KeyRegAccountSelectionFragment"
android:label="fragment_key_reg_account_selection"
tools:layout="@layout/fragment_base_account_selection">
<argument
android:name="keyRegTransactionDetail"
app:argType="com.algorand.android.modules.keyreg.ui.model.KeyRegTransactionDetail" />
<action
android:id="@+id/action_keyRegAccountSelectionFragment_to_keyRegTransactionFragment"
app:destination="@id/keyRegTransactionFragment">
<argument
android:name="keyRegTransactionDetail"
app:argType="com.algorand.android.modules.keyreg.ui.model.KeyRegTransactionDetail" />
<argument
android:name="signingAccountAddress"
app:argType="string" />
</action>
</fragment>

<fragment
android:id="@+id/keyRegTransactionFragment"
android:name="com.algorand.android.modules.keyreg.ui.KeyRegTransactionFragment"
Expand All @@ -370,9 +346,6 @@
<argument
android:name="keyRegTransactionDetail"
app:argType="com.algorand.android.modules.keyreg.ui.model.KeyRegTransactionDetail" />
<argument
android:name="signingAccountAddress"
app:argType="string" />
<action
android:id="@+id/action_KeyRegTransactionFragment_to_addNoteNavigation"
app:destination="@id/addNoteNavigation">
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1434,4 +1434,6 @@
<string name="pera_wallet_now_provides">Pera Wallet now provides an easy and fast way to stake with various dApps.</string>
<string name="stake_in_pera">Stake in Pera</string>

<string name="you_dont_have_any">You don\'t have any authorized account matching with %1$s</string>

</resources>
Loading

0 comments on commit 8f3bfed

Please sign in to comment.