Skip to content

Commit

Permalink
feat(suite): include Solana staking balance in assets
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-pvl committed Dec 23, 2024
1 parent e58f97b commit bf16abe
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Account } from '@suite-common/wallet-types';
import { selectCoinDefinitions } from '@suite-common/token-definitions';
import { selectEthAccountHasStaked, selectSolStakingAccounts } from '@suite-common/wallet-core';
import { selectEthAccountHasStaked, selectSolAccountHasStaked } from '@suite-common/wallet-core';
import { isSupportedStakingNetworkSymbol } from '@suite-common/wallet-utils';

import { useSelector } from 'src/hooks/suite';
Expand Down Expand Up @@ -37,12 +37,13 @@ export const AccountSection = ({

const coinDefinitions = useSelector(state => selectCoinDefinitions(state, symbol));
const hasEthStaked = useSelector(state => selectEthAccountHasStaked(state, account.key));
const solStakingAccounts = useSelector(state => selectSolStakingAccounts(state, account.key));
const hasSolStaked = useSelector(state => selectSolAccountHasStaked(state, account.key));

// TODO: remove isDebugModeActive when staking will be ready for launch
const hasSolStakingAccount = !!solStakingAccounts?.length && isDebugModeActive; // for solana
const isSolStakingEnabled = hasSolStaked && isDebugModeActive;

const isStakeShown =
isSupportedStakingNetworkSymbol(symbol) && (hasEthStaked || hasSolStakingAccount);
isSupportedStakingNetworkSymbol(symbol) && (hasEthStaked || isSolStakingEnabled);

const showGroup = ['ethereum', 'solana', 'cardano'].includes(networkType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { useAccountSearch, useLoadingSkeleton, useSelector } from 'src/hooks/suite';
import { goto } from 'src/actions/suite/routerActions';
import { FiatHeader } from 'src/components/wallet/FiatHeader';
import { selectIsDebugModeActive } from 'src/reducers/suite/suiteReducer';

import { CoinmarketBuyButton } from '../CoinmarketBuyButton';
import { AssetCardInfo, AssetCardInfoSkeleton } from './AssetCardInfo';
Expand Down Expand Up @@ -127,10 +128,16 @@ export const AssetCard = ({
selectAssetAccountsThatStaked(state, stakingAccountsForAsset),
);

// TODO: remove this logic when Solana staking is available
const isDebugModeActive = useSelector(selectIsDebugModeActive);
const debugFilteredStakedAccounts = !isDebugModeActive
? accountsThatStaked.filter(account => account.networkType !== 'solana')
: accountsThatStaked;

const { tokensFiatBalance, assetStakingBalance, shouldRenderStakingRow, shouldRenderTokenRow } =
handleTokensAndStakingData(
assetTokens,
accountsThatStaked,
debugFilteredStakedAccounts,
symbol,
localCurrency,
coinDefinitions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { goto } from 'src/actions/suite/routerActions';
import { useAccountSearch, useDispatch, useSelector } from 'src/hooks/suite';
import { TokenIconSetWrapper } from 'src/components/wallet/TokenIconSetWrapper';
import { selectIsDebugModeActive } from 'src/reducers/suite/suiteReducer';

import { AssetCoinLogo } from '../AssetCoinLogo';
import { AssetCoinName } from '../AssetCoinName';
Expand Down Expand Up @@ -85,14 +86,20 @@ export const AssetRow = memo(
selectAssetAccountsThatStaked(state, stakingAccountsForAsset),
);

// TODO: remove this logic when Solana staking is available
const isDebugModeActive = useSelector(selectIsDebugModeActive);
const debugFilteredStakedAccounts = !isDebugModeActive
? accountsThatStaked.filter(account => account.networkType !== 'solana')
: accountsThatStaked;

const {
tokensFiatBalance,
assetStakingBalance,
shouldRenderStakingRow,
shouldRenderTokenRow,
} = handleTokensAndStakingData(
assetTokens,
accountsThatStaked,
debugFilteredStakedAccounts,
symbol,
localCurrency,
coinDefinitions,
Expand Down
7 changes: 5 additions & 2 deletions packages/suite/src/views/dashboard/AssetsView/AssetsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getFiatRateKey,
toFiatCurrency,
isSupportedEthStakingNetworkSymbol,
isSupportedSolStakingNetworkSymbol,
} from '@suite-common/wallet-utils';
import {
type NetworkSymbol,
Expand Down Expand Up @@ -139,8 +140,10 @@ export const AssetsView = () => {
? assetNativeCryptoBalance.toNumber()
: '0',
assetTokens: assetTokens?.length ? assetTokens : undefined,
stakingAccounts: accounts.filter(account =>
isSupportedEthStakingNetworkSymbol(account.symbol),
stakingAccounts: accounts.filter(
account =>
isSupportedEthStakingNetworkSymbol(account.symbol) ||
isSupportedSolStakingNetworkSymbol(account.symbol),
),
accounts,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { selectEthAccountHasStaked, selectSolStakingAccounts } from '@suite-common/wallet-core';
import { selectEthAccountHasStaked, selectSolAccountHasStaked } from '@suite-common/wallet-core';
import { SelectedAccountStatus } from '@suite-common/wallet-types';

import { WalletLayout } from 'src/components/wallet';
Expand All @@ -16,14 +16,13 @@ export const StakingDashboard = ({ selectedAccount, dashboard }: StakingDashboar
const hasEthStaked = useSelector(state =>
selectEthAccountHasStaked(state, selectedAccount.account?.key ?? ''),
);
const solStakingAccounts = useSelector(state =>
selectSolStakingAccounts(state, selectedAccount.account?.key),
const hasSolStaked = useSelector(state =>
selectSolAccountHasStaked(state, selectedAccount.account?.key),
);

if (selectedAccount.status !== 'loaded') return null;

const hasSolStakingAccount = !!solStakingAccounts?.length;
const shouldShowDashboard = hasEthStaked || hasSolStakingAccount;
const shouldShowDashboard = hasEthStaked || hasSolStaked;

return (
<WalletLayout
Expand Down
6 changes: 6 additions & 0 deletions suite-common/wallet-core/src/accounts/accountsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,9 @@ export const selectSolStakingAccounts = createMemoizedSelector([selectAccountByK

return account.misc.solStakingAccounts ?? [];
});

export const selectSolAccountHasStaked = createMemoizedSelector([selectAccountByKey], account => {
if (!account || account.networkType !== 'solana') return false;

return !!account.misc.solStakingAccounts?.length;
});
13 changes: 11 additions & 2 deletions suite-common/wallet-core/src/transactions/transactionsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import {
fetchTransactionsPageThunk,
fetchAllTransactionsForAccountThunk,
} from './transactionsThunks';
import { AccountsRootState, selectAccountByKey } from '../accounts/accountsReducer';
import {
AccountsRootState,
selectAccountByKey,
selectSolAccountHasStaked,
} from '../accounts/accountsReducer';

export type AccountTransactionsFetchStatusDetail =
| {
Expand Down Expand Up @@ -386,7 +390,12 @@ export const selectEthAccountHasStaked = createMemoizedSelector(
export const selectAssetAccountsThatStaked = (
state: TransactionsRootState & AccountsRootState,
accounts: Account[],
) => accounts.filter(account => selectEthAccountHasStaked(state, account.key));
) =>
accounts.filter(
account =>
selectEthAccountHasStaked(state, account.key) ||
selectSolAccountHasStaked(state, account.key),
);

export const selectAccountTransactionsFetchStatus = (
state: TransactionsRootState,
Expand Down

0 comments on commit bf16abe

Please sign in to comment.