Skip to content

Commit

Permalink
fix(suite): subscribe to solana blocks in coinmarket form
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Jan 23, 2025
1 parent 2b85a29 commit 9902f9d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
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

0 comments on commit 9902f9d

Please sign in to comment.