Skip to content

Commit

Permalink
Merge branch 'fix/sign-helper' into tmp/20241101
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Nov 1, 2024
2 parents 8d732fd + 50ed9ce commit 3db9d16
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 55 deletions.
14 changes: 13 additions & 1 deletion src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,25 @@ class ProviderController extends BaseController {
reported: false,
};

let signedTx;
try {
const signedTx = await keyringService.signTransaction(
signedTx = await keyringService.signTransaction(
keyring,
tx,
txParams.from,
opts
);
} catch (e) {
const errObj =
typeof e === 'object'
? { message: e.message }
: ({ message: e } as any);
errObj.method = EVENTS.COMMON_HARDWARE.REJECTED;

throw errObj;
}

try {
if (
currentAccount.type === KEYRING_TYPE.GnosisKeyring ||
currentAccount.type === KEYRING_TYPE.CoboArgusKeyring
Expand Down
20 changes: 13 additions & 7 deletions src/background/controller/provider/rpcFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,21 @@ const flowContext = flow
})
.then(resolve)
.catch((e: any) => {
const payload = {
method: EVENTS.SIGN_FINISHED,
params: {
success: false,
errorMsg: e?.message || JSON.stringify(e),
},
};
if (e.method) {
payload.method = e.method;
payload.params = e.message;
}

Sentry.captureException(e);
if (isSignApproval(approvalType)) {
eventBus.emit(EVENTS.broadcastToUI, {
method: EVENTS.SIGN_FINISHED,
params: {
success: false,
errorMsg: e?.message || JSON.stringify(e),
},
});
eventBus.emit(EVENTS.broadcastToUI, payload);
}
})
);
Expand Down
15 changes: 1 addition & 14 deletions src/background/service/keyring/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export const throwError = (error, method = EVENTS.COMMON_HARDWARE.REJECTED) => {
method,
params: error,
});
throw new Error(error);
};

export class SignHelper {
signFn: any;
errorEventName: string;
Expand All @@ -27,18 +25,7 @@ export class SignHelper {
}

async invoke(fn: () => Promise<any>) {
return new Promise((resolve) => {
this.signFn = async () => {
try {
const result = await fn();
resolve(result);
} catch (e) {
Sentry.captureException(e);
throwError(e?.message ?? e, this.errorEventName);
}
};
this.signFn();
});
return fn();
}
}

Expand Down
48 changes: 19 additions & 29 deletions src/ui/utils/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,36 +448,26 @@ export const sendTransaction = async ({
// submit tx
let hash = '';
try {
hash = await Promise.race([
wallet.ethSendTransaction({
data: {
$ctx: {
ga,
},
params: [transaction],
hash = await wallet.ethSendTransaction({
data: {
$ctx: {
ga,
},
session: INTERNAL_REQUEST_SESSION,
approvalRes: {
...transaction,
signingTxId,
logId: logId,
lowGasDeadline,
isGasLess,
isGasAccount: autoUseGasAccount ? canUseGasAccount : isGasAccount,
pushType,
},
pushed: false,
result: undefined,
}),
new Promise((_, reject) => {
eventBus.once(EVENTS.LEDGER.REJECTED, async (data) => {
if (signingTxId != null) {
wallet.removeSigningTx(signingTxId);
}
reject(new Error(data));
});
}),
]);
params: [transaction],
},
session: INTERNAL_REQUEST_SESSION,
approvalRes: {
...transaction,
signingTxId,
logId: logId,
lowGasDeadline,
isGasLess,
isGasAccount: autoUseGasAccount ? canUseGasAccount : isGasAccount,
pushType,
},
pushed: false,
result: undefined,
});
await handleSendAfter();
} catch (e) {
await handleSendAfter();
Expand Down
5 changes: 1 addition & 4 deletions src/ui/views/Approval/components/LedgerHardwareWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ const LedgerHardwareWaiting = ({ params }: { params: ApprovalParams }) => {
method: params?.extra?.signTextMethod,
});
}
eventBus.addEventListener(EVENTS.LEDGER.REJECT_APPROVAL, (data) => {
rejectApproval(data, false, true);
});
eventBus.addEventListener(EVENTS.LEDGER.REJECTED, async (data) => {
eventBus.addEventListener(EVENTS.COMMON_HARDWARE.REJECTED, async (data) => {
setErrorMessage(data);
if (/DisconnectedDeviceDuringOperation/i.test(data)) {
await rejectApproval('User rejected the request.');
Expand Down

0 comments on commit 3db9d16

Please sign in to comment.