Skip to content

Commit 50f8b21

Browse files
committed
chore(custom addresses): make sure we don't accidentally create an empty census
refs #42
1 parent 60a3c3b commit 50f8b21

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/components/create-vote-form.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,25 @@ export function CreateVoteForm() {
288288
break
289289
}
290290
default: {
291-
if (data.customAddresses.length === 0) {
291+
// Filter out empty addresses to ensure we only process valid ones
292+
const validAddresses = data.customAddresses.filter(Boolean)
293+
294+
if (validAddresses.length === 0) {
292295
throw new Error('Please add at least one address to the custom addresses list')
293296
}
294297

295298
// Step 1: Create census
296299
const censusId = await api.census.createCensus()
297300

298-
// Step 2: Add participants
299-
const participants = data.customAddresses.map((address, index) => ({
300-
key: address,
301-
weight: data.useWeightedVoting && data.customAddressWeights[index] ? data.customAddressWeights[index] : '1',
302-
}))
301+
// Step 2: Add participants (only with valid addresses)
302+
const participants = validAddresses.map((address) => {
303+
// Find the original index to get the correct weight
304+
const originalIndex = data.customAddresses.indexOf(address)
305+
return {
306+
key: address,
307+
weight: data.useWeightedVoting && data.customAddressWeights[originalIndex] ? data.customAddressWeights[originalIndex] : '1',
308+
}
309+
})
303310
await api.census.addParticipants(censusId, participants)
304311
const censusRoot = await api.census.getCensusRoot(censusId)
305312
const censusSize = await api.census.getCensusSize(censusId)

0 commit comments

Comments
 (0)