Skip to content

Commit

Permalink
Fixes and (kinda breaking) changes
Browse files Browse the repository at this point in the history
- Ensure the `connected` field is properly checked via
  Object.keys().length
- Remove SpreadsheetAccess component logic from VoteButton (import it on
  your own if you need it, this is the most breaking change)
- Use election context instead of clients one (refs #171)
  • Loading branch information
elboletaire committed Jun 13, 2024
1 parent 9b9ee25 commit 3de74f2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ export const SpreadsheetAccess = (rest: ChakraProps) => {
const { connected, clearClient } = useElection()
const [loading, setLoading] = useState<boolean>(false)
const toast = useToast()
const { env, client: cl } = useClient()
const { env } = useClient()
const {
election,
client: cl,
setClient,
localize,
sikPassword,
Expand Down Expand Up @@ -84,6 +85,7 @@ export const SpreadsheetAccess = (rest: ChakraProps) => {
setClient(client)
} catch (error) {
console.warn('Error trying to login with private key ', error)
// this should not be required... if it fails, the client should already be the one set
setClient(cl)
}
})()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import { ArchivedElection, ElectionStatus, InvalidElection, PublishedElection }
import { useEffect, useState } from 'react'
import { Button } from '../layout/Button'
import { results } from './Results'
import { SpreadsheetAccess } from './SpreadsheetAccess'

export const VoteButton = (props: ButtonProps) => {
const { connected } = useClient()
const {
client,
loading: { voting },
connected: lconnected,
ConnectButton,
isAbleToVote,
election,
Expand All @@ -35,10 +33,6 @@ export const VoteButton = (props: ButtonProps) => {
return <ConnectButton />
}

if (!lconnected && election.get('census.type') === 'spreadsheet') {
return <SpreadsheetAccess />
}

const button: ButtonProps = {
type: 'submit',
...props,
Expand Down
6 changes: 3 additions & 3 deletions packages/react-providers/src/client/use-client-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const clientReducer: Reducer<ClientState, ClientAction> = (state: ClientState, a
return {
...state,
client,
connected: !!client.wallet,
connected: client.wallet ? !!Object.keys(client.wallet as unknown as any).length : false,
}
}
case ClientEnvSet: {
Expand All @@ -285,7 +285,7 @@ const clientReducer: Reducer<ClientState, ClientAction> = (state: ClientState, a
client,
census3,
env,
connected: !!client.wallet,
connected: client.wallet ? !!Object.keys(client.wallet as unknown as any).length : false,
}
}
case ClientSignerSet: {
Expand All @@ -295,7 +295,7 @@ const clientReducer: Reducer<ClientState, ClientAction> = (state: ClientState, a
...state,
client,
signer,
connected: !!client.wallet,
connected: client.wallet ? !!Object.keys(client.wallet as unknown as any).length : false,
}
}
default:
Expand Down

0 comments on commit 3de74f2

Please sign in to comment.