-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centrifuge App: Fetch DAO data dynamically (#1755)
* Fetch dao config from public github repo * Remove author * Remove showPortfolio debug flag
- Loading branch information
1 parent
c25825d
commit ee974d5
Showing
8 changed files
with
91 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Network } from '@centrifuge/centrifuge-react' | ||
import { useQuery } from 'react-query' | ||
import { isTestEnv } from '../config' | ||
|
||
export type DAO = { | ||
name: string | ||
slug: string | ||
network: Network | ||
logo: string | ||
address: string | ||
resolutions: Resolution[] | ||
} | ||
|
||
export type Resolution = { | ||
title: string | ||
image: string | ||
timestamp: number | ||
excerpt: string | ||
link: string | ||
} | ||
|
||
export const useDAOConfig = () => { | ||
const query = useQuery( | ||
'daoData', | ||
async () => { | ||
const res = await fetch( | ||
`https://api.github.com/repos/centrifuge/prime-data/contents/data${isTestEnv ? '-dev' : ''}.json`, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
} | ||
) | ||
|
||
if (!res.ok) { | ||
throw new Error('Network response was not ok') | ||
} | ||
|
||
const json = await res.json() | ||
const content = atob(json.content) | ||
|
||
const data = JSON.parse(content) | ||
return Object.values(data) as DAO[] | ||
}, | ||
{ | ||
staleTime: Infinity, | ||
} | ||
) | ||
return query | ||
} |