mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-04-29 13:15:32 +08:00
feat: add hiro api test
This commit is contained in:
@@ -16,7 +16,11 @@ export function PsbtInputWithInscription({
|
||||
inputValue,
|
||||
path,
|
||||
}: PsbtInputWithInscriptionProps) {
|
||||
const { isLoading, isError, data: inscription } = useInscription(path);
|
||||
const {
|
||||
isLoading,
|
||||
isError,
|
||||
data: inscription,
|
||||
} = useInscription(path.replace('/inscription/', ''));
|
||||
|
||||
if (isLoading || isError) return null;
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ export function convertInscriptionToSupportedInscriptionType(inscription: Inscri
|
||||
});
|
||||
}
|
||||
|
||||
export function useInscription(path: string) {
|
||||
return useGetInscriptionQuery(path, {
|
||||
export function useInscription(id: string) {
|
||||
return useGetInscriptionQuery(id, {
|
||||
select: resp => convertInscriptionToSupportedInscriptionType(resp),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,11 +13,9 @@ const inscriptionQueryOptions = {
|
||||
/**
|
||||
* @param path - inscription/:inscription_id
|
||||
*/
|
||||
function fetchInscription() {
|
||||
return async (path: string) => {
|
||||
const res = await fetch(
|
||||
`https://api.hiro.so/ordinals/v1${path.replace('inscription', 'inscriptions')}`
|
||||
);
|
||||
export function fetchInscription() {
|
||||
return async (id: string) => {
|
||||
const res = await fetch(`https://api.hiro.so/ordinals/v1/inscriptions/${id}`);
|
||||
if (!res.ok) throw new Error('Error retrieving inscription metadata');
|
||||
const data = await res.json();
|
||||
return data as Inscription;
|
||||
@@ -27,13 +25,13 @@ function fetchInscription() {
|
||||
type FetchInscriptionResp = Awaited<ReturnType<ReturnType<typeof fetchInscription>>>;
|
||||
|
||||
export function useGetInscriptionQuery<T extends unknown = FetchInscriptionResp>(
|
||||
path: string,
|
||||
id: string,
|
||||
options?: AppUseQueryConfig<FetchInscriptionResp, T>
|
||||
) {
|
||||
return useQuery({
|
||||
enabled: !!path,
|
||||
queryKey: [QueryPrefixes.InscriptionMetadata, path],
|
||||
queryFn: () => fetchInscription()(path),
|
||||
enabled: !!id,
|
||||
queryKey: [QueryPrefixes.InscriptionMetadata, id],
|
||||
queryFn: () => fetchInscription()(id),
|
||||
...inscriptionQueryOptions,
|
||||
...options,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { test } from '@playwright/test';
|
||||
|
||||
import { fetchInscription } from '@app/query/bitcoin/ordinals/inscription.query';
|
||||
import { getNumberOfInscriptionOnUtxo } from '@app/query/bitcoin/ordinals/ordinals-aware-utxo.query';
|
||||
import { fetchData } from '@app/query/utils';
|
||||
|
||||
test.describe(getNumberOfInscriptionOnUtxo.name, () => {
|
||||
test('should return 3 in case of 3 inscriptions', async () => {
|
||||
@@ -19,3 +21,20 @@ test.describe(getNumberOfInscriptionOnUtxo.name, () => {
|
||||
test.expect(resp).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Check Hiro API', () => {
|
||||
test('should get same inscription info as in ordapi', async () => {
|
||||
const id = '43af4721f64f6db20ab2c0b41d084c5e3733d346925bd613abd6fd64ad2b6645i0';
|
||||
const [respHiroApi, respOrdApi] = await Promise.all([
|
||||
// fetch inscription from hiro api
|
||||
fetchInscription()(id),
|
||||
// fetch inscription from ordapi
|
||||
fetchData({
|
||||
errorMsg: 'Failed to fetch inscription',
|
||||
url: `https://ordapi.xyz/inscription/${id}`,
|
||||
}),
|
||||
]);
|
||||
test.expect(respHiroApi.id).toBe(respOrdApi.id);
|
||||
test.expect(respHiroApi.number).toBe(respOrdApi.inscription_number);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user