Skip to content

Commit

Permalink
fixup! feat(suite): solana staking fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-pvl committed Feb 6, 2025
1 parent e6c78b5 commit 22e4cd8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@suite-common/wallet-constants';
import { ComposeActionContext, selectSelectedDevice } from '@suite-common/wallet-core';
import {
Account,
AddressDisplayOptions,
BlockchainNetworks,
ExternalOutput,
Expand All @@ -26,6 +27,7 @@ import { BigNumber } from '@trezor/utils/src/bigNumber';
import { selectAddressDisplayType } from 'src/reducers/suite/suiteReducer';
import { Dispatch, GetState } from 'src/types/suite';
import {
PrepareStakeSolTxResponse,
prepareClaimSolTx,
prepareStakeSolTx,
prepareUnstakeSolTx,
Expand Down Expand Up @@ -123,7 +125,10 @@ const getTransactionData = async (
return txData;
};

async function estimateFee(txData: any, account: any): Promise<Fee[number] | undefined> {
async function estimateFee(
account: Account,
txData?: PrepareStakeSolTxResponse,
): Promise<Fee[number] | undefined> {
if (!txData?.success) return undefined;

const estimatedFee = await TrezorConnect.blockchainEstimateFee({
Expand Down Expand Up @@ -159,7 +164,7 @@ export const composeTransaction =
let estimatedFee;
// it is not needed to estimate fee for empty input
if (formValues.cryptoInput) {
estimatedFee = await estimateFee(txData, account);
estimatedFee = await estimateFee(account, txData);
}

const { feeInfo } = formState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const getInfoRowsData = (
case 'ethereum':
return {
payoutDays: (
<>
~
<Translation id="TR_STAKE_DAYS" values={{ count: daysToAddToPool }} />
</>
<Translation
id="TR_STAKE_APPROXIMATE_DAYS"
values={{ count: daysToAddToPool }}
/>
),
rewardsPeriodHeading: <Translation id="TR_STAKE_ENTER_THE_STAKING_POOL" />,
rewardsPeriodSubheading: (
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/support/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8941,6 +8941,10 @@ export default defineMessages({
id: 'TR_STAKE_DAYS',
defaultMessage: '{count, plural, one {# day} other {# days}}',
},
TR_STAKE_APPROXIMATE_DAYS: {
id: 'TR_STAKE_APPROXIMATE_DAYS',
defaultMessage: '~{count, plural, one {# day} other {# days}}',
},
TR_STAKE_MAX_REWARD_DAYS: {
id: 'TR_STAKE_MAX_REWARD_DAYS',
defaultMessage: 'Max {count, plural, one {# day} other {# days}}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,7 @@ export const StakingCard = ({
const solReward = calculateSolanaStakingReward(depositedBalance, apy?.toString());

const stakingReward = selectedAccount.networkType === 'solana' ? solReward : restakedReward;
const isEth = selectedAccount.networkType === 'ethereum';
const unstakeMessage = (
<>
{isEth && '~'}
<Translation
id={isEth ? 'TR_STAKE_DAYS' : 'TR_UP_TO_DAYS'}
values={{ count: daysToUnstake }}
/>
</>
);
const isEthereumNetwork = selectedAccount.networkType === 'ethereum';

return (
<Card>
Expand Down Expand Up @@ -232,7 +223,20 @@ export const StakingCard = ({
label={
<>
<Translation id="TR_STAKE_UNSTAKING" />{' '}
{isDaysToUnstakeShown && <>({unstakeMessage})</>}
{isDaysToUnstakeShown && (
<>
(
<Translation
id={
isEthereumNetwork
? 'TR_STAKE_APPROXIMATE_DAYS'
: 'TR_UP_TO_DAYS'
}
values={{ count: daysToUnstake }}
/>
)
</>
)}
</>
}
iconName="spinnerGap"
Expand Down

0 comments on commit 22e4cd8

Please sign in to comment.