Skip to content

Commit

Permalink
chore: fix small dapp bug (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 authored Mar 4, 2024
1 parent 81585c8 commit fc649de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/dapp/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const ScanQRCodeView = ({ onQRCodeScanned }: ScanQRCodeViewProps) => {
// Same device
if (isConnected && deviceType === 'primary') {
changeRequestData(decodedText);
onQRCodeScanned();
return;
}

Expand Down Expand Up @@ -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({
Expand Down
13 changes: 10 additions & 3 deletions packages/dapp/src/components/EncryptedSessionProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
'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';

export const EncryptedSessionProvider = () => {
const t = useTranslations('EncryptedSessionProvider');
const token = useAuthStore((state) => state.token);
const [client, setClient] = useState<null | SupabaseClient<Database>>(null);

const { address } = useAccount();

Expand All @@ -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,
Expand Down Expand Up @@ -136,6 +137,7 @@ export const EncryptedSessionProvider = () => {
};

useEffect(() => {
if (!client) return;
if (sessionId && deviceType === 'primary') {
client
.channel('realtime encrypted_sessions')
Expand Down Expand Up @@ -198,5 +200,10 @@ export const EncryptedSessionProvider = () => {
});
}, [address]);

useEffect(() => {
if (!token) return;
setClient(createClient(token));
}, [token]);

return null;
};

0 comments on commit fc649de

Please sign in to comment.