Skip to content

Commit

Permalink
Fix error management (#82)
Browse files Browse the repository at this point in the history
* fix error msg

* fix loader

* rm handleMembership

* add redirection

* add getName

* fix voteNo

* update firstIteration
  • Loading branch information
julienbrg authored Jun 12, 2024
1 parent cea60fb commit 82fd179
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 90 deletions.
6 changes: 3 additions & 3 deletions src/pages/add-member/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ export default function AddMember() {
} catch (e) {
console.log('error submitting proposal:', e)
toast({
title: "Can't propose",
title: "Can't submit a proposal",
position: 'bottom',
description: "You can't submit this kind of proposal.",
status: 'info',
description: 'To submit a proposal, you must (1) be a member and (2) delegate your voting power to yourself.',
status: 'error',
variant: 'subtle',
duration: 9000,
isClosable: true,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ban-member/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ export default function BanMember() {
} catch (e) {
console.log('error submitting proposal:', e)
toast({
title: "Can't propose",
title: "Can't submit a proposal",
position: 'bottom',
description: "You can't submit this kind of proposal.",
status: 'info',
description: 'To submit a proposal, you must (1) be a member and (2) delegate your voting power to yourself.',
status: 'error',
variant: 'subtle',
duration: 9000,
isClosable: true,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/delegate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export default function Delegate() {

setCurrentDelegate(String(address))
setLoadingDelegateToSelf(false)
setIsDelegatedToSelf(true)
setIsDelegatedToSelf(false)
toast({
title: 'Success',
position: 'bottom',
Expand Down
8 changes: 7 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Home() {
const [initialized, setInitialized] = useState<boolean>(false)
const [isLoading, setIsLoading] = useState<boolean>(false)
const [provider, setProvider] = useState<any>(undefined)
const [name, setName] = useState<string>('Test DAO')
const [name, setName] = useState<string>('')
const [proposal, setProposal] = useState<{ id: string; link: string; title: string; state: number }[]>([])
const stateText = ['Pending', 'Active', 'Canceled', 'Defeated', 'Succeeded', 'Queued', 'Expired', 'Executed']
const stateColor = ['orange', 'green', 'blue', 'red', 'purple', 'blue', 'blue', 'blue']
Expand All @@ -40,6 +40,11 @@ export default function Home() {
return await gov.state(proposalId)
}

const getName = async () => {
const gov = new ethers.Contract(govContract.address, govContract.abi, customProvider)
setName(await gov.name())
}

const makeProposalObject = async () => {
try {
console.log('fetching proposals...')
Expand Down Expand Up @@ -180,6 +185,7 @@ export default function Home() {
useEffect(() => {
if (!initialized) {
makeProposalObject()
getName()
}
}, [initialized])

Expand Down
6 changes: 3 additions & 3 deletions src/pages/manifesto/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ export default function Manifesto() {
} catch (e) {
console.log('error submitting proposal:', e)
toast({
title: "Can't propose",
title: "Can't submit a proposal",
position: 'bottom',
description: "You can't submit this kind of proposal.",
status: 'info',
description: 'To submit a proposal, you must (1) be a member and (2) delegate your voting power to yourself.',
status: 'error',
variant: 'subtle',
duration: 9000,
isClosable: true,
Expand Down
15 changes: 14 additions & 1 deletion src/pages/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { HeadingComponent } from '../../components/layout/HeadingComponent'
import { LinkComponent } from '../../components/layout/LinkComponent'
import QRCode from 'react-qr-code'
import { faucetAmount } from '../../utils/config'
import { useRouter } from 'next/router'

export default function Profile() {
const { address, isConnected } = useWeb3ModalAccount()
const { walletProvider } = useWeb3ModalProvider()
const customProvider = new ethers.JsonRpcProvider(process.env.NEXT_PUBLIC_RPC_ENDPOINT_URL)
const toast = useToast()
const router = useRouter()

const [isLoading, setIsLoading] = useState<boolean>(false)
const [isLoadingBurn, setIsLoadingBurn] = useState<boolean>(false)
Expand Down Expand Up @@ -96,6 +98,17 @@ export default function Profile() {
console.log('receipt:', receipt)
console.log('membership done')
setIsLoading(false)
toast({
title: 'Success',
position: 'bottom',
description: "Congrats, you're now a member of the DAO! You can now delegate your voting power to yourself.",
status: 'success',
variant: 'subtle',
duration: 8000,
isClosable: true,
})
const targetURL = '/delegate/'
router.push(targetURL)
return true
} else {
console.log('already member')
Expand Down Expand Up @@ -272,7 +285,7 @@ export default function Profile() {
variant="outline"
type="submit"
isLoading={isLoadingBurn}
loadingText="Burning ..."
loadingText="Leaving the DAO ..."
onClick={!isLoadingBurn ? burn : undefined}>
{isLoadingBurn ? 'Burning your NFT...' : 'Leave the DAO'}
</Button>
Expand Down
134 changes: 62 additions & 72 deletions src/pages/proposal/[proposalId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,63 +155,6 @@ export default function Proposal() {
}
}

const handleMembership = async () => {
try {
console.log('handleMembership start')

await handleBalance()

const nft = new ethers.Contract(nftContract.address, nftContract.abi, signer)
const nftBal = Number(await nft.balanceOf(address))
console.log('nftBal:', nftBal)

if (nftBal < 1) {
console.log('joining...')

const uri = 'https://bafkreicj62l5xu6pk2xx7x7n6b7rpunxb4ehlh7fevyjapid3556smuz4y.ipfs.w3s.link/'
const tx = await nft.safeMint(address, uri)
console.log('tx:', tx)
const receipt = await tx.wait(1)
console.log('receipt:', receipt)
console.log('membership done')
return true
} else {
console.log('already member')
console.log('membership done')
return true
}
} catch (e: any) {
console.log('handleMembership error', e)

if (e.toString().includes('could not coalesce error')) {
console.log('This is the coalesce error.')
toast({
title: 'Email login not supported',
position: 'bottom',
description: "Sorry, this feature is not supported yet if you're using the email login.",
status: 'info',
variant: 'subtle',
duration: 3000,
isClosable: true,
})
setIsLoading(false)
return false
} else {
toast({
title: 'Error',
position: 'bottom',
description: 'handleMembership error',
status: 'error',
variant: 'subtle',
duration: 9000,
isClosable: true,
})
setIsLoading(false)
return false
}
}
}

const voteYes = async () => {
// https://docs.openzeppelin.com/contracts/4.x/api/governance#IGovernor-COUNTING_MODE--
// 0 = Against, 1 = For, 2 = Abstain
Expand Down Expand Up @@ -368,25 +311,28 @@ export default function Proposal() {
duration: 2000,
isClosable: true,
})
setIsLoading(false)
return
}

const nft = new ethers.Contract(nftContract.address, nftContract.abi, signer)
const delegateTo = await nft.delegates(address)

if (delegateTo != address || delegateTo != '0x0000000000000000000000000000000000000000') {
console.log('delegated to someone else')
const nftBal = Number(await nft.balanceOf(address))
console.log('nftBal:', nftBal)

if (nftBal < 1) {
toast({
title: 'Delegated to someone else',
title: 'Not a member',
position: 'bottom',
description: "You've delegated to someone else. Delegate to yourself if you want to vote.",
description: 'Please join as a member if you want to vote.',
status: 'info',
variant: 'subtle',
duration: 3000,
isClosable: true,
})
return false
setIsLoading(false)
return
}

if (delegateTo === '0x0000000000000000000000000000000000000000') {
Expand All @@ -401,7 +347,8 @@ export default function Proposal() {
duration: 3000,
isClosable: true,
})
return false
setIsLoading(false)
return
}

if (delegateTo === address) {
Expand All @@ -427,18 +374,61 @@ export default function Proposal() {
duration: 5000,
isClosable: true,
})
} else {
setIsLoading(false)
toast({
title: 'Delegation',
position: 'bottom',
description: 'You need to delegate to yourself before voting',
status: 'info',
variant: 'subtle',
duration: 3000,
isClosable: true,
})
return
}
} catch (e: any) {
console.log('vote error:', e)
toast({
title: 'Error',
position: 'bottom',
description: "You can't vote twice.",
status: 'info',
variant: 'subtle',
duration: 3000,
isClosable: true,
})

switch (e) {
case String(e).includes('coalesce'):
console.log('This is the coalesce error.')
toast({
title: 'Woops',
position: 'bottom',
description: 'Please refresh the page and try again.',
status: 'info',
variant: 'subtle',
duration: 3000,
isClosable: true,
})
break

default:
console.log('Basic error')
}

if (state === 'Pending') {
toast({
title: 'Pending proposal',
position: 'bottom',
description: 'The proposal is still pending. Please try again in a few seconds.',
status: 'info',
variant: 'subtle',
duration: 3000,
isClosable: true,
})
} else {
toast({
title: 'Already voted',
position: 'bottom',
description: "You can't vote twice.",
status: 'info',
variant: 'subtle',
duration: 3000,
isClosable: true,
})
}
setIsLoading(false)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/request-eth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ export default function RequestEth() {
} catch (e) {
console.log('delegate error:', e)
toast({
title: "Can't propose",
title: "Can't submit a proposal",
position: 'bottom',
description: "You can't submit this kind of proposal.",
status: 'info',
description: 'To submit a proposal, you must (1) be a member and (2) delegate your voting power to yourself.',
status: 'error',
variant: 'subtle',
duration: 9000,
isClosable: true,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/request-eur/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ export default function RequestEur() {
} catch (e) {
console.log('submitProposal error:', e)
toast({
title: 'Error',
title: "Can't submit a proposal",
position: 'bottom',
description: 'submitProposal error',
description: 'To submit a proposal, you must (1) be a member and (2) delegate your voting power to yourself.',
status: 'error',
variant: 'subtle',
duration: 9000,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SOCIAL_TWITTER = 'w3hc8'
export const SOCIAL_GITHUB = 'w3hc/gov-ui'

export const ERC20_CONTRACT_ADRESS = '0xe6BCD785b90dc16d667B022cc871c046587d9Ac5'
export const firstIteration = 2
export const firstIteration = 5
export const faucetAmount = 0.005
export const startBlock = 6031421
// export const listOfBlocks = [6043490, 6043750]
Expand Down

0 comments on commit 82fd179

Please sign in to comment.