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

fix: re-designs signatures, continue to use old designs when signing with hardware wallets #12976

Merged
merged 15 commits into from
Jan 15, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,43 @@ import { useMemo } from 'react';
import { useSelector } from 'react-redux';

import { ApprovalTypes } from '../../../../core/RPCMethods/RPCMethodMiddleware';
import { isExternalHardwareAccount } from '../../../../util/address';
import { selectRemoteFeatureFlags } from '../../../../selectors/featureFlagController';
import useApprovalRequest from './useApprovalRequest';
import useQRHardwareAwareness from './useQRHardwareAwareness';

const useConfirmationRedesignEnabled = () => {
const { approvalRequest } = useApprovalRequest();
const { isSigningQRObject, isSyncingQRHardware } = useQRHardwareAwareness();
const { confirmation_redesign } = useSelector(selectRemoteFeatureFlags);

const { type: approvalRequestType } = approvalRequest ?? {
const {
type: approvalRequestType,
requestData: { from: fromAddress },
} = approvalRequest ?? {
requestData: {},
};

const isRedesignedEnabled = useMemo(
() =>
(confirmation_redesign as Record<string, string>)?.signatures &&
process.env.REDESIGNED_SIGNATURE_REQUEST === 'true' &&
// following condition will ensure that user is redirected to old designs is using QR scan aware hardware
!isSyncingQRHardware &&
jpuri marked this conversation as resolved.
Show resolved Hide resolved
jpuri marked this conversation as resolved.
Show resolved Hide resolved
!isSigningQRObject &&
// following condition will ensure that user is redirected to old designs for hardware wallets
!isExternalHardwareAccount(fromAddress) &&
approvalRequestType &&
[ApprovalTypes.PERSONAL_SIGN, ApprovalTypes.ETH_SIGN_TYPED_DATA].includes(
approvalRequestType as ApprovalTypes,
),
[approvalRequestType, confirmation_redesign],
[
approvalRequestType,
confirmation_redesign,
fromAddress,
isSigningQRObject,
isSyncingQRHardware,
],
);

return { isRedesignedEnabled };
Expand Down
jpuri marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useState, useEffect } from 'react';
jpuri marked this conversation as resolved.
Show resolved Hide resolved

import Engine from '../../../../core/Engine';
import { IQRState } from '../../../UI/QRHardware/types';

const useQRHardwareAwareness = () => {
const [QRState, SetQRState] = useState<IQRState>({
sync: {
reading: false,
},
sign: {},
});

// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const subscribeKeyringState = (value: any) => {
SetQRState(value);
};

useEffect(() => {
// This ensures that a QR keyring gets created if it doesn't already exist.
// This is intentionally not awaited (the subscription still gets setup correctly if called
// before the keyring is created).
// TODO: Stop automatically creating keyrings
Engine.context.KeyringController.getOrAddQRKeyring();
Engine.controllerMessenger.subscribe(
'KeyringController:qrKeyringStateChange',
subscribeKeyringState,
);
return () => {
Engine.controllerMessenger.unsubscribe(
'KeyringController:qrKeyringStateChange',
subscribeKeyringState,
);
};
}, []);

return {
isSigningQRObject: !!QRState.sign?.request,
isSyncingQRHardware: QRState.sync.reading,
QRState,
};
};

export default useQRHardwareAwareness;
Loading