Skip to content

Commit

Permalink
rpc node updated & loading for casting vote
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolalombardim committed May 25, 2024
1 parent 32024b4 commit 769a301
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/modules/lite/explorer/components/Choices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { useDAOID } from "modules/explorer/pages/DAO/router"
import { useDAO } from "services/services/dao/hooks/useDAO"
import { useTokenVoteWeight } from "services/contracts/token/hooks/useTokenVoteWeight"
import { useCommunity } from "../hooks/useCommunity"
import BigNumber from "bignumber.js"

const ChoicesContainer = styled(Grid)(({ theme }) => ({
marginTop: 24,
Expand Down
38 changes: 24 additions & 14 deletions src/modules/lite/explorer/pages/ProposalDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react"
import { Button, Grid, Typography, styled, useMediaQuery, useTheme } from "@material-ui/core"
import { CircularProgress, Grid, Typography, styled, useMediaQuery, useTheme } from "@material-ui/core"
import { ProposalDetailCard } from "../../components/ProposalDetailCard"
import { GridContainer } from "modules/common/GridContainer"
import { ChoiceItemSelected } from "../../components/ChoiceItemSelected"
Expand All @@ -14,13 +14,13 @@ import { usePollChoices } from "../../hooks/usePollChoices"
import { useCommunity } from "../../hooks/useCommunity"
import { useSinglePoll } from "../../hooks/usePoll"
import { ProposalStatus } from "../../components/ProposalTableRowStatusBadge"
import { BackButton } from "modules/lite/components/BackButton"
import { voteOnLiteProposal } from "services/services/lite/lite-services"
import { useDAO } from "services/services/dao/hooks/useDAO"
import { useTokenVoteWeight } from "services/contracts/token/hooks/useTokenVoteWeight"
import BigNumber from "bignumber.js"
import { ArrowBackIosOutlined } from "@material-ui/icons"
import { useIsMember } from "../../hooks/useIsMember"
import { SmallButton } from "modules/common/SmallButton"

const DescriptionText = styled(Typography)({
fontSize: 24,
Expand Down Expand Up @@ -81,6 +81,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
const { network } = useTezos()
const [selectedVotes, setSelectedVotes] = useState<Choice[]>([])
const isMember = useIsMember(network, community?.tokenAddress || "", account)
const [isLoading, setIsLoading] = useState(false)

const votingPower = poll?.isXTZ ? voteWeight?.votingXTZWeight : voteWeight?.votingWeight

Expand All @@ -104,7 +105,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
if (!wallet) {
return
}

setIsLoading(true)
try {
const publicKey = (await wallet?.client.getActiveAccount())?.publicKey
const { signature, payloadBytes } = await getSignature(account, wallet, JSON.stringify(votesData))
Expand All @@ -114,6 +115,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
autoHideDuration: 3000,
variant: "error"
})
setIsLoading(false)
return
}
const resp = await voteOnLiteProposal(signature, publicKey, payloadBytes)
Expand All @@ -126,7 +128,9 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
})
setRefresh(Math.random())
setSelectedVotes([])
setIsLoading(false)
} else {
setIsLoading(false)
console.log("Error: ", response.message)
openNotification({
message: response.message,
Expand All @@ -136,6 +140,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
return
}
} catch (error) {
setIsLoading(false)
console.log("error: ", error)
openNotification({
message: `Could not submit vote, Please Try Again!`,
Expand Down Expand Up @@ -166,7 +171,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
<Grid container item xs={12}>
{choices && choices.length > 0 ? (
<>
<LinearContainer container style={{ gap: 32 }} direction="row">
<LinearContainer container style={{ gap: 32 }} direction="row" justifyContent="center">
<Grid item xs={12}>
<DescriptionText color="textPrimary">Options</DescriptionText>
</Grid>
Expand All @@ -190,16 +195,21 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
})}
</Grid>
{poll?.isActive === ProposalStatus.ACTIVE ? (
<Button
disabled={
(selectedVotes.length === 0 || (votingPower && votingPower.eq(new BigNumber(0)))) && isMember
}
variant="contained"
color="secondary"
onClick={() => saveVote()}
>
{votingPower && votingPower.gt(new BigNumber(0)) ? "Cast your vote" : "No Voting Weight"}
</Button>
!isLoading ? (
<SmallButton
disabled={
(selectedVotes.length === 0 || (votingPower && votingPower.eq(new BigNumber(0)))) && isMember
}
variant="contained"
color="secondary"
onClick={() => saveVote()}
style={{ marginTop: 20 }}
>
{votingPower && votingPower.gt(new BigNumber(0)) ? "Cast your vote" : "No Voting Weight"}
</SmallButton>
) : (
<CircularProgress color="secondary" />
)
) : null}
</LinearContainer>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/services/beacon/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ALICE_PRIV_KEY = "edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSp

export const rpcNodes: Record<Network, string> = {
mainnet: "https://mainnet.api.tez.ie",
ghostnet: "https://ghostnet.tezos.marigold.dev"
ghostnet: "https://ghostnet.smartpy.io"
}

export const getTezosNetwork = (): Network => {
Expand Down
3 changes: 3 additions & 0 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ export const theme = createTheme({
color: "#bfc5ca !important",
background: "inherit !important"
}
},
containedSecondary: {
backgroundColor: "#4ed092"
}
},
MuiInputBase: {
Expand Down

0 comments on commit 769a301

Please sign in to comment.