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

Fix: old participations tx history tagging #3338

Merged
merged 3 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/shared/components/ActivityRow.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="typescript">
import { formatDate, localize } from '@core/i18n'
import { Icon, Text } from 'shared/components'
import { truncateString } from 'shared/lib/helpers'
import { formatDate, localize } from '@core/i18n'
import { Payload } from 'shared/lib/typings/message'
import { getMessageParticipationAction } from 'shared/lib/participation'
import { ParticipationAction } from 'shared/lib/participation/types'
import { Payload, Transaction } from 'shared/lib/typings/message'
import { formatUnitBestMatch } from 'shared/lib/units'
import {
findAccountWithAddress,
Expand All @@ -16,8 +17,6 @@
sendAddressFromTransactionPayload,
wallet,
} from 'shared/lib/wallet'
import { Transaction } from 'shared/lib/typings/message'
import { getMessageParticipationAction } from 'shared/lib/participation'

export let id: string
export let timestamp: string
Expand Down Expand Up @@ -53,7 +52,7 @@
$: hasCachedMigrationTx, milestonePayload, txPayload, (messageValue = getMessageValue())
$: senderAddress = sendAddressFromTransactionPayload(payload)
$: receiverAddresses = receiverAddressesFromTransactionPayload(payload)
$: participationAction = getMessageParticipationAction(id)
$: participationAction = getMessageParticipationAction(id, timestamp)

// There can only be one sender address
$: senderAccount = findAccountWithAddress(senderAddress)
Expand Down
16 changes: 8 additions & 8 deletions packages/shared/lib/participation/participation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
isFetchingParticipationInfo,
} from './stores'
import { AccountParticipationAbility, ParticipationAction, ParticipationEventState, StakingAirdrop } from './types'
import { getDurationString, milestoneToDate } from '@lib/time'

let shouldPollParticipation = true
let participationPollTimeout
Expand Down Expand Up @@ -144,17 +145,16 @@ export const getAccountParticipationAbility = (account: WalletAccount): AccountP
*
* @returns {ParticipationAction}
*/
export const getMessageParticipationAction = (messageId: string): ParticipationAction => {
export const getMessageParticipationAction = (messageId: string, timestamp: string): ParticipationAction => {
const matchedHistoryItem = get(participationHistory)?.find((item) => item.messageId === messageId)
if (matchedHistoryItem?.action) {
return matchedHistoryItem.action
}
const stakingEndMilestoneIndexes = get(participationEvents)
?.filter((event) => event.eventId === ASSEMBLY_EVENT_ID || event.eventId === SHIMMER_EVENT_ID)
?.map((event) => event.information?.milestoneIndexEnd)
if (stakingEndMilestoneIndexes?.find((milestone) => milestone > LAST_MILESTONE_BEFORE_TREASURY_EVENT)) {
return ParticipationAction.Stake
} else if (stakingEndMilestoneIndexes?.length) {
return ParticipationAction.Vote
if (timestamp) {
const lastDateBeforeTreasuryEvent = milestoneToDate(LAST_MILESTONE_BEFORE_TREASURY_EVENT)
const messageDate = new Date(timestamp)
if (messageDate <= lastDateBeforeTreasuryEvent) {
return ParticipationAction.Stake
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
if (searchValue) {
queryTransactions = filteredTransactions.filter((transaction) => {
const transactionValue = (transaction?.payload as Transaction)?.data?.essence?.data?.value
const participationAction = getMessageParticipationAction(transaction.id)
const participationAction = getMessageParticipationAction(transaction.id, transaction.timestamp)
return (
sendAddressFromTransactionPayload(transaction?.payload) === searchValue ||
receiverAddressesFromTransactionPayload(transaction?.payload).find(
Expand Down