Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/bridge-v2' into tmp/20241108
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Nov 11, 2024
2 parents 6ec34cb + 30ecb71 commit 1b04664
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 74 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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
2 changes: 1 addition & 1 deletion src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
};
Expand Down
49 changes: 20 additions & 29 deletions src/ui/utils/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export const MiniLedgerAction: React.FC<Props> = ({
}
};

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);
};
}, []);

Expand All @@ -106,7 +106,7 @@ export const MiniLedgerAction: React.FC<Props> = ({

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
5 changes: 5 additions & 0 deletions src/ui/views/Bridge/Component/BridgeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const BridgeContent = () => {
isCustomSlippage,
setAutoSlippage,
setIsCustomSlippage,

clearExpiredTimer,
} = useBridge();

const amountAvailable = useMemo(() => Number(amount) > 0, [amount]);
Expand Down Expand Up @@ -305,6 +307,7 @@ export const BridgeContent = () => {
) {
await runBuildSwapTxs();
setIsShowSign(true);
clearExpiredTimer();
} else {
gotoBridge();
}
Expand Down Expand Up @@ -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={() => {
Expand Down
1 change: 0 additions & 1 deletion src/ui/views/Bridge/Component/BridgeToTokenSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
9 changes: 8 additions & 1 deletion src/ui/views/Bridge/Component/BridgeToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ export const BridgeToken = ({

const openFeePopup = useSetSettingVisible();

const isMaxRef = useRef(false);

const inputRef = useRef<Input>();

useLayoutEffect(() => {
if (isFromToken) {
if (document?.activeElement !== inputRef.current?.input) {
if (
document?.activeElement !== inputRef.current?.input &&
!isMaxRef.current
) {
inputRef.current?.focus();
}
isMaxRef.current = false;
}
}, [value]);

Expand All @@ -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]);
Expand Down
8 changes: 8 additions & 0 deletions src/ui/views/Bridge/hooks/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]-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/[email protected]":
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"
Expand All @@ -4808,10 +4808,10 @@
sha256-uint8array "^0.10.3"
url-parse "^1.5.1"

"@rabby-wallet/[email protected]-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/[email protected]":
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"
Expand Down

0 comments on commit 1b04664

Please sign in to comment.