Skip to content

Commit 024c979

Browse files
committed
feat(suite-native): solana staking view only
1 parent 802d170 commit 024c979

File tree

10 files changed

+609
-62
lines changed

10 files changed

+609
-62
lines changed

suite-common/wallet-utils/src/solanaStakingUtils.ts

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ export const getSolAccountTotalStakingBalance = (account: Account) => {
8686
return formatNetworkAmount(totalStakingBalance, account.symbol);
8787
};
8888

89+
export const getSolanaCryptoBalanceWithStaking = (account: Account) => {
90+
const stakingBalance = getSolAccountTotalStakingBalance(account);
91+
92+
return new BigNumber(account.formattedBalance).plus(stakingBalance ?? 0).toString();
93+
};
94+
8995
export const calculateSolanaStakingReward = (accountBalance?: string, apy?: string) => {
9096
if (!accountBalance || !apy) return '0';
9197

suite-native/intl/src/en.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1244,12 +1244,15 @@ export const en = {
12441244
},
12451245
staked: 'Staked',
12461246
rewards: 'Rewards',
1247+
rewardsPerEpoch: 'Rewards per Epoch',
12471248
apy: 'Annual percentage yield',
12481249
stakingCanBeManaged: 'Staking can be currently managed only in',
12491250
trezorDesktop: 'Trezor Suite for desktop.',
12501251
stakePendingCard: {
12511252
totalStakePending: 'Total stake pending',
12521253
addingToStakingPool: 'Adding to staking pool',
1254+
activatingStake: 'Activating stake',
1255+
totalStakeActivating: 'Total stake activating',
12531256
transactionPending: 'Transaction pending',
12541257
unknownStatus: 'Unknown status',
12551258
},

suite-native/module-staking-management/src/components/StakePendingCard.tsx

+33-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TouchableOpacity } from 'react-native';
33
import { useSelector } from 'react-redux';
44

