Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cache service bugs #839

Merged
merged 3 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pages/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const ConfigPage = observer(() => {
async function clearCache() {
localStorage.clear();
caches.delete(`dxvote-cache`);
window.location.reload();
}

return (
Expand Down
54 changes: 25 additions & 29 deletions src/services/CacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,18 +1197,13 @@ export default class UtilsService {
);
const fromBlock = networkCache.blockNumber + 1;

let schemeEvents = [];
for (let i = 0; i < schemeTypeData.newProposalTopics.length; i++) {
schemeEvents = schemeEvents.concat(
await getRawEvents(
web3,
schemeAddress,
fromBlock,
toBlock,
schemeTypeData.newProposalTopics[i]
)
);
}
let schemeEvents = await getRawEvents(
web3,
schemeAddress,
fromBlock,
toBlock,
schemeTypeData.newProposalTopics
);

await batchPromisesOntarget(
schemeEvents.map(schemeEvent => {
Expand Down Expand Up @@ -1382,19 +1377,20 @@ export default class UtilsService {
let decodedProposer;
let creationLogDecoded;

if (newProposal && isWalletScheme(schemeOfProposal)) {
// @ts-ignore
schemeProposalInfo.to = callsResponse.decodedReturnData[6].to;
schemeProposalInfo.callData = callsResponse.decodedReturnData[6].callData;
schemeProposalInfo.value = callsResponse.decodedReturnData[6].value;
schemeProposalInfo.state = callsResponse.decodedReturnData[6].state;
schemeProposalInfo.title = callsResponse.decodedReturnData[6].title;
schemeProposalInfo.descriptionHash =
callsResponse.decodedReturnData[6].descriptionHash;
schemeProposalInfo.submittedTime =
callsResponse.decodedReturnData[6].submittedTime;
} else if (isWalletScheme(schemeOfProposal)) {
if (isWalletScheme(schemeOfProposal)) {
schemeProposalInfo.state = callsResponse.decodedReturnData[6].state;

if (newProposal) {
schemeProposalInfo.to = callsResponse.decodedReturnData[6].to;
schemeProposalInfo.callData =
callsResponse.decodedReturnData[6].callData;
schemeProposalInfo.value = callsResponse.decodedReturnData[6].value;
schemeProposalInfo.title = callsResponse.decodedReturnData[6].title;
schemeProposalInfo.descriptionHash =
callsResponse.decodedReturnData[6].descriptionHash;
schemeProposalInfo.submittedTime =
callsResponse.decodedReturnData[6].submittedTime;
}
} else {
// Here we get the events triggered in the GenericMulticall to get their final state
// When the proposal is executed by the voting machine we get if the proposal was rejected
Expand Down Expand Up @@ -1452,18 +1448,18 @@ export default class UtilsService {
// If any of the values of the redeemPeriods of the contribution reward is higher than zero it means that it executed the reward
} else if (schemeOfProposal.type === 'ContributionReward') {
if (
callsResponse.decodedReturnData[0].winningVote === '2' &&
callsResponse.decodedReturnData[0].state === '2'
) {
schemeProposalInfo.state = WalletSchemeProposalState.Rejected;
} else if (
callsResponse.decodedReturnData[6][0] > 0 ||
callsResponse.decodedReturnData[7][0] > 0 ||
callsResponse.decodedReturnData[8][0] > 0 ||
callsResponse.decodedReturnData[9][0] > 0
) {
schemeProposalInfo.state =
WalletSchemeProposalState.ExecutionSucceded;
} else if (
callsResponse.decodedReturnData[0].state === '1' ||
callsResponse.decodedReturnData[0].state === '2'
) {
schemeProposalInfo.state = WalletSchemeProposalState.Rejected;
} else {
schemeProposalInfo.state = WalletSchemeProposalState.Submitted;
}
Expand Down
30 changes: 2 additions & 28 deletions src/utils/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,7 @@ export const decodeProposalStatus = function (
pendingAction: PendingAction.None,
};
case VotingMachineProposalState.Executed:
if (
proposal.stateInScheme === WalletSchemeProposalState.Rejected &&
schemeType === 'ContributionReward'
)
return {
status: 'Passed',
boostTime: boostedPhaseTime,
finishTime: proposalStateChangeEvents.find(
event => Number(event.state) === VotingMachineProposalState.Executed
)
? bnum(
proposalStateChangeEvents.find(
event =>
Number(event.state) === VotingMachineProposalState.Executed
).timestamp
)
: bnum(0),
pendingAction: PendingAction.Redeem,
};
else if (
proposal.winningVote == '2' ||
proposal.stateInScheme === WalletSchemeProposalState.Rejected
)
if (proposal.stateInScheme === WalletSchemeProposalState.Rejected)
return {
status: 'Proposal Rejected',
boostTime: boostedPhaseTime,
Expand All @@ -236,11 +214,7 @@ export const decodeProposalStatus = function (
).timestamp
)
: bnum(0),
pendingAction:
schemeType === 'ContributionReward' &&
proposal.stateInVotingMachine < 3
? PendingAction.Redeem
: PendingAction.None,
pendingAction: PendingAction.None,
};
else if (
proposal.stateInScheme === WalletSchemeProposalState.ExecutionSucceded
Expand Down