Skip to content

Commit

Permalink
feast: sync wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
adetyaz committed Oct 9, 2024
1 parent f0e1f35 commit 7496ef7
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 49 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@react-three/fiber": "^8.16.8",
"@react-three/postprocessing": "^2.16.2",
"@readyplayerme/visage": "^5.2.1",
"@reown/walletkit": "^1.1.0",
"@tanstack/react-query": "^5.51.23",
"@tanstack/react-query-devtools": "^5.51.23",
"@wagmi/core": "^2.11.5",
Expand Down
32 changes: 10 additions & 22 deletions src/app/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { InfoCard } from '@/components/info-card'
import Image from 'next/image'
import { Avatar } from '@readyplayerme/visage'
import { useAccount, useChainId } from 'wagmi'
import { useAccount, useChainId, useConnect } from 'wagmi'
import { useEffect, useState } from 'react'
import { ClaimNft } from '@/components/claim-nft'
import { toast } from 'react-toastify'
Expand All @@ -12,14 +12,17 @@ import { baseURI, getAvatars, getPhygital, getWebXR } from '@/utils/queries'
import { AvatarType } from '@/types/types'
import Header from '@/components/header'
import Moralis from 'moralis'
import { injected } from 'wagmi/connectors'

export default function Home({ params }: { params: { id: string } }) {
const { id } = params
const [unlockClaimed, setUnlockClaimed] = useState(false)
const [showCard, setShowCard] = useState(false)
const [mintedNFTs, setMintedNFTs] = useState([])

const account = useAccount()
const { address, isConnected } = useAccount()
const { connect } = useConnect()

const chainId = useChainId()
const apiKey = process.env.NEXT_PUBLIC_MORALIS_API_KEY

Expand All @@ -46,20 +49,6 @@ export default function Home({ params }: { params: { id: string } }) {
const [phygitalResult, webxrResult, avatarResult] = results

useEffect(() => {
const getUserNfts = async () => {
try {
const response = await fetch(
`${baseURI}/get-mint-fantoken/${account.address}`
)
const results = await response.json()

console.log(results)
} catch (error) {
console.error(error)
toast.error('Error fetching NFTs')
}
}

const fetchNFTs = async () => {
try {
await Moralis.start({ apiKey })
Expand All @@ -68,7 +57,7 @@ export default function Home({ params }: { params: { id: string } }) {
chain: chainId,
format: 'decimal',
mediaItems: false,
address: account.address!,
address: address!,
})

//@ts-ignore
Expand All @@ -79,11 +68,10 @@ export default function Home({ params }: { params: { id: string } }) {
}
}

if (account.address && chainId) {
if (address && chainId) {
fetchNFTs()
getUserNfts()
}
}, [account])
}, [address])

useEffect(() => {
//@ts-ignore
Expand All @@ -92,7 +80,7 @@ export default function Home({ params }: { params: { id: string } }) {
setUnlockClaimed(true)
}, 60000)
}
}, [mintedNFTs, account])
}, [mintedNFTs, address])

