Skip to content

Commit

Permalink
feat(suite-native): register for solana blockhash also on address screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Dec 17, 2024
1 parent d035575 commit e79fee1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEffect } from 'react';

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

export const useSubscribeForSolanaBlockUpdates = (account: Account | null) => {
useEffect(() => {
// Subscribe to blocks for Solana, since they are not fetched globally
// this is needed for correct Solana fee estimation
if (account && account.networkType === 'solana') {
TrezorConnect.blockchainSubscribe({
coin: account.symbol,
blocks: true,
});

return () => {
TrezorConnect.blockchainUnsubscribe({
coin: account.symbol,
blocks: true,
});
};
}
}, [account]);
};
21 changes: 0 additions & 21 deletions suite-native/module-send/src/screens/SendFeesScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useSelector } from 'react-redux';
import { useEffect } from 'react';

import { SendStackParamList, SendStackRoutes, StackProps } from '@suite-native/navigation';
import { AccountsRootState, selectAccountByKey } from '@suite-common/wallet-core';
import TrezorConnect from '@trezor/connect';

import { SendFeesForm } from '../components/SendFeesForm';
import { SendScreen } from '../components/SendScreen';
Expand All @@ -17,25 +15,6 @@ export const SendFeesScreen = ({
const account = useSelector((state: AccountsRootState) =>
selectAccountByKey(state, accountKey),
);

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

return () => {
TrezorConnect.blockchainUnsubscribe({
coin: account.symbol,
blocks: true,
});
};
}
}, [account]);

if (!account) return;

return (
Expand Down
6 changes: 5 additions & 1 deletion suite-native/module-send/src/screens/SendOutputsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { calculateFeeLevelsMaxAmountThunk } from '../sendFormThunks';
import { constructFormDraft } from '../utils';
import { FeeLevelsMaxAmount } from '../types';
import { storeFeeLevels } from '../sendFormSlice';
import { useSubscribeForSolanaBlockUpdates } from '../hooks/useSubscribeForSolanaBlockUpdates';

const buttonWrapperStyle = prepareNativeStyle(utils => ({
width: '100%',
Expand Down Expand Up @@ -97,6 +98,8 @@ export const SendOutputsScreen = ({
selectSendFormDraftByKey(state, accountKey, tokenContract),
);

useSubscribeForSolanaBlockUpdates(account);

const deviceUnavailableCapabilities = useSelector(selectDeviceUnavailableCapabilities);

const network = account ? getNetwork(account.symbol) : null;
Expand Down Expand Up @@ -210,7 +213,8 @@ export const SendOutputsScreen = ({
setValue('rippleDestinationTag', sendFormDraft.rippleDestinationTag, {
shouldTouch: true,
});
await calculateNormalFeeMaxAmount();
// The max amount is equal to the total token balance for tokens. (fee is paid in mainnet currency)
if (!tokenContract) await calculateNormalFeeMaxAmount();
trigger();
}
};
Expand Down

0 comments on commit e79fee1

Please sign in to comment.