Skip to content

Commit

Permalink
Merge branch 'tmp/20241101' of github.com:RabbyHub/Rabby into tmp/202…
Browse files Browse the repository at this point in the history
…41101
  • Loading branch information
cs1707 committed Nov 1, 2024
2 parents 4cbbf51 + d19084f commit 0ea93d9
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 62 deletions.
2 changes: 1 addition & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@
},
"loginConfirmModal": {
"title": "Log in with Current Address",
"desc": "You can only use this address to deposit and view your GasAccount balance."
"desc": "Once confirmed, you can only deposit it at this address"
},
"logoutConfirmModal": {
"title": "Log out current GasAccount",
Expand Down
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
33 changes: 31 additions & 2 deletions src/ui/views/GasAccount/components/LoginPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { useBrandIcon } from '@/ui/hooks/useBrandIcon';

export const GasACcountCurrentAddress = ({
account,
twoColumn,
}: {
twoColumn?: boolean;
account?: {
address: string;
type: string;
Expand All @@ -34,10 +36,37 @@ export const GasACcountCurrentAddress = ({
brandName: account?.brandName || currentAccount!.brandName,
type: account?.type || currentAccount!.type,
});

if (twoColumn) {
return (
<div className="mb-[20px] h-[56px] px-16 rounded-[6px] flex gap-10 items-center bg-r-neutral-card-2">
<img src={addressTypeIcon} className="w-24 h-24" />
<div className="flex flex-col overflow-hidden">
<span className="text-13 font-medium text-r-neutral-title-1 truncate">
{alias}
</span>
<div className="flex items-center">
<AddressViewer
address={account?.address || currentAccount!.address}
showArrow={false}
className="text-[12px] text-r-neutral-body relative top-1"
/>
<CopyChecked
addr={account?.address || currentAccount!.address}
className={clsx(
'w-[14px] h-[14px] ml-4 text-14 cursor-pointer relative top-1'
)}
checkedClassName={clsx('text-[#00C087]')}
/>
</div>
</div>
</div>
);
}
return (
<div className="mb-[20px] py-12 px-16 rounded-[6px] flex items-center bg-r-neutral-card-2">
<div className="max-w-[calc(100%-40px)] mb-[20px] py-12 px-16 rounded-[6px] flex items-center bg-r-neutral-card-2 overflow-hidden">
<img src={addressTypeIcon} className="w-24 h-24" />
<span className="ml-[8px] mr-4 text-15 font-medium text-r-neutral-title-1">
<span className="ml-[8px] mr-4 text-15 font-medium text-r-neutral-title-1 truncate">
{alias}
</span>
<AddressViewer
Expand Down
7 changes: 3 additions & 4 deletions src/ui/views/GasAccount/components/SwitchLoginAddrModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import { Modal } from '@/ui/component';
import { TokenItem } from '@rabby-wallet/rabby-api/dist/types';
import { useTranslation } from 'react-i18next';
import { Button } from 'antd';
import clsx from 'clsx';
Expand Down Expand Up @@ -43,8 +42,8 @@ export const SwitchLoginAddrBeforeDepositModal = ({
<div className="mt-12 mb-20 text-14 text-r-neutral-body">
{t('page.gasAccount.switchLoginAddressBeforeDeposit.desc')}
</div>
<div className="mb-12">
<GasACcountCurrentAddress account={gasAccount} />
<div className="mb-12 w-full">
<GasACcountCurrentAddress account={gasAccount} twoColumn />
</div>

<Button
Expand Down

0 comments on commit 0ea93d9

Please sign in to comment.