Skip to content

Commit

Permalink
fixup! 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 0c3a403 commit 4460aff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AssetFiatBalance } from '@suite-common/assets';
import { TokenInfo } from '@trezor/connect';
import { Account, RatesByKey } from '@suite-common/wallet-types';
import { isTestnet } from '@suite-common/wallet-utils';
import { selectAssetAccountsThatStaked } from '@suite-common/wallet-core';
import { selectDebugFilteredAssetAccountsThatStaked } from '@suite-common/wallet-core';
import { selectCoinDefinitions } from '@suite-common/token-definitions';
import { FiatCurrencyCode } from '@suite-common/suite-config';

Expand Down Expand Up @@ -124,15 +124,16 @@ export const AssetCard = ({

const stakingAccountsForAsset = stakingAccounts.filter(account => account.symbol === symbol);
const coinDefinitions = useSelector(state => selectCoinDefinitions(state, symbol));
const accountsThatStaked = useSelector(state =>
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 debugFilteredStakedAccounts = useSelector(state =>
selectDebugFilteredAssetAccountsThatStaked(
state,
stakingAccountsForAsset,
isDebugModeActive,
),
);

const { tokensFiatBalance, assetStakingBalance, shouldRenderStakingRow, shouldRenderTokenRow } =
handleTokensAndStakingData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isTestnet } from '@suite-common/wallet-utils';
import { spacings } from '@trezor/theme';
import { TokenInfo } from '@trezor/blockchain-link-types';
import { selectCoinDefinitions } from '@suite-common/token-definitions';
import { selectAssetAccountsThatStaked } from '@suite-common/wallet-core';
import { selectDebugFilteredAssetAccountsThatStaked } from '@suite-common/wallet-core';
import { Account, RatesByKey } from '@suite-common/wallet-types';
import { AssetFiatBalance } from '@suite-common/assets';
import { FiatCurrencyCode } from '@suite-common/suite-config';
Expand Down Expand Up @@ -82,15 +82,16 @@ export const AssetRow = memo(
const stakingAccountsForAsset = stakingAccounts.filter(
account => account.symbol === network.symbol,
);
const accountsThatStaked = useSelector(state =>
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 debugFilteredStakedAccounts = useSelector(state =>
selectDebugFilteredAssetAccountsThatStaked(
state,
stakingAccountsForAsset,
isDebugModeActive,
),
);

const {
tokensFiatBalance,
Expand Down
12 changes: 12 additions & 0 deletions suite-common/wallet-core/src/transactions/transactionsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,18 @@ export const selectAssetAccountsThatStaked = (
selectSolAccountHasStaked(state, account.key),
);

export const selectDebugFilteredAssetAccountsThatStaked = (
state: TransactionsRootState & AccountsRootState,
accounts: Account[],
isDebugModeActive: boolean,
) => {
const accountsThatStaked = selectAssetAccountsThatStaked(state, accounts);

return !isDebugModeActive
? accountsThatStaked.filter(account => account.networkType !== 'solana')
: accountsThatStaked;
};

export const selectAccountTransactionsFetchStatus = (
state: TransactionsRootState,
accountKey: AccountKey,
Expand Down

0 comments on commit 4460aff

Please sign in to comment.