Skip to content

Commit

Permalink
update sign transaction button
Browse files Browse the repository at this point in the history
  • Loading branch information
zerts committed Jun 11, 2024
1 parent f84429f commit 0661348
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
16 changes: 11 additions & 5 deletions src/ui/components/SignTransactionButton/SignTransactionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import CheckIcon from 'jsx:src/ui/assets/checkmark-checked.svg';
import { HStack } from 'src/ui/ui-kit/HStack';
import { wait } from 'src/shared/wait';
import { usePreferences } from 'src/ui/features/preferences';
import { WithReadonlyWarningDialog } from './ReadonlyWarningDialog';

type SendTxParams = TransactionContextParams & {
Expand All @@ -46,10 +47,11 @@ export const SignTransactionButton = React.forwardRef(
wallet: ExternallyOwnedAccount;
buttonTitle?: React.ReactNode;
buttonKind?: ButtonKind;
holdToSign: boolean | null;
holdToSign: boolean;
},
ref: React.Ref<SendTxBtnHandle>
) {
const { preferences } = usePreferences();
const hardwareSignRef = useRef<SignTransactionHandle | null>(null);
const { mutateAsync: sendTransactionInner, ...sendTxMutationInner } =
useMutation({
Expand Down Expand Up @@ -105,8 +107,12 @@ export const SignTransactionButton = React.forwardRef(
<WithReadonlyWarningDialog
address={wallet.address}
onClick={onClick}
render={({ handleClick }) =>
holdToSign ? (
render={({ handleClick }) => {
if (!preferences) {
return null;
}

return holdToSign && preferences.enableHoldToSignButton ? (
<HoldableButton
text={`Hold to ${title}`}
successText={
Expand Down Expand Up @@ -139,8 +145,8 @@ export const SignTransactionButton = React.forwardRef(
>
{children || (sendTxMutation.isLoading ? 'Sending...' : title)}
</Button>
)
}
);
}}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import type {
} from 'src/modules/ethereum/types/IncomingTransaction';
import { getError } from 'src/shared/errors/getError';
import { CircleSpinner } from 'src/ui/ui-kit/CircleSpinner';
import { usePreferences } from 'src/ui/features/preferences';
import { NetworkFee } from '../../../SendTransaction/NetworkFee';
import { useTransactionFee } from '../../../SendTransaction/TransactionConfiguration/useTransactionFee';
import {
Expand All @@ -57,7 +56,6 @@ function CancelTxContent({
onDismiss: () => void;
onSuccess: () => void;
}) {
const { preferences } = usePreferences();
const { address } = wallet;
const { transaction: originalTransaction } = addressAction;
const [configuration, setConfiguration] = useState(DEFAULT_CONFIGURATION);
Expand Down Expand Up @@ -207,14 +205,12 @@ function CancelTxContent({
>
Back
</Button>
{preferences ? (
<SignTransactionButton
wallet={wallet}
ref={signTxBtnRef}
onClick={() => sendTransaction()}
holdToSign={preferences.enableHoldToSignButton}
/>
) : null}
<SignTransactionButton
wallet={wallet}
ref={signTxBtnRef}
onClick={() => sendTransaction()}
holdToSign={true}
/>
</div>
</VStack>
</VStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type { ExternallyOwnedAccount } from 'src/shared/types/ExternallyOwnedAcc
import { Spacer } from 'src/ui/ui-kit/Spacer';
import { invariant } from 'src/shared/invariant';
import { INTERNAL_ORIGIN } from 'src/background/constants';
import { usePreferences } from 'src/ui/features/preferences';
import { NetworkFee } from '../../../SendTransaction/NetworkFee';
import { useTransactionFee } from '../../../SendTransaction/TransactionConfiguration/useTransactionFee';
import {
Expand All @@ -45,7 +44,6 @@ export function SpeedUp({
onDismiss: () => void;
onSuccess: () => void;
}) {
const { preferences } = usePreferences();
const { address } = wallet;
const { transaction: originalTransaction } = addressAction;
const [configuration, setConfiguration] = useState(DEFAULT_CONFIGURATION);
Expand Down Expand Up @@ -201,14 +199,12 @@ export function SpeedUp({
>
Back
</Button>
{preferences ? (
<SignTransactionButton
wallet={wallet}
ref={signTxBtnRef}
onClick={() => sendTransaction()}
holdToSign={preferences.enableHoldToSignButton}
/>
) : null}
<SignTransactionButton
wallet={wallet}
ref={signTxBtnRef}
onClick={() => sendTransaction()}
holdToSign={true}
/>
</div>
</VStack>
</VStack>
Expand Down

0 comments on commit 0661348

Please sign in to comment.