Skip to content

Commit

Permalink
fix(staking): zero amounts when bumping fee of claim tx
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-pvl authored and tomasklim committed Nov 3, 2024
1 parent 0c1733c commit fe65440
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const TransactionReviewOutput = forwardRef<HTMLDivElement, TransactionRev
fiatSymbol={symbol}
fiatVisible={fiatVisible}
displayMode={displayMode}
ethereumStakeType={ethereumStakeType}
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { TransactionReviewStepIndicatorProps } from './TransactionReviewStepIndi
import { zIndices } from '@trezor/theme';
import { DeviceDisplay } from '../../../../DeviceDisplay/DeviceDisplay';
import { DisplayMode } from 'src/types/suite';
import { StakeType } from '@suite-common/wallet-types';
import { hasZeroAmountWhenClaiming } from 'src/utils/suite/stake';

const TYPES_TO_BE_DISPLAYED_IN_SCREEN_BOX = ['address', 'regular_legacy', 'data', 'opreturn'];

Expand Down Expand Up @@ -148,6 +150,7 @@ export type TransactionReviewOutputElementProps = {
account?: Account;
state?: TransactionReviewStepIndicatorProps['state'];
displayMode?: DisplayMode;
ethereumStakeType?: StakeType;
};

export const TransactionReviewOutputElement = forwardRef<
Expand All @@ -165,18 +168,24 @@ export const TransactionReviewOutputElement = forwardRef<
account,
state,
displayMode,
ethereumStakeType,
},
ref,
) => {
const network = account?.networkType;
const cardanoFingerprint = getFingerprint(account?.tokens, token?.symbol);
const isActive = state === 'active';
const hasMultipleLines = lines.length > 1;

const hasZeroAmount = Boolean(
lines.find(line => hasZeroAmountWhenClaiming(line, ethereumStakeType)),
);

const showMultiIndicator = lines.length > 1 && !hasZeroAmount;

return (
<OutputWrapper ref={ref}>
<OutputLeft $isCentered={hasMultipleLines}>
{hasMultipleLines ? (
<OutputLeft $isCentered={showMultiIndicator}>
{showMultiIndicator ? (
<MultiIndicatorWrapper $linesCount={lines.length - 1}>
{indicator}
</MultiIndicatorWrapper>
Expand All @@ -185,72 +194,86 @@ export const TransactionReviewOutputElement = forwardRef<
)}
</OutputLeft>
<OutputRight>
{lines.map(line => (
<OutputRightLine key={line.id}>
<OutputHeadline>
{isActive && (line.id === 'address' || line.id === 'regular_legacy')
? line.confirmLabel
: line.label}
</OutputHeadline>
<OutputValue>
{isActive &&
displayMode &&
TYPES_TO_BE_DISPLAYED_IN_SCREEN_BOX.includes(line.id) ? (
<DeviceDisplay displayMode={displayMode} address={line.value} />
) : (
<OutputValueWrapper>
{line.plainValue ? (
line.value
) : (
<FormattedCryptoAmount
disableHiddenPlaceholder
value={line.value}
symbol={
// TX fee is so far always paid in network native coin
line.id !== 'fee' && token
? token.symbol
: cryptoSymbol
}
/>
)}
</OutputValueWrapper>
)}
{/* temporary solution until fiat value for ERC20 tokens will be fixed */}
{fiatSymbol && fiatVisible && !(line.id !== 'fee' && token) && (
<>
<DotSeparatorWrapper>
<DotSeparator />
</DotSeparatorWrapper>
<OutputValueWrapper>
<FiatValue
disableHiddenPlaceholder
amount={line.value}
symbol={fiatSymbol}
/>
</OutputValueWrapper>
</>
)}
</OutputValue>
{network === 'cardano' && cardanoFingerprint && (
<CardanoTrezorAmountWrapper>
{lines.map(
line =>
!hasZeroAmountWhenClaiming(line, ethereumStakeType) && (
<OutputRightLine key={line.id}>
<OutputHeadline>
<Translation id="TR_CARDANO_FINGERPRINT_HEADLINE" />
</OutputHeadline>
<OutputValue>{cardanoFingerprint}</OutputValue>
</CardanoTrezorAmountWrapper>
)}
{network === 'cardano' && token && token.decimals !== 0 && (
<CardanoTrezorAmountWrapper>
<OutputHeadline>
<Translation id="TR_CARDANO_TREZOR_AMOUNT_HEADLINE" />
{isActive &&
(line.id === 'address' || line.id === 'regular_legacy')
? line.confirmLabel
: line.label}
</OutputHeadline>

<OutputValue>
{formatAmountWithDecimals(line.value, token.decimals)}
{isActive &&
displayMode &&
TYPES_TO_BE_DISPLAYED_IN_SCREEN_BOX.includes(line.id) ? (
<DeviceDisplay
displayMode={displayMode}
address={line.value}
/>
) : (
<OutputValueWrapper>
{line.plainValue ? (
line.value
) : (
<FormattedCryptoAmount
disableHiddenPlaceholder
value={line.value}
symbol={
// TX fee is so far always paid in network native coin
line.id !== 'fee' && token
? token.symbol
: cryptoSymbol
}
/>
)}
</OutputValueWrapper>
)}
{/* temporary solution until fiat value for ERC20 tokens will be fixed */}
{fiatSymbol &&
fiatVisible &&
!(line.id !== 'fee' && token) && (
<>
<DotSeparatorWrapper>
<DotSeparator />
</DotSeparatorWrapper>
<OutputValueWrapper>
<FiatValue
disableHiddenPlaceholder
amount={line.value}
symbol={fiatSymbol}
/>
</OutputValueWrapper>
</>
)}
</OutputValue>
</CardanoTrezorAmountWrapper>
)}
</OutputRightLine>
))}

{network === 'cardano' && cardanoFingerprint && (
<CardanoTrezorAmountWrapper>
<OutputHeadline>
<Translation id="TR_CARDANO_FINGERPRINT_HEADLINE" />
</OutputHeadline>
<OutputValue>{cardanoFingerprint}</OutputValue>
</CardanoTrezorAmountWrapper>
)}
{network === 'cardano' && token && token.decimals !== 0 && (
<CardanoTrezorAmountWrapper>
<OutputHeadline>
<Translation id="TR_CARDANO_TREZOR_AMOUNT_HEADLINE" />
</OutputHeadline>
<OutputValue>
{formatAmountWithDecimals(
line.value,
token.decimals,
)}
</OutputValue>
</CardanoTrezorAmountWrapper>
)}
</OutputRightLine>
),
)}
</OutputRight>
</OutputWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export const TransactionReviewOutputList = ({
outputs={outputs}
buttonRequestsCount={buttonRequestsCount}
precomposedTx={precomposedTx}
ethereumStakeType={ethereumStakeType}
/>
)}
</RightTopInner>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const getLines = (
export const TransactionReviewTotalOutput = forwardRef<
HTMLDivElement,
TransactionReviewTotalOutputProps
>(({ account, signedTx, outputs, buttonRequestsCount, precomposedTx }, ref) => {
>(({ account, signedTx, outputs, buttonRequestsCount, precomposedTx, ethereumStakeType }, ref) => {
const device = useSelector(selectDevice);

if (!device) {
Expand All @@ -139,6 +139,7 @@ export const TransactionReviewTotalOutput = forwardRef<
fiatVisible={!isTestnet(symbol)}
ref={ref}
token={precomposedTx?.token}
ethereumStakeType={ethereumStakeType}
/>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export const TransactionReviewSummary = ({
const formFeeRate = drafts[currentAccountKey]?.feePerUnit;
const isFeeCustom = drafts[currentAccountKey]?.selectedFee === 'custom';
const isComposedFeeRateDifferent = isFeeCustom && formFeeRate !== fee;
const hasZeroAmountWhenClaiming = amount === '0' && ethereumStakeType === 'claim';

return (
<Wrapper>
Expand All @@ -254,13 +255,15 @@ export const TransactionReviewSummary = ({

<Headline>
<Translation id={actionText} />
<HeadlineAmount>
<FormattedCryptoAmount
disableHiddenPlaceholder
value={amount}
symbol={tx.token?.symbol ?? symbol}
/>
</HeadlineAmount>
{!hasZeroAmountWhenClaiming && (
<HeadlineAmount>
<FormattedCryptoAmount
disableHiddenPlaceholder
value={amount}
symbol={tx.token?.symbol ?? symbol}
/>
</HeadlineAmount>
)}
</Headline>

<AccountWrapper>
Expand Down
10 changes: 10 additions & 0 deletions packages/suite/src/utils/suite/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
MAX_ETH_AMOUNT_FOR_STAKING,
} from 'src/constants/suite/ethStaking';
import { TranslationFunction } from 'src/hooks/suite/useTranslation';
import { OutputElementLine } from 'src/components/suite/modals/ReduxModal/TransactionReviewModal/TransactionReviewOutputList/TransactionReviewOutputElement';

// source is a required parameter for some functions in the Everstake Wallet SDK.
// This parameter is used for some contract calls.
Expand Down Expand Up @@ -664,3 +665,12 @@ export const simulateUnstake = async ({

return fromWei(approximatedAmount, 'ether');
};

export const hasZeroAmountWhenClaiming = (
line: OutputElementLine,
ethereumStakeType?: StakeType,
) => {
if (!ethereumStakeType) return false;

return line.id === 'amount' && line.value === '0' && ethereumStakeType === 'claim';
};

0 comments on commit fe65440

Please sign in to comment.