Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into tooling-wallet/add…
Browse files Browse the repository at this point in the history
…-objects-from-indexer
  • Loading branch information
panteleymonchuk committed Jan 24, 2025
2 parents 6c9c84a + ff30b96 commit 88f9c02
Show file tree
Hide file tree
Showing 118 changed files with 1,042 additions and 2,415 deletions.
60 changes: 1 addition & 59 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apps/core/src/components/gas/GasSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { ExplorerLinkType, useFormatCoin, type GasSummaryType } from '../../';
import { CoinFormat, ExplorerLinkType, useFormatCoin, type GasSummaryType } from '../../';
import { RenderExplorerLink } from '../../types';
import { formatAddress, IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';

Expand All @@ -26,7 +26,7 @@ export function GasSummary({
activeAddress,
}: GasSummaryProps) {
const address = sender || activeAddress;
const [gas, symbol] = useFormatCoin(gasSummary?.totalGas, IOTA_TYPE_ARG);
const [gas, symbol] = useFormatCoin(gasSummary?.totalGas, IOTA_TYPE_ARG, CoinFormat.FULL);

const gasValueText = isPending
? 'Estimating...'
Expand Down
3 changes: 2 additions & 1 deletion apps/core/src/components/inputs/SendTokenFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { ButtonPill, Input, InputType } from '@iota/apps-ui-kit';
import { CoinStruct } from '@iota/iota-sdk/client';
import { useFormatCoin, useGasBudgetEstimation } from '../../hooks';
import { CoinFormat, useFormatCoin, useGasBudgetEstimation } from '../../hooks';
import { useEffect } from 'react';
import { useField, useFormikContext } from 'formik';
import { TokenForm } from '../../forms';
Expand Down Expand Up @@ -44,6 +44,7 @@ export function SendTokenFormInput({
const [formattedGasBudgetEstimation, gasToken] = useFormatCoin(
gasBudgetEstimation,
IOTA_TYPE_ARG,
CoinFormat.FULL,
);

const [field, meta, helpers] = useField<string>(name);
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/components/transaction/TransactionReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function TransactionReceipt({
{stakeTypeTransaction ? (
<StakeTransactionDetails
activeAddress={activeAddress}
event={stakeTypeTransaction}
events={events ?? []}
gasSummary={summary?.gas}
renderExplorerLink={renderExplorerLink}
/>
Expand All @@ -54,7 +54,7 @@ export function TransactionReceipt({
{unstakeTypeTransaction ? (
<UnstakeTransactionInfo
activeAddress={activeAddress}
event={unstakeTypeTransaction}
events={events ?? []}
gasSummary={summary?.gas}
renderExplorerLink={renderExplorerLink}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { CardType } from '@iota/apps-ui-kit';
import { IotaEvent } from '@iota/iota-sdk/client';
import { formatPercentageDisplay, getStakeDetailsFromEvent } from '../../../utils';
import { formatPercentageDisplay, getStakeDetailsFromEvents } from '../../../utils';
import { useGetValidatorsApy } from '../../../hooks';
import { TransactionAmount } from '../amount';
import { StakeTransactionInfo } from '../info';
Expand All @@ -12,19 +12,21 @@ import { Validator } from '../../../';
import type { GasSummaryType, RenderExplorerLink } from '../../../types';

interface StakeTransactionDetailsProps {
event: IotaEvent;
events: IotaEvent[];
activeAddress: string | null;
renderExplorerLink: RenderExplorerLink;
gasSummary?: GasSummaryType;
}

export function StakeTransactionDetails({
event,
events,
gasSummary,
activeAddress,
renderExplorerLink,
}: StakeTransactionDetailsProps) {
const { stakedAmount, validatorAddress, epoch } = getStakeDetailsFromEvent(event);
const stakeDetails = getStakeDetailsFromEvents(events);

const { totalStakedAmount, validatorAddress, epoch } = stakeDetails;
const { data: rollingAverageApys } = useGetValidatorsApy();
const { apy, isApyApproxZero } = rollingAverageApys?.[validatorAddress] ?? {
apy: null,
Expand All @@ -42,9 +44,9 @@ export function StakeTransactionDetails({
isSelected
/>
)}
{stakedAmount && (
{totalStakedAmount && (
<TransactionAmount
amount={stakedAmount}
amount={totalStakedAmount}
coinType={IOTA_TYPE_ARG}
subtitle="Stake"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,41 @@ import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import type { GasSummaryType, RenderExplorerLink } from '../../../types';
import { useFormatCoin } from '../../../hooks';
import { Divider, KeyValueInfo, Panel, CardType } from '@iota/apps-ui-kit';
import { GasSummary, getUnstakeDetailsFromEvent, Validator } from '../../..';
import { GasSummary, getUnstakeDetailsFromEvents, Validator } from '../../..';

interface UnstakeTransactionInfoProps {
activeAddress: string | null;
event: IotaEvent;
events: IotaEvent[];
renderExplorerLink: RenderExplorerLink;
gasSummary?: GasSummaryType;
}

export function UnstakeTransactionInfo({
activeAddress,
event,
events,
gasSummary,
renderExplorerLink,
}: UnstakeTransactionInfoProps) {
const { principalAmount, rewardAmount, totalAmount, validatorAddress } =
getUnstakeDetailsFromEvent(event);

const [formatPrinciple, symbol] = useFormatCoin(principalAmount, IOTA_TYPE_ARG);
const [formatRewards] = useFormatCoin(rewardAmount || 0, IOTA_TYPE_ARG);
const unstakeDetails = getUnstakeDetailsFromEvents(events);
const { totalUnstakeAmount, validatorAddress, unstakeAmount, unstakeRewards } = unstakeDetails;

const [formatTotalAmountWithoutRewards, symbol] = useFormatCoin(unstakeAmount, IOTA_TYPE_ARG);
const [formatRewards] = useFormatCoin(unstakeRewards || 0, IOTA_TYPE_ARG);
return (
<div className="flex flex-col gap-y-md">
{validatorAddress && <Validator address={validatorAddress} type={CardType.Filled} />}
{totalAmount !== 0n && (
<TransactionAmount amount={totalAmount} coinType={IOTA_TYPE_ARG} subtitle="Total" />
{totalUnstakeAmount !== 0n && (
<TransactionAmount
amount={totalUnstakeAmount}
coinType={IOTA_TYPE_ARG}
subtitle="Total"
/>
)}
<Panel hasBorder>
<div className="flex flex-col gap-y-sm p-md">
<KeyValueInfo
keyText="Your Stake"
value={`${formatPrinciple} ${symbol}`}
value={`${formatTotalAmountWithoutRewards} ${symbol}`}
fullwidth
/>
<KeyValueInfo
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/useTransactionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { useFormatCoin } from '.';
import { CoinFormat, useFormatCoin } from '.';
import { useIotaClient } from '@iota/dapp-kit';
import { Transaction, type TransactionData } from '@iota/iota-sdk/transactions';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
Expand All @@ -29,7 +29,7 @@ export function useTransactionData(sender?: string | null, transaction?: Transac
export function useTransactionGasBudget(sender?: string | null, transaction?: Transaction | null) {
const { data, ...rest } = useTransactionData(sender, transaction);

const [formattedGas] = useFormatCoin(data?.gasData.budget, IOTA_TYPE_ARG);
const [formattedGas] = useFormatCoin(data?.gasData.budget, IOTA_TYPE_ARG, CoinFormat.FULL);

return {
data: formattedGas,
Expand Down
18 changes: 0 additions & 18 deletions apps/core/src/utils/stake/getStakeDetailsFromEvent.ts

This file was deleted.

24 changes: 24 additions & 0 deletions apps/core/src/utils/stake/getStakeDetailsFromEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { STAKING_REQUEST_EVENT } from '../../constants';
import { StakeEventJson } from '../../interfaces';
import type { IotaEvent } from '@iota/iota-sdk/client';

export function getStakeDetailsFromEvents(events: IotaEvent[]): {
totalStakedAmount: string;
validatorAddress: string;
epoch: number;
} {
const stakeEvent = events.find((event) => event.type === STAKING_REQUEST_EVENT);

const eventJson = stakeEvent?.parsedJson as StakeEventJson;
const totalStakedAmount = events?.reduce((sum, event) => {
return sum + Number((event.parsedJson as { amount: number }).amount || 0);
}, 0);
return {
totalStakedAmount: totalStakedAmount.toString(),
validatorAddress: eventJson.validator_address || '',
epoch: Number(eventJson.epoch || '0'),
};
}
17 changes: 7 additions & 10 deletions apps/core/src/utils/stake/getTransactionAmountForTimelocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
// SPDX-License-Identifier: Apache-2.0

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

export function getTransactionAmountForTimelocked(
events: IotaEvent[],
isTimelockedStaking: boolean,
isTimelockedUnstaking: boolean,
): bigint | undefined | string {
if (!events) return;
const { isTimelockedStaking, isTimelockedUnstaking } = checkIfIsTimelockedStaking(events);

if (isTimelockedStaking) {
const { stakedAmount } = getStakeDetailsFromEvent(events[0]);
return stakedAmount;
const { totalStakedAmount } = getStakeDetailsFromEvents(events);
return totalStakedAmount;
} else if (isTimelockedUnstaking) {
const { totalAmount } = getUnstakeDetailsFromEvent(events[0]);
return totalAmount;
const { totalUnstakeAmount } = getUnstakeDetailsFromEvents(events);
return totalUnstakeAmount;
}
}
23 changes: 0 additions & 23 deletions apps/core/src/utils/stake/getUnstakeDetailsFromEvent.ts

This file was deleted.

Loading

0 comments on commit 88f9c02

Please sign in to comment.