const closeClaimed = () => {
setUnlockClaimed(false)
Expand Down Expand Up @@ -154,7 +142,7 @@ export default function Home({ params }: { params: { id: string } }) {
<div className='absolute transform -translate-x-1/2 md:-translate-x-0 md:left-4 bottom-48 md:bottom-16 h-3/5 md:h-3/4'>
<Avatar modelSrc={avatar && avatar.url} cameraInitialDistance={3.5} />
<button className='hidden border-2 border-white text-white bg-black mx-auto md:block bg-opacity-40 backdrop-filter backdrop-blur-sm rounded-full px-8 py-2'>
{account.address ? 'Customize' : 'Unlock'}
{address ? 'Customize' : 'Unlock'}
</button>
</div>
{/* {!account.address && (
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function RootLayout({
return (
<html lang='en' suppressHydrationWarning>
<head>
<link rel='icon' href='/favicon.ico' sizes='any' />
<link rel='icon' href='favicon.ico' sizes='any' />
<Script src='https://aframe.io/releases/1.5.0/aframe.min.js'></Script>
</head>
<Providers>
Expand Down
3 changes: 1 addition & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use client'
import Link from 'next/link'

import LeaderBoard from '@/components/leaderboard'
import AvatarLeaderboard from '@/components/avatar-leaderboard'
import Footer from '@/components/footer'
import Image from 'next/image'

import { ConnectWallet } from '@/components/connect-wallet'
import Header from '../components/header'

Expand Down
25 changes: 23 additions & 2 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import React, { useState, useEffect, useRef } from 'react'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { toast, ToastContainer } from 'react-toastify'
import { useAccount, useDisconnect } from 'wagmi'
import { useAccount, useDisconnect, useConnect } from 'wagmi'
import { BadgeInfo } from 'lucide-react'
import { injected } from 'wagmi/connectors'

const Header = ({
home,
Expand All @@ -16,7 +17,8 @@ const Header = ({
const [isScrolled, setIsScrolled] = useState(false)
const [isDropdownOpen, setIsDropdownOpen] = useState(false)
const [isProfileMenuOpen, setIsProfileMenuOpen] = useState(false)
const { address } = useAccount()
const { isConnected, address } = useAccount()
const { connect } = useConnect()
const { disconnect } = useDisconnect()
const pathname = usePathname()
const [name, setName] = useState('')
Expand All @@ -26,6 +28,24 @@ const Header = ({

const baseUri = process.env.NEXT_PUBLIC_URI || 'https://app.myriadflow.com'

useEffect(() => {
// Check for saved wallet address in localStorage
const savedAddress = localStorage.getItem('walletAddress')

if (savedAddress) {
// Automatically connect if there's an address saved and not currently connected
if (!isConnected) {
connect({ connector: injected() })
}
}

// Manage session details in localStorage based on connection status
if (isConnected && !savedAddress) {
// Store session details in localStorage
localStorage.setItem('walletAddress', address!)
}
}, [connect, isConnected, address])

useEffect(() => {
const getUserData = async () => {
if (address) {
Expand Down Expand Up @@ -96,6 +116,7 @@ const Header = ({
}

const handleLogout = () => {
localStorage.removeItem('walletAddress')
disconnect()
}

Expand Down
38 changes: 16 additions & 22 deletions src/lib/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
'use client'

import React, { ReactNode } from 'react'


import { ReactNode } from 'react'
import { createWeb3Modal } from '@web3modal/wagmi/react'

import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

import { State, WagmiProvider } from 'wagmi'
import { config } from './wagmi'


// Setup queryClient
const queryClient = new QueryClient()

const projectId = "c26b357532f63f7ba31efebac88d0eed";
const projectId = 'c26b357532f63f7ba31efebac88d0eed'

if (!projectId) throw new Error('Wallet Connect Project ID is not defined')

// Create modal
createWeb3Modal({
wagmiConfig: config,
projectId,
enableAnalytics: true, // Optional - defaults to your Cloud configuration
enableOnramp: true // Optional - false as default
wagmiConfig: config,
projectId,
enableAnalytics: true, // Optional - defaults to your Cloud configuration
enableOnramp: true, // Optional - false as default
})

export default function AppKitProvider({
children,
initialState
children,
initialState,
}: {
children: ReactNode
initialState?: State
children: ReactNode
initialState?: State
}) {
return (
<WagmiProvider config={config} initialState={initialState}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
)
}
return (
<WagmiProvider config={config} initialState={initialState}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
)
}
104 changes: 104 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,19 @@
dependencies:
jotai "^2.2.2"

"@reown/walletkit@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@reown/walletkit/-/walletkit-1.1.0.tgz#b323733439860c4e743e6676d3e8e86c1cd01052"
integrity sha512-KAWbA2H0MzsrqU680/tQ3ecm23Ip5scClzzgQD7/u3c+FlSYDlGToz7SqIShpeoDT1ZI+WepoKUdkkA8UXUtJQ==
dependencies:
"@walletconnect/core" "2.17.0"
"@walletconnect/jsonrpc-provider" "1.0.14"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/logger" "2.1.2"
"@walletconnect/sign-client" "2.17.0"
"@walletconnect/types" "2.17.0"
"@walletconnect/utils" "2.17.0"

"@rushstack/eslint-patch@^1.3.3":
version "1.10.4"
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.10.4.tgz#427d5549943a9c6fce808e39ea64dbe60d4047f1"
Expand Down Expand Up @@ -1641,6 +1654,28 @@
lodash.isequal "4.5.0"
uint8arrays "3.1.0"

"@walletconnect/core@2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@walletconnect/core/-/core-2.17.0.tgz#bf490e85a4702eff0f7cf81ba0d3c1016dffff33"
integrity sha512-On+uSaCfWdsMIQsECwWHZBmUXfrnqmv6B8SXRRuTJgd8tUpEvBkLQH4X7XkSm3zW6ozEkQTCagZ2ox2YPn3kbw==
dependencies:
"@walletconnect/heartbeat" "1.2.2"
"@walletconnect/jsonrpc-provider" "1.0.14"
"@walletconnect/jsonrpc-types" "1.0.4"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/jsonrpc-ws-connection" "1.0.14"
"@walletconnect/keyvaluestorage" "1.1.1"
"@walletconnect/logger" "2.1.2"
"@walletconnect/relay-api" "1.0.11"
"@walletconnect/relay-auth" "1.0.4"
"@walletconnect/safe-json" "1.0.2"
"@walletconnect/time" "1.0.2"
"@walletconnect/types" "2.17.0"
"@walletconnect/utils" "2.17.0"
events "3.3.0"
lodash.isequal "4.5.0"
uint8arrays "3.1.0"

"@walletconnect/environment@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@walletconnect/environment/-/environment-1.0.1.tgz#1d7f82f0009ab821a2ba5ad5e5a7b8ae3b214cd7"
Expand Down Expand Up @@ -1793,6 +1828,13 @@
dependencies:
"@walletconnect/jsonrpc-types" "^1.0.2"

"@walletconnect/relay-api@1.0.11":
version "1.0.11"
resolved "https://registry.yarnpkg.com/@walletconnect/relay-api/-/relay-api-1.0.11.tgz#80ab7ef2e83c6c173be1a59756f95e515fb63224"
integrity sha512-tLPErkze/HmC9aCmdZOhtVmYZq1wKfWTJtygQHoWtgg722Jd4homo54Cs4ak2RUFUZIGO2RsOpIcWipaua5D5Q==
dependencies:
"@walletconnect/jsonrpc-types" "^1.0.2"

"@walletconnect/relay-auth@1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@walletconnect/relay-auth/-/relay-auth-1.0.4.tgz#0b5c55c9aa3b0ef61f526ce679f3ff8a5c4c2c7c"
Expand Down Expand Up @@ -1827,6 +1869,21 @@
"@walletconnect/utils" "2.14.0"
events "3.3.0"

"@walletconnect/sign-client@2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@walletconnect/sign-client/-/sign-client-2.17.0.tgz#efe811b1bb10082d964e2f0378aaa1b40f424503"
integrity sha512-sErYwvSSHQolNXni47L3Bm10ptJc1s1YoJvJd34s5E9h9+d3rj7PrhbiW9X82deN+Dm5oA8X9tC4xty1yIBrVg==
dependencies:
"@walletconnect/core" "2.17.0"
"@walletconnect/events" "1.0.1"
"@walletconnect/heartbeat" "1.2.2"
"@walletconnect/jsonrpc-utils" "1.0.8"
"@walletconnect/logger" "2.1.2"
"@walletconnect/time" "1.0.2"
"@walletconnect/types" "2.17.0"
"@walletconnect/utils" "2.17.0"
events "3.3.0"

"@walletconnect/time@1.0.2", "@walletconnect/time@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@walletconnect/time/-/time-1.0.2.tgz#6c5888b835750ecb4299d28eecc5e72c6d336523"
Expand Down Expand Up @@ -1858,6 +1915,18 @@
"@walletconnect/logger" "2.1.2"
events "3.3.0"

"@walletconnect/types@2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.17.0.tgz#20eda5791e3172f8ab9146caa3f317701d4b3232"
integrity sha512-i1pn9URpvt9bcjRDkabuAmpA9K7mzyKoLJlbsAujRVX7pfaG7wur7u9Jz0bk1HxvuABL5LHNncTnVKSXKQ5jZA==
dependencies:
"@walletconnect/events" "1.0.1"
"@walletconnect/heartbeat" "1.2.2"
"@walletconnect/jsonrpc-types" "1.0.4"
"@walletconnect/keyvaluestorage" "1.1.1"
"@walletconnect/logger" "2.1.2"
events "3.3.0"

"@walletconnect/universal-provider@2.14.0":
version "2.14.0"
resolved "https://registry.yarnpkg.com/@walletconnect/universal-provider/-/universal-provider-2.14.0.tgz#39d029be80374894b5f4249b76282dd9211d8b9f"
Expand Down Expand Up @@ -1913,6 +1982,28 @@
query-string "7.1.3"
uint8arrays "3.1.0"

"@walletconnect/utils@2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.17.0.tgz#02b3af0b80d0c1a994d692d829d066271b04d071"
integrity sha512-1aeQvjwsXy4Yh9G6g2eGmXrEl+BzkNjHRdCrGdMYqFTFa8ROEJfTGsSH3pLsNDlOY94CoBUvJvM55q/PMoN/FQ==
dependencies:
"@stablelib/chacha20poly1305" "1.0.1"
"@stablelib/hkdf" "1.0.1"
"@stablelib/random" "1.0.2"
"@stablelib/sha256" "1.0.1"
"@stablelib/x25519" "1.0.3"
"@walletconnect/relay-api" "1.0.11"
"@walletconnect/relay-auth" "1.0.4"
"@walletconnect/safe-json" "1.0.2"
"@walletconnect/time" "1.0.2"
"@walletconnect/types" "2.17.0"
"@walletconnect/window-getters" "1.0.1"
"@walletconnect/window-metadata" "1.0.1"
detect-browser "5.3.0"
elliptic "^6.5.7"
query-string "7.1.3"
uint8arrays "3.1.0"

"@walletconnect/window-getters@1.0.1", "@walletconnect/window-getters@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@walletconnect/window-getters/-/window-getters-1.0.1.tgz#f36d1c72558a7f6b87ecc4451fc8bd44f63cbbdc"
Expand Down Expand Up @@ -3030,6 +3121,19 @@ elliptic@^6.5.4:
minimalistic-assert "^1.0.1"
minimalistic-crypto-utils "^1.0.1"

elliptic@^6.5.7:
version "6.5.7"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.7.tgz#8ec4da2cb2939926a1b9a73619d768207e647c8b"
integrity sha512-ESVCtTwiA+XhY3wyh24QqRGBoP3rEdDUl3EDUUo9tft074fi19IrdpH7hLCMMP3CIj7jb3W96rn8lt/BqIlt5Q==
dependencies:
bn.js "^4.11.9"
brorand "^1.1.0"
hash.js "^1.0.0"
hmac-drbg "^1.0.1"
inherits "^2.0.4"
minimalistic-assert "^1.0.1"
minimalistic-crypto-utils "^1.0.1"

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
Expand Down

0 comments on commit 7496ef7

Please sign in to comment.