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

test pipelines #15030 #15177

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isDesktop } from '@trezor/env-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import { PROTO } from '@trezor/connect';
import {
amountToSatoshi,
amountToSmallestUnit,
formatAmount,
getAccountDecimals,
hasNetworkFeatures,
Expand Down Expand Up @@ -204,7 +204,7 @@ export const convertDrafts = () => (dispatch: Dispatch, getState: GetState) => {

if (draft) {
const areSatsSelected = settings.bitcoinAmountUnit === PROTO.AmountUnit.SATOSHI;
const conversion = areSatsSelected ? amountToSatoshi : formatAmount;
const conversion = areSatsSelected ? amountToSmallestUnit : formatAmount;
const decimals = getAccountDecimals(relatedAccount.symbol)!;

if (draft.cryptoInput) {
Expand Down
7 changes: 5 additions & 2 deletions packages/suite/src/components/suite/FormattedCryptoAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SignValue } from '@suite-common/suite-types';
import {
formatCoinBalance,
localizeNumber,
networkAmountToSatoshi,
networkAmountToSmallestUnit,
} from '@suite-common/wallet-utils';
import { isSignValuePositive } from '@suite-common/formatters';
import { selectLanguage } from 'src/reducers/suite/suiteReducer';
Expand Down Expand Up @@ -68,7 +68,10 @@ export const FormattedCryptoAmount = ({

// convert to satoshis if needed
if (isSatoshis) {
formattedValue = networkAmountToSatoshi(String(value), lowerCaseSymbol as NetworkSymbol);
formattedValue = networkAmountToSmallestUnit(
String(value),
lowerCaseSymbol as NetworkSymbol,
);

formattedSymbol = isTestnet ? `sat ${symbol?.toUpperCase()}` : 'sat';
}
Expand Down
5 changes: 2 additions & 3 deletions packages/suite/src/components/suite/UnstakingTxAmount.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import { isUnstakeTx } from '@suite-common/suite-utils';
import { getUnstakeAmountByEthereumDataHex, isUnstakeTx } from '@suite-common/suite-utils';
import { WalletAccountTransaction } from '@suite-common/wallet-types';
import { formatNetworkAmount } from '@suite-common/wallet-utils';
import { getUnstakingAmount } from 'src/utils/suite/stake';
import { FormattedCryptoAmount } from './FormattedCryptoAmount';

interface UnstakingTxAmountProps {
Expand All @@ -15,7 +14,7 @@ export const UnstakingTxAmount = ({ transaction }: UnstakingTxAmountProps) => {

if (!isUnstakeTx(txSignature)) return null;

const amount = getUnstakingAmount(ethereumSpecific?.data);
const amount = getUnstakeAmountByEthereumDataHex(ethereumSpecific?.data);

if (!amount) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export type TransactionReviewOutputProps = {

export const TransactionReviewOutput = forwardRef<HTMLDivElement, TransactionReviewOutputProps>(
(props, ref) => {
const { type, state, label, value, symbol, token, account, ethereumStakeType } = props;
const { type, state, label, value, symbol, token, account, ethereumStakeType, isRbf } =
props;
let outputLabel: ReactNode = label;
const { networkType } = account;
const { translationString } = useTranslation();
Expand Down Expand Up @@ -156,6 +157,11 @@ export const TransactionReviewOutput = forwardRef<HTMLDivElement, TransactionRev
} else if (['data', 'address'].includes(type) && ethereumStakeType) {
const displayModeStringsMap = getDisplayModeStringsMap();

// prevents double label when bumping stake type txs
if (type === 'address' && isRbf) {
return null;
}

outputLines = [
{
id: 'data',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FiatValue, FormattedCryptoAmount, Translation } from 'src/components/su
import { Account } from 'src/types/wallet';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { TokenInfo } from '@trezor/connect';
import { amountToSatoshi } from '@suite-common/wallet-utils';
import { amountToSmallestUnit } from '@suite-common/wallet-utils';
import { TransactionReviewStepIndicatorProps } from './TransactionReviewStepIndicator';
import { zIndices } from '@trezor/theme';
import { DeviceDisplay } from '../../../../DeviceDisplay/DeviceDisplay';
Expand Down Expand Up @@ -171,12 +171,13 @@ export const TransactionReviewOutputElement = forwardRef<
const network = account?.networkType;
const cardanoFingerprint = getFingerprint(account?.tokens, token?.symbol);
const isActive = state === 'active';
const hasMultipleLines = lines.length > 1;

const showMultiIndicator = lines.length > 1;

return (
<OutputWrapper ref={ref}>
<OutputLeft $isCentered={hasMultipleLines}>
{hasMultipleLines ? (
<OutputLeft $isCentered={showMultiIndicator}>
{showMultiIndicator ? (
<MultiIndicatorWrapper $linesCount={lines.length - 1}>
{indicator}
</MultiIndicatorWrapper>
Expand Down Expand Up @@ -245,7 +246,7 @@ export const TransactionReviewOutputElement = forwardRef<
<Translation id="TR_CARDANO_TREZOR_AMOUNT_HEADLINE" />
</OutputHeadline>
<OutputValue>
{amountToSatoshi(line.value, token.decimals)}
{amountToSmallestUnit(line.value, token.decimals)}
</OutputValue>
</CardanoTrezorAmountWrapper>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ export const TransactionReviewOutputList = ({
outputs={outputs}
buttonRequestsCount={buttonRequestsCount}
precomposedTx={precomposedTx}
ethereumStakeType={ethereumStakeType}
isRbfAction={isRbfAction}
/>
)}
</RightTopInner>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
OutputElementLine,
} from './TransactionReviewOutputElement';
import type { TransactionReviewOutputListProps } from './TransactionReviewOutputList';
import { StakeType } from '@suite-common/wallet-types';

type StepIndicatorProps = Pick<
TransactionReviewOutputListProps,
Expand All @@ -35,14 +36,16 @@ const StepIndicator = ({ signedTx, outputs, buttonRequestsCount }: StepIndicator

type TransactionReviewTotalOutputProps = Omit<
TransactionReviewOutputListProps,
'precomposedForm' | 'decision' | 'detailsOpen' | 'isRbfAction' | 'actionText'
'precomposedForm' | 'decision' | 'detailsOpen' | 'actionText'
>;

const getLines = (
device: TrezorDevice,
networkType: TransactionReviewOutputListProps['account']['networkType'],
symbol: TransactionReviewOutputListProps['account']['symbol'],
precomposedTx: TransactionReviewOutputListProps['precomposedTx'],
isRbfAction?: boolean,
ethereumStakeType?: StakeType,
): Array<OutputElementLine> => {
const isUpdatedSendFlow = getIsUpdatedSendFlow(device);
const isUpdatedEthereumSendFlow = getIsUpdatedEthereumSendFlow(device, networkType);
Expand All @@ -65,20 +68,21 @@ const getLines = (
.toString();

if (isUpdatedEthereumSendFlow) {
return [
{
id: 'amount', // In updated ethereum send flow there is no total amount shown, only amount without fee
label: <Translation id="AMOUNT" />,
value: tokenInfo
? formatAmount(precomposedTx.totalSpent, tokenInfo.decimals)
: formatNetworkAmount(amountWithoutFee, symbol),
},
{
id: 'fee',
label: <Translation id="MAX_FEE" />,
value: formatNetworkAmount(precomposedTx.fee, symbol),
},
];
const isUnknownStakingClaimValue = isRbfAction && ethereumStakeType === 'claim';
const amountLine = {
id: 'amount', // In updated ethereum send flow there is no total amount shown, only amount without fee
label: <Translation id="AMOUNT" />,
value: tokenInfo
? formatAmount(precomposedTx.totalSpent, tokenInfo.decimals)
: formatNetworkAmount(amountWithoutFee, symbol),
};
const feeLine = {
id: 'fee',
label: <Translation id="MAX_FEE" />,
value: formatNetworkAmount(precomposedTx.fee, symbol),
};

return isUnknownStakingClaimValue ? [feeLine] : [amountLine, feeLine];
}
if (isUpdatedSendFlow) {
return [
Expand Down Expand Up @@ -112,33 +116,53 @@ const getLines = (
export const TransactionReviewTotalOutput = forwardRef<
HTMLDivElement,
TransactionReviewTotalOutputProps
>(({ account, signedTx, outputs, buttonRequestsCount, precomposedTx }, ref) => {
const device = useSelector(selectDevice);
>(
(
{
account,
signedTx,
outputs,
buttonRequestsCount,
precomposedTx,
ethereumStakeType,
isRbfAction,
},
ref,
) => {
const device = useSelector(selectDevice);

if (!device) {
return null;
}
if (!device) {
return null;
}

const { symbol, networkType } = account;
const { symbol, networkType } = account;

const lines = getLines(device, networkType, symbol, precomposedTx);
const lines = getLines(
device,
networkType,
symbol,
precomposedTx,
isRbfAction,
ethereumStakeType,
);

return (
<TransactionReviewOutputElement
account={account}
indicator={
<StepIndicator
signedTx={signedTx}
outputs={outputs}
buttonRequestsCount={buttonRequestsCount}
/>
}
lines={lines}
cryptoSymbol={symbol}
fiatSymbol={symbol}
fiatVisible={!isTestnet(symbol)}
ref={ref}
token={precomposedTx?.token}
/>
);
});
return (
<TransactionReviewOutputElement
account={account}
indicator={
<StepIndicator
signedTx={signedTx}
outputs={outputs}
buttonRequestsCount={buttonRequestsCount}
/>
}
lines={lines}
cryptoSymbol={symbol}
fiatSymbol={symbol}
fiatVisible={!isTestnet(symbol)}
ref={ref}
token={precomposedTx?.token}
/>
);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ export const TransactionReviewSummary = ({
const isFeeCustom = drafts[currentAccountKey]?.selectedFee === 'custom';
const isComposedFeeRateDifferent = isFeeCustom && formFeeRate !== fee;

const isZeroAmount = amount === '0'; // bump claim tx and trade approve has 0 value

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

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

<AccountWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Network } from '@suite-common/wallet-config';
import { Account } from '@suite-common/wallet-types';
import { amountToSatoshi, formatAmount } from '@suite-common/wallet-utils';
import { amountToSmallestUnit, formatAmount } from '@suite-common/wallet-utils';
import { useDidUpdate } from '@trezor/react-utils';
import { UseFormReturn, useWatch } from 'react-hook-form';
import {
Expand Down Expand Up @@ -56,7 +56,7 @@ export const useCoinmarketCurrencySwitcher = <T extends CoinmarketAllFormProps>(

if (!amountInCrypto) {
const amount = shouldSendInSats
? amountToSatoshi(quoteCryptoAmount ?? '', networkDecimals)
? amountToSmallestUnit(quoteCryptoAmount ?? '', networkDecimals)
: quoteCryptoAmount;

setValue(inputNames.cryptoInput, amount === '-1' ? '' : amount);
Expand All @@ -73,7 +73,7 @@ export const useCoinmarketCurrencySwitcher = <T extends CoinmarketAllFormProps>(
};

useDidUpdate(() => {
const conversion = shouldSendInSats ? amountToSatoshi : formatAmount;
const conversion = shouldSendInSats ? amountToSmallestUnit : formatAmount;

if (!cryptoInputValue) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { networks, NetworkSymbol } from '@suite-common/wallet-config';
import { selectFiatRatesByFiatRateKey, updateFiatRatesThunk } from '@suite-common/wallet-core';
import { FiatRatesResult, Rate, Timestamp, TokenAddress } from '@suite-common/wallet-types';
import { amountToSatoshi, getFiatRateKey, toFiatCurrency } from '@suite-common/wallet-utils';
import { amountToSmallestUnit, getFiatRateKey, toFiatCurrency } from '@suite-common/wallet-utils';
import { CryptoId, FiatCurrencyCode } from 'invity-api';
import { useCallback, useEffect } from 'react';
import { useDispatch, useSelector } from 'src/hooks/suite';
Expand Down Expand Up @@ -90,7 +90,7 @@ export const useCoinmarketFiatValues = ({

const decimals = getNetworkDecimals(network?.decimals);
const formattedBalance = shouldSendInSats
? amountToSatoshi(accountBalance, decimals)
? amountToSmallestUnit(accountBalance, decimals)
: accountBalance;
const fiatValue = toFiatCurrency(accountBalance, fiatRate?.rate, 2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isChanged } from '@suite-common/suite-utils';
import { selectAccounts, selectDevice } from '@suite-common/wallet-core';
import {
amountToSatoshi,
amountToSmallestUnit,
formatAmount,
fromFiatCurrency,
isEthereumAccountSymbol,
Expand Down Expand Up @@ -132,7 +132,7 @@ export const useCoinmarketFormActions = <T extends CoinmarketSellExchangeFormPro

const formattedCryptoAmount =
cryptoAmount && shouldSendInSats
? amountToSatoshi(cryptoAmount, networkDecimals)
? amountToSmallestUnit(cryptoAmount, networkDecimals)
: cryptoAmount ?? '';
setValue(FORM_OUTPUT_AMOUNT, formattedCryptoAmount, { shouldValidate: true });
},
Expand Down Expand Up @@ -235,7 +235,7 @@ export const useCoinmarketFormActions = <T extends CoinmarketSellExchangeFormPro
.decimalPlaces(networkDecimals)
.toString();
const cryptoInputValue = shouldSendInSats
? amountToSatoshi(amount, networkDecimals)
? amountToSmallestUnit(amount, networkDecimals)
: amount;
clearErrors([FORM_OUTPUT_FIAT, FORM_OUTPUT_AMOUNT]);
setValue(FORM_OUTPUT_AMOUNT, cryptoInputValue, { shouldDirty: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
FiatCurrencyCode,
} from 'invity-api';
import useDebounce from 'react-use/lib/useDebounce';
import { amountToSatoshi, formatAmount, toFiatCurrency } from '@suite-common/wallet-utils';
import { amountToSmallestUnit, formatAmount, toFiatCurrency } from '@suite-common/wallet-utils';
import { isChanged } from '@suite-common/suite-utils';
import { useDispatch, useSelector } from 'src/hooks/suite';
import invityAPI from 'src/services/suite/invityAPI';
Expand Down Expand Up @@ -484,7 +484,7 @@ export const useCoinmarketExchangeForm = ({
selectedQuote.sendStringAmount
) {
const sendStringAmount = shouldSendInSats
? amountToSatoshi(selectedQuote.sendStringAmount, network.decimals)
? amountToSmallestUnit(selectedQuote.sendStringAmount, network.decimals)
: selectedQuote.sendStringAmount;
const result = await recomposeAndSign(
account,
Expand Down
Loading
Loading