Skip to content

Commit

Permalink
chore: add bestinslot testnet for runes setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Apr 10, 2024
1 parent 250089e commit c0cd932
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/app/query/bitcoin/bitcoin-client.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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}`,
Expand Down Expand Up @@ -145,6 +160,15 @@ class BestinslotApi {
);
return resp.data;
}

/* RUNES ON TESTNET */
async getRunesWalletBalances(address: string) {
const resp = await axios.get<RunesWalletBalanceResponse[]>(
`${this.testnetUrl}/runes/wallet_balances?address=${address}`,
{ ...this.defaultOptions }
);
return resp.data;
}
}

class HiroApi {
Expand Down
14 changes: 14 additions & 0 deletions src/app/query/bitcoin/runes/runes-wallet-balances.query.ts
Original file line number Diff line number Diff line change
@@ -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),
});
}
3 changes: 3 additions & 0 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit c0cd932

Please sign in to comment.