Skip to content

Commit

Permalink
Merge pull request #117 from radixdlt/bug/ABW-906
Browse files Browse the repository at this point in the history
Update transaction approval success response and add new failure caus…
  • Loading branch information
jakub-rdx authored Feb 9, 2023
2 parents 3ef95bc + 0aac47a commit 18bc786
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ class DAppMessengerImpl @Inject constructor(
requestId: String,
txId: String
): Result<Unit> {
val message = Json.encodeToString(
WalletInteractionSuccessResponse(
interactionId = requestId,
items = WalletTransactionResponseItems(SendTransactionResponseItem(txId))
)
val response: WalletInteractionResponse = WalletInteractionSuccessResponse(
interactionId = requestId,
items = WalletTransactionResponseItems(SendTransactionResponseItem(txId))
)
val message = Json.encodeToString(response)
return when (peerdroidClient.sendMessage(message)) {
is rdx.works.peerdroid.helpers.Result.Error -> Result.Error()
is rdx.works.peerdroid.helpers.Result.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ enum class WalletErrorType {
@SerialName("failedToCompileTransaction")
FailedToCompileTransaction,

@SerialName("failedToFindAccountWithEnoughFundsToLockFee")
FailedToFindAccountWithEnoughFundsToLockFee,

@SerialName("failedToSignTransaction")
FailedToSignTransaction,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sealed interface TransactionApprovalFailure {
object ConvertManifest : TransactionApprovalFailure

object BuildTransactionHeader : TransactionApprovalFailure
object NoFunds : TransactionApprovalFailure
object FailedToFindAccountWithEnoughFundsToLockFee : TransactionApprovalFailure

object PrepareNotarizedTransaction : TransactionApprovalFailure

Expand All @@ -39,7 +39,7 @@ sealed interface TransactionApprovalFailure {
RejectedByUser -> WalletErrorType.RejectedByUser
SubmitNotarizedTransaction -> WalletErrorType.FailedToSubmitTransaction
is WrongNetwork -> WalletErrorType.WrongNetwork
NoFunds -> WalletErrorType.FailedToPrepareTransaction
FailedToFindAccountWithEnoughFundsToLockFee -> WalletErrorType.FailedToFindAccountWithEnoughFundsToLockFee
}
}

Expand All @@ -57,7 +57,7 @@ sealed interface TransactionApprovalFailure {
RejectedByUser -> R.string.tx_fail_rejected_by_user
SubmitNotarizedTransaction -> R.string.tx_fail_submit
is WrongNetwork -> R.string.tx_fail_network
NoFunds -> R.string.no_funds_to_approve_transaction
FailedToFindAccountWithEnoughFundsToLockFee -> R.string.no_funds_to_approve_transaction
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class TransactionClient @Inject constructor(
is Result.Success -> manifestConversionResult.data
}
val accountAddressToLockFee = getAccountAddressToLockFee() ?: return Result.Error(
TransactionApprovalException(TransactionApprovalFailure.NoFunds)
TransactionApprovalException(TransactionApprovalFailure.FailedToFindAccountWithEnoughFundsToLockFee)
)
return Result.Success(
addLockFeeInstructionToManifest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fun SettingsConnectionScreen(
)
}

@OptIn(ExperimentalPermissionsApi::class)
@Composable
private fun SettingsAddConnectionContent(
connectionName: String?,
Expand Down Expand Up @@ -128,11 +129,12 @@ private fun SettingsAddConnectionContent(
}
SettingsConnectionMode.ShowDetails -> {
ActiveConnectionDetails(
connectionName,
onAddConnection,
cameraPermissionState,
onDeleteConnectionClick,
Modifier.fillMaxWidth()
connectionName = connectionName,
onAddConnection = onAddConnection,
cameraPermissionState = cameraPermissionState,
onDeleteConnectionClick = onDeleteConnectionClick,
isLoading = isLoading,
modifier = Modifier.fillMaxWidth()
)
}
SettingsConnectionMode.ScanQr -> {
Expand All @@ -159,6 +161,7 @@ private fun ActiveConnectionDetails(
onAddConnection: () -> Unit,
cameraPermissionState: PermissionState,
onDeleteConnectionClick: () -> Unit,
isLoading: Boolean,
modifier: Modifier = Modifier
) {
Column(modifier, horizontalAlignment = Alignment.CenterHorizontally) {
Expand All @@ -169,7 +172,7 @@ private fun ActiveConnectionDetails(
color = RadixTheme.colors.gray2
)
Divider(color = RadixTheme.colors.gray5)
AnimatedVisibility(visible = connectionName == null) {
AnimatedVisibility(visible = connectionName == null && !isLoading) {
Column {
Spacer(modifier = Modifier.height(RadixTheme.dimensions.paddingDefault))
RadixSecondaryButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SettingsConnectionViewModel @Inject constructor(
}

data class SettingsConnectionUiState(
val isLoading: Boolean = false,
val isLoading: Boolean = true,
val connectionName: String? = null,
val editedConnectionDisplayName: String = "",
val buttonEnabled: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import com.babylon.wallet.android.data.dapp.model.AuthUsePersonaRequestItem
import com.babylon.wallet.android.data.dapp.model.OneTimeAccountsRequestResponseItem
import com.babylon.wallet.android.data.dapp.model.OneTimeAccountsWithProofOfOwnershipRequestResponseItem
import com.babylon.wallet.android.data.dapp.model.OneTimeAccountsWithoutProofOfOwnershipRequestResponseItem
import com.babylon.wallet.android.data.dapp.model.SendTransactionResponseItem
import com.babylon.wallet.android.data.dapp.model.WalletAuthorizedRequestItems
import com.babylon.wallet.android.data.dapp.model.WalletInteraction
import com.babylon.wallet.android.data.dapp.model.WalletInteractionResponse
import com.babylon.wallet.android.data.dapp.model.WalletInteractionSuccessResponse
import com.babylon.wallet.android.data.dapp.model.WalletTransactionItems
import com.babylon.wallet.android.data.dapp.model.WalletTransactionResponseItems
import com.babylon.wallet.android.data.dapp.model.WalletUnauthorizedRequestItems
import com.babylon.wallet.android.data.dapp.model.walletRequestJson
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import org.junit.Assert
import org.junit.Test

class WalletInteractionModelsTest {
Expand Down Expand Up @@ -370,4 +375,14 @@ class WalletInteractionModelsTest {
assert(item.send.transactionManifest == "manifest")
}

@Test
fun `transaction approval response matches expected`() {
val expected = """{"discriminator":"success","interactionId":"1","items":{"discriminator":"transaction","send":{"transactionIntentHash":"1"}}}"""
val response: WalletInteractionResponse = WalletInteractionSuccessResponse(
interactionId = "1", items = WalletTransactionResponseItems(SendTransactionResponseItem("1"))
)
val result = walletRequestJson.encodeToString(response)
Assert.assertEquals(expected, result)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
Expand Down Expand Up @@ -59,7 +61,12 @@ fun RadixTextField(
textColor = RadixTheme.colors.gray1,
focusedBorderColor = RadixTheme.colors.gray1,
unfocusedBorderColor = Color.Transparent,
errorBorderColor = RadixTheme.colors.red1
errorBorderColor = RadixTheme.colors.red1,
cursorColor = RadixTheme.colors.gray1,
selectionColors = TextSelectionColors(
RadixTheme.colors.gray1,
LocalTextSelectionColors.current.backgroundColor
)
),
placeholder = {
hint?.let { Text(text = it, style = RadixTheme.typography.body1Regular) }
Expand Down

0 comments on commit 18bc786

Please sign in to comment.