Skip to content

Commit

Permalink
fix: user can disable custom rpc when meet custom rpc error (#2285)
Browse files Browse the repository at this point in the history
* fix: user can disable custom rpc when meet custom rpc error

* fix: style
  • Loading branch information
vvvvvv1vvvvvv authored May 24, 2024
1 parent 4845690 commit d00bb0e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
7 changes: 6 additions & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
"enoughSafeSigCollected": "Enough signature collected",
"moreSafeSigNeeded": "{{0}} more confirmation needed",
"safeAdminSigned": "Signed",
"customRPCErrorModal": {
"title": "Custom RPC Error",
"content": "Your custom RPC is unavailable now. You can disable it and continue signing using Rabby's official RPC",
"button": "Disable Custom RPC"
},
"swap": {
"title": "Swap Token",
"payToken": "Pay",
Expand Down Expand Up @@ -2110,4 +2115,4 @@
},
"IMPORTED_HD_KEYRING_NEED_PASSPHRASE": "Imported by Seed Phrase (Passphrase)"
}
}
}
2 changes: 1 addition & 1 deletion src/ui/style/antd-overwrite.less
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
justify-content: space-between;
width: 100%;
.ant-btn {
width: 144px;
min-width: 144px;
font-size: 15px;
font-weight: 500;
height: 44px;
Expand Down
10 changes: 0 additions & 10 deletions src/ui/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ export const useApproval = () => {
history.push('/');
}
};

useEffect(() => {
if (!getUiType().isNotification) {
return;
}
window.addEventListener('beforeunload', rejectApproval);

return () => window.removeEventListener('beforeunload', rejectApproval);
}, []);

return [getApproval, resolveApproval, rejectApproval] as const;
};

Expand Down
59 changes: 44 additions & 15 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import GasSelector, { GasSelectorResponse } from './TxComponents/GasSelecter';
import GnosisDrawer from './TxComponents/GnosisDrawer';
import Loading from './TxComponents/Loading';
import { useLedgerDeviceConnected } from '@/ui/utils/ledger';
import { TransactionGroup } from 'background/service/transactionHistory';
import { intToHex } from 'ui/utils/number';
import { calcMaxPriorityFee } from '@/utils/transaction';
import { FooterBar } from './FooterBar/FooterBar';
Expand All @@ -62,7 +61,6 @@ import {
fetchActionRequiredData,
ActionRequireData,
formatSecurityEngineCtx,
getActionTypeText,
} from '../components/Actions/utils';
import Actions from './Actions';
import { useSecurityEngine } from 'ui/utils/securityEngine';
Expand Down Expand Up @@ -778,6 +776,23 @@ const SignTx = ({ params, origin }: SignTxProps) => {
}
};

const triggerCustomRPCErrorModal = () => {
Modal.error({
className: 'modal-support-darkmode',
closable: true,
title: t('page.signTx.customRPCErrorModal.title'),
content: t('page.signTx.customRPCErrorModal.content'),
okText: t('page.signTx.customRPCErrorModal.button'),
okButtonProps: {
className: 'w-[280px]',
},
async onOk() {
await wallet.setRPCEnable(chain.enum, false);
location.reload();
},
});
};

const {
data = '0x',
from,
Expand Down Expand Up @@ -916,12 +931,18 @@ const SignTx = ({ params, origin }: SignTxProps) => {
const explainTx = async (address: string) => {
let recommendNonce = '0x0';
if (!isGnosisAccount && !isCoboArugsAccount) {
recommendNonce = await getRecommendNonce({
tx,
wallet,
chainId,
});
setRecommendNonce(recommendNonce);
try {
recommendNonce = await getRecommendNonce({
tx,
wallet,
chainId,
});
setRecommendNonce(recommendNonce);
} catch (e) {
if (await wallet.hasCustomRPC(chain.enum)) {
triggerCustomRPCErrorModal();
}
}
}
if (updateNonce && !isGnosisAccount && !isCoboArugsAccount) {
setRealNonce(recommendNonce);
Expand Down Expand Up @@ -986,7 +1007,9 @@ const SignTx = ({ params, origin }: SignTxProps) => {
);
setBlockInfo(block);
} catch (e) {
// DO NOTHING
if (await wallet.hasCustomRPC(chain.enum)) {
triggerCustomRPCErrorModal();
}
}
if (tx.gas && origin === INTERNAL_REQUEST_ORIGIN) {
setGasLimit(intToHex(Number(tx.gas))); // use origin gas as gasLimit when tx is an internal tx with gasLimit(i.e. for SendMax native token)
Expand Down Expand Up @@ -1635,13 +1658,19 @@ const SignTx = ({ params, origin }: SignTxProps) => {
(item) => item.type === currentAccount.type
)
);
const balance = await getNativeTokenBalance({
wallet,
chainId,
address: currentAccount.address,
});
try {
const balance = await getNativeTokenBalance({
wallet,
chainId,
address: currentAccount.address,
});

setNativeTokenBalance(balance);
setNativeTokenBalance(balance);
} catch (e) {
if (await wallet.hasCustomRPC(chain.enum)) {
triggerCustomRPCErrorModal();
}
}

wallet.reportStats('createTransaction', {
type: currentAccount.brandName,
Expand Down

0 comments on commit d00bb0e

Please sign in to comment.