Skip to content

Commit

Permalink
wallet connect/disconnect. hero section. image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
iskysun96 committed Jan 13, 2024
1 parent 7a667d6 commit 74fff01
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 18 deletions.
10 changes: 7 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import algosdk from 'algosdk'
import { SnackbarProvider } from 'notistack'
import { useState } from 'react'
import Gallery from './components/Gallery'
import MintNft from './components/mintNft'
import Hero from './components/Hero'
import { getAlgodConfigFromViteEnvironment, getKmdConfigFromViteEnvironment } from './utils/network/getAlgoClientConfigs'

let providersArray: ProvidersArray
Expand Down Expand Up @@ -65,8 +65,12 @@ export default function App() {
<SnackbarProvider maxSnack={3}>
<WalletProvider value={walletProviders}>
<div className="flex justify-center items-center flex-col">
<MintNft />
<Gallery />
<Hero />
{activeAddress && (
<div>
<Gallery />
</div>
)}
</div>
</WalletProvider>
</SnackbarProvider>
Expand Down
40 changes: 40 additions & 0 deletions src/components/Hero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useWallet } from '@txnlab/use-wallet'
import { useState } from 'react'
import ConnectWallet from './ConnectWallet'
import MintNft from './mintNft'

const Hero = () => {
const [openWalletModal, setOpenWalletModal] = useState<boolean>(false)
const { activeAddress } = useWallet()

const toggleWalletModal = () => {
setOpenWalletModal(!openWalletModal)
}
return (
<div className="hero min-h-screen bg-base-200">
<div className="hero-content text-center">
<div className="max-w-md">
<h1 className="text-5xl font-bold">Hello there</h1>

<p className="py-6">
{activeAddress
? 'Enjoy your permanent photo diary recorded on the Algorand blockchain'
: 'Welcome to your Photo Diary on the Blockchain. Connect your wallet to get started.'}
</p>
<div>
<button
className="btn m-2 bg-green-500 rounded border-none hover:bg-green-600 transition-colors duration-300"
onClick={toggleWalletModal}
>
{activeAddress ? 'Disconnect' : 'Connect Wallet'}
</button>
<ConnectWallet openModal={openWalletModal} closeModal={toggleWalletModal} />
</div>
{activeAddress && <MintNft />}
</div>
</div>
</div>
)
}

export default Hero
73 changes: 58 additions & 15 deletions src/components/MintNft.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { useState } from 'react'
import ConnectWallet from './ConnectWallet'

/*
NFT Minting / Wallet Connect component
Expand All @@ -21,22 +18,68 @@ Minting
= NFT name should be the emotion of the day + date (e.g. "happy 2021-09-01")
*/

import { useEffect, useState } from 'react'

const MintNft = () => {
const [openWalletModal, setOpenWalletModal] = useState<boolean>(false)
// const { activeAddress } = useWallet()
const [nftImage, setNftImage] = useState<File>()
const [nftImageUrl, setNftImageUrl] = useState<string>('')
const [nftName, setNftName] = useState<string>('')

Check warning on line 26 in src/components/MintNft.tsx

View workflow job for this annotation

GitHub Actions / checks

'nftName' is assigned a value but never used. Allowed unused elements of array destructuring patterns must match /^_/u

Check warning on line 26 in src/components/MintNft.tsx

View workflow job for this annotation

GitHub Actions / CI dApp / checks

'nftName' is assigned a value but never used. Allowed unused elements of array destructuring patterns must match /^_/u

// store user nft image file upload to CharityFormData
const handleFileUpload = (e: { target: { files: FileList | null } }) => {
const file = e.target.files?.[0]
if (file) {
setNftImage(file)
const reader = new FileReader()
reader.onload = () => {
setNftImageUrl(reader.result as string)
}
reader.readAsDataURL(file)
}
}

const toggleWalletModal = () => {
setOpenWalletModal(!openWalletModal)
const handleTextInput = (e: { target: { value: string } }) => {
setNftName(e.target.value)
}

useEffect(() => {
console.log(nftImage)

Check warning on line 46 in src/components/MintNft.tsx

View workflow job for this annotation

GitHub Actions / checks

Unexpected console statement

Check warning on line 46 in src/components/MintNft.tsx

View workflow job for this annotation

GitHub Actions / CI dApp / checks

Unexpected console statement
console.log(nftImageUrl)

Check warning on line 47 in src/components/MintNft.tsx

View workflow job for this annotation

GitHub Actions / checks

Unexpected console statement

Check warning on line 47 in src/components/MintNft.tsx

View workflow job for this annotation

GitHub Actions / CI dApp / checks

Unexpected console statement
}, [nftImage, nftImageUrl])

return (
<div>
<button
className="btn m-2 bg-green-500 rounded border-none hover:bg-green-600 transition-colors duration-300"
onClick={toggleWalletModal}
>
Connect Wallet
</button>
<ConnectWallet openModal={openWalletModal} closeModal={toggleWalletModal} />
<div className="max-w-xl mt-4 mb-4">
{nftImage ? (
<div className="flex flex-col">
<img src={nftImageUrl} alt="Fundraiser" />
<input type="text" className="rounded mt-2 mb-2" placeholder="Enter NFT Name" onChange={handleTextInput} />
<button>Create Photo Diary</button>
</div>
) : (
<label className="flex justify-center w-full h-32 px-4 transition bg-white border-2 border-gray-300 border-dashed rounded-md appearance-none cursor-pointer hover:border-gray-400 focus:outline-none">
<span className="flex items-center space-x-2">
<svg
xmlns="http://www.w3.org/2000/svg"
className="w-6 h-6 text-gray-600"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth="2"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
/>
</svg>
<span className="font-medium text-gray-600">
Drop files to Attach, or
<span className="text-blue-600 underline"> browse</span>
</span>
</span>
<input type="file" name="file_upload" className="hidden" onChange={handleFileUpload} />
</label>
)}
</div>
)
}
Expand Down

0 comments on commit 74fff01

Please sign in to comment.