-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#589] Vote context fix (plus small fix to supporting links in GA)
- Loading branch information
1 parent
40a69af
commit e029800
Showing
12 changed files
with
107 additions
and
27 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
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
24 changes: 24 additions & 0 deletions
24
govtool/frontend/src/hooks/queries/useGetVoteContextFromFile.ts
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,24 @@ | ||
import { useQuery } from "react-query"; | ||
|
||
import { getVoteContextTextFromFile } from "@/services"; | ||
import { QUERY_KEYS } from "@/consts"; | ||
import { useCardano } from "@/context"; | ||
import { useGetVoterInfo } from "."; | ||
|
||
export const useGetVoteContextFromFile = (url: string | undefined) => { | ||
const { dRepID } = useCardano(); | ||
const { voter } = useGetVoterInfo(); | ||
|
||
const { data, isLoading } = useQuery( | ||
[QUERY_KEYS.useGetVoteContextFromFile, url], | ||
() => getVoteContextTextFromFile(url), | ||
{ | ||
enabled: | ||
!!url && | ||
!!dRepID && | ||
(!!voter?.isRegisteredAsDRep || !!voter?.isRegisteredAsSoleVoter), | ||
}, | ||
); | ||
|
||
return { contextText: data, isLoading }; | ||
}; |
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
14 changes: 14 additions & 0 deletions
14
govtool/frontend/src/services/requests/getVoteContextFromFile.ts
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,14 @@ | ||
import axios from "axios"; | ||
|
||
export const getVoteContextTextFromFile = async (url: string | undefined) => { | ||
if (!url) { | ||
throw new Error("URL is undefined"); | ||
} | ||
|
||
const response = await axios.get(url); | ||
|
||
const voteContextText = | ||
response.data.body["CIP108:voteContextText"]["@value"]; | ||
|
||
return voteContextText; | ||
}; |
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