diff --git a/package.json b/package.json index b45a17fbe48..f9b85b7c132 100644 --- a/package.json +++ b/package.json @@ -61,9 +61,9 @@ "@rabby-wallet/gnosis-sdk": "1.3.9", "@rabby-wallet/page-provider": "0.4.2", "@rabby-wallet/rabby-action": "0.1.4", - "@rabby-wallet/rabby-api": "0.8.4-beta.0", + "@rabby-wallet/rabby-api": "0.8.4", "@rabby-wallet/rabby-security-engine": "2.0.7", - "@rabby-wallet/rabby-swap": "0.0.42-beta.1", + "@rabby-wallet/rabby-swap": "0.0.42", "@rabby-wallet/widgets": "1.0.9", "@rematch/core": "2.2.0", "@rematch/select": "3.1.2", diff --git a/src/background/controller/provider/controller.ts b/src/background/controller/provider/controller.ts index e08e490b4b3..6f6cfa2bd07 100644 --- a/src/background/controller/provider/controller.ts +++ b/src/background/controller/provider/controller.ts @@ -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 diff --git a/src/background/controller/provider/rpcFlow.ts b/src/background/controller/provider/rpcFlow.ts index 65171dc605d..74dae649a2b 100644 --- a/src/background/controller/provider/rpcFlow.ts +++ b/src/background/controller/provider/rpcFlow.ts @@ -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); } }) ); diff --git a/src/background/service/keyring/helper.ts b/src/background/service/keyring/helper.ts index 6b126bbf56f..158d062fdc7 100644 --- a/src/background/service/keyring/helper.ts +++ b/src/background/service/keyring/helper.ts @@ -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; @@ -27,18 +25,7 @@ export class SignHelper { } async invoke(fn: () => Promise) { - 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(); } } diff --git a/src/constant/index.ts b/src/constant/index.ts index b8579677cb8..36950ea1c34 100644 --- a/src/constant/index.ts +++ b/src/constant/index.ts @@ -1493,7 +1493,7 @@ export const DEX = { [DEX_ENUM.ZEROXAPIV2]: { id: DEX_ENUM.ZEROXAPIV2, logo: Logo0X, - name: '0x_v2', + name: '0x', chains: DEX_SUPPORT_CHAINS[DEX_ENUM.ZEROXAPIV2], }, }; diff --git a/src/ui/utils/sendTransaction.ts b/src/ui/utils/sendTransaction.ts index 426fac1e2fb..11c24cd3884 100644 --- a/src/ui/utils/sendTransaction.ts +++ b/src/ui/utils/sendTransaction.ts @@ -458,41 +458,32 @@ 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(); const err = new Error(e.message); err.name = FailedCode.SubmitTxFailed; + eventBus.emit(EVENTS.COMMON_HARDWARE.REJECTED, e.message); throw err; } diff --git a/src/ui/views/Approval/components/LedgerHardwareWaiting.tsx b/src/ui/views/Approval/components/LedgerHardwareWaiting.tsx index b33f4ba7c00..e61b6794125 100644 --- a/src/ui/views/Approval/components/LedgerHardwareWaiting.tsx +++ b/src/ui/views/Approval/components/LedgerHardwareWaiting.tsx @@ -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.'); diff --git a/src/ui/views/Approval/components/MiniSignTx/MiniLedgerAction.tsx b/src/ui/views/Approval/components/MiniSignTx/MiniLedgerAction.tsx index 9a0a1644b14..6f7cef6ff18 100644 --- a/src/ui/views/Approval/components/MiniSignTx/MiniLedgerAction.tsx +++ b/src/ui/views/Approval/components/MiniSignTx/MiniLedgerAction.tsx @@ -89,10 +89,10 @@ export const MiniLedgerAction: React.FC = ({ } }; - eventBus.addEventListener(EVENTS.LEDGER.REJECTED, listener); + eventBus.addEventListener(EVENTS.COMMON_HARDWARE.REJECTED, listener); return () => { - eventBus.removeEventListener(EVENTS.LEDGER.REJECTED, listener); + eventBus.removeEventListener(EVENTS.COMMON_HARDWARE.REJECTED, listener); }; }, []); @@ -106,7 +106,7 @@ export const MiniLedgerAction: React.FC = ({ React.useEffect(() => { if (task.status === 'active' && status === 'DISCONNECTED') { - eventBus.emit(EVENTS.LEDGER.REJECTED, 'DISCONNECTED'); + eventBus.emit(EVENTS.COMMON_HARDWARE.REJECTED, 'DISCONNECTED'); } }, [task.status, status]); const { t } = useTranslation(); diff --git a/src/ui/views/ApprovalManagePage/components/BatchRevoke/RevokeActionLedgerButton.tsx b/src/ui/views/ApprovalManagePage/components/BatchRevoke/RevokeActionLedgerButton.tsx index 20b76a38d8e..7813fc17817 100644 --- a/src/ui/views/ApprovalManagePage/components/BatchRevoke/RevokeActionLedgerButton.tsx +++ b/src/ui/views/ApprovalManagePage/components/BatchRevoke/RevokeActionLedgerButton.tsx @@ -59,16 +59,16 @@ export const RevokeActionLedgerButton: React.FC<{ } }; - eventBus.addEventListener(EVENTS.LEDGER.REJECTED, listener); + eventBus.addEventListener(EVENTS.COMMON_HARDWARE.REJECTED, listener); return () => { - eventBus.removeEventListener(EVENTS.LEDGER.REJECTED, listener); + eventBus.removeEventListener(EVENTS.COMMON_HARDWARE.REJECTED, listener); }; }, [task.addRevokeTask]); React.useEffect(() => { if (task.status === 'active' && status === 'DISCONNECTED') { - eventBus.emit(EVENTS.LEDGER.REJECTED, 'DISCONNECTED'); + eventBus.emit(EVENTS.COMMON_HARDWARE.REJECTED, 'DISCONNECTED'); } }, [task.status, status]); diff --git a/src/ui/views/Bridge/Component/BridgeContent.tsx b/src/ui/views/Bridge/Component/BridgeContent.tsx index 4648b9a2dc0..d2db4039161 100644 --- a/src/ui/views/Bridge/Component/BridgeContent.tsx +++ b/src/ui/views/Bridge/Component/BridgeContent.tsx @@ -67,6 +67,8 @@ export const BridgeContent = () => { isCustomSlippage, setAutoSlippage, setIsCustomSlippage, + + clearExpiredTimer, } = useBridge(); const amountAvailable = useMemo(() => Number(amount) > 0, [amount]); @@ -305,6 +307,7 @@ export const BridgeContent = () => { ) { await runBuildSwapTxs(); setIsShowSign(true); + clearExpiredTimer(); } else { gotoBridge(); } @@ -528,12 +531,14 @@ export const BridgeContent = () => { txs={txs} onClose={() => { setIsShowSign(false); + refresh((e) => e + 1); setTimeout(() => { mutateTxs([]); }, 500); }} onReject={() => { setIsShowSign(false); + refresh((e) => e + 1); mutateTxs([]); }} onResolve={() => { diff --git a/src/ui/views/Bridge/Component/BridgeToTokenSelect.tsx b/src/ui/views/Bridge/Component/BridgeToTokenSelect.tsx index 9e8bd0ad851..7f743d3bfae 100644 --- a/src/ui/views/Bridge/Component/BridgeToTokenSelect.tsx +++ b/src/ui/views/Bridge/Component/BridgeToTokenSelect.tsx @@ -137,7 +137,6 @@ const BridgeToTokenSelect = ({ const list = await wallet.openapi.getBridgeToTokenList({ from_chain_id: fromChainId, from_token_id: fromTokenId, - // @ts-expect-error to_chain_id to_chain_id: chainId, q: queryConds.keyword, }); diff --git a/src/ui/views/Bridge/Component/BridgeToken.tsx b/src/ui/views/Bridge/Component/BridgeToken.tsx index 3acf158e268..f009a7d0114 100644 --- a/src/ui/views/Bridge/Component/BridgeToken.tsx +++ b/src/ui/views/Bridge/Component/BridgeToken.tsx @@ -90,13 +90,19 @@ export const BridgeToken = ({ const openFeePopup = useSetSettingVisible(); + const isMaxRef = useRef(false); + const inputRef = useRef(); useLayoutEffect(() => { if (isFromToken) { - if (document?.activeElement !== inputRef.current?.input) { + if ( + document?.activeElement !== inputRef.current?.input && + !isMaxRef.current + ) { inputRef.current?.focus(); } + isMaxRef.current = false; } }, [value]); @@ -120,6 +126,7 @@ export const BridgeToken = ({ const handleMax = React.useCallback(() => { if (token) { + isMaxRef.current = true; onInputChange?.(tokenAmountBn(token)?.toString(10)); } }, [token?.raw_amount_hex_str, onInputChange]); diff --git a/src/ui/views/Bridge/hooks/token.tsx b/src/ui/views/Bridge/hooks/token.tsx index f45d2934c4f..b6754c806e4 100644 --- a/src/ui/views/Bridge/hooks/token.tsx +++ b/src/ui/views/Bridge/hooks/token.tsx @@ -601,7 +601,15 @@ export const useBridge = () => { return false; }, [fromToken, toToken, amount, selectedBridgeQuote]); + const clearExpiredTimer = useCallback(() => { + if (expiredTimer.current) { + clearTimeout(expiredTimer.current); + } + }, []); + return { + clearExpiredTimer, + fromChain, fromToken, setFromToken, diff --git a/yarn.lock b/yarn.lock index 9470fba170d..78130aa34e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4781,10 +4781,10 @@ resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-action/-/rabby-action-0.1.4.tgz#c82e7c8b538b7dfd94506c4f89f78aca7ca880ef" integrity sha512-6ttnlpGHcO2v/qyYo8epBbSutfS9OZXfXr9mfapuveoBvzqUwvE6ej3bsmdtc+qFhFeH7HeiwASpY6xaTM4E1w== -"@rabby-wallet/rabby-api@0.8.4-beta.0": - version "0.8.4-beta.0" - resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-api/-/rabby-api-0.8.4-beta.0.tgz#1ae4418a79a6e9d3b50305f50d8951ae0a82e0cb" - integrity sha512-XsLXk2rtacIG4fh5NUa3CYT3oYvu9V9+56P+YdgsxBZGMpKQL+NJJ2Bq8oN7gLoz1g13FtRAWDHjHuR9DOiuSw== +"@rabby-wallet/rabby-api@0.8.4": + version "0.8.4" + resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-api/-/rabby-api-0.8.4.tgz#ef1979eea94eb5fe4e07fe123444a7213178ce15" + integrity sha512-pN6fL6YHhmW7MTmtJEftfvkljYdgcEtJKk2hX2uBfHJQVRXU+jiGOPhSHPE1yfKV4LNwptdV1jtBv3KaYyKa8Q== dependencies: "@rabby-wallet/rabby-sign" "0.4.0" axios "^0.27.2" @@ -4808,10 +4808,10 @@ sha256-uint8array "^0.10.3" url-parse "^1.5.1" -"@rabby-wallet/rabby-swap@0.0.42-beta.1": - version "0.0.42-beta.1" - resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-swap/-/rabby-swap-0.0.42-beta.1.tgz#1a03c5087b8599d0b28b8d2d1fefd649e0c04ac8" - integrity sha512-hJc/eJe0+/8uYCRTTjXmaPG/KsHHM60PE8ynNM0tZuPxjWKcv/JZ/XC78YcYA3ZSAxqL8ZTnNi8NKoObA3r1rg== +"@rabby-wallet/rabby-swap@0.0.42": + version "0.0.42" + resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-swap/-/rabby-swap-0.0.42.tgz#b0fc3c156874e0566df94c892752d01f0e1df1fb" + integrity sha512-k1yhqs+UROMCBseQBrirZ/qwa0iEC7wozDmeOTSJQEKdEXSifhL0W4HLoL1Zh2mZQytv3b86TN8TvoI7Yboh0Q== dependencies: "@ethersproject/abi" "^5.7.0" axios "^0.27.2"