-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55aae57
commit 61b2b33
Showing
13 changed files
with
5,482 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// TODO: remove legacy | ||
import { useEffect, useState } from "react"; | ||
import { | ||
PROPOSAL_VOTING_APPROVED, | ||
PROPOSAL_VOTING_REJECTED, | ||
PROPOSAL_VOTING_INELIGIBLE | ||
} from "src/constants"; | ||
import legacyProposalsInfo from "src/legacyproposals.json"; | ||
import tokenInventory from "src/legacytokeninventory.json"; | ||
|
||
const mapOldToNewStatus = { | ||
// old public | ||
4: 2, | ||
// old abandoned | ||
6: 4 | ||
}; | ||
|
||
const newLegacyProposalsInfo = legacyProposalsInfo.proposals.map((p) => ({ | ||
...p, | ||
status: mapOldToNewStatus[p.status] | ||
})); | ||
|
||
const mapStatusToString = { | ||
[PROPOSAL_VOTING_APPROVED]: "approved", | ||
[PROPOSAL_VOTING_REJECTED]: "rejected", | ||
[PROPOSAL_VOTING_INELIGIBLE]: "abandoned" | ||
}; | ||
|
||
export default function useLegacyVettedProposals(shouldReturn = false, status) { | ||
const [legacyProposals, setLegacyProposals] = useState([]); | ||
const [legacyProposalsTokens, setLegacyProposalsTokens] = useState({}); | ||
useEffect(() => { | ||
// shouldReturn is a boolean to control when the proposals are done fetching so we can return the legacy props. | ||
if (shouldReturn) { | ||
const proposalsTokensList = tokenInventory[mapStatusToString[status]]; | ||
// filter propsals by tab and transform from Array to Object where the key is the proposal token and the value is the proposal info | ||
const finalList = newLegacyProposalsInfo | ||
.filter( | ||
(p) => | ||
proposalsTokensList && | ||
proposalsTokensList.includes(p.censorshiprecord.token) | ||
) | ||
.reduce( | ||
(acc, cur) => ({ ...acc, [cur.censorshiprecord.token]: cur }), | ||
{} | ||
); | ||
setLegacyProposals(finalList); | ||
setLegacyProposalsTokens(tokenInventory); | ||
} else { | ||
setLegacyProposals([]); | ||
setLegacyProposalsTokens({}); | ||
} | ||
}, [legacyProposals.proposals, shouldReturn, status]); | ||
return { legacyProposals, legacyProposalsTokens }; | ||
} |
Oops, something went wrong.