Skip to content

Commit 1d7add7

Browse files
committed
chore(suite): unify staking files
1 parent c9e9759 commit 1d7add7

File tree

42 files changed

+155
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+155
-139
lines changed

packages/suite/src/actions/wallet/stake/stakeFormEthereumActions.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
PrecomposedTransactionFinal,
2020
ExternalOutput,
2121
} from '@suite-common/wallet-types';
22-
import { selectDevice } from '@suite-common/wallet-core';
22+
import {
23+
MIN_ETH_AMOUNT_FOR_STAKING,
24+
MIN_ETH_BALANCE_FOR_STAKING,
25+
MIN_ETH_FOR_WITHDRAWALS,
26+
} from '@suite-common/wallet-constants';
27+
import { selectDevice, ComposeActionContext } from '@suite-common/wallet-core';
2328

2429
import { Dispatch, GetState } from 'src/types/suite';
2530
import { selectAddressDisplayType } from 'src/reducers/suite/suiteReducer';
@@ -31,13 +36,7 @@ import {
3136
prepareStakeEthTx,
3237
prepareUnstakeEthTx,
3338
} from 'src/utils/suite/stake';
34-
import {
35-
MIN_ETH_AMOUNT_FOR_STAKING,
36-
MIN_ETH_BALANCE_FOR_STAKING,
37-
MIN_ETH_FOR_WITHDRAWALS,
38-
} from 'src/constants/suite/ethStaking';
3939
import { NetworkSymbol } from '@suite-common/wallet-config';
40-
import { ComposeActionContext } from '@suite-common/wallet-core';
4140

4241
const calculate = (
4342
availableBalance: string,

packages/suite/src/components/suite/FormFractionButtons.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import styled from 'styled-components';
22
import { Translation } from 'src/components/suite';
33
import { Button, Tooltip } from '@trezor/components';
44
import { BigNumber } from '@trezor/utils/src/bigNumber';
5-
import { MIN_ETH_AMOUNT_FOR_STAKING } from 'src/constants/suite/ethStaking';
5+
import { MIN_ETH_AMOUNT_FOR_STAKING } from '@suite-common/wallet-constants';
66
import { NetworkSymbol } from '@suite-common/wallet-config';
77

88
const Flex = styled.div`

packages/suite/src/components/suite/UnstakingTxAmount.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
2-
import { isUnstakeTx } from '@suite-common/suite-utils';
32
import { WalletAccountTransaction } from '@suite-common/wallet-types';
4-
import { formatNetworkAmount } from '@suite-common/wallet-utils';
3+
import { formatNetworkAmount, isUnstakeTx } from '@suite-common/wallet-utils';
54
import { getUnstakingAmount } from 'src/utils/suite/stake';
65
import { FormattedCryptoAmount } from './FormattedCryptoAmount';
76

packages/suite/src/components/suite/modals/ReduxModal/TransactionReviewModal/TransactionReviewModalContent.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
StakeState,
1212
} from '@suite-common/wallet-core';
1313
import { FormState, StakeFormState } from '@suite-common/wallet-types';
14-
import { constructTransactionReviewOutputs, isRbfTransaction } from '@suite-common/wallet-utils';
14+
import {
15+
constructTransactionReviewOutputs,
16+
isRbfTransaction,
17+
getTxStakeNameByDataHex,
18+
} from '@suite-common/wallet-utils';
1519
import { SendState } from '@suite-common/wallet-core';
1620
import { useSelector } from 'src/hooks/suite';
1721
import { selectIsActionAbortable } from 'src/reducers/suite/suiteReducer';
@@ -20,7 +24,6 @@ import { Modal, Translation } from 'src/components/suite';
2024
import { TransactionReviewSummary } from './TransactionReviewSummary';
2125
import { TransactionReviewOutputList } from './TransactionReviewOutputList/TransactionReviewOutputList';
2226
import { TransactionReviewEvmExplanation } from './TransactionReviewEvmExplanation';
23-
import { getTxStakeNameByDataHex } from '@suite-common/suite-utils';
2427
import { ConfirmOnDevice } from '@trezor/product-components';
2528
import { networks } from '@suite-common/wallet-config';
2629
import { selectAccountIncludingChosenInCoinmarket } from 'src/reducers/wallet/selectedAccountReducer';

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeModal/StakeEthForm/Inputs.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
validateReserveOrBalance,
1414
} from 'src/utils/suite/validation';
1515
import { FIAT_INPUT, CRYPTO_INPUT } from 'src/types/wallet/stakeForms';
16-
import { MIN_ETH_FOR_WITHDRAWALS } from 'src/constants/suite/ethStaking';
16+
import { MIN_ETH_FOR_WITHDRAWALS } from '@suite-common/wallet-constants';
1717
import { spacingsPx } from '@trezor/theme';
1818
import { validateStakingMax } from 'src/utils/suite/stake';
1919

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/TxDetailModal/AdvancedTxDetails/AmountDetails.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
isNftTokenTransfer,
1515
isTxFeePaid,
1616
roundTimestampToNearestPastHour,
17+
isStakeTypeTx,
1718
} from '@suite-common/wallet-utils';
1819
import { BigNumber } from '@trezor/utils/src/bigNumber';
1920
import { FormattedNftAmount } from 'src/components/suite/FormattedNftAmount';
@@ -24,7 +25,6 @@ import {
2425
selectHistoricFiatRatesByTimestamp,
2526
} from '@suite-common/wallet-core';
2627
import { Timestamp, TokenAddress } from '@suite-common/wallet-types';
27-
import { isStakeTypeTx } from '@suite-common/suite-utils';
2828

2929
const MainContainer = styled.div`
3030
display: flex;

packages/suite/src/components/suite/notifications/NotificationRenderer/TransactionRenderer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getAccountTransactions,
1414
findTransaction,
1515
getConfirmations,
16+
isStakeTypeTx,
1617
} from '@suite-common/wallet-utils';
1718

