Skip to content

Commit

Permalink
[FIX] Wallet connect signed typed and eth sign throwing error back to…
Browse files Browse the repository at this point in the history
… the dapp (#5103)

* Wallet connect signed typed and eth sign throwing error back to the dapp

* fix code to git ts notation

* eth sign error moved to a constant and refactor logic on typed sign to the try catch

* remove duplicated import
  • Loading branch information
tommasini authored Nov 23, 2022
1 parent 08a5c4e commit 1c0ebb4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
37 changes: 25 additions & 12 deletions app/components/UI/TypedSign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ class TypedSign extends PureComponent {
);
};

walletConnectNotificationTitle = (confirmation, isError) => {
if (isError) return strings('notifications.wc_signed_failed_title');
return confirmation
? strings('notifications.wc_signed_title')
: strings('notifications.wc_signed_rejected_title');
};

showWalletConnectNotification = (
messageParams = {},
confirmation = false,
isError = false,
) => {
InteractionManager.runAfterInteractions(() => {
messageParams.origin &&
Expand All @@ -125,9 +133,7 @@ class TypedSign extends PureComponent {
NotificationManager.showSimpleNotification({
status: `simple_notification${!confirmation ? '_rejected' : ''}`,
duration: 5000,
title: confirmation
? strings('notifications.wc_signed_title')
: strings('notifications.wc_signed_rejected_title'),
title: this.walletConnectNotificationTitle(confirmation, isError),
description: strings('notifications.wc_description'),
});
});
Expand All @@ -138,15 +144,22 @@ class TypedSign extends PureComponent {
const { KeyringController, TypedMessageManager } = Engine.context;
const messageId = messageParams.metamaskId;
const version = messageParams.version;
const cleanMessageParams = await TypedMessageManager.approveMessage(
messageParams,
);
const rawSig = await KeyringController.signTypedMessage(
cleanMessageParams,
version,
);
TypedMessageManager.setMessageStatusSigned(messageId, rawSig);
this.showWalletConnectNotification(messageParams, true);
let rawSig;
let cleanMessageParams;
try {
cleanMessageParams = await TypedMessageManager.approveMessage(
messageParams,
);
rawSig = await KeyringController.signTypedMessage(
cleanMessageParams,
version,
);
TypedMessageManager.setMessageStatusSigned(messageId, rawSig);
this.showWalletConnectNotification(messageParams, true);
} catch (error) {
TypedMessageManager.setMessageStatusSigned(messageId, error.message);
this.showWalletConnectNotification(messageParams, false, true);
}
};

rejectMessage = () => {
Expand Down
1 change: 1 addition & 0 deletions app/core/AppConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ export default {
},
CANCEL_RATE: 'Transactions (Cancel)',
SPEED_UP_RATE: 'Transactions (Speed Up)',
ETH_SIGN_ERROR: 'eth_sign requires 32 byte message hash',
};
5 changes: 2 additions & 3 deletions app/core/RPCMethods/RPCMethodMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,8 @@ export const getRpcMethodMiddleware = ({

res.result = rawSig;
} else {
throw ethErrors.rpc.invalidParams(
'eth_sign requires 32 byte message hash',
);
res.result = AppConstants.ETH_SIGN_ERROR;
throw ethErrors.rpc.invalidParams(AppConstants.ETH_SIGN_ERROR);
}
},

Expand Down
1 change: 1 addition & 0 deletions locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@
"wc_sent_tx_title": "Sent transaction",
"wc_connected_rejected_title": "You've rejected the connect request",
"wc_signed_rejected_title": "You've rejected the sign request",
"wc_signed_failed_title": "This sign request failed",
"wc_sent_tx_rejected_title": "You've rejected the transaction request",
"wc_description": "Please check the application"
},
Expand Down

0 comments on commit 1c0ebb4

Please sign in to comment.