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(wallet,wallet-dashboard): fix total stake/unstake amount in timelocks transaction summary #4824

Merged
merged 16 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 9 additions & 2 deletions apps/core/src/components/transaction/TransactionReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import { InfoBox, InfoBoxStyle, InfoBoxType } from '@iota/apps-ui-kit';
import type { useTransactionSummary } from '../../hooks';
import { CheckmarkFilled } from '@iota/ui-icons';
import { IotaTransactionBlockResponse } from '@iota/iota-sdk/client';
import { IotaEvent, IotaTransactionBlockResponse } from '@iota/iota-sdk/client';
import { STAKING_REQUEST_EVENT, UNSTAKING_REQUEST_EVENT } from '../../constants';
import { StakeTransactionDetails } from './details';
import { UnstakeTransactionInfo } from './info';
import { TransactionSummary } from './summary';
import { RenderExplorerLink, RenderValidatorLogo } from '../../types';
import { GasFees } from '../gas';
import { formatDate } from '../../utils';
import { formatDate, getTransactionAmountForTimelocked } from '../../utils';

interface TransactionReceiptProps {
txn: IotaTransactionBlockResponse;
Expand All @@ -35,6 +35,12 @@ export function TransactionReceipt({
const stakeTypeTransaction = events?.find(({ type }) => type === STAKING_REQUEST_EVENT);
const unstakeTypeTransaction = events?.find(({ type }) => type === UNSTAKING_REQUEST_EVENT);

function calculateTimelockedStakingAmount(events: IotaEvent[]): bigint | undefined | string {
return getTransactionAmountForTimelocked(events);
}

const timelockedStakingAmount = events ? calculateTimelockedStakingAmount(events) : null;

return (
<div className="flex flex-col gap-md overflow-y-auto overflow-x-hidden">
<TransactionStatus
Expand All @@ -51,6 +57,7 @@ export function TransactionReceipt({
gasSummary={summary?.gas}
renderValidatorLogo={renderValidatorLogo}
renderExplorerLink={renderExplorerLink}
timelockedStakingAmount={timelockedStakingAmount}
evavirseda marked this conversation as resolved.
Show resolved Hide resolved
/>
) : null}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface StakeTransactionDetailsProps {
renderExplorerLink: RenderExplorerLink;
renderValidatorLogo: RenderValidatorLogo;
gasSummary?: GasSummaryType;
timelockedStakingAmount?: bigint | undefined | string | null;
}

export function StakeTransactionDetails({
Expand All @@ -23,6 +24,7 @@ export function StakeTransactionDetails({
activeAddress,
renderValidatorLogo: ValidatorLogo,
renderExplorerLink,
timelockedStakingAmount,
}: StakeTransactionDetailsProps) {
const { stakedAmount, validatorAddress, epoch } = getStakeDetailsFromEvent(event);
const { data: rollingAverageApys } = useGetValidatorsApy();
Expand All @@ -43,7 +45,7 @@ export function StakeTransactionDetails({
)}
{stakedAmount && (
<TransactionAmount
amount={stakedAmount}
amount={timelockedStakingAmount ?? stakedAmount}
coinType={IOTA_TYPE_ARG}
subtitle="Stake"
/>
Expand Down
15 changes: 8 additions & 7 deletions apps/core/src/utils/stake/getTransactionAmountForTimelocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { IotaEvent } from '@iota/iota-sdk/client';
import {
getStakeDetailsFromEvent,
getUnstakeDetailsFromEvent,
checkIfIsTimelockedStaking,
} from '.';
import { getUnstakeDetailsFromEvent, checkIfIsTimelockedStaking } from '.';

export function getTransactionAmountForTimelocked(
events: IotaEvent[],
Expand All @@ -15,8 +11,13 @@ export function getTransactionAmountForTimelocked(
const { isTimelockedStaking, isTimelockedUnstaking } = checkIfIsTimelockedStaking(events);
cpl121 marked this conversation as resolved.
Show resolved Hide resolved

if (isTimelockedStaking) {
const { stakedAmount } = getStakeDetailsFromEvent(events[0]);
return stakedAmount;
let amount = 0;
events?.forEach((event) => {
evavirseda marked this conversation as resolved.
Show resolved Hide resolved
if ((event.parsedJson as { amount: number }).amount) {
amount += Number((event.parsedJson as { amount: number }).amount);
}
});
return BigInt(amount);
} else if (isTimelockedUnstaking) {
const { totalAmount } = getUnstakeDetailsFromEvent(events[0]);
return totalAmount;
Expand Down
4 changes: 3 additions & 1 deletion apps/wallet-dashboard/app/(protected)/vesting/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default function VestingDashboardPage(): JSX.Element {
unlockAllSupplyIncreaseVesting,
refreshStakeList,
isSupplyIncreaseVestingScheduleEmpty,
supplyIncreaseVestingMapped,
} = useGetSupplyIncreaseVestingObjects(address);

const timelockedStakedObjectsGrouped: TimelockedStakedObjectsGrouped[] =
Expand Down Expand Up @@ -297,7 +298,8 @@ export default function VestingDashboardPage(): JSX.Element {
</div>
</Panel>

{isSupplyIncreaseVestingScheduleEmpty ? (
{supplyIncreaseVestingMapped.length > 0 &&
supplyIncreaseVestingSchedule.totalStaked === 0n ? (
<Banner
videoSrc={videoSrc}
title="Stake Vested Tokens"
Expand Down
20 changes: 16 additions & 4 deletions apps/wallet/src/ui/app/components/transactions-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
useFormatCoin,
useTransactionSummary,
TransactionIcon,
checkIfIsTimelockedStaking,
getTransactionAmountForTimelocked,
} from '@iota/core';
import type { IotaTransactionBlockResponse } from '@iota/iota-sdk/client';
import { Link } from 'react-router-dom';
Expand Down Expand Up @@ -39,14 +41,24 @@ export function TransactionCard({ txn, address }: TransactionCardProps) {
currentAddress: address,
recognizedPackagesList,
});
const { isTimelockedStaking, isTimelockedUnstaking } = checkIfIsTimelockedStaking(txn.events);

// we only show IOTA Transfer amount or the first non-Iota transfer amount
// Get the balance changes for the transaction and the amount
const balanceChanges = getBalanceChangeSummary(txn, recognizedPackagesList);
const [formatAmount, symbol] = useFormatCoin(
Math.abs(Number(balanceChanges?.[address]?.[0]?.amount ?? 0)),
IOTA_TYPE_ARG,
);

function getAmount(tx: IotaTransactionBlockResponse) {
if ((isTimelockedStaking || isTimelockedUnstaking) && tx.events) {
return getTransactionAmountForTimelocked(tx.events);
} else {
return address && balanceChanges?.[address]?.[0]?.amount
? Math.abs(Number(balanceChanges?.[address]?.[0]?.amount))
: 0;
}
}

const transactionAmount = getAmount(txn);
const [formatAmount, symbol] = useFormatCoin(transactionAmount, IOTA_TYPE_ARG);

const error = txn.effects?.status.error;

Expand Down
Loading