55
import { BASE_CRYPTO_MAX_DISPLAYED_DECIMALS } from '@suite-common/formatters';
6+
import { NetworkSymbol } from '@suite-common/wallet-config';
67
import { AccountsRootState, selectAccountNetworkSymbol } from '@suite-common/wallet-core';
78
import { Box, Card, Text } from '@suite-native/atoms';
89
import { CryptoAmountFormatter, CryptoToFiatAmountFormatter } from '@suite-native/formatters';
@@ -15,20 +16,34 @@ import {
1516
import { NativeStakingRootState } from '@suite-native/staking/src/types';
1617
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
1718

19+
type StakePendingCardProps = {
20+
accountKey: string;
21+
handleToggleBottomSheet: (value: boolean) => void;
22+
};
1823
const stakingItemStyle = prepareNativeStyle(utils => ({
1924
flexDirection: 'row',
2025
alignItems: 'center',
2126
gap: utils.spacings.sp4,
2227
}));
2328

2429
const valuesContainerStyle = prepareNativeStyle(utils => ({
25-
maxWidth: '40%',
30+
maxWidth: '45%',
2631
flexShrink: 0,
2732
alignItems: 'flex-end',
2833
paddingLeft: utils.spacings.sp8,
2934
}));
3035

31-
const getCardAlertProps = (isStakeConfirming: boolean, isStakePending: boolean) => {
36+
const isSolana = (symbol: NetworkSymbol) => ['sol', 'dsol'].includes(symbol);
37+
38+
const getCardAlertProps = (
39+
symbol: NetworkSymbol | null,
40+
isStakeConfirming: boolean,
41+
isStakePending: boolean,
42+
) => {
43+
if (!symbol) {
44+
return { alertTitle: undefined, alertVariant: undefined } as const;
45+
}
46+
3247
if (isStakeConfirming && !isStakePending) {
3348
return {
3449
alertTitle: <Translation id="staking.stakePendingCard.transactionPending" />,
@@ -37,7 +52,11 @@ const getCardAlertProps = (isStakeConfirming: boolean, isStakePending: boolean)
3752
}
3853
if (!isStakeConfirming && isStakePending) {
3954
return {
40-
alertTitle: <Translation id="staking.stakePendingCard.addingToStakingPool" />,
55+
alertTitle: isSolana(symbol) ? (
56+
<Translation id="staking.stakePendingCard.activatingStake" />
57+
) : (
58+
<Translation id="staking.stakePendingCard.addingToStakingPool" />
59+
),
4160
alertVariant: 'loading',
4261
} as const;
4362
}
@@ -48,10 +67,12 @@ const getCardAlertProps = (isStakeConfirming: boolean, isStakePending: boolean)
4867
} as const;
4968
};
5069

51-
type StakePendingCardProps = {
52-
accountKey: string;
53-
handleToggleBottomSheet: (value: boolean) => void;
54-
};
70+
const getTitle = (symbol: NetworkSymbol) =>
71+
isSolana(symbol) ? (
72+
<Translation id="staking.stakePendingCard.totalStakeActivating" />
73+
) : (
74+
<Translation id="staking.stakePendingCard.totalStakePending" />
75+
);
5576

5677
export const StakePendingCard = ({
5778
accountKey,
@@ -75,20 +96,20 @@ export const StakePendingCard = ({
7596
);
7697

7798
const cardAlertProps = useMemo(
78-
() => getCardAlertProps(isStakeConfirming, isStakePending),
79-
[isStakeConfirming, isStakePending],
99+
() => getCardAlertProps(symbol, isStakeConfirming, isStakePending),
100+
[symbol, isStakeConfirming, isStakePending],
80101
);
81102

82103
if (!symbol || !cardAlertProps.alertVariant) return null;
83104

105+
const title = getTitle(symbol);
106+
84107
return (
85108
<TouchableOpacity onPress={() => handleToggleBottomSheet(true)}>
86109
<Card {...cardAlertProps}>
87110
<Box style={applyStyle(stakingItemStyle)}>
88111
<Box flex={1} flexDirection="row" alignItems="center">
89-
<Text>
90-
<Translation id="staking.stakePendingCard.totalStakePending" />
91-
</Text>
112+
<Text>{title}</Text>
92113
</Box>
93114
<Box style={applyStyle(valuesContainerStyle)}>
94115
<CryptoAmountFormatter

suite-native/module-staking-management/src/components/StakingBalancesOverviewCard.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export const StakingBalancesOverviewCard = ({
6767

6868
if (!symbol) return null;
6969

70+
const rewardsTitle = ['sol', 'dsol'].includes(symbol) ? (
71+
<Translation id="staking.rewardsPerEpoch" />
72+
) : (
73+
<Translation id="staking.rewards" />
74+
);
75+
7076
return (
7177
<TouchableOpacity onPress={() => handleToggleBottomSheet(true)}>
7278
<Card style={applyStyle(stakingCardStyle)}>
@@ -99,7 +105,7 @@ export const StakingBalancesOverviewCard = ({
99105
<Box style={applyStyle(stakingItemStyle)}>
100106
<Icon name="plusCircle" color="textSubdued" size="medium" />
101107
<Text color="textSubdued" variant="label">
102-
<Translation id="staking.rewards" />
108+
{rewardsTitle}
103109
</Text>
104110
</Box>
105111
<CryptoAmountFormatter

suite-native/staking/jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { ...baseConfig } = require('../../jest.config.native');
2+
3+
module.exports = {
4+
...baseConfig,
5+
};

suite-native/staking/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"main": "src/index",
88
"scripts": {
99
"depcheck": "yarn g:depcheck",
10-
"type-check": "yarn g:tsc --build"
10+
"type-check": "yarn g:tsc --build",
11+
"test:unit": "yarn g:jest"
1112
},
1213
"dependencies": {
1314
"@suite-common/wallet-config": "workspace:*",

0 commit comments

Comments
 (0)