From 2e4dfa6b3d6d9391930ccb19631551310863b37b Mon Sep 17 00:00:00 2001 From: siandreev Date: Thu, 21 Nov 2024 16:30:04 +0100 Subject: [PATCH] fix: throw error and notify user if bin parameter is passed to the transfer link --- .../core/src/service/deeplinkingService.ts | 4 ++ .../src/components/connect/connectHook.ts | 59 +++++++++++-------- packages/uikit/src/hooks/useNotification.ts | 1 - 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/packages/core/src/service/deeplinkingService.ts b/packages/core/src/service/deeplinkingService.ts index 894fecfd8..6f6850332 100644 --- a/packages/core/src/service/deeplinkingService.ts +++ b/packages/core/src/service/deeplinkingService.ts @@ -28,6 +28,10 @@ export function parseTonTransferWithAddress(options: { url: string }) { } } + if (data.query.bin) { + throw new Error('Unsupported link'); + } + const result: Omit & { address: string } = { address: linkAddress, ...data.query diff --git a/packages/uikit/src/components/connect/connectHook.ts b/packages/uikit/src/components/connect/connectHook.ts index 01ca68f62..bdc13b271 100644 --- a/packages/uikit/src/components/connect/connectHook.ts +++ b/packages/uikit/src/components/connect/connectHook.ts @@ -20,47 +20,54 @@ import { sendEventToBridge } from '@tonkeeper/core/dist/service/tonConnect/httpB import { useAppSdk } from '../../hooks/appSdk'; import { useTranslation } from '../../hooks/translation'; import { QueryKey } from '../../libs/queryKey'; -import { useActiveAccountQuery, useActiveWallet } from '../../state/wallet'; +import { useActiveAccountQuery } from '../../state/wallet'; import { BLOCKCHAIN_NAME } from '@tonkeeper/core/dist/entries/crypto'; +import { useToast } from '../../hooks/useNotification'; export const useGetConnectInfo = () => { const sdk = useAppSdk(); const { t } = useTranslation(); + const notifyError = useToast(); return useMutation(async url => { - const transfer = parseTonTransferWithAddress({ url }); + try { + const transfer = parseTonTransferWithAddress({ url }); + + if (transfer) { + sdk.uiEvents.emit('copy', { + method: 'copy', + id: Date.now(), + params: t('loading') + }); + + sdk.uiEvents.emit('transfer', { + method: 'transfer', + id: Date.now(), + params: { chain: BLOCKCHAIN_NAME.TON, ...transfer, from: 'qr-code' } + }); + return null; + } + + const params = parseTonConnect({ url }); + + if (typeof params === 'string') { + console.error(params); + throw new Error('Unsupported link'); + } + + // TODO: handle auto connect - if (transfer) { sdk.uiEvents.emit('copy', { method: 'copy', id: Date.now(), params: t('loading') }); - sdk.uiEvents.emit('transfer', { - method: 'transfer', - id: Date.now(), - params: { chain: BLOCKCHAIN_NAME.TON, ...transfer, from: 'qr-code' } - }); - return null; - } - - const params = parseTonConnect({ url }); - - if (typeof params === 'string') { - console.error(params); - return null; + return params; + } catch (e) { + notifyError(String(e)); + throw e; } - - // TODO: handle auto connect - - sdk.uiEvents.emit('copy', { - method: 'copy', - id: Date.now(), - params: t('loading') - }); - - return params; }); }; diff --git a/packages/uikit/src/hooks/useNotification.ts b/packages/uikit/src/hooks/useNotification.ts index 63adb1a9a..2e338e385 100644 --- a/packages/uikit/src/hooks/useNotification.ts +++ b/packages/uikit/src/hooks/useNotification.ts @@ -1,4 +1,3 @@ -import { useQueryClient } from '@tanstack/react-query'; import { useTranslation } from './translation'; import { useCallback, useEffect } from 'react'; import { notifyError } from '../components/transfer/common';