diff --git a/app/spaces/[spaceid]/trustful/components/GiveBadge.tsx b/app/spaces/[spaceid]/trustful/components/GiveBadge.tsx index ee9f469e..e7d220ae 100644 --- a/app/spaces/[spaceid]/trustful/components/GiveBadge.tsx +++ b/app/spaces/[spaceid]/trustful/components/GiveBadge.tsx @@ -341,7 +341,7 @@ export const GiveBadge = () => { refUID: inputBadge.title === 'Check-out' ? (commentBadge as `0x${string}`) - : zeroAddress, + : '0x0000000000000000000000000000000000000000000000000000000000000000', data: data, value: BigInt(0), }; diff --git a/app/spaces/[spaceid]/trustful/constants/constants.ts b/app/spaces/[spaceid]/trustful/constants/constants.ts index 7b61e883..3008f8c6 100644 --- a/app/spaces/[spaceid]/trustful/constants/constants.ts +++ b/app/spaces/[spaceid]/trustful/constants/constants.ts @@ -56,7 +56,7 @@ export const EAS_CONTRACT_SCROLL = isDev ? EAS_CONTRACT_SCROLL_SEPOLIA : EAS_CONTRACT_SCROLL_MAINET; -const RESOLVER_CONTRACT_SCROLL = '0x0A16dD89b4F06F111977D0F3bBab6165F08A5362'; +const RESOLVER_CONTRACT_SCROLL = '0x0a830dd5C0c56752F5f1846F1a5cEA32bCf5Bc56'; const RESOLVER_CONTRACT_SCROLL_SEPOLIA = '0x882977D73d7B2E67F088853B9065d4FD887e6bA0'; @@ -68,16 +68,16 @@ export const RESOLVER_CONTRACT_SCROLL_TRUSTFUL = isDev export const SCHEMA_UIDS = { ATTEST_MANAGER: isDev ? '0xf2f1d17213d5d5bed91abafecfc9862e857573d821ce0eeb36d8fe9cfebfc562' - : '0x6dc178b7782b9bd47ceab9e98aef9e9656a5b27722d384e74a3c654131657951', + : '0x7bbb090951d344668e6ba068d8382835460bcc21097f75b0821ba5695df5d274', ATTEST_VILLAGER: isDev ? '0xfd6e98168eff2ca555ccf9cae1cf43198202f5495134b752b7a4cc0bc480c99d' - : '0x2b781f38ef65bdba6f7c70df32f90e53e4f9fc9f497e0324419de097cece3f3d', + : '0x50f27f787d0d055d5eca23bb55e256cfb729ba6c5eb3773c617fa03bb3ba3cd3', ATTEST_EVENT: isDev ? '0x9b55966a9b4a7676a329f026bff451265f83fdc46eef72dc8b252a1121fc7ecc' - : '0x50a3ad32ee748ad7758f7429d8b30543dd6a60542e519ee0c85d7897144b0be3', + : '0xa34db27c36d14edb7ca5169307c3db8672e921040afcb7d47a3ed0fe4ae250ab', ATTEST_RESPONSE: isDev ? '0x4a84dcaa2a5fffeb8dd99bfb2d12ef6fa0e233e9cfb11f2c8e08ad9714938ac8' - : '0x3a12210b37dd53be53954015c7e163b9be5445f7f7d397b5d7cb14f77a5c5510', + : '0xda260d1881382274f5d5101fe3a45b2c06e33bd6f1263ab3b5468d738dbb76ae', }; export enum ROLES { diff --git a/app/spaces/[spaceid]/trustful/events/[eventid]/[sessionid]/components/DropdownSessionDetails.tsx b/app/spaces/[spaceid]/trustful/events/[eventid]/[sessionid]/components/DropdownSessionDetails.tsx index 49df3a08..80deff12 100644 --- a/app/spaces/[spaceid]/trustful/events/[eventid]/[sessionid]/components/DropdownSessionDetails.tsx +++ b/app/spaces/[spaceid]/trustful/events/[eventid]/[sessionid]/components/DropdownSessionDetails.tsx @@ -12,14 +12,23 @@ import { Box, } from '@chakra-ui/react'; import { BeatLoader } from 'react-spinners'; -import { Address, isAddress } from 'viem'; +import { + Address, + encodeAbiParameters, + isAddress, + keccak256, + zeroAddress, +} from 'viem'; import { useAccount } from 'wagmi'; import { Event, Role, ROLES, } from '@/app/spaces/[spaceid]/trustful/constants/constants'; -import { removeSession } from '@/app/spaces/[spaceid]/trustful/service/smart-contract'; +import { + closeSession, + removeSession, +} from '@/app/spaces/[spaceid]/trustful/service/smart-contract'; import { EthereumAddress } from '@/app/spaces/[spaceid]/trustful/utils/types'; import { useTrustful } from '@/context/TrustfulContext'; import toast from 'react-hot-toast'; @@ -33,8 +42,11 @@ import { deleteSession, getAllEventsBySpaceId, wrapSession, + getSession, + Session, } from '@/app/spaces/[spaceid]/trustful/service/backend/'; -import { useParams } from 'next/navigation'; +import { useParams, useRouter } from 'next/navigation'; +import { solidityPackedKeccak256 } from 'ethers'; export const DropdownSessionDetails = () => { const { address } = useAccount(); @@ -51,13 +63,16 @@ export const DropdownSessionDetails = () => { const [inputValuesTextArea, setInputValuesTextArea] = useState<{ [key: string]: string; }>({}); - const [inputValuesChange, setInputValuesChange] = useState<{ - [key: string]: string; - }>({}); - const [events, setEvents] = useState([]); + // const [inputValuesChange, setInputValuesChange] = useState<{ + // [key: string]: string; + // }>({}); + const [session, setSession] = useState(undefined); const params = useParams(); - const spaceId = params.spaceid.toString(); + console.log('params', params); const sessionId = params.sessionid.toString(); + const spaceId = params.spaceid.toString(); + const eventId = params.eventid.toString(); + const router = useRouter(); // Updates the validAddress when the inputAddress changes useEffect(() => { @@ -71,20 +86,55 @@ export const DropdownSessionDetails = () => { }, [sessionAction]); useEffect(() => { - const fetchAllEvents = async () => { + const fetchSession = async () => { try { - const eventsData = await getAllEventsBySpaceId({ - spaceId: Number(spaceId), - userAddress: address as Address, + const sessionsData = await getSession({ + eventid: Number(params.eventid), }); - setEvents(eventsData); + console.log('da um session aqui po', sessionsData); + + if (sessionsData && sessionsData.sessions.length > 0) { + const sessionById = sessionsData.sessions.find( + (session) => session.sessionId === Number(params.sessionid), + ); + + if (sessionById) { + console.log('sessinById po ', sessionById); + setSession(sessionById); + } + } } catch (error) { console.log('error', error); } }; - fetchAllEvents(); + + fetchSession(); }, []); + useEffect(() => { + const fetchSession = async () => { + try { + const sessionsData = await getSession({ + eventid: Number(params.eventid), + }); + + if (sessionsData && sessionsData.sessions.length > 0) { + const sessionById = sessionsData.sessions.find( + (session) => session.sessionId === Number(params.sessionid), + ); + + if (sessionById) { + setSession(sessionById); + } + } + } catch (error) { + console.log('error', error); + } + }; + + fetchSession(); + }, [address, params.eventid, params.sessionid]); + /**Root */ const handleRemoveSession = async () => { if (!address || !userRole) { @@ -92,25 +142,35 @@ export const DropdownSessionDetails = () => { toast.error('Please connect first. No address found.'); return; } + console.log('session', session); - if (!validAddress) { - setIsLoading(false); - toast.error('Please enter a valid address.'); + if (!session) { return; } - const responseSmartContract = await removeSession({ - from: address, - sessionTitle: inputValuesTextArea['removeSessionTitle'], - sessionOwner: validAddress.address as Address, - msgValue: BigInt(0), - }); + // if (address !== session.hostAddress) { + // return; + // } const responseBackend = await deleteSession({ role: userRole.role, sessionId: Number(sessionId), - userAddress: validAddress.address as Address, + userAddress: address as Address, }); + if (responseBackend) { + const responseSmartContract = await removeSession({ + from: address, + sessionTitle: session.sessionTitle, + sessionOwner: address as Address, + msgValue: BigInt(0), + }); + if (!responseSmartContract) { + setIsLoading(false); + toast.error('Transaction Rejected'); + return; + } + router.push(`/spaces/${spaceId}/trustful/events/${eventId}`); + } setIsLoading(false); // toast.success( @@ -154,11 +214,42 @@ export const DropdownSessionDetails = () => { return; } + if (!session) { + return; + } + + // console.log('session', session.name + '_' + session.title); + // const mockedSession = 'TKDWClass_1731430187447'; + + const sessionIdSC = solidityPackedKeccak256( + ['address', 'string'], + [session.hostAddress, session.sessionTitle], + ); + console.log('sessionId', sessionId); + const response = await wrapSession({ role: userRole.role, sessionId: Number(sessionId), userAddress: address as Address, }); + console.log('wrapa a session', response); + + if (response) { + console.log('response entrou', response); + const responseSC = await closeSession({ + from: address, + sessionId: sessionIdSC as Address, + msgValue: BigInt(0), + }); + console.log('closeSessionResponseSC', responseSC); + + if (responseSC instanceof Error) { + setIsLoading(false); + toast.error(`Transaction Rejected: ${responseSC.message}`); + return; + } + console.log('responseSC', responseSC); + } if (response instanceof Error) { setIsLoading(false); @@ -212,7 +303,7 @@ export const DropdownSessionDetails = () => { > -