From ec145f4369829ca54b3d3a5ea4142e00ec14333f Mon Sep 17 00:00:00 2001 From: siandreev Date: Fri, 20 Dec 2024 10:26:20 +0100 Subject: [PATCH] fix: correct account hasn't been activated on ton connect tx request received --- .../app/components/TonConnectSubscription.tsx | 16 ++++++++++++++-- .../app/components/TonConnectSubscription.tsx | 10 +++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/components/TonConnectSubscription.tsx b/apps/desktop/src/app/components/TonConnectSubscription.tsx index 676a6f185..635c0d174 100644 --- a/apps/desktop/src/app/components/TonConnectSubscription.tsx +++ b/apps/desktop/src/app/components/TonConnectSubscription.tsx @@ -8,6 +8,8 @@ import { } from '@tonkeeper/uikit/dist/state/tonConnect'; import { sendBackground } from '../../libs/backgroudService'; import { SendTransactionAppRequest } from '@tonkeeper/core/dist/entries/tonConnect'; +import { QueryKey } from '@tonkeeper/uikit/dist/libs/queryKey'; +import { useQueryClient } from '@tanstack/react-query'; export const TonConnectSubscription = () => { const [request, setRequest] = useState(undefined); @@ -15,11 +17,21 @@ export const TonConnectSubscription = () => { const { mutateAsync: responseSendAsync } = useResponseSendMutation(); const { mutate: disconnect } = useDisconnectTonConnectApp({ skipEmit: true }); + const queryClient = useQueryClient(); + + const onTransaction = useCallback( + async (request: SendTransactionAppRequest) => { + await queryClient.invalidateQueries([QueryKey.account]); + setRequest(request); + }, + [setRequest] + ); + useSendNotificationAnalytics(request?.connection?.manifest); useEffect(() => { - window.backgroundApi.onTonConnectTransaction(setRequest); - }, [setRequest]); + window.backgroundApi.onTonConnectTransaction(onTransaction); + }, [onTransaction]); useEffect(() => { window.backgroundApi.onTonConnectDisconnect(disconnect); diff --git a/apps/tablet/src/app/components/TonConnectSubscription.tsx b/apps/tablet/src/app/components/TonConnectSubscription.tsx index 2b84c2adb..0bc81e111 100644 --- a/apps/tablet/src/app/components/TonConnectSubscription.tsx +++ b/apps/tablet/src/app/components/TonConnectSubscription.tsx @@ -13,6 +13,8 @@ import { tonConnectSSE } from "../../libs/tonConnect"; import { useActiveWallet } from "@tonkeeper/uikit/dist/state/wallet"; +import { useQueryClient } from "@tanstack/react-query"; +import { QueryKey } from "@tonkeeper/uikit/dist/libs/queryKey"; export const TonConnectSubscription = () => { const [request, setRequest] = useState(undefined); @@ -22,10 +24,16 @@ export const TonConnectSubscription = () => { const { data: appConnections } = useAppTonConnectConnections(); const wallet = useActiveWallet(); const activeWalletConnections = useMemo(() => appConnections?.find(c => c.wallet.id === wallet.id)?.connections, [appConnections, wallet.id]); + const queryClient = useQueryClient(); useSendNotificationAnalytics(request?.connection?.manifest); - useEffect(() => subscribeToTonConnectSendTransaction(setRequest), [setRequest]); + const onTransaction = useCallback(async (request: SendTransactionAppRequest) => { + await queryClient.invalidateQueries([QueryKey.account]); + setRequest(request); + }, [setRequest]); + + useEffect(() => subscribeToTonConnectSendTransaction(onTransaction), [onTransaction]); useEffect(() => subscribeToTonConnectDisconnect(disconnect), [disconnect]);