-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init dapp warnings * fix info alert title weight * query clean up * info alert * i18n * rm logs * types + authRequests * i18n + verified context for wc connections * fix text padding * clean up * lint
- Loading branch information
1 parent
452fdcd
commit 5f3aa45
Showing
12 changed files
with
508 additions
and
42 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,109 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { metadataClient } from '@/graphql'; | ||
import { DAppStatus } from '@/graphql/__generated__/metadata'; | ||
import { QueryFunctionArgs, createQueryKey, queryClient } from '@/react-query'; | ||
|
||
import { | ||
getDappHost, | ||
getDappHostname, | ||
getHardcodedDappInformation, | ||
isValidUrl, | ||
} from '@/utils/connectedApps'; | ||
import { capitalize } from 'lodash'; | ||
|
||
export interface DappMetadata { | ||
url: string; | ||
appHost: string; | ||
appHostName: string; | ||
appName: string; | ||
appShortName: string; | ||
appLogo?: string; | ||
timestamp?: number; | ||
status?: DAppStatus; | ||
} | ||
|
||
// /////////////////////////////////////////////// | ||
// Query Types | ||
|
||
type DappMetadataArgs = { | ||
url?: string; | ||
}; | ||
|
||
// /////////////////////////////////////////////// | ||
// Query Key | ||
|
||
const DappMetadataQueryKey = ({ url }: DappMetadataArgs) => | ||
createQueryKey('dappMetadata', { url }, { persisterVersion: 1 }); | ||
|
||
type DappMetadataQueryKey = ReturnType<typeof DappMetadataQueryKey>; | ||
|
||
// /////////////////////////////////////////////// | ||
// Query Function | ||
|
||
export async function fetchDappMetadata({ | ||
url, | ||
status, | ||
}: { | ||
url: string; | ||
status: boolean; | ||
}) { | ||
const appHostName = url && isValidUrl(url) ? getDappHostname(url) : ''; | ||
const hardcodedAppName = | ||
url && isValidUrl(url) | ||
? getHardcodedDappInformation(appHostName)?.name || '' | ||
: ''; | ||
|
||
const response = await metadataClient.getdApp({ | ||
shortName: hardcodedAppName, | ||
url, | ||
status, | ||
}); | ||
|
||
const appHost = url && isValidUrl(url) ? getDappHost(url) : ''; | ||
const appName = response?.dApp?.name | ||
? capitalize(response?.dApp?.name) | ||
: hardcodedAppName || appHost; | ||
const appShortName = response?.dApp?.shortName | ||
? capitalize(response?.dApp?.shortName) | ||
: appName; | ||
const dappMetadata = { | ||
url, | ||
appHost, | ||
appHostName, | ||
appName, | ||
appShortName, | ||
appLogo: response?.dApp?.iconURL, | ||
status: response.dApp?.status, | ||
}; | ||
return dappMetadata; | ||
} | ||
|
||
export async function dappMetadataQueryFunction({ | ||
queryKey: [{ url }], | ||
}: QueryFunctionArgs< | ||
typeof DappMetadataQueryKey | ||
>): Promise<DappMetadata | null> { | ||
if (!url) return null; | ||
const dappMetadata = await fetchDappMetadata({ url, status: true }); | ||
return dappMetadata; | ||
} | ||
|
||
export async function prefetchDappMetadata({ url }: { url: string }) { | ||
queryClient.prefetchQuery( | ||
DappMetadataQueryKey({ url }), | ||
async () => fetchDappMetadata({ url, status: false }), | ||
{ | ||
staleTime: 60000, | ||
} | ||
); | ||
} | ||
|
||
// /////////////////////////////////////////////// | ||
// Query Hook | ||
|
||
export function useDappMetadata({ url }: DappMetadataArgs) { | ||
return useQuery(DappMetadataQueryKey({ url }), dappMetadataQueryFunction, { | ||
cacheTime: 1000 * 60 * 60 * 24, | ||
enabled: !!url, | ||
}); | ||
} |
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
Oops, something went wrong.