-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Humanity score integration * isLoading fix
- Loading branch information
Showing
9 changed files
with
129 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Feature } from './types'; | ||
|
||
import { getEnvValue } from '../utils'; | ||
|
||
const title = 'Xname score'; | ||
const url = getEnvValue('NEXT_PUBLIC_XNAME_SCORE_URL'); | ||
|
||
const config: Feature<{ url: string }> = (() => { | ||
if (url) { | ||
return Object.freeze({ | ||
title, | ||
url, | ||
isEnabled: true, | ||
}); | ||
} | ||
|
||
return Object.freeze({ | ||
title, | ||
isEnabled: false, | ||
}); | ||
})(); | ||
|
||
export default config; |
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 React from 'react'; | ||
import * as v from 'valibot'; | ||
|
||
import config from 'configs/app'; | ||
import buildUrl from 'lib/api/buildUrl'; | ||
import useApiQuery from 'lib/api/useApiQuery'; | ||
|
||
interface Params { | ||
hash: string; | ||
} | ||
|
||
const RESOURCE_NAME = 'address_xstar_score'; | ||
const ERROR_NAME = 'Invalid response schema'; | ||
|
||
export default function useFetchXStarScore({ hash }: Params) { | ||
const query = useApiQuery(RESOURCE_NAME, { | ||
pathParams: { hash }, | ||
queryOptions: { | ||
select: (response) => { | ||
const parsedResponse = v.safeParse(v.object({ data: v.string() }), response); | ||
|
||
if (!parsedResponse.success) { | ||
throw Error(ERROR_NAME); | ||
} | ||
|
||
return parsedResponse.output; | ||
}, | ||
enabled: Boolean(hash) && config.features.xStarScore.isEnabled, | ||
placeholderData: { | ||
data: 'Base' as const, | ||
}, | ||
retry: 0, | ||
}, | ||
}); | ||
|
||
const errorMessage = query.error && 'message' in query.error ? query.error.message : undefined; | ||
|
||
React.useEffect(() => { | ||
if (errorMessage === ERROR_NAME) { | ||
fetch('/node-api/monitoring/invalid-api-schema', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
resource: RESOURCE_NAME, | ||
url: buildUrl(RESOURCE_NAME, { hash }, undefined, true), | ||
}), | ||
}); | ||
} | ||
}, [ errorMessage, hash ]); | ||
|
||
return query; | ||
} |
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