store finalized ballots in local storage
This commit is contained in:
parent
e569caf9f6
commit
cbf63a0b9d
|
@ -242,13 +242,26 @@ class ContractsStore {
|
||||||
console.log(e.message)
|
console.log(e.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
const [keysCards, minTresholdCards, proxyCards, emissionFundsCards] = await Promise.all([
|
const [keysBallots, minTresholdBallots, proxyBallots, emissionFundsBallots] = await Promise.all([
|
||||||
this.getCards(keysNextBallotId, 'votingToChangeKeys'),
|
this.getBallots(keysNextBallotId, 'votingToChangeKeys'),
|
||||||
this.getCards(minThresholdNextBallotId, 'votingToChangeMinThreshold'),
|
this.getBallots(minThresholdNextBallotId, 'votingToChangeMinThreshold'),
|
||||||
this.getCards(proxyNextBallotId, 'votingToChangeProxy'),
|
this.getBallots(proxyNextBallotId, 'votingToChangeProxy'),
|
||||||
this.getCards(emissionFundsNextBallotId, 'votingToManageEmissionFunds')
|
this.getBallots(emissionFundsNextBallotId, 'votingToManageEmissionFunds')
|
||||||
])
|
])
|
||||||
ballotsStore.ballotCards = [...keysCards, ...minTresholdCards, ...proxyCards, ...emissionFundsCards]
|
|
||||||
|
const ballots = [...keysBallots, ...minTresholdBallots, ...proxyBallots, ...emissionFundsBallots]
|
||||||
|
ballotsStore.ballotCards = this.mapBallotsToCards(ballots)
|
||||||
|
|
||||||
|
const finalizedOrCancelled = item => item.isFinalized || item.isCanceled
|
||||||
|
window.localStorage.setItem(
|
||||||
|
`ballots-${this.netId}`,
|
||||||
|
JSON.stringify({
|
||||||
|
votingToChangeKeys: keysBallots.filter(finalizedOrCancelled),
|
||||||
|
votingToChangeMinThreshold: minTresholdBallots.filter(finalizedOrCancelled),
|
||||||
|
votingToChangeProxy: proxyBallots.filter(finalizedOrCancelled),
|
||||||
|
votingToManageEmissionFunds: emissionFundsBallots.filter(finalizedOrCancelled)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const allBallotsIDsLength =
|
const allBallotsIDsLength =
|
||||||
keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId + emissionFundsNextBallotId
|
keysNextBallotId + minThresholdNextBallotId + proxyNextBallotId + emissionFundsNextBallotId
|
||||||
|
@ -335,73 +348,59 @@ class ContractsStore {
|
||||||
return votingState
|
return votingState
|
||||||
}
|
}
|
||||||
|
|
||||||
getCard = async (id, contractType) => {
|
mapBallotsToCards = cards => {
|
||||||
|
return cards.map(card => {
|
||||||
|
let component
|
||||||
|
let params = {
|
||||||
|
id: card.id,
|
||||||
|
key: card.contractType + card.id,
|
||||||
|
pos: ballotsStore.ballotCards.length,
|
||||||
|
votingState: card
|
||||||
|
}
|
||||||
|
switch (card.contractType) {
|
||||||
|
case 'votingToChangeKeys':
|
||||||
|
component = <BallotKeysCard {...params} type={ballotStore.BallotType.keys} />
|
||||||
|
break
|
||||||
|
case 'votingToChangeMinThreshold':
|
||||||
|
component = <BallotMinThresholdCard {...params} type={ballotStore.BallotType.minThreshold} />
|
||||||
|
break
|
||||||
|
case 'votingToChangeProxy':
|
||||||
|
component = <BallotProxyCard {...params} type={ballotStore.BallotType.proxy} />
|
||||||
|
break
|
||||||
|
case 'votingToManageEmissionFunds':
|
||||||
|
component = <BallotEmissionFundsCard {...params} type={ballotStore.BallotType.emissionFunds} />
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return component
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getBallot = async (id, contractType) => {
|
||||||
let votingState
|
let votingState
|
||||||
try {
|
try {
|
||||||
votingState = await this[contractType].getBallotInfo(id, this.votingKey)
|
votingState = await this[contractType].getBallotInfo(id, this.votingKey)
|
||||||
votingState = this.fillCardVotingState(votingState, contractType)
|
votingState = this.fillCardVotingState(votingState, contractType)
|
||||||
|
votingState.contractType = contractType
|
||||||
|
votingState.id = id
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e.message)
|
console.log(e.message)
|
||||||
}
|
}
|
||||||
|
return votingState
|
||||||
let card
|
|
||||||
switch (contractType) {
|
|
||||||
case 'votingToChangeKeys':
|
|
||||||
card = (
|
|
||||||
<BallotKeysCard
|
|
||||||
id={id}
|
|
||||||
type={ballotStore.BallotType.keys}
|
|
||||||
key={contractType + id}
|
|
||||||
pos={ballotsStore.ballotCards.length}
|
|
||||||
votingState={votingState}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
break
|
|
||||||
case 'votingToChangeMinThreshold':
|
|
||||||
card = (
|
|
||||||
<BallotMinThresholdCard
|
|
||||||
id={id}
|
|
||||||
type={ballotStore.BallotType.minThreshold}
|
|
||||||
key={contractType + id}
|
|
||||||
pos={ballotsStore.ballotCards.length}
|
|
||||||
votingState={votingState}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
break
|
|
||||||
case 'votingToChangeProxy':
|
|
||||||
card = (
|
|
||||||
<BallotProxyCard
|
|
||||||
id={id}
|
|
||||||
type={ballotStore.BallotType.proxy}
|
|
||||||
key={contractType + id}
|
|
||||||
pos={ballotsStore.ballotCards.length}
|
|
||||||
votingState={votingState}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
break
|
|
||||||
case 'votingToManageEmissionFunds':
|
|
||||||
card = (
|
|
||||||
<BallotEmissionFundsCard
|
|
||||||
id={id}
|
|
||||||
type={ballotStore.BallotType.emissionFunds}
|
|
||||||
key={contractType + id}
|
|
||||||
pos={ballotsStore.ballotCards.length}
|
|
||||||
votingState={votingState}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return card
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCards = async (nextBallotId, contractType) => {
|
getBallots = async (nextBallotId, contractType) => {
|
||||||
const promises = Array(nextBallotId)
|
const ballotsObject = JSON.parse(window.localStorage.getItem(`ballots-${this.netId}`) || '{}')
|
||||||
|
const existingBallots = ballotsObject[contractType] || []
|
||||||
|
const existingBallotsIds = existingBallots.map(item => item.id)
|
||||||
|
const allBallotsIds = Array(nextBallotId)
|
||||||
.fill(undefined)
|
.fill(undefined)
|
||||||
.map((item, index) => this.getCard(index, contractType))
|
.map((item, index) => index)
|
||||||
return Promise.all(promises)
|
const newBallotsIds = allBallotsIds.filter(item => !existingBallotsIds.includes(item))
|
||||||
|
const promises = newBallotsIds.map(id => this.getBallot(id, contractType))
|
||||||
|
const newBallots = await Promise.all(promises)
|
||||||
|
return existingBallots.concat(newBallots)
|
||||||
}
|
}
|
||||||
|
|
||||||
@action('Get all keys next ballot ids')
|
@action('Get all keys next ballot ids')
|
||||||
|
|
Loading…
Reference in New Issue