From c0cd9324f3f7c5f817b3a284a8f7938ecb77b627 Mon Sep 17 00:00:00 2001 From: Fara Woolf Date: Wed, 10 Apr 2024 12:47:11 -0500 Subject: [PATCH] chore: add bestinslot testnet for runes setup --- src/app/query/bitcoin/bitcoin-client.ts | 28 +++++++++++++++++-- .../runes/runes-wallet-balances.query.ts | 14 ++++++++++ src/shared/constants.ts | 3 ++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/app/query/bitcoin/runes/runes-wallet-balances.query.ts diff --git a/src/app/query/bitcoin/bitcoin-client.ts b/src/app/query/bitcoin/bitcoin-client.ts index 5ed7a546830..870eeba5acd 100644 --- a/src/app/query/bitcoin/bitcoin-client.ts +++ b/src/app/query/bitcoin/bitcoin-client.ts @@ -1,7 +1,11 @@ import axios from 'axios'; import PQueue from 'p-queue'; -import { HIRO_API_BASE_URL_MAINNET } from '@shared/constants'; +import { + BESTINSLOT_API_BASE_URL_MAINNET, + BESTINSLOT_API_BASE_URL_TESTNET, + HIRO_API_BASE_URL_MAINNET, +} from '@shared/constants'; import { Paginated } from '@shared/models/api-types'; import type { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model'; @@ -96,8 +100,19 @@ interface BestinslotBrc20AddressBalanceResponse { data: Brc20TokenResponse[]; } +interface RunesWalletBalanceResponse { + pkscript: string; + wallet_addr: string; + rune_id: string; + total_balance: string; + rune_name: string; + spaced_rune_name: string; +} + class BestinslotApi { - url = 'https://api.bestinslot.xyz/v3'; + url = BESTINSLOT_API_BASE_URL_MAINNET; + testnetUrl = BESTINSLOT_API_BASE_URL_TESTNET; + private defaultOptions = { headers: { 'x-api-key': `${process.env.BESTINSLOT_API_KEY}`, @@ -145,6 +160,15 @@ class BestinslotApi { ); return resp.data; } + + /* RUNES ON TESTNET */ + async getRunesWalletBalances(address: string) { + const resp = await axios.get( + `${this.testnetUrl}/runes/wallet_balances?address=${address}`, + { ...this.defaultOptions } + ); + return resp.data; + } } class HiroApi { diff --git a/src/app/query/bitcoin/runes/runes-wallet-balances.query.ts b/src/app/query/bitcoin/runes/runes-wallet-balances.query.ts new file mode 100644 index 00000000000..afd0fe9a2d4 --- /dev/null +++ b/src/app/query/bitcoin/runes/runes-wallet-balances.query.ts @@ -0,0 +1,14 @@ +import { useQuery } from '@tanstack/react-query'; + +import { useBitcoinClient } from '@app/store/common/api-clients.hooks'; + +// ts-unused-exports:disable-next-line +export function useGetRunesWalletBalancesQuery(address: string) { + const client = useBitcoinClient(); + + return useQuery({ + enabled: !!address, + queryKey: ['runes-wallet-balances', address], + queryFn: () => client.BestinslotApi.getRunesWalletBalances(address), + }); +} diff --git a/src/shared/constants.ts b/src/shared/constants.ts index c6114a1f327..071eda6f524 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -75,6 +75,9 @@ export interface NetworkConfiguration { }; } +export const BESTINSLOT_API_BASE_URL_MAINNET = 'https://api.bestinslot.xyz/v3'; +export const BESTINSLOT_API_BASE_URL_TESTNET = 'https://testnet.api.bestinslot.xyz/v3'; + export const HIRO_API_BASE_URL_MAINNET = 'https://api.hiro.so'; export const HIRO_API_BASE_URL_TESTNET = 'https://api.testnet.hiro.so'; export const HIRO_INSCRIPTIONS_API_URL = 'https://api.hiro.so/ordinals/v1/inscriptions';