From fc649deaf245509efb8625082c191b0665e928ce Mon Sep 17 00:00:00 2001 From: Martin Domajnko <35891136+martines3000@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:03:09 +0100 Subject: [PATCH] chore: fix small dapp bug (#574) --- packages/dapp/.env.example | 2 +- .../EncryptedSessionDisplay/ScanQRCodeView.tsx | 3 +++ .../components/EncryptedSessionProvider/index.tsx | 13 ++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/dapp/.env.example b/packages/dapp/.env.example index 75576437f..0bee1758a 100644 --- a/packages/dapp/.env.example +++ b/packages/dapp/.env.example @@ -10,7 +10,7 @@ SEPOLIA_RPC_URL= IPFS_GATEWAY= POLYGON_RPC_URL= POLYGON_MUMBAI_RPC_URL= -= + # Masca version NEXT_PUBLIC_MASCA_VERSION=v1.1.0 diff --git a/packages/dapp/src/components/EncryptedSessionDisplay/ScanQRCodeView.tsx b/packages/dapp/src/components/EncryptedSessionDisplay/ScanQRCodeView.tsx index a70454187..8472b19aa 100644 --- a/packages/dapp/src/components/EncryptedSessionDisplay/ScanQRCodeView.tsx +++ b/packages/dapp/src/components/EncryptedSessionDisplay/ScanQRCodeView.tsx @@ -36,6 +36,7 @@ export const ScanQRCodeView = ({ onQRCodeScanned }: ScanQRCodeViewProps) => { // Same device if (isConnected && deviceType === 'primary') { changeRequestData(decodedText); + onQRCodeScanned(); return; } @@ -104,6 +105,8 @@ export const ScanQRCodeView = ({ onQRCodeScanned }: ScanQRCodeViewProps) => { .eq('id', sessionId); if (error) throw new Error('Failed to send data'); + + onQRCodeScanned(); } catch (e) { setTimeout(() => { useToastStore.setState({ diff --git a/packages/dapp/src/components/EncryptedSessionProvider/index.tsx b/packages/dapp/src/components/EncryptedSessionProvider/index.tsx index ede1b146e..661bd0232 100644 --- a/packages/dapp/src/components/EncryptedSessionProvider/index.tsx +++ b/packages/dapp/src/components/EncryptedSessionProvider/index.tsx @@ -1,11 +1,13 @@ 'use client'; -import { useEffect, useMemo } from 'react'; +import { useEffect, useState } from 'react'; import { hexToUint8Array } from '@blockchain-lab-um/masca-connector'; +import { SupabaseClient } from '@supabase/supabase-js'; import { useTranslations } from 'next-intl'; import { useAccount } from 'wagmi'; import { createClient } from '@/utils/supabase/client'; +import { Database } from '@/utils/supabase/database.types'; import { useMascaStore, useToastStore } from '@/stores'; import { useAuthStore } from '@/stores/authStore'; import { useEncryptedSessionStore } from '@/stores/encryptedSessionStore'; @@ -13,6 +15,7 @@ import { useEncryptedSessionStore } from '@/stores/encryptedSessionStore'; export const EncryptedSessionProvider = () => { const t = useTranslations('EncryptedSessionProvider'); const token = useAuthStore((state) => state.token); + const [client, setClient] = useState>(null); const { address } = useAccount(); @@ -36,8 +39,6 @@ export const EncryptedSessionProvider = () => { const api = useMascaStore((state) => state.mascaApi); - const client = useMemo(() => createClient(token ?? ''), [token]); - // Decrypt data const decryptData = async ({ iv, @@ -136,6 +137,7 @@ export const EncryptedSessionProvider = () => { }; useEffect(() => { + if (!client) return; if (sessionId && deviceType === 'primary') { client .channel('realtime encrypted_sessions') @@ -198,5 +200,10 @@ export const EncryptedSessionProvider = () => { }); }, [address]); + useEffect(() => { + if (!token) return; + setClient(createClient(token)); + }, [token]); + return null; };