Skip to content

Commit

Permalink
Show event id for pool rewards instead of tx hash (#1121)
Browse files Browse the repository at this point in the history
* Show event id for pool rewards instead of tx hash

* Code style
  • Loading branch information
valentunn authored Sep 14, 2023
1 parent 56dae16 commit 4fb2279
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import io.novafoundation.nova.core_db.migrations.AddContributions_23_24
import io.novafoundation.nova.core_db.migrations.AddCurrencies_18_19
import io.novafoundation.nova.core_db.migrations.AddDAppAuthorizations_1_2
import io.novafoundation.nova.core_db.migrations.AddEnabledColumnToChainAssets_30_31
import io.novafoundation.nova.core_db.migrations.AddEventIdToOperation_47_48
import io.novafoundation.nova.core_db.migrations.AddExternalBalances_45_46
import io.novafoundation.nova.core_db.migrations.AddExternalBalances_46_47
import io.novafoundation.nova.core_db.migrations.AddExtrinsicContentField_37_38
import io.novafoundation.nova.core_db.migrations.AddFavouriteDApps_9_10
import io.novafoundation.nova.core_db.migrations.AddGovernanceDapps_25_26
Expand All @@ -62,6 +62,7 @@ import io.novafoundation.nova.core_db.migrations.AddLocks_22_23
import io.novafoundation.nova.core_db.migrations.AddMetaAccountType_14_15
import io.novafoundation.nova.core_db.migrations.AddNfts_5_6
import io.novafoundation.nova.core_db.migrations.AddNodeSelectionStrategyField_38_39
import io.novafoundation.nova.core_db.migrations.AddPoolIdToOperations_46_47
import io.novafoundation.nova.core_db.migrations.AddRewardAccountToStakingDashboard_43_44
import io.novafoundation.nova.core_db.migrations.AddRuntimeFlagToChains_36_37
import io.novafoundation.nova.core_db.migrations.AddSitePhishing_6_7
Expand Down Expand Up @@ -121,7 +122,7 @@ import io.novafoundation.nova.core_db.model.chain.ChainRuntimeInfoLocal
import io.novafoundation.nova.core_db.model.chain.MetaAccountLocal

@Database(
version = 47,
version = 48,
entities = [
AccountLocal::class,
NodeLocal::class,
Expand Down Expand Up @@ -202,7 +203,7 @@ abstract class AppDatabase : RoomDatabase() {
.addMigrations(AddWalletConnectSessions_39_40, TransferFiatAmount_40_41)
.addMigrations(AddStakingDashboardItems_41_42, StakingRewardPeriods_42_43)
.addMigrations(AddRewardAccountToStakingDashboard_43_44, AddStakingTypeToTotalRewards_44_45, AddExternalBalances_45_46)
.addMigrations(AddExternalBalances_46_47)
.addMigrations(AddPoolIdToOperations_46_47, AddEventIdToOperation_47_48)
.build()
}
return instance!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.novafoundation.nova.core_db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

val AddExternalBalances_46_47 = object : Migration(46, 47) {
val AddPoolIdToOperations_46_47 = object : Migration(46, 47) {

override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE operations ADD COLUMN poolId INTEGER")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.novafoundation.nova.core_db.migrations

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

val AddEventIdToOperation_47_48 = object : Migration(47, 48) {

override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE operations ADD COLUMN eventId TEXT")

database.execSQL("DELETE FROM operations")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data class OperationLocal(
val era: Int? = null,
val validator: String? = null,
val poolId: Int? = null,
val eventId: String? = null,
) {
enum class Type {
EXTRINSIC, TRANSFER, REWARD, POOL_REWARD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ fun mapOperationToOperationLocalDb(
isReward = rewardOrNull()?.isReward,
era = rewardOrNull()?.directKindOrNull()?.era,
validator = rewardOrNull()?.directKindOrNull()?.validator,
poolId = rewardOrNull()?.poolKindOrNull()?.poolId
poolId = rewardOrNull()?.poolKindOrNull()?.poolId,
eventId = rewardOrNull()?.eventId
)
}
}
Expand Down Expand Up @@ -151,15 +152,17 @@ fun mapOperationLocalToOperation(
kind = RewardKind.Direct(
era = era!!,
validator = validator
)
),
eventId = eventId!!
)
OperationLocal.Type.POOL_REWARD -> Type.Reward(
amount = amount!!,
fiatAmount = coinRate?.convertPlanks(chainAsset, amount!!),
isReward = isReward!!,
kind = RewardKind.Pool(
poolId = poolId!!
)
),
eventId = eventId!!
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sealed class OperationParcelizeModel : Parcelable {
val amount: AmountParcelModel,
val type: String,
val poolId: Int,
val extrinsicHash: String?,
val eventId: String,
) : OperationParcelizeModel()

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import io.novafoundation.nova.feature_assets.presentation.model.showOperationSta
import io.novafoundation.nova.feature_assets.presentation.model.toAmountModel
import io.novafoundation.nova.feature_staking_api.presentation.nominationPools.display.showPool
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailAmount
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailEventId
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailNetwork
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailPool
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailStatus
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailToolbar
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailTransactionId
import kotlinx.android.synthetic.main.fragment_pool_reward_details.poolRewardDetailType

class PoolRewardDetailFragment : BaseFragment<PoolRewardDetailViewModel>() {
Expand All @@ -44,8 +44,8 @@ class PoolRewardDetailFragment : BaseFragment<PoolRewardDetailViewModel>() {
override fun initViews() {
poolRewardDetailToolbar.setHomeButtonListener { viewModel.backClicked() }

poolRewardDetailTransactionId.setOnClickListener {
viewModel.transactionIdClicked()
poolRewardDetailEventId.setOnClickListener {
viewModel.eventIdClicked()
}

poolRewardDetailPool.setOnClickListener {
Expand All @@ -71,7 +71,7 @@ class PoolRewardDetailFragment : BaseFragment<PoolRewardDetailViewModel>() {
setupExternalActions(viewModel)

with(viewModel.operation) {
poolRewardDetailTransactionId.showValueOrHide(extrinsicHash)
poolRewardDetailEventId.showValueOrHide(eventId)
poolRewardDetailToolbar.setTitle(time.formatDateTime())
poolRewardDetailAmount.setAmount(amount.toAmountModel())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ class PoolRewardDetailViewModel(
router.back()
}

fun transactionIdClicked() {
operation.extrinsicHash?.let { hash ->
shoExternalActions(ExternalActions.Type.Extrinsic(hash))
}
fun eventIdClicked() {
shoExternalActions(ExternalActions.Type.Event(operation.eventId))
}

fun poolClicked() = launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ suspend fun mapOperationToParcel(
when (val rewardKind = operationType.kind) {
is RewardKind.Direct -> OperationParcelizeModel.Reward(
chainId = chainAsset.chainId,
eventId = id,
eventId = operationType.eventId,
address = address,
time = time,
amount = amount,
Expand All @@ -327,7 +327,7 @@ suspend fun mapOperationToParcel(
amount = amount,
type = resourceManager.getString(typeRes),
poolId = rewardKind.poolId,
extrinsicHash = extrinsicHash
eventId = operationType.eventId
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@
android:layout_marginBottom="24dp">

<io.novafoundation.nova.common.view.TableCellView
android:id="@+id/poolRewardDetailTransactionId"
android:id="@+id/poolRewardDetailEventId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:primaryValueIcon="@drawable/ic_info_cicrle_filled_16"
app:primaryValueIconTint="@color/icon_secondary"
app:title="@string/common_transaction_id" />
app:title="@string/common_event" />

<io.novafoundation.nova.common.view.TableCellView
android:id="@+id/poolRewardDetailType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data class Operation(
val amount: BigInteger,
val fiatAmount: BigDecimal?,
val isReward: Boolean,
val eventId: String,
val kind: RewardKind
) : Type() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ abstract class SubstrateAssetHistory(
kind = Operation.Type.Reward.RewardKind.Direct(
era = era,
validator = validator.nullIfEmpty(),
)
),
eventId = eventId(node.blockNumber, node.reward.eventIdx)
)
}

Expand All @@ -158,7 +159,8 @@ abstract class SubstrateAssetHistory(
isReward = isReward,
kind = Operation.Type.Reward.RewardKind.Pool(
poolId = poolId
)
),
eventId = eventId(node.blockNumber, node.poolReward.eventIdx)
)
}

Expand Down Expand Up @@ -207,4 +209,8 @@ abstract class SubstrateAssetHistory(
extrinsicHash = node.extrinsicHash
)
}

private fun eventId(blockNumber: Long, eventIdx: Int): String {
return "$blockNumber-$eventIdx"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SubqueryHistoryRequest(
id
timestamp
extrinsicHash
blockNumber
address
${rewardsResponseSections(asset)}
extrinsic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SubqueryHistoryElementResponse(val query: Query) {
val extrinsicHash: String?,
val address: String,
val reward: Reward?,
val blockNumber: Long,
val poolReward: PoolReward?,
val transfer: Transfer?,
val extrinsic: Extrinsic?,
Expand All @@ -25,12 +26,14 @@ class SubqueryHistoryElementResponse(val query: Query) {
class Reward(
val era: Int,
val amount: BigInteger,
val eventIdx: Int,
val isReward: Boolean,
val validator: String?,
)

class PoolReward(
val amount: BigInteger,
val eventIdx: Int,
val poolId: Int,
val isReward: Boolean,
)
Expand Down

0 comments on commit 4fb2279

Please sign in to comment.