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-2674] Pool redemption/contribution tx preview types #745

Merged
merged 5 commits into from
Jan 17, 2024

Conversation

jakub-rdx
Copy link
Contributor

@jakub-rdx jakub-rdx commented Jan 12, 2024

Description

  • adds pool contribution/redemption tx preview types
  • changes to state database so that we keep metadata for Pool
  • created PreviewType subtype called Transfer, and Pool, Stake and "General" transfer subtypes. Extracted common UI logic to use common "template" for transfer related types, since they were very similar.
  • crowdin strings to be added soon

How to test

  1. Use Sandbox dapp to trigger pool contributions/redemption.
  2. Validate if transfer/staking tx previews work as expected.

Video

screen-20240104-091533.2.1.mp4

PR submission checklist

  • I have tested pool contribution/redemption, stake and transfer tx types.

@jakub-rdx jakub-rdx marked this pull request as ready for review January 12, 2024 14:22
Copy link
Contributor

@micbakos-rdx micbakos-rdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work! Don't forget the todos. Also will this be included in this PR?

@@ -69,6 +69,8 @@ data class PoolWithResourceResponse(
val poolUnitAddress: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this can be deleted now, since the same info exists in the poolMetadata.

is TransferableResource.LsuAmount -> GuaranteeAssertion.ForAmount(
amount = transferable.amount * predicted.guaranteeOffset.toBigDecimal(),
instructionIndex = predicted.instructionIndex
)
is TransferableResource.StakeClaimNft -> null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to ask Matt about stake claim NFTs and their assertions?

data class Pool(
val address: String,
val poolUnitAddress: String,
val metadata: List<Metadata>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@@ -23,10 +23,10 @@ class GetPoolUnitDetailsUseCase @Inject constructor(
val poolAddress = poolResource.poolAddress ?: return@then runCatching {
error("Resource $resourceAddress is not associated with a pool")
}
stateRepository.getPool(poolAddress).map {
stateRepository.getPools(setOf(poolAddress)).map {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use mapCatching here since first() can throw an exception.

@@ -321,7 +321,7 @@ class TransactionReviewViewModel @Inject constructor(
)

val isRawManifestToggleVisible: Boolean
get() = previewType is PreviewType.Transfer
get() = true // previewType is PreviewType.Transfer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this set to always true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, was for testing

Comment on lines +436 to +503
sealed interface Transfer : PreviewType {
val from: List<AccountWithTransferableResources>
val to: List<AccountWithTransferableResources>

data class Staking(
override val from: List<AccountWithTransferableResources>,
override val to: List<AccountWithTransferableResources>,
val validators: List<ValidatorDetail>,
val actionType: ActionType
) : Transfer {
enum class ActionType {
Stake, Unstake, ClaimStake
}
}

fun getNewlyCreatedResources() = (from + to).map { allTransfers ->
allTransfers.resources.filter { it.transferable.isNewlyCreated }.map { it.transferable }
}.flatten()
}
data class Pool(
override val from: List<AccountWithTransferableResources>,
override val to: List<AccountWithTransferableResources>,
val pools: List<com.babylon.wallet.android.domain.model.resources.Pool>,
val actionType: ActionType
) : Transfer {
enum class ActionType {
Contribution, Redemption
}
}

data class GeneralTransfer(
override val from: List<AccountWithTransferableResources>,
override val to: List<AccountWithTransferableResources>,
val badges: List<Badge> = emptyList(),
val dApps: List<Pair<DApp, Boolean>> = emptyList()
) : Transfer {

data class Staking(
val from: List<AccountWithTransferableResources>,
val to: List<AccountWithTransferableResources>,
val validators: List<ValidatorDetail>,
val actionType: ActionType
) : PreviewType {
enum class ActionType {
Stake, Unstake, ClaimStake
fun getNewlyCreatedResources() = (from + to).map { allTransfers ->
allTransfers.resources.filter { it.transferable.isNewlyCreated }.map { it.transferable }
}.flatten()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done 👏

getProfileUseCase: GetProfileUseCase,
resources: List<Resource>,
involvedPools: List<Pool>
): PreviewType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set the return type to be more explicit like PreviewType.Transfer.Pool. The same with the rest of the analysis methods.

Comment on lines 71 to 73
manifest.toPrettyString().let { prettyString ->
logger.d(prettyString)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better of with:
logger.d(manifest.toPrettyString())

Comment on lines +24 to +27
val poolSectionLabel = when (previewType.actionType) {
PreviewType.Transfer.Pool.ActionType.Contribution -> "Contributing to pools"
PreviewType.Transfer.Pool.ActionType.Redemption -> "Redeeming from pools"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crowdin

@Composable
fun Pool(
modifier: Modifier = Modifier,
pool: Pool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

}
}

return result
}

data class FetchPoolsResult(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why fetch? Fetch is the action ⚠️
PoolsResponse

@@ -99,19 +116,25 @@ sealed interface TransferableResource {
get() = resource.resourceAddress
val isNewlyCreated: Boolean

data class Amount(
val amount: BigDecimal,
data class FungibleAmount(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏽

@jakub-rdx jakub-rdx force-pushed the feature/ABW-2674-pool-redeem-controbute-tx-types branch from df475b1 to 221a495 Compare January 16, 2024 10:19
@jakub-rdx jakub-rdx force-pushed the feature/ABW-2674-pool-redeem-controbute-tx-types branch from 30efd2a to 9a8bf7d Compare January 17, 2024 14:28
Copy link

sonarcloud bot commented Jan 17, 2024

Quality Gate Failed Quality Gate failed

Failed conditions

9.7% Coverage on New Code (required ≥ 40%)
14.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@micbakos-rdx micbakos-rdx merged commit 4bc4dee into main Jan 17, 2024
8 of 9 checks passed
@micbakos-rdx micbakos-rdx deleted the feature/ABW-2674-pool-redeem-controbute-tx-types branch January 17, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants