Skip to content

Commit

Permalink
refactor(suite): fee component
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Feb 27, 2025
1 parent 0959e86 commit 9991cd3
Show file tree
Hide file tree
Showing 22 changed files with 779 additions and 550 deletions.
27 changes: 23 additions & 4 deletions packages/product-components/src/components/FeeRate/FeeRate.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import { NetworkType } from '@suite-common/wallet-config';
import { NetworkSymbol, NetworkType, hasNetworkSettlementLayer } from '@suite-common/wallet-config';
import { getFeeUnits } from '@suite-common/wallet-utils';
import { BigNumber } from '@trezor/utils';

type FeeRateProps = {
feeRate?: string | BigNumber;
networkType: NetworkType;
symbol: NetworkSymbol;
};

export const FeeRate = ({ feeRate, networkType }: FeeRateProps) => {
export const FeeRate = ({ feeRate, networkType, symbol }: FeeRateProps) => {
if (!feeRate) return null;

const fee = typeof feeRate === 'string' ? new BigNumber(feeRate) : feeRate;
let fee;

const numOfDecimalPlaces = hasNetworkSettlementLayer(symbol) ? 4 : 2;
const multiplier = Math.pow(10, numOfDecimalPlaces);
switch (networkType) {
case 'ethereum':
fee = (Math.ceil((Number(feeRate) || 0) * multiplier) / multiplier).toFixed(
numOfDecimalPlaces,
);
break;
case 'bitcoin':
fee =
typeof feeRate === 'string'
? new BigNumber(feeRate).toFixed(2)
: feeRate.toFixed(2);
break;
default:
fee = typeof feeRate === 'string' ? feeRate : feeRate.toString();
}

return (
<span>
{networkType === 'bitcoin' ? fee.toFixed(2) : fee.toString()}&nbsp;
{fee}&nbsp;
{getFeeUnits(networkType)}
</span>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ export const TransactionReviewSummary = ({
) as string;
const fees = useSelector(state => state.wallet.fees);
const locale = useLocales();

const network = networks[account.symbol];
const { symbol, accountType, index, networkType } = account;
const network = networks[symbol];
const fee = getFee(networkType, tx);
const estimateTime = getEstimatedTime(networkType, fees[account.symbol], tx);

Expand Down Expand Up @@ -87,11 +86,11 @@ export const TransactionReviewSummary = ({
<Note iconName="gasPump">
<Translation id="TR_GAS_PRICE" />
{': '}
<FeeRate feeRate={fee} networkType={network.networkType} />
<FeeRate feeRate={fee} networkType={network.networkType} symbol={symbol} />
</Note>
) : (
<Note iconName="receipt">
<FeeRate feeRate={fee} networkType={network.networkType} />
<FeeRate feeRate={fee} networkType={network.networkType} symbol={symbol} />
</Note>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const BasicTxDetails = ({
<FeeRate
feeRate={tx?.feeRate ? tx.feeRate : getFeeRate(tx)}
networkType="bitcoin"
symbol={network.symbol}
/>
</Item>
)}
Expand All @@ -174,6 +175,7 @@ export const BasicTxDetails = ({
<FeeRate
feeRate={fromWei(tx.ethereumSpecific?.gasPrice ?? '0', 'gwei')}
networkType="ethereum"
symbol={network.symbol}
/>
</Item>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export const CancelTransaction = ({ tx, selectedAccount }: CancelTransactionProp
<Row gap={spacings.md}>
<Translation id="TR_CANCEL_TX_FEE" />
<Text variant="tertiary">
<FeeRate feeRate={feePerByte} networkType={networkType} />
<FeeRate
feeRate={feePerByte}
networkType={networkType}
symbol={tx.symbol}
/>
</Text>
</Row>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ChangeFeeLoaded = (props: ChangeFeeProps) => {

const feeRate =
networkType === 'bitcoin' && tx.rbfParams?.feeRate !== undefined ? (
<FeeRate feeRate={tx.rbfParams.feeRate} networkType={networkType} />
<FeeRate feeRate={tx.rbfParams.feeRate} networkType={networkType} symbol={tx.symbol} />
) : null;

const fee = formatNetworkAmount(tx.fee, tx.symbol);
Expand Down
236 changes: 0 additions & 236 deletions packages/suite/src/components/wallet/Fees/CustomFee.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions packages/suite/src/components/wallet/Fees/CustomFee/CurrentFee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NetworkType } from '@suite-common/wallet-config';
import { getFeeUnits } from '@suite-common/wallet-utils';
import { Icon, IconName, Row, Text } from '@trezor/components';
import { spacings } from '@trezor/theme';

import { Translation } from 'src/components/suite';

type CurrentFeeProps = {
networkType: NetworkType;
feeIconName: IconName;
currentFee: string;
isEip1559?: boolean;
};

// For priority fees it should show current base fee
export const CurrentFee = ({ networkType, feeIconName, currentFee }: CurrentFeeProps) => (
<Row justifyContent="space-between">
<Text variant="tertiary" typographyStyle="hint">
<Translation id="TR_CURRENT_FEE_CUSTOM_FEES" />
</Text>
<Text variant="default" typographyStyle="hint">
<Row alignItems="center" gap={spacings.xxs}>
<Text>
{currentFee} {getFeeUnits(networkType)}
</Text>
<Icon name={feeIconName} size="mediumLarge" />
</Row>
</Text>
</Row>
);
Loading

0 comments on commit 9991cd3

Please sign in to comment.