Skip to content

Commit

Permalink
remove qr modal from root rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Jun 15, 2023
1 parent f2b367a commit 0b8a205
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 67 deletions.
65 changes: 0 additions & 65 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { connect, useSelector } from 'react-redux';
import { ethers } from 'ethers';
import abi from 'human-standard-token-abi';
import { ethErrors } from 'eth-json-rpc-errors';
import { v1 as random } from 'uuid';

import Approval from '../../Views/Approval';
import NotificationManager from '../../../core/NotificationManager';
Expand Down Expand Up @@ -50,7 +49,6 @@ import AnalyticsV2 from '../../../util/analyticsV2';

import { useTheme } from '../../../util/theme';
import withQRHardwareAwareness from '../../UI/QRHardware/withQRHardwareAwareness';
import QRSigningModal from '../../UI/QRHardware/QRSigningModal';
import SignatureRequestRoot from '../../UI/SignatureRequest/Root';
import { networkSwitched } from '../../../actions/onboardNetwork';
import {
Expand Down Expand Up @@ -79,7 +77,6 @@ const RootRPCMethodsUI = (props) => {

const [customNetworkToAdd, setCustomNetworkToAdd] = useState(null);
const [customNetworkToSwitch, setCustomNetworkToSwitch] = useState(null);
const [qrSigningState, setQrSigningState] = useState(null);

const [hostToApprove, setHostToApprove] = useState(null);

Expand All @@ -89,8 +86,6 @@ const RootRPCMethodsUI = (props) => {

const setTransactionObject = props.setTransactionObject;
const setEtherTransaction = props.setEtherTransaction;
const QRState = props.QRState;
const isSigningQRObject = props.isSigningQRObject;

const TransactionModalType = {
Transaction: 'transaction',
Expand Down Expand Up @@ -382,28 +377,6 @@ const RootRPCMethodsUI = (props) => {
],
);

const onQRSigningApproval = () => {
setShowPendingApproval(false);
acceptPendingApproval(qrSigningState.id, qrSigningState.data);
setQrSigningState(undefined);
};

const onQRSigningRejected = () => {
setShowPendingApproval(false);
rejectPendingApproval(qrSigningState.id, qrSigningState.data);
setQrSigningState(undefined);
};

const renderQRSigningModal = () =>
showPendingApproval && (
<QRSigningModal
isVisible={showPendingApproval?.type === ApprovalTypes.QR_SIGNING}
QRState={qrSigningState?.data}
onSuccess={onQRSigningApproval}
onCancel={onQRSigningRejected}
/>
);

const onWalletConnectSessionApproval = () => {
setShowPendingApproval(false);
acceptPendingApproval(
Expand Down Expand Up @@ -778,13 +751,6 @@ const RootRPCMethodsUI = (props) => {
origin: request.origin,
});
break;
case ApprovalTypes.QR_SIGNING:
setQrSigningState({ data: requestData, id: request.id });
showPendingApprovalModal({
type: ApprovalTypes.QR_SIGNING,
origin: request.origin,
});
break;
default:
break;
}
Expand All @@ -793,34 +759,6 @@ const RootRPCMethodsUI = (props) => {
}
};

useEffect(() => {
async function checkAndAddQRSigningApproval() {
if (
isSigningQRObject &&
!approveModalVisible &&
!dappTransactionModalVisible
) {
const { ApprovalController } = Engine.context;
try {
await ApprovalController.add({
id: random(),
origin: 'metamask',
requestData: QRState,
type: ApprovalTypes.QR_SIGNING,
});
} catch (error) {
throw new Error('QR signing failed');
}
}
}
checkAndAddQRSigningApproval();
}, [
QRState,
approveModalVisible,
dappTransactionModalVisible,
isSigningQRObject,
]);

useEffect(() => {
initializeWalletConnect();

Expand Down Expand Up @@ -849,7 +787,6 @@ const RootRPCMethodsUI = (props) => {
{renderAddCustomNetworkModal()}
{renderSwitchCustomNetworkModal()}
{renderWatchAssetModal()}
{renderQRSigningModal()}
{renderAccountsApprovalModal()}
</React.Fragment>
);
Expand Down Expand Up @@ -881,8 +818,6 @@ RootRPCMethodsUI.propTypes = {
* Chain id
*/
chainId: PropTypes.string,
isSigningQRObject: PropTypes.bool,
QRState: PropTypes.object,
/**
* updates redux when network is switched
*/
Expand Down
25 changes: 24 additions & 1 deletion app/components/UI/SignatureRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Analytics from '../../../core/Analytics/Analytics';
import { MetaMetricsEvents } from '../../../core/Analytics';
import { ThemeContext, mockTheme } from '../../../util/theme';
import withQRHardwareAwareness from '../QRHardware/withQRHardwareAwareness';
import QRSigningDetails from '../QRHardware/QRSigningDetails';
import { selectProviderType } from '../../../selectors/networkController';

const createStyles = (colors) =>
Expand Down Expand Up @@ -152,6 +153,8 @@ class SignatureRequest extends PureComponent {
* Active address of account that triggered signing.
*/
fromAddress: PropTypes.string,
isSigningQRObject: PropTypes.bool,
QRState: PropTypes.object,
testID: PropTypes.string,
};

Expand Down Expand Up @@ -323,8 +326,28 @@ class SignatureRequest extends PureComponent {
);
}

renderQRDetails() {
const { QRState, fromAddress } = this.props;
const styles = this.getStyles();

return (
<View style={[styles.root]}>
<QRSigningDetails
QRState={QRState}
showCancelButton
showHint={false}
bypassAndroidCameraAccessCheck={false}
fromAddress={fromAddress}
/>
</View>
);
}

render() {
return this.renderSignatureRequest();
const { isSigningQRObject } = this.props;
return isSigningQRObject
? this.renderQRDetails()
: this.renderSignatureRequest();
}
}

Expand Down
1 change: 0 additions & 1 deletion app/core/RPCMethods/RPCMethodMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export enum ApprovalTypes {
ETH_SIGN_TYPED_DATA = 'eth_signTypedData',
WATCH_ASSET = 'wallet_watchAsset',
TRANSACTION = 'transaction',
QR_SIGNING = 'QR_SIGNING',
}

interface RPCMethodsMiddleParameters {
Expand Down

0 comments on commit 0b8a205

Please sign in to comment.