Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Integration of Discord and Farcaster for Authentication #14

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
env:
VITE_TWITTER_SERVERLESS_API: ${{secrets.VITE_TWITTER_SERVERLESS_API}}
VITE_ENCLAVE_API: ${{secrets.VITE_ENCLAVE_API}}
VITE_DYNAMIC_ENV_ID: ${{secrets.VITE_DYNAMIC_ENV_ID}}
- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions packages/client/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VITE_ENCLAVE_API=http://127.0.0.1:4000
VITE_TWITTER_SERVERLESS_API=
VITE_DYNAMIC_ENV_ID=
2 changes: 2 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"deploy": "gh-pages -d dist"
},
"dependencies": {
"@dynamic-labs/sdk-react-core": "^2.2.8",
"@emotion/babel-plugin": "^11.11.0",
"@emotion/react": "^11.11.4",
"@phosphor-icons/react": "^2.1.4",
Expand All @@ -28,6 +29,7 @@
"react-markdown": "^9.0.1",
"react-router-dom": "^6.22.3",
"react-syntax-highlighter": "^15.5.0",
"viem": "^2.17.0",
"vite-plugin-top-level-await": "^1.4.1",
"vite-tsconfig-paths": "^4.3.2"
},
Expand Down
18 changes: 13 additions & 5 deletions packages/client/src/components/NavMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import React, { useEffect, useRef, useState } from 'react'
import LogoutIcon from '@/assets/icons/logout.svg'
import { useNavigate } from 'react-router-dom'
import { useVoteManagementContext } from '@/context/voteManagement'
//Icons
import { CaretRight, CalendarCheck, CheckFat, Notebook } from '@phosphor-icons/react'
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'

interface NavMenuProps {}

