import { GITHUB_ORG , GITHUB_REPO } from '@shared/constants' ; import { useQuery } from 'react-query' ; export interface HiroMessage { title : string ; text : string ; purpose : 'error' | 'info' | 'warning' ; publishedAt : string ; dismissible : boolean ; learnMoreUrl ? : string ; } export interface ActiveFiatProviderType { name : string ; enabled : boolean ; } interface HiroConfig { messages : any ; activeFiatProviders : Record < string , ActiveFiatProviderType > ; } const GITHUB_PRIMARY_BRANCH = 'main' ; const githubWalletConfigRawUrl = `https://raw.githubusercontent.com/${ GITHUB_ORG }/${ GITHUB_REPO }/${ GITHUB_PRIMARY_BRANCH }/config/wallet-config.json` ; async function fetchHiroMessages ( ) { return fetch ( githubWalletConfigRawUrl ) . then ( msg => msg . json ( ) ) ; } export function useRemoteHiroConfig ( ) { const { data } = useQuery ( [ 'walletConfig' ] , fetchHiroMessages , { staleTime : 1000 * 60 * 10 , retryDelay : 1000 * 60 , } ) ; return data ; } export function useActiveFiatProviders ( ) { const config = useRemoteHiroConfig ( ) ; if ( ! config ?. activeFiatProviders ) return { } as Record < string , ActiveFiatProviderType > ; return Object . fromEntries ( Object . entries ( config . activeFiatProviders ) . filter ( ( [ _ , provider ] ) => provider . enabled ) ) ; } export function useHasFiatProviders ( ) { const activeProviders = useActiveFiatProviders ( ) ; return ( activeProviders && Object . keys ( activeProviders ) . reduce ( ( acc , key ) => activeProviders [ key ] . enabled || acc , false ) ) ; }