Skip to content

Commit

Permalink
delegatee -> delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Aug 28, 2024
1 parent 550ae66 commit 51eefef
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
The easiest way to delegate on Polkadot

## Delegation made simple

- 2 click flow to delegate, even with complex setup
- See your current governance locks
- Delegatees can link to their page direction
- Delegates can link to their page direction

### Why

Elections are only meaningful if the participation turnout is high.
This applies to politics around the world, and to Polkadot.

To increase turnout (1-3% currently) we need more participation, which leads to more decentralization
Delegation is a way to give power to delegatees, that can vote on your behalf.
Delegation is a way to give power to delegates, that can vote on your behalf.

## Development

Requirements, [node](https://nodejs.org/en/download/package-manager/current) and [pnpm](https://pnpm.io/installation). <-- install them by clicking on the links

To run the project

- clone this repo
`git clone https://github.com/delegit-xyz/dashboard.git && cd dashboard`
- install dependencies
Expand Down
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ReDotProvider, ReDotChainProvider } from '@reactive-dot/react'
import { Suspense } from 'react'
import { AccountContextProvider } from './contexts/AccountsContext'
import { LocksContextProvider } from './contexts/LocksContext'
import { DelegateeContextProvider } from '@/contexts/DelegateesContext'
import { DelegateContextProvider } from '@/contexts/DelegatesContext'

Check failure on line 15 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@/contexts/DelegatesContext' or its corresponding type declarations.
import { NetworkContextProvider } from './contexts/NetworkContext'