Expand All @@ -28,11 +28,19 @@ const NAV_MENU_OPTIONS = [

const NavMenu: React.FC<NavMenuProps> = () => {
const navigate = useNavigate()
const { user, logout } = useVoteManagementContext()
const { user: userProfile, handleLogOut } = useDynamicContext()
const menuRef = useRef<HTMLDivElement>(null)
const [isOpen, setIsOpen] = useState<boolean>(false)
const buttonRef = useRef<HTMLButtonElement>(null)

const user =
userProfile &&
userProfile.verifiedCredentials.find((credential) => {
if (credential.format === 'oauth') {
return credential
}
})

const handleClickOutside = (event: MouseEvent) => {
if (
isOpen &&
Expand Down Expand Up @@ -66,7 +74,7 @@ const NavMenu: React.FC<NavMenuProps> = () => {

const handleLogout = () => {
navigate('/')
logout()
handleLogOut()
return setIsOpen(!isOpen)
}

Expand All @@ -77,8 +85,8 @@ const NavMenu: React.FC<NavMenuProps> = () => {
onClick={toggleMenu}
className='flex items-center justify-between space-x-1 rounded-lg border-2 bg-white/60 px-2 py-1 duration-300 ease-in-out hover:bg-white'
>
<img src={user.avatar} className='h-[20px] w-[20px] rounded-full' />
<p className='text-xs font-bold'>@{user.username}</p>
<img src={user.oauthAccountPhotos?.length ? user.oauthAccountPhotos[0] : ''} className='h-[20px] w-[20px] rounded-full' />
<p className='text-xs font-bold'>{user.publicIdentifier}</p>
<CaretRight className={isOpen ? '-rotate-90 transition-transform duration-200' : ''} />
</button>

Expand Down
18 changes: 13 additions & 5 deletions packages/client/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import './globals.css'
import { HashRouter } from 'react-router-dom'
import { VoteManagementProvider } from '@/context/voteManagement/index.ts'
import { NotificationAlertProvider } from './context/NotificationAlert/NotificationAlert.context.tsx'
import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core'

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.Fragment>
<HashRouter>
<NotificationAlertProvider>
<VoteManagementProvider>
<App />
</VoteManagementProvider>
</NotificationAlertProvider>
<DynamicContextProvider
settings={{
environmentId: import.meta.env.VITE_DYNAMIC_ENV_ID,
debugError: true,
}}
>
<NotificationAlertProvider>
<VoteManagementProvider>
<App />
</VoteManagementProvider>
</NotificationAlertProvider>
</DynamicContextProvider>
</HashRouter>
</React.Fragment>,
)
14 changes: 11 additions & 3 deletions packages/client/src/pages/DailyPoll/DailyPoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import { useVoteManagementContext } from '@/context/voteManagement'
import { useNotificationAlertContext } from '@/context/NotificationAlert'
import { useNavigate } from 'react-router-dom'
import { convertTimestampToDate } from '@/utils/methods'
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'

const DailyPoll: React.FC = () => {
const navigate = useNavigate()
const { showToast } = useNotificationAlertContext()
const { encryptVote, broadcastVote, getRoundStateLite, existNewRound, setTxUrl, votingRound, roundState, user } =
useVoteManagementContext()
const { encryptVote, broadcastVote, getRoundStateLite, existNewRound, setTxUrl, votingRound, roundState } = useVoteManagementContext()
const { user: userProfile } = useDynamicContext()
const [loading, setLoading] = useState<boolean>(false)
const [newRoundLoading, setNewRoundLoading] = useState<boolean>(false)
const endTime = roundState && convertTimestampToDate(roundState?.start_time, roundState?.poll_length)
const user =
userProfile &&
userProfile.verifiedCredentials.find((credential) => {
if (credential.format === 'oauth') {
return credential
}
})

useEffect(() => {
const checkRound = async () => {
Expand Down Expand Up @@ -43,7 +51,7 @@ const DailyPoll: React.FC = () => {
return broadcastVote({
round_id: votingRound.round_id,
enc_vote_bytes: Array.from(voteEncrypted),
postId: user.token,
postId: user.id,
})
},
[broadcastVote, user, votingRound],
Expand Down
8 changes: 5 additions & 3 deletions packages/client/src/pages/Landing/components/DailyPoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useVoteManagementContext } from '@/context/voteManagement'
import LoadingAnimation from '@/components/LoadingAnimation'
import { hasPollEnded } from '@/utils/methods'
import CountdownTimer from '@/components/CountdownTime'
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'

type DailyPollSectionProps = {
onVoted?: (vote: Poll) => void
Expand All @@ -16,14 +17,15 @@ type DailyPollSectionProps = {
}

const DailyPollSection: React.FC<DailyPollSectionProps> = ({ onVoted, loading, endTime }) => {
const { user, pollOptions, setPollOptions, roundState } = useVoteManagementContext()
const { setShowAuthFlow, isAuthenticated, user } = useDynamicContext()

const { pollOptions, setPollOptions, roundState } = useVoteManagementContext()
const isEnded = roundState ? hasPollEnded(roundState?.poll_length, roundState?.start_time) : false
const status = roundState?.status
const [pollSelected, setPollSelected] = useState<Poll | null>(null)
const [noPollSelected, setNoPollSelected] = useState<boolean>(true)
const [modalOpen, setModalOpen] = useState(false)

const openModal = () => setModalOpen(true)
const closeModal = () => {
setModalOpen(false)
}
Expand All @@ -39,7 +41,7 @@ const DailyPollSection: React.FC<DailyPollSectionProps> = ({ onVoted, loading, e
}

const castVote = () => {
if (!user) return openModal()
if (!isAuthenticated && !user) return setShowAuthFlow(true)
if (pollSelected && onVoted) {
onVoted(pollSelected)
}
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/pages/Landing/components/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom'
import { Keyhole, ListMagnifyingGlass, ShieldCheck } from '@phosphor-icons/react'

const HeroSection: React.FC = () => {

return (
<div className='relative flex w-full flex-1 items-center justify-center px-6'>
<div className='absolute bottom-0 right-0 grid w-full grid-cols-2 gap-2 max-md:opacity-50 md:w-[70vh]'>
Expand Down
Loading
Loading