Skip to content

Commit

Permalink
fix: utxos and transaction request cancellation, closes #5058
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed May 14, 2024
1 parent 16a9e6e commit ae1b04b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/app/query/bitcoin/bitcoin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ interface RunesOutputsByAddressArgs {
order?: 'asc' | 'desc';
offset?: number;
count?: number;
signal?: AbortSignal;
}

interface RunesOutputsByAddressResponse {
Expand Down Expand Up @@ -272,6 +273,7 @@ class BestinSlotApi {
order = 'asc',
offset = 0,
count = 100,
signal,
}: RunesOutputsByAddressArgs) {
const baseUrl = network === 'mainnet' ? this.url : this.testnetUrl;
const queryParams = new URLSearchParams({
Expand All @@ -284,7 +286,7 @@ class BestinSlotApi {

const resp = await axios.get<RunesOutputsByAddressResponse>(
`${baseUrl}/runes/wallet_valid_outputs?${queryParams}`,
{ ...this.defaultOptions }
{ ...this.defaultOptions, signal }
);
return resp.data.data;
}
Expand All @@ -298,15 +300,21 @@ class AddressApi {

async getTransactionsByAddress(address: string, signal?: AbortSignal) {
const resp = await this.rateLimiter.add(
() => axios.get<BitcoinTx[]>(`${this.configuration.baseUrl}/address/${address}/txs`),
() =>
axios.get<BitcoinTx[]>(`${this.configuration.baseUrl}/address/${address}/txs`, {
signal,
}),
{ signal, throwOnTimeout: true }
);
return resp.data;
}

async getUtxosByAddress(address: string, signal?: AbortSignal): Promise<UtxoResponseItem[]> {
const resp = await this.rateLimiter.add(
() => axios.get<UtxoResponseItem[]>(`${this.configuration.baseUrl}/address/${address}/utxo`),
() =>
axios.get<UtxoResponseItem[]>(`${this.configuration.baseUrl}/address/${address}/utxo`, {
signal,
}),
{ signal, priority: 1, throwOnTimeout: true }
);
return resp.data.sort((a, b) => a.vout - b.vout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export function useGetRunesOutputsByAddressQuery<T extends unknown = RunesOutput
return useQuery({
enabled: !!address && runesEnabled,
queryKey: ['runes-outputs-by-address', address],
queryFn: () =>
queryFn: ({ signal }) =>
client.bestinSlotApi.getRunesOutputsByAddress({
address,
network: network.chain.bitcoin.bitcoinNetwork,
signal,
}),
...queryOptions,
...options,
Expand Down

0 comments on commit ae1b04b

Please sign in to comment.