Skip to content

Commit

Permalink
fixup! fix: use the useRbf hook only once, so state is initialized ju…
Browse files Browse the repository at this point in the history
…st once and used at all places (via context)
  • Loading branch information
peter-sanderson committed Dec 17, 2024
1 parent b7cb6a1 commit 6f3d9fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { NewModal } from '@trezor/components';

import { Translation } from 'src/components/suite';
import { useDevice } from 'src/hooks/suite';

import { useRbfContext } from '../../../../../../../hooks/wallet/useRbfForm';
import { useRbfContext } from 'src/hooks/wallet/useRbfForm';

export const ReplaceTxButton = () => {
const { device, isLocked } = useDevice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ import { RequiredKey } from '@trezor/type-utils';
import { useSelector } from 'src/hooks/suite';
import { Translation } from 'src/components/suite';
import { Account, WalletAccountTransaction } from 'src/types/wallet';
import { RbfContext, useRbf } from 'src/hooks/wallet/useRbfForm';

import { AdvancedTxDetails, TabID } from './AdvancedTxDetails/AdvancedTxDetails';
import { ChangeFee } from './ChangeFee/ChangeFee';
import { ReplaceTxButton } from './ChangeFee/ReplaceTxButton';
import { TxDetailModalBase } from './TxDetailModalBase';
import { RbfContext, useRbf } from '../../../../../../hooks/wallet/useRbfForm';

const hasRbfParams = (
tx: WalletAccountTransaction,
): tx is RequiredKey<WalletAccountTransaction, 'rbfParams'> => tx.rbfParams !== undefined;

type DetailModalProps = {
tx: WalletAccountTransaction;
Expand Down Expand Up @@ -140,18 +144,16 @@ export const TxDetailModal = ({ tx, rbfForm, onCancel }: TxDetailModalProps) =>
setTab(undefined);
};

const { rbfParams } = tx; // This is just for trick to enforce type-narrowing

if (
hasRbfParams(tx) &&
section === 'CHANGE_FEE' &&
networkFeatures?.includes('rbf') &&
rbfParams !== undefined &&
!tx.deadline &&
selectedAccount.status === 'loaded'
) {
return (
<BumpFeeModal
tx={{ ...tx, rbfParams }} // This is just for trick to enforce type-narrowing
tx={tx}
onCancel={onCancel}
onBackClick={onBackClick}
onShowChained={onShowChained}
Expand Down

0 comments on commit 6f3d9fe

Please sign in to comment.