1819
import {
@@ -24,7 +25,6 @@ import {
2425
import { goto } from 'src/actions/suite/routerActions';
2526
import { useDispatch, useSelector } from 'src/hooks/suite';
2627
import { getTxAnchor } from 'src/utils/suite/anchor';
27-
import { isStakeTypeTx } from '@suite-common/suite-utils';
2828

2929
type TransactionRendererProps = NotificationViewProps &
3030
NotificationRendererProps<

packages/suite/src/components/wallet/TransactionItem/InstantStakeBadge.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Translation, FormattedCryptoAmount } from 'src/components/suite';
22
import { WalletAccountTransaction } from 'src/types/wallet';
3-
import { StakeType } from '@suite-common/wallet-types/src/stake';
3+
import { StakeType } from '@suite-common/wallet-types';
44

55
import { Badge, Icon } from '@trezor/components';
66
import styled from 'styled-components';

packages/suite/src/components/wallet/TransactionItem/TransactionHeader.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Translation } from 'src/components/suite';
2-
import { getTxHeaderSymbol } from '@suite-common/wallet-utils';
2+
import { getTxHeaderSymbol, isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-utils';
33
import { WalletAccountTransaction } from 'src/types/wallet';
44
import { AccountTransaction } from '@trezor/connect';
55
import { UnstakingTxAmount } from 'src/components/suite/UnstakingTxAmount';
6-
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-core';
76

87
interface TransactionHeaderProps {
98
transaction: WalletAccountTransaction;

packages/suite/src/components/wallet/TransactionItem/TransactionHeading.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import {
1313
getTargetAmount,
1414
getTxHeaderSymbol,
1515
getTxOperation,
16+
isSupportedEthStakingNetworkSymbol,
1617
} from '@suite-common/wallet-utils';
1718
import { TransactionHeader } from './TransactionHeader';
1819
import { WalletAccountTransaction } from 'src/types/wallet';
1920
import { BigNumber } from '@trezor/utils/src/bigNumber';
2021
import { BlurWrapper } from './TransactionItemBlurWrapper';
2122
import { spacingsPx } from '@trezor/theme';
2223
import { InstantStakeBadge } from './InstantStakeBadge';
23-
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-core';
2424

2525
const Wrapper = styled.span`
2626
display: flex;

packages/suite/src/components/wallet/TransactionItem/TransactionItem.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import { variables, Button, Card, Link } from '@trezor/components';
66
import { Translation } from 'src/components/suite';
77
import { useDispatch, useSelector } from 'src/hooks/suite';
88
import { openModal } from 'src/actions/suite/modalActions';
9-
import { formatNetworkAmount, isTestnet, isTxFeePaid } from '@suite-common/wallet-utils';
9+
import {
10+
formatNetworkAmount,
11+
isTestnet,
12+
isTxFeePaid,
13+
isStakeTypeTx,
14+
} from '@suite-common/wallet-utils';
1015
import { AccountLabels } from 'src/types/suite/metadata';
1116
import { WalletAccountTransaction } from 'src/types/wallet';
1217
import { AccountType, Network } from '@suite-common/wallet-config';
@@ -34,7 +39,6 @@ import { SUBPAGE_NAV_HEIGHT } from 'src/constants/suite/layout';
3439
import { BlurWrapper } from './TransactionItemBlurWrapper';
3540
import { selectSelectedAccount } from 'src/reducers/wallet/selectedAccountReducer';
3641
import { getInstantStakeType } from 'src/utils/suite/stake';
37-
import { isStakeTypeTx } from '@suite-common/suite-utils';
3842
import { Tooltip } from '@trezor/components';
3943
import { HELP_CENTER_REPLACE_BY_FEE } from '@trezor/urls';
4044

packages/suite/src/components/wallet/WalletLayout/AccountBanners/AccountBanners.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { EvmExplanationBanner } from './EvmExplanationBanner';
1515
import { TaprootBanner } from './TaprootBanner';
1616
import { Context } from '@suite-common/message-system';
1717
import { useSelector } from 'src/hooks/suite';
18-
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-core';
18+
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-utils';
1919

2020
const BannersWrapper = styled.div`
2121
display: flex;

packages/suite/src/components/wallet/WalletLayout/AccountBanners/StakeEthBanner.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { setFlag } from 'src/actions/suite/suiteActions';
77
import { selectSuiteFlags } from '../../../../reducers/suite/suiteReducer';
88
import { Account } from '@suite-common/wallet-types';
99
import { selectPoolStatsApyData } from '@suite-common/wallet-core';
10-
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-core';
11-
import { MIN_ETH_AMOUNT_FOR_STAKING } from 'src/constants/suite/ethStaking';
10+
import { MIN_ETH_AMOUNT_FOR_STAKING } from '@suite-common/wallet-constants';
11+
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-utils';
1212
import { useTheme } from 'styled-components';
1313

1414
interface StakeEthBannerProps {

packages/suite/src/components/wallet/WalletLayout/AccountsMenu/AcccountSection.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import { AccountItemsGroup } from './AccountItemsGroup';
33
import { AccountItem } from './AccountItem';
44
import { useSelector } from 'src/hooks/suite';
55
import { selectCoinDefinitions } from '@suite-common/token-definitions';
6-
import {
7-
isSupportedEthStakingNetworkSymbol,
8-
selectAccountHasStaked,
9-
} from '@suite-common/wallet-core';
6+
import { selectAccountHasStaked } from '@suite-common/wallet-core';
7+
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-utils';
108
import { getTokens } from 'src/utils/wallet/tokenUtils';
119

1210
interface AccountSectionProps {

packages/suite/src/constants/suite/ethStaking.ts

-8
This file was deleted.

packages/suite/src/hooks/wallet/useStakeEthForm.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ import { useFormDraft } from './useFormDraft';
2424

2525
import { fromWei } from 'web3-utils';
2626
import { useStakeCompose } from './form/useStakeCompose';
27-
import {
28-
MIN_ETH_AMOUNT_FOR_STAKING,
29-
MIN_ETH_BALANCE_FOR_STAKING,
30-
MIN_ETH_FOR_WITHDRAWALS,
31-
} from 'src/constants/suite/ethStaking';
3227
import { selectLocalCurrency } from 'src/reducers/wallet/settingsReducer';
3328

3429
import { signTransaction } from 'src/actions/wallet/stakeActions';
@@ -39,6 +34,11 @@ import {
3934
StakeContextValues,
4035
selectFiatRatesByFiatRateKey,
4136
} from '@suite-common/wallet-core';
37+
import {
38+
MIN_ETH_AMOUNT_FOR_STAKING,
39+
MIN_ETH_BALANCE_FOR_STAKING,
40+
MIN_ETH_FOR_WITHDRAWALS,
41+
} from '@suite-common/wallet-constants';
4242
import { selectNetwork } from '@everstake/wallet-sdk/ethereum';
4343
import { useFees } from './form/useFees';
4444

packages/suite/src/reducers/wallet/selectedAccountReducer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { accountsActions } from '@suite-common/wallet-core';
2+
import { MIN_ETH_BALANCE_FOR_STAKING } from '@suite-common/wallet-constants';
23
import type { Action } from 'src/types/suite';
34
import type { SelectedAccountStatus } from '@suite-common/wallet-types';
4-
import { MIN_ETH_BALANCE_FOR_STAKING } from 'src/constants/suite/ethStaking';
55
import { State as CoinmarketState } from 'src/reducers/wallet/coinmarketReducer';
66

77
export type State = SelectedAccountStatus;

packages/suite/src/utils/suite/stake.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import { fromWei, hexToNumberString, numberToHex, toWei } from 'web3-utils';
1111
import { getEthereumEstimateFeeParams, isPending, sanitizeHex } from '@suite-common/wallet-utils';
1212
import TrezorConnect, { EthereumTransaction, Success, InternalTransfer } from '@trezor/connect';
1313
import { BigNumber } from '@trezor/utils/src/bigNumber';
14-
import { STAKE_GAS_LIMIT_RESERVE, ValidatorsQueue } from '@suite-common/wallet-core';
15-
import { BlockchainEstimatedFee } from '@trezor/connect/src/types/api/blockchainEstimateFee';
14+
import { ValidatorsQueue } from '@suite-common/wallet-core';
1615
import {
16+
STAKE_GAS_LIMIT_RESERVE,
1717
MIN_ETH_AMOUNT_FOR_STAKING,
1818
MAX_ETH_AMOUNT_FOR_STAKING,
19-
} from 'src/constants/suite/ethStaking';
19+
} from '@suite-common/wallet-constants';
20+
import { BlockchainEstimatedFee } from '@trezor/connect/src/types/api/blockchainEstimateFee';
2021
import { TranslationFunction } from 'src/hooks/suite/useTranslation';
2122

2223
// source is a required parameter for some functions in the Everstake Wallet SDK.

packages/suite/src/views/dashboard/StakeEthCard/StakeEthCard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import { Translation, StakingFeature } from 'src/components/suite';
1616
import { StakeEthCardFooter } from './StakeEthCardFooter/StakeEthCardFooter';
1717
import { useDevice, useDiscovery, useDispatch, useSelector } from 'src/hooks/suite';
1818
import { useAccounts } from 'src/hooks/wallet';
19-
import { MIN_ETH_BALANCE_FOR_STAKING } from 'src/constants/suite/ethStaking';
2019
import { spacings } from '@trezor/theme';
2120
import { selectEnabledNetworks } from 'src/reducers/wallet/settingsReducer';
2221
import { selectSuiteFlags } from 'src/reducers/suite/suiteReducer';
2322
import { setFlag } from 'src/actions/suite/suiteActions';
2423
import { selectPoolStatsApyData } from '@suite-common/wallet-core';
24+
import { MIN_ETH_BALANCE_FOR_STAKING } from '@suite-common/wallet-constants';
2525
import { hasBitcoinOnlyFirmware } from '@trezor/device-utils';
2626

2727
const bannerSymbol = 'eth';

packages/suite/src/views/wallet/staking/components/EthStakingDashboard/components/PayoutCard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Translation } from 'src/components/suite';
66
import { AccentP, CardBottomContent, GreyP } from './styled';
77
import { selectSelectedAccount } from 'src/reducers/wallet/selectedAccountReducer';
88
import { useSelector } from 'src/hooks/suite';
9-
import { BACKUP_REWARD_PAYOUT_DAYS } from 'src/constants/suite/ethStaking';
9+
import { BACKUP_REWARD_PAYOUT_DAYS } from '@suite-common/wallet-constants';
1010
import { getAccountAutocompoundBalance } from '@suite-common/wallet-utils';
1111

1212
interface PayoutCardProps {

suite-common/suite-utils/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export * from './build';
55
export * from './resolveStaticPath';
66
export * from './comparison';
77
export * from './txsPerPage';
8-
export * from './stake';
98
export * from './parseFirmwareChangelog';
109
export * from './uppercaseType';
1110
export * from './protocol';

suite-common/suite-utils/src/stake.ts

-33
This file was deleted.

suite-common/wallet-constants/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'",
1010
"depcheck": "yarn g:depcheck",
1111
"type-check": "yarn g:tsc --build"
12+
},
13+
"dependencies": {
14+
"@trezor/utils": "workspace:*"
1215
}
1316
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { BigNumber } from '@trezor/utils/src/bigNumber';
2+
3+
// Used when Everstake pool stats are not available from the API.
4+
export const BACKUP_ETH_APY = 4.13;
5+
6+
// Slack discussion https://satoshilabs.slack.com/archives/C0543DJBK0C/p1719409880504649?thread_ts=1719403259.875369&cid=C0543DJBK0C
7+
// increasing gas limit as tx can consume more than it was estimated due to edge cases
8+
// stake/unstake method usually consumes 97k-425k but can take up to 1M
9+
// claim method 97k-300k
10+
export const STAKE_GAS_LIMIT_RESERVE = 220_000;
11+
12+
export const MIN_ETH_AMOUNT_FOR_STAKING = new BigNumber(0.1);
13+
export const MAX_ETH_AMOUNT_FOR_STAKING = new BigNumber(1_000_000);
14+
export const MIN_ETH_FOR_WITHDRAWALS = new BigNumber(0.03);
15+
export const MIN_ETH_BALANCE_FOR_STAKING = MIN_ETH_AMOUNT_FOR_STAKING.plus(MIN_ETH_FOR_WITHDRAWALS);
16+
17+
export const BACKUP_REWARD_PAYOUT_DAYS = 7;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './formDraft';
22
export * from './sendForm';
33
export * from './discovery';
4+
export * from './ethereumStakingConstants';
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": { "outDir": "libDev" },
4-
"references": []
4+
"references": [
5+
{ "path": "../../packages/utils" }
6+
]
57
}

suite-common/wallet-core/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ export * from './stake/stakeSelectors';
3737
export * from './stake/stakeMiddleware';
3838
export * from './stake/stakeThunks';
3939
export * from './stake/stakeTypes';
40+
export * from './stake/stakeConstants';

suite-common/wallet-core/src/send/sendFormEthereumThunks.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ import {
1414
formatAmount,
1515
isPending,
1616
getAccountIdentity,
17+
getTxStakeNameByDataHex,
1718
} from '@suite-common/wallet-utils';
1819
import { createThunk } from '@suite-common/redux-utils';
19-
import { ERC20_BACKUP_GAS_LIMIT, ETH_BACKUP_GAS_LIMIT } from '@suite-common/wallet-constants';
20+
import {
21+
ERC20_BACKUP_GAS_LIMIT,
22+
ETH_BACKUP_GAS_LIMIT,
23+
STAKE_GAS_LIMIT_RESERVE,
24+
} from '@suite-common/wallet-constants';
2025
import {
2126
PrecomposedLevels,
2227
PrecomposedTransaction,
2328
ExternalOutput,
2429
} from '@suite-common/wallet-types';
2530
import { AddressDisplayOptions } from '@suite-common/wallet-types';
2631
import { getNetwork } from '@suite-common/wallet-config';
27-
import { getTxStakeNameByDataHex } from '@suite-common/suite-utils';
2832

2933
import { selectTransactions } from '../transactions/transactionsReducer';
3034
import {
@@ -34,7 +38,6 @@ import {
3438
SignTransactionError,
3539
} from './sendFormTypes';
3640
import { SEND_MODULE_PREFIX } from './sendFormConstants';
37-
import { STAKE_GAS_LIMIT_RESERVE } from '../stake/stakeTypes';
3841

3942
const calculate = (
4043
availableBalance: string,

0 commit comments

Comments
 (0)