const App = () => {
Expand All @@ -27,7 +27,7 @@ const App = () => {
<ReDotChainProvider chainId="polkadot">
<Suspense>
<NetworkContextProvider>
<DelegateeContextProvider>
<DelegateContextProvider>
<AccountContextProvider>
<LocksContextProvider>
<TooltipProvider>
Expand All @@ -41,7 +41,7 @@ const App = () => {
</TooltipProvider>
</LocksContextProvider>
</AccountContextProvider>
</DelegateeContextProvider>
</DelegateContextProvider>
</NetworkContextProvider>
</Suspense>
</ReDotChainProvider>
Expand Down
6 changes: 3 additions & 3 deletions src/components/DelegateeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { ellipsisFn } from '@polkadot-ui/utils'
import { useNavigate } from 'react-router-dom'
import copy from 'copy-to-clipboard'
import { useEffect, useState } from 'react'
import { Delegatee } from '@/contexts/DelegateesContext'
import { Delegate } from '@/contexts/DelegatesContext'

Check failure on line 15 in src/components/DelegateeCard.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@/contexts/DelegatesContext' or its corresponding type declarations.

interface Props {
delegatee: Delegatee
delegate: Delegate
}
export const DelegateeCard = ({ delegatee: d }: Props) => {
export const DelegateCard = ({ delegate: d }: Props) => {
const [copied, setCopied] = useState<boolean>(false)
const navigate = useNavigate()

Expand Down
44 changes: 21 additions & 23 deletions src/contexts/DelegateesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { useNetwork } from './NetworkContext'
import { DelegeeListKusama, DelegeeListPolkadot } from '@/lib/constants'
// import { dotApi } from '@/clients'

type DelegateesContextProps = {
type DelegatesContextProps = {
children: React.ReactNode | React.ReactNode[]
}

export type Delegatee = {
export type Delegate = {
address: string
name: string
image: string
Expand All @@ -17,18 +17,16 @@ export type Delegatee = {
isOrganization: boolean
}

export interface IDelegateesContext {
delegatees: Delegatee[]
getDelegateeByAddress: (address: string) => Delegatee | undefined
export interface IDelegatesContext {
delegates: Delegate[]
getDelegateByAddress: (address: string) => Delegate | undefined
}

const DelegateesContext = createContext<IDelegateesContext | undefined>(
undefined,
)
const DelegatesContext = createContext<IDelegatesContext | undefined>(undefined)

const DelegateeContextProvider = ({ children }: DelegateesContextProps) => {
const DelegateContextProvider = ({ children }: DelegatesContextProps) => {
const { network } = useNetwork()
const [delegatees, setDelegatees] = useState<Delegatee[]>([])
const [delegates, setDelegates] = useState<Delegate[]>([])

useEffect(() => {
const fetchOpenPRs = async () => {
Expand All @@ -37,42 +35,42 @@ const DelegateeContextProvider = ({ children }: DelegateesContextProps) => {
network === 'polkadot' ? DelegeeListPolkadot : DelegeeListKusama,
)!
).json()
setDelegatees(response)
setDelegates(response)
}
fetchOpenPRs()
}, [network])

const getDelegateeByAddress = (address: string) =>
delegatees.find((d) => d.address === address)
const getDelegateByAddress = (address: string) =>
delegates.find((d) => d.address === address)

// Votes thingy - pause for now
// useEffect(() => {
// const a = async (delegatees: any[]) => {
// const result: Promise<any>[] = delegatees.map((d) => {
// const a = async (delegates: any[]) => {
// const result: Promise<any>[] = delegates.map((d) => {
// return dotApi.query.ConvictionVoting.VotingFor.getEntries(d.address)
// })
// await Promise.all(result).then((res) => {
// console.log(res)
// })
// }
// a(delegatees)
// }, [delegatees])
// a(delegates)
// }, [delegates])

return (
<DelegateesContext.Provider value={{ delegatees, getDelegateeByAddress }}>
<DelegatesContext.Provider value={{ delegates, getDelegateByAddress }}>
{children}
</DelegateesContext.Provider>
</DelegatesContext.Provider>
)
}

const useDelegatees = () => {
const context = useContext(DelegateesContext)
const useDelegates = () => {
const context = useContext(DelegatesContext)
if (context === undefined) {
throw new Error(
'useDelegatees must be used within a DelegateesContextProvider',
'useDelegates must be used within a DelegatesContextProvider',
)
}
return context
}

export { DelegateeContextProvider, useDelegatees }
export { DelegateContextProvider, useDelegates }
22 changes: 11 additions & 11 deletions src/pages/Delegate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { useDelegatees } from '@/contexts/DelegateesContext'
import { useDelegates } from '@/contexts/DelegatesContext'

Check failure on line 3 in src/pages/Delegate/index.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@/contexts/DelegatesContext' or its corresponding type declarations.
import { useNetwork } from '@/contexts/NetworkContext'
import { getLockTimes } from '@/lib/locks'
import { VotingConviction } from '@polkadot-api/descriptors'
Expand Down Expand Up @@ -34,9 +34,9 @@ export const Delegate = () => {
const { api, assetInfo } = useNetwork()
const { address } = useParams()

const { getDelegateeByAddress } = useDelegatees()
const [delegatee, setDelegatee] = useState(
address && getDelegateeByAddress(address),
const { getDelegateByAddress } = useDelegates()
const [delegate, setDelegate] = useState(
address && getDelegateByAddress(address),
)
const [amount, setAmount] = useState<bigint>(0n)
const [amountVisible, setAmountVisible] = useState<string>('0')
Expand Down Expand Up @@ -75,12 +75,12 @@ export const Delegate = () => {
}, [convictionNo, convictionList])

useEffect(() => {
if (!address || delegatee) return
const res = getDelegateeByAddress(address)
setDelegatee(res)
}, [address, delegatee, getDelegateeByAddress])
if (!address || delegate) return
const res = getDelegateByAddress(address)
setDelegate(res)
}, [address, delegate, getDelegateByAddress])

if (!delegatee || !api) return <div>No delegatee found</div>
if (!delegate || !api) return <div>No delegate found</div>

const onChangeAmount = (
e: React.ChangeEvent<HTMLInputElement>,
Expand All @@ -103,7 +103,7 @@ export const Delegate = () => {

const tx = getDelegateTx({
from: selectedAccount?.address,
target: delegatee.address,
target: delegate.address,
conviction: conviction,
amount,
tracks: allTracks || [],
Expand Down Expand Up @@ -139,7 +139,7 @@ export const Delegate = () => {
/>
)}
<h1 className="font-unbounded text-primary flex-1 shrink-0 whitespace-nowrap text-xl font-semibold tracking-tight sm:grow-0">
Delegate to {delegatee.name}
Delegate to {delegate.name}
</h1>
<div className="pageTop">
<Label>Amount</Label>
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { LocksCard } from '@/components/LocksCard'
import { useDelegatees } from '@/contexts/DelegateesContext'
import { DelegateeCard } from '@/components/DelegateeCard'
import { useDelegates } from '@/contexts/DelegatesContext'

Check failure on line 2 in src/pages/Home/index.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@/contexts/DelegatesContext' or its corresponding type declarations.
import { DelegateCard } from '@/components/DelegateCard'

Check failure on line 3 in src/pages/Home/index.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module '@/components/DelegateCard' or its corresponding type declarations.

export const Home = () => {
const { delegatees } = useDelegatees()
const { delegates } = useDelegates()

return (
<main className="grid flex-1 items-start gap-4 p-4 sm:mx-[5%] xl:mx-[20%] mx-0 sm:px-6 sm:py-0 md:gap-8">
<LocksCard />
<h1 className="font-unbounded text-primary flex-1 shrink-0 whitespace-nowrap text-xl font-semibold tracking-tight sm:grow-0">
Delegatees
Delegates
</h1>
<div className="pageTop">
{delegatees?.map((d) => <DelegateeCard delegatee={d} />)}
{delegates?.map((d) => <DelegateCard delegate={d} />)}

Check failure on line 15 in src/pages/Home/index.tsx

View workflow job for this annotation

GitHub Actions / build

Parameter 'd' implicitly has an 'any' type.
</div>
</main>
)
Expand Down

0 comments on commit 51eefef

Please sign in to comment.