Skip to content

Commit

Permalink
PERA-931 :: Fix ARC-78 navigation issues (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
yasin-ce authored Nov 29, 2024
1 parent fa88d42 commit e0a5e85
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ data class OnlineKeyRegTransactionPayload(
val voteFirstRound: String,
val voteLastRound: String,
val voteKeyDilution: String,
val txnParams: TransactionParams
val txnParams: TransactionParams,
val note: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ package com.algorand.android.modules.algosdk.domain.usecase
import com.algorand.android.models.TransactionParams

interface BuildKeyRegOfflineTransaction {
operator fun invoke(address: String, txnParams: TransactionParams): ByteArray?
operator fun invoke(address: String, note: String?, txnParams: TransactionParams): ByteArray?
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ internal class BuildKeyRegOfflineTransactionImpl @Inject constructor(
private val transactionParametersResponseMapper: TransactionParametersResponseMapper
) : BuildKeyRegOfflineTransaction {

override fun invoke(address: String, txnParams: TransactionParams): ByteArray? {
override fun invoke(address: String, note: String?, txnParams: TransactionParams): ByteArray? {
return try {
createTransaction(address, txnParams)
createTransaction(address, note, txnParams)
} catch (e: Exception) {
null
}
}

private fun createTransaction(address: String, txnParams: TransactionParams): ByteArray {
private fun createTransaction(
address: String,
note: String?,
txnParams: TransactionParams
): ByteArray {
val params = transactionParametersResponseMapper(txnParams)
return KeyRegistrationTransactionBuilder.Builder()
.suggestedParams(params)
.sender(address)
.noteUTF8(note)
.build()
.bytes()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal class BuildKeyRegOnlineTransactionImpl @Inject constructor(
.voteFirst(params.voteFirstRound.toLong())
.voteLast(params.voteLastRound.toLong())
.voteKeyDilution(params.voteKeyDilution.toLong())
.noteUTF8(params.note)
.build()
.bytes()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,23 @@ internal class CreateKeyRegTransactionUseCase @Inject constructor(
Success(createKeyRegTransactionResult(txnDetail, txnByteArray))
}
}

is Error -> {
Error(params.exception, params.code)
}
}
}

private fun createTransactionByteArray(txnDetail: KeyRegTransactionDetail, params: TransactionParams): ByteArray? {
private fun createTransactionByteArray(
txnDetail: KeyRegTransactionDetail,
params: TransactionParams
): ByteArray? {
Security.removeProvider("BC")
Security.insertProviderAt(BouncyCastleProvider(), 0)
return if (txnDetail.isOnlineKeyRegTxn()) {
buildKeyRegOnlineTransaction(txnDetail.toOnlineTxnPayload(params))
} else {
buildKeyRegOfflineTransaction(txnDetail.address, params)
buildKeyRegOfflineTransaction(txnDetail.address, txnDetail.note, params)
}
}

Expand All @@ -87,12 +91,13 @@ internal class CreateKeyRegTransactionUseCase @Inject constructor(
voteFirstRound = voteFirstRound.orEmpty(),
voteLastRound = voteLastRound.orEmpty(),
voteKeyDilution = voteKeyDilution.orEmpty(),
txnParams = params
txnParams = params,
note = xnote ?: note
)
}

private fun KeyRegTransactionDetail.isOnlineKeyRegTxn(): Boolean {
return !voteKey.isNullOrBlank() && !selectionPublicKey.isNullOrBlank() && !voteFirstRound.isNullOrBlank() &&
!voteLastRound.isNullOrBlank() && !voteKeyDilution.isNullOrBlank()
!voteLastRound.isNullOrBlank() && !voteKeyDilution.isNullOrBlank()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ import com.algorand.android.modules.transaction.signmanager.ExternalTransactionS
import com.algorand.android.modules.transaction.signmanager.ExternalTransactionSignResult.NotInitialized
import com.algorand.android.modules.transaction.signmanager.ExternalTransactionSignResult.Success
import com.algorand.android.modules.transaction.signmanager.ExternalTransactionSignResult.TransactionCancelled
import com.algorand.android.ui.send.shared.AddNoteBottomSheet
import com.algorand.android.utils.extensions.collectLatestOnLifecycle
import com.algorand.android.utils.extensions.hide
import com.algorand.android.utils.extensions.show
import com.algorand.android.utils.getXmlStyledString
import com.algorand.android.utils.showAlertDialog
import com.algorand.android.utils.showWithStateCheck
import com.algorand.android.utils.startSavedStateListener
import com.algorand.android.utils.useSavedStateValue
import com.algorand.android.utils.viewbinding.viewBinding
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
Expand All @@ -57,7 +60,8 @@ class KeyRegTransactionFragment : TransactionBaseFragment(R.layout.fragment_key_
startIconClick = ::navBack
)

override val fragmentConfiguration = FragmentConfiguration(toolbarConfiguration = toolbarConfiguration)
override val fragmentConfiguration =
FragmentConfiguration(toolbarConfiguration = toolbarConfiguration)

private val keyRegTransactionViewModel by viewModels<KeyRegTransactionViewModel>()

Expand Down Expand Up @@ -93,8 +97,7 @@ class KeyRegTransactionFragment : TransactionBaseFragment(R.layout.fragment_key_
}
}

private val isTransactionConfirmedCollector: suspend (String?) -> Unit = {
transactionId ->
private val isTransactionConfirmedCollector: suspend (String?) -> Unit = { transactionId ->
if (transactionId == KeyRegTransactionViewModel.TRANSACTION_ERROR) {
activity?.showAlertDialog(
getString(R.string.error),
Expand All @@ -105,18 +108,19 @@ class KeyRegTransactionFragment : TransactionBaseFragment(R.layout.fragment_key_
}
}

private val externalTransactionSignManagerCollector: suspend (ExternalTransactionSignResult) -> Unit = {
if (it !is Loading) hideLoader()
when (it) {
is Success<*> -> sendSignedTransactions(it.signedTransaction)
is Error -> showTransactionSignResultError(it)
LedgerScanFailed -> showLedgerNotFoundDialog()
is LedgerWaitingForApproval -> showLedgerWaitingForApprovalBottomSheet(it)
Loading -> showLoader()
NotInitialized -> Unit
is TransactionCancelled -> showTransactionCancelledError(it)
private val externalTransactionSignManagerCollector: suspend (ExternalTransactionSignResult) -> Unit =
{
if (it !is Loading) hideLoader()
when (it) {
is Success<*> -> sendSignedTransactions(it.signedTransaction)
is Error -> showTransactionSignResultError(it)
LedgerScanFailed -> showLedgerNotFoundDialog()
is LedgerWaitingForApproval -> showLedgerWaitingForApprovalBottomSheet(it)
Loading -> showLoader()
NotInitialized -> Unit
is TransactionCancelled -> showTransactionCancelledError(it)
}
}
}

private val ledgerLoadingDialogListener = LedgerLoadingDialog.Listener {
ledgerLoadingDialog = null
Expand All @@ -127,6 +131,7 @@ class KeyRegTransactionFragment : TransactionBaseFragment(R.layout.fragment_key_
super.onViewCreated(view, savedInstanceState)
initUi()
initObservers()
initSavedStateListener()
keyRegTransactionSignManager.setup(viewLifecycleOwner.lifecycle)
keyRegTransactionViewModel.initUi()
}
Expand Down Expand Up @@ -163,6 +168,17 @@ class KeyRegTransactionFragment : TransactionBaseFragment(R.layout.fragment_key_
}
}

private fun initSavedStateListener() {
startSavedStateListener(R.id.keyRegTransactionFragment) {
useSavedStateValue<String>(AddNoteBottomSheet.ADD_NOTE_RESULT_KEY) {
if (transactionNote.second) {
transactionNote = Pair(it, transactionNote.second)
}
keyRegTransactionViewModel.updateTransactionNotes(transactionNote.first)
}
}
}

private fun showLedgerNotFoundDialog() {
nav(HomeNavigationDirections.actionGlobalLedgerConnectionIssueBottomSheet())
}
Expand Down Expand Up @@ -210,11 +226,12 @@ class KeyRegTransactionFragment : TransactionBaseFragment(R.layout.fragment_key_
}

private fun navToConfirmationFragment(transactionId: String) {
nav(KeyRegTransactionFragmentDirections
.actionKeyRegTransactionFragmentToTransactionConfirmationFragment(
transactionId = transactionId,
titleResId = R.string.operation_completed,
)
nav(
KeyRegTransactionFragmentDirections
.actionKeyRegTransactionFragmentToTransactionConfirmationFragment(
transactionId = transactionId,
titleResId = R.string.operation_completed,
)
)
}

Expand Down Expand Up @@ -288,32 +305,31 @@ class KeyRegTransactionFragment : TransactionBaseFragment(R.layout.fragment_key_

private fun setTransactionDetails(preview: KeyRegTransactionPreview) {
with(binding) {
typeTextView.setText(preview.type)
addressTextView.setText(preview.address)
typeTextView.text = preview.type
addressTextView.text = preview.address
feeAmountView.setAmountAsFee(preview.fee.toLong())
}
}

private fun setKeyRegDetails(preview: KeyRegTransactionPreview) {
with(binding) {
selectionKeyTextView.setText(preview.selectionKey)
voteKeyTextView.setText(preview.votingKey)
stateProofKeyTextView.setText(preview.stateProofKey)
validFirstRoundTextView.setText(preview.firstValid)
validLastRoundTextView.setText(preview.lastValid)
voteKeyDilutionTextView.setText(preview.keyDilution)
selectionKeyTextView.text = preview.selectionKey
voteKeyTextView.text = preview.votingKey
stateProofKeyTextView.text = preview.stateProofKey
validFirstRoundTextView.text = preview.firstValid
validLastRoundTextView.text = preview.lastValid
voteKeyDilutionTextView.text = preview.keyDilution
}
}

private fun setTransactionNote(xNote: String?, note: String?, isEditable: Boolean) {
binding.xNoteTextView.text = xNote
transactionNote = Pair(note, isEditable)
transactionNote = Pair(xNote ?: note, isEditable)
}

private fun onAddEditNoteClicked() {
nav(
KeyRegTransactionFragmentDirections
.actionKeyRegTransactionFragmentToAddNoteBottomSheet(
.actionKeyRegTransactionFragmentToAddNoteNavigation(
note = transactionNote.first,
isInputFieldEnabled = transactionNote.second
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class KeyRegTransactionViewModel @Inject constructor(
savedStateHandle: SavedStateHandle
) : ViewModel() {

var signingAccountAddress = savedStateHandle.getOrThrow<String>(
private var signingAccountAddress = savedStateHandle.getOrThrow<String>(
SIGNING_ACCOUNT_ADDRSS
)
var keyRegTransactionDetail = savedStateHandle.getOrThrow<KeyRegTransactionDetail>(
private var keyRegTransactionDetail = savedStateHandle.getOrThrow<KeyRegTransactionDetail>(
KEY_REG_DETAIL
)

Expand Down Expand Up @@ -90,6 +90,12 @@ class KeyRegTransactionViewModel @Inject constructor(
}
}

fun updateTransactionNotes(transactionNote: String?) {
keyRegTransactionDetail = keyRegTransactionDetail.copy(
note = transactionNote
)
}

companion object {
const val SIGNING_ACCOUNT_ADDRSS = "signingAccountAddress"
const val KEY_REG_DETAIL = "keyRegTransactionDetail"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class AssetTransferAmountFragment : TransactionBaseFragment(R.layout.fragment_as
val note = lockedNote ?: transactionNote
nav(
AssetTransferAmountFragmentDirections
.actionAssetTransferAmountFragmentToAddNoteBottomSheet(note, lockedNote == null)
.actionAssetTransferAmountFragmentToAddNoteNavigation(note, lockedNote == null)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class AssetTransferPreviewFragment : TransactionBaseFragment(R.layout.fragment_t
private fun onAddEditNoteClicked() {
nav(
AssetTransferPreviewFragmentDirections
.actionAssetTransferPreviewFragmentToAddNoteBottomSheet(
.actionAssetTransferPreviewFragmentToAddNoteNavigation(
note = transactionNote.first,
isInputFieldEnabled = transactionNote.second
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/bottom_sheet_swap_preview_summary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
app:constraint_referenced_ids="minimumReceivedLabelTextView, minimumReceivedTextView" />

<View
android:id="@+id/feeDivider"
android:id="@+id/typeDivider"
style="@style/Divider"
android:layout_width="0dp"
android:layout_height="@dimen/divider_height"
Expand Down Expand Up @@ -237,7 +237,7 @@
app:layout_constraintEnd_toStartOf="@id/endGuideline"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toEndOf="@id/exchangeFeeLabelTextView"
app:layout_constraintTop_toBottomOf="@id/feeDivider"
app:layout_constraintTop_toBottomOf="@id/typeDivider"
tools:text="0.219412" />

<androidx.constraintlayout.widget.Barrier
Expand Down
Loading

0 comments on commit e0a5e85

Please sign in to comment.