Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Solana fixes from Sentry #16554

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/blockchain-link/src/workers/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,13 @@ const handleAccountNotification = async (
});
}
} catch (error) {
console.error('Solana subscription error:', error);
if (isSolanaError(error, SOLANA_ERROR__RPC_SUBSCRIPTIONS__CHANNEL_CONNECTION_CLOSED)) {
// The WS was closed, we should unsubscribe
if (account.subscriptionId) abortSubscription(account.subscriptionId);
state.removeAccounts([account]);
context.onNetworkDisconnect();
} else {
console.error('Solana subscription error:', error);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { useCoinmarketFiatValues } from 'src/hooks/wallet/coinmarket/form/common
import type { CryptoAmountLimitProps } from 'src/utils/suite/validation';
import { useCoinmarketExchangeQuotesFilter } from 'src/hooks/wallet/coinmarket/form/common/useCoinmarketExchangeQuotesFilter';
import { useCoinmarketPreviousRoute } from 'src/hooks/wallet/coinmarket/form/common/useCoinmarketPreviousRoute';
import { useSolanaSubscribeBlocks } from 'src/hooks/wallet/form/useSolanaSubscribeBlocks';

import { useCoinmarketInitializer } from './common/useCoinmarketInitializer';

Expand Down Expand Up @@ -681,6 +682,9 @@ export const useCoinmarketExchangeForm = ({
};
}, []);

// Subscribe to blocks for Solana, since they are not fetched globally
useSolanaSubscribeBlocks(account);

return {
type,
...methods,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { useCoinmarketAccount } from 'src/hooks/wallet/coinmarket/form/common/us
import { useCoinmarketInfo } from 'src/hooks/wallet/coinmarket/useCoinmarketInfo';
import type { AmountLimitProps } from 'src/utils/suite/validation';
import { useCoinmarketPreviousRoute } from 'src/hooks/wallet/coinmarket/form/common/useCoinmarketPreviousRoute';
import { useSolanaSubscribeBlocks } from 'src/hooks/wallet/form/useSolanaSubscribeBlocks';

import { useCoinmarketInitializer } from './common/useCoinmarketInitializer';

Expand Down Expand Up @@ -657,6 +658,9 @@ export const useCoinmarketSellForm = ({
};
}, []);

// Subscribe to blocks for Solana, since they are not fetched globally
useSolanaSubscribeBlocks(account);

return {
type,
form: {
Expand Down
22 changes: 22 additions & 0 deletions packages/suite/src/hooks/wallet/form/useSolanaSubscribeBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect } from 'react';

import TrezorConnect from '@trezor/connect';
import { Account } from '@suite-common/wallet-types';

export const useSolanaSubscribeBlocks = (account: Account) => {
useEffect(() => {
if (account.networkType === 'solana') {
TrezorConnect.blockchainSubscribe({
coin: account.symbol,
blocks: true,
});

return () => {
TrezorConnect.blockchainUnsubscribe({
coin: account.symbol,
blocks: true,
});
};
}
}, [account]);
};
21 changes: 4 additions & 17 deletions packages/suite/src/hooks/wallet/useSendFormCompose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
import { useDebounce } from '@trezor/react-utils';
import { isChanged } from '@suite-common/suite-utils';
import { findComposeErrors } from '@suite-common/wallet-utils';
import TrezorConnect, { FeeLevel } from '@trezor/connect';
import { FeeLevel } from '@trezor/connect';
import { COMPOSE_ERROR_TYPES } from '@suite-common/wallet-constants';
import { composeSendFormTransactionFeeLevelsThunk } from '@suite-common/wallet-core';

import { TranslationKey } from 'src/components/suite/Translation';
import { SendContextValues, UseSendFormState } from 'src/types/wallet/sendForm';

import { useTranslation } from '../suite';
import { useSolanaSubscribeBlocks } from './form/useSolanaSubscribeBlocks';

type Props = UseFormReturn<FormState> & {
state: UseSendFormState;
Expand Down Expand Up @@ -344,22 +345,8 @@ export const useSendFormCompose = ({
setLoading,
]);

useEffect(() => {
// Subscribe to blocks for Solana, since they are not fetched globally
if (state.account.networkType === 'solana') {
TrezorConnect.blockchainSubscribe({
coin: state.account.symbol,
blocks: true,
});

return () => {
TrezorConnect.blockchainUnsubscribe({
coin: state.account.symbol,
blocks: true,
});
};
}
}, [state.account]);
// Subscribe to blocks for Solana, since they are not fetched globally
useSolanaSubscribeBlocks(state.account);

return {
composeDraft,
Expand Down
4 changes: 2 additions & 2 deletions suite-common/wallet-core/src/accounts/accountsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,13 @@ export const selectIsDeviceNotEmpty = createMemoizedSelector(
);

export const selectSolStakingAccounts = createMemoizedSelector([selectAccountByKey], account => {
if (!account || account.networkType !== 'solana') return null;
if (!account?.misc || account.networkType !== 'solana') return null;

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

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

return !!account.misc.solStakingAccounts?.length;
});
2 changes: 1 addition & 1 deletion suite-common/wallet-core/src/send/sendFormSolanaThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const composeSolanaTransactionFeeLevelsThunk = createThunk<
output,
level,
decimals,
account.misc.rent ?? 0,
account.misc?.rent ?? 0,
tokenInfo,
),
);
Expand Down
2 changes: 1 addition & 1 deletion suite-common/wallet-types/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type AccountNetworkSpecific =
}
| {
networkType: 'solana';
misc: {
misc?: {
rent?: number;
solStakingAccounts?: SolanaStakingAccount[];
solEpoch?: number;
Expand Down
4 changes: 2 additions & 2 deletions suite-common/wallet-utils/src/solanaStakingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const calculateTotalSolStakingBalance = (stakingAccounts: SolanaStakingAc
};

export const getSolAccountTotalStakingBalance = (account: Account) => {
if (!account || account.networkType !== 'solana') {
if (!account?.misc || account.networkType !== 'solana') {
return null;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ interface StakingAccountWithStatus extends SolDelegation {
export const getSolanaStakingAccountsWithStatus = (
account: Account,
): StakingAccountWithStatus[] | null => {
if (account.networkType !== 'solana') return null;
if (!account.misc || account.networkType !== 'solana') return null;

const { solStakingAccounts, solEpoch } = account.misc;
if (!solStakingAccounts?.length || !solEpoch) return null;
Expand Down
Loading