'use client'; import { useState, useEffect } from 'react'; import styles from '@/app/app.module.css'; import { Cards } from '@/components/cards'; import { HelloNearContract } from '@/config'; import { useNearWallet } from 'near-connect-hooks'; export default function HelloNear() { const { signedAccountId, viewFunction, callFunction } = useNearWallet(); const [greeting, setGreeting] = useState('loading...'); const [newGreeting, setNewGreeting] = useState('loading...'); const [loggedIn, setLoggedIn] = useState(false); const [showSpinner, setShowSpinner] = useState(false); useEffect(() => { viewFunction({ contractId: HelloNearContract, method: 'get_greeting' }).then((greeting) => setGreeting(greeting as string)); }, []); useEffect(() => { setLoggedIn(!!signedAccountId); }, [signedAccountId]); const saveGreeting = async () => { // Try to store greeting, revert if it fails callFunction({ contractId: HelloNearContract, method: 'set_greeting', args: { greeting: newGreeting } }) .then(async () => { const greeting = (await viewFunction({ contractId: HelloNearContract, method: 'get_greeting' })) as string; setGreeting(greeting); setShowSpinner(false); }); // Assume the transaction will be successful and update the UI optimistically setShowSpinner(true); setGreeting(newGreeting); }; return (

Interacting with the contract:   {HelloNearContract}

The contract says: {greeting}

); }