@berachain/berajs 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{HoneyConfigProvider-Dkj-_a5x.d.ts → HoneyConfigProvider-COOuDNra.d.ts} +1 -1
- package/dist/actions/clients/exports.d.ts +77 -1
- package/dist/actions/clients/exports.mjs +13 -4
- package/dist/actions/exports.d.ts +121 -39
- package/dist/actions/exports.mjs +75 -34
- package/dist/actions/governance/exports.d.ts +3 -11
- package/dist/actions/governance/exports.mjs +3 -3
- package/dist/actions/server/exports.mjs +4 -4
- package/dist/{chunk-4Z4AK6SH.mjs → chunk-3JJLQ2JX.mjs} +3 -3
- package/dist/{chunk-EXIUPSFN.mjs → chunk-7YVNSDXG.mjs} +2 -2
- package/dist/{chunk-WXXOISTU.mjs → chunk-AUOPN6NK.mjs} +1 -1
- package/dist/{chunk-75M6TF7M.mjs → chunk-DQRH5VE3.mjs} +1 -1
- package/dist/{chunk-CDFWPU2R.mjs → chunk-E7YFXBBQ.mjs} +0 -124
- package/dist/{chunk-AFN4CVD3.mjs → chunk-GUURQAME.mjs} +1 -1
- package/dist/{chunk-KQUMKB66.mjs → chunk-GY6B3PD5.mjs} +1 -1
- package/dist/{chunk-HSSJKHZ4.mjs → chunk-HYDP32P6.mjs} +3 -3
- package/dist/{chunk-NPBQLVL3.mjs → chunk-IXIBY5FP.mjs} +2 -2
- package/dist/{chunk-J5I45WGQ.mjs → chunk-KHXJDYA4.mjs} +7 -0
- package/dist/chunk-MRQGHXAN.mjs +54 -0
- package/dist/{chunk-FFB5LFDW.mjs → chunk-QVHEM4BG.mjs} +2 -2
- package/dist/{chunk-3EARVV7K.mjs → chunk-SXUNCX5E.mjs} +22 -9
- package/dist/chunk-UD5IUNCW.mjs +34 -0
- package/dist/{chunk-QJIXTYTZ.mjs → chunk-VAA2FVPP.mjs} +162 -41
- package/dist/chunk-Y6THHG77.mjs +126 -0
- package/dist/{chunk-XIYN6AL6.mjs → chunk-ZLTMIFCZ.mjs} +10 -5
- package/dist/contexts/exports.d.ts +2 -2
- package/dist/contexts/exports.mjs +11 -9
- package/dist/enum/exports.d.ts +8 -2
- package/dist/errors/exports.mjs +5 -5
- package/dist/getProposalVotes-DAUrdX2n.d.ts +12 -0
- package/dist/{getValidatorQueuedOperatorAddress-Dw5KN5sh.d.ts → getValidatorQueuedOperatorAddress-Cxt-DlL_.d.ts} +2 -2
- package/dist/{global.d-BuGDKh4k.d.ts → global.d-q_LQWQqs.d.ts} +2 -4
- package/dist/hooks/exports.d.ts +114 -164
- package/dist/hooks/exports.mjs +535 -522
- package/dist/hooks/governance/exports.d.ts +20 -15
- package/dist/hooks/governance/exports.mjs +43 -41
- package/dist/{pol.d-CqPA9K6m.d.ts → pol.d-CeRgXBL8.d.ts} +33 -8
- package/dist/types/exports.d.ts +5 -5
- package/dist/{useHoneySwapState-vFmuFF0g.d.ts → useHoneySwapState-twi7NTaO.d.ts} +1 -1
- package/dist/utils/exports.d.ts +2 -2
- package/dist/utils/exports.mjs +15 -9
- package/package.json +9 -8
- package/src/actions/bend/getMaxDeposit.ts +28 -2
- package/src/actions/clients/exports.ts +3 -0
- package/src/actions/clients/fetchBeep.ts +34 -0
- package/src/actions/clients/fetchOpenApi.ts +97 -0
- package/src/actions/clients/fetchOpenApi.unit.test.ts +245 -0
- package/src/actions/clients/fetchRailwayBackend.ts +34 -0
- package/src/actions/enso/getEnsoUserTokensWithBalances.ts +18 -0
- package/src/actions/exports.ts +2 -0
- package/src/actions/honey/getChartData.ts +53 -12
- package/src/actions/honey/getHoney24hVolume.ts +34 -6
- package/src/actions/honey/getHoneyTxns.ts +93 -0
- package/src/actions/honey/getPythLatestPrices.ts +7 -0
- package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +1 -1
- package/src/actions/pol/getAutoclaimedIncentives.ts +21 -10
- package/src/actions/pol/getAutoclaimedIncentivesTxHash.ts +41 -0
- package/src/actions/pol/getBgtIncentiveDistributorPaused.ts +5 -12
- package/src/actions/pol/getEarnedStakedBeraVault.ts +20 -16
- package/src/actions/pol/getRewardVaults.ts +4 -4
- package/src/actions/pol/getStakingDailyAssets.ts +18 -14
- package/src/actions/validators/getValidatorIncentiveDistribution.ts +64 -12
- package/src/actions/validators/utils/getValidatorBoostApy.ts +1 -1
- package/src/contexts/SwrFallback.tsx +2 -1
- package/src/data/contracts.ts +4 -0
- package/src/errors/RequestError.ts +12 -3
- package/src/errors/RequestError.unit.test.ts +55 -0
- package/src/errors/errorMap.ts +8 -0
- package/src/errors/getRevertReason.integration.test.ts +5 -1
- package/src/hooks/bend/useGetConvertToAssets.ts +2 -3
- package/src/hooks/dex/useAggregatorsQuotes.ts +10 -10
- package/src/hooks/dex/useAggregatorsRouterFeeBps.ts +1 -1
- package/src/hooks/dex/useAllUserPools.ts +7 -5
- package/src/hooks/dex/useApiPool.ts +1 -1
- package/src/hooks/dex/useGlobalLiquidityAndSwapVolume.ts +1 -1
- package/src/hooks/dex/useOnChainPoolData.ts +1 -1
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +2 -2
- package/src/hooks/dex/usePoolEvents.ts +1 -2
- package/src/hooks/dex/usePoolHistoricalData.ts +2 -3
- package/src/hooks/dex/usePools.ts +4 -2
- package/src/hooks/dex/useSingleAggregatorQuote.ts +6 -18
- package/src/hooks/enso/useBendDemultiply.ts +3 -4
- package/src/hooks/enso/useBendMultiply.ts +3 -4
- package/src/hooks/enso/useBendZapSupply.ts +3 -4
- package/src/hooks/enso/useEnsoSwapBundle.ts +1 -1
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +3 -5
- package/src/hooks/enso/useEnsoWalletV2Address.ts +1 -1
- package/src/hooks/enso/useIsBendAuthorized.ts +1 -1
- package/src/hooks/enso/useZapStakeBera.ts +2 -2
- package/src/hooks/exports.ts +2 -0
- package/src/hooks/governance/useGetPastVotes.ts +1 -1
- package/src/hooks/governance/useHasVoted.ts +1 -1
- package/src/hooks/governance/useIsCanceller.ts +1 -1
- package/src/hooks/governance/usePollAllProposals.ts +13 -12
- package/src/hooks/governance/usePollProposal.ts +3 -3
- package/src/hooks/governance/usePollProposalThreshold.ts +1 -1
- package/src/hooks/governance/usePollProposalVotes.ts +23 -5
- package/src/hooks/governance/usePollUserDelegates.ts +3 -3
- package/src/hooks/governance/useProposalFromTx.ts +2 -1
- package/src/hooks/governance/useProposalSnapshot.ts +2 -3
- package/src/hooks/governance/useProposalState.ts +2 -2
- package/src/hooks/governance/useProposalTimelockState.ts +2 -1
- package/src/hooks/governance/useQuorum.ts +1 -2
- package/src/hooks/honey/useCappedGlobally.ts +3 -6
- package/src/hooks/honey/useCappedRelatively.ts +2 -2
- package/src/hooks/honey/useCollateralWeights.ts +3 -3
- package/src/hooks/honey/useHoney24hVolume.ts +1 -1
- package/src/hooks/honey/useHoneyBalances.ts +1 -1
- package/src/hooks/honey/useHoneyChartData.ts +1 -1
- package/src/hooks/honey/useHoneyVaultsBalance.ts +2 -3
- package/src/hooks/honey/useIsBadCollateralAsset.ts +4 -7
- package/src/hooks/honey/useIsBasketModeEnabled.ts +4 -7
- package/src/hooks/honey/usePythLatestPrices.ts +13 -9
- package/src/hooks/perps/usePythUpdateFee.ts +13 -11
- package/src/hooks/pol/useAutoclaimedIncentives.ts +2 -12
- package/src/hooks/pol/useAutoclaimedIncentivesTxHash.ts +44 -0
- package/src/hooks/pol/useBgtIncentiveDistributorPaused.ts +39 -0
- package/src/hooks/pol/useBgtUnstakedBalance.ts +2 -2
- package/src/hooks/pol/useClaimableFees.ts +1 -1
- package/src/hooks/pol/useHighestVaultsAPR.ts +4 -6
- package/src/hooks/pol/useOnChainRewardVault.ts +77 -72
- package/src/hooks/pol/usePollGlobalData.ts +2 -3
- package/src/hooks/pol/usePollMarkets.ts +2 -2
- package/src/hooks/pol/useQueuedBeraUnlock.ts +2 -2
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +2 -2
- package/src/hooks/pol/useRewardVault.ts +7 -6
- package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +4 -4
- package/src/hooks/pol/useRewardVaultFromToken.ts +1 -1
- package/src/hooks/pol/useRewardVaultIncentives.ts +1 -1
- package/src/hooks/pol/useRewardVaultRewards.ts +2 -2
- package/src/hooks/pol/useRewardVaults.ts +3 -6
- package/src/hooks/pol/useStakedAPR.ts +1 -2
- package/src/hooks/pol/useStakedData.ts +90 -41
- package/src/hooks/pol/useStakedSnapshots.ts +1 -1
- package/src/hooks/pol/useStakingVaultsMetadata.ts +1 -1
- package/src/hooks/pol/useTotalStakedAmount.ts +1 -2
- package/src/hooks/pol/useUserVaultInfo.ts +2 -2
- package/src/hooks/pol/useUserVaults.ts +2 -3
- package/src/hooks/pol/useVaultAddress.ts +1 -1
- package/src/hooks/pol/useVaultHistory.ts +1 -2
- package/src/hooks/pol/useVaultValidators.ts +2 -2
- package/src/hooks/tokens/useMultipleTokenInformation.ts +2 -2
- package/src/hooks/tokens/usePollAllowances.ts +3 -4
- package/src/hooks/tokens/usePollBalance.ts +2 -2
- package/src/hooks/tokens/usePollWalletBalances.ts +2 -2
- package/src/hooks/tokens/useStakingTokenInformation.ts +2 -2
- package/src/hooks/tokens/useTokenCurrentPrices.ts +11 -13
- package/src/hooks/tokens/useTokenInformation.ts +2 -2
- package/src/hooks/tokens/useTokenPrice.ts +2 -1
- package/src/hooks/tokens/useTokenPrices.ts +3 -4
- package/src/hooks/tokens/useTotalSupply.ts +1 -1
- package/src/hooks/tokens/useUnderlyingAsset.ts +1 -2
- package/src/hooks/useBlockToTimestamp.ts +1 -2
- package/src/hooks/useGetVerifiedAbi.ts +2 -1
- package/src/hooks/validators/useAllValidators.ts +2 -3
- package/src/hooks/validators/useApiEnrichedAllocation.ts +1 -1
- package/src/hooks/validators/useApiValidator.ts +3 -6
- package/src/hooks/validators/useBaselineRewardAllocation.ts +1 -2
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +1 -1
- package/src/hooks/validators/useDefaultRewardAllocation.ts +2 -3
- package/src/hooks/validators/useManagedValidatorRole.ts +2 -2
- package/src/hooks/validators/useOnChainValidator.ts +3 -3
- package/src/hooks/validators/useStakingPoolBatch.ts +3 -4
- package/src/hooks/validators/useUserActiveValidators.ts +2 -3
- package/src/hooks/validators/useUserBoostsOnValidator.ts +1 -1
- package/src/hooks/validators/useUserClaimableIncentives.ts +1 -1
- package/src/hooks/validators/useUserStakingPositions.ts +2 -1
- package/src/hooks/validators/useValidator.ts +4 -8
- package/src/hooks/validators/useValidatorAnalytics.ts +1 -1
- package/src/hooks/validators/useValidatorCommission.ts +2 -2
- package/src/hooks/validators/useValidatorIncentiveDistribution.ts +3 -3
- package/src/hooks/validators/useValidatorQueuedCommission.ts +2 -2
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +2 -2
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +2 -2
- package/src/hooks/validators/useValidatorRewardAllocation.ts +2 -2
- package/src/types/bribe-boost.d.ts +14 -3
- package/src/types/global.d.ts +3 -4
- package/src/types/pol.d.ts +17 -3
- package/src/utils/polyfillAbortSignalAny.ts +53 -0
- package/src/utils/polyfillAbortSignalAny.unit.test.ts +81 -0
- package/dist/polling-BKnyavLI.d.ts +0 -8
- /package/dist/{exports-BcUTGFUb.d.ts → getApolloClient-BcUTGFUb.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import useSWR from "swr";
|
|
2
1
|
import type { Address, PublicClient } from "viem";
|
|
3
2
|
|
|
4
3
|
import { usePublicClient } from "@berachain/wagmi/hooks";
|
|
4
|
+
import { useSWR } from "@berachain/utils/pkg/swr";
|
|
5
5
|
|
|
6
6
|
import { getValidatorRewardAllocation } from "../../actions/validators/getValidatorRewardAllocation";
|
|
7
7
|
import type { DefaultHookOptions } from "../../types/global";
|
|
@@ -25,7 +25,7 @@ export function useValidatorRewardAllocation(
|
|
|
25
25
|
});
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
...options
|
|
28
|
+
...options,
|
|
29
29
|
},
|
|
30
30
|
);
|
|
31
31
|
|
|
@@ -33,11 +33,22 @@ export interface BribeBoostRewardProof {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Response shape of GET /api/v1/wallets/:wallet/autoclaimed:
|
|
36
|
-
// { [wallet]: { [validatorPubkey]: { [tokenAddress]:
|
|
37
|
-
//
|
|
36
|
+
// { [wallet]: { [validatorPubkey]: { [tokenAddress]: { amount } } } }
|
|
37
|
+
// `amount` is a stringified bigint in token base units. The backend now
|
|
38
|
+
// aggregates across validators under a single fake pubkey (`0x000…000`),
|
|
39
|
+
// so consumers can collapse the validator dimension blindly.
|
|
38
40
|
export type AutoclaimedIncentivesResponse = Record<
|
|
39
41
|
Address,
|
|
40
|
-
Record<Address, Record<Address, string>>
|
|
42
|
+
Record<Address, Record<Address, { amount: string }>>
|
|
43
|
+
>;
|
|
44
|
+
|
|
45
|
+
// Response shape of GET /api/v1/wallets/:wallet/autoclaimed/txhash: same
|
|
46
|
+
// nesting, but each token leaf is `{ txhash }`. Tokens still pending are
|
|
47
|
+
// simply absent — when a token from `/autoclaimed` has no entry here, the
|
|
48
|
+
// bot hasn't distributed it yet.
|
|
49
|
+
export type AutoclaimedIncentivesTxHashResponse = Record<
|
|
50
|
+
Address,
|
|
51
|
+
Record<Address, Record<Address, { txhash: string }>>
|
|
41
52
|
>;
|
|
42
53
|
|
|
43
54
|
export interface BribeBoostValidatorApr {
|
package/src/types/global.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Config, GetWalletClientReturnType } from "@wagmi/core";
|
|
2
|
-
import type { SWRConfiguration, SWRResponse } from "swr";
|
|
3
2
|
import type {
|
|
4
3
|
Abi,
|
|
5
4
|
Account,
|
|
@@ -13,6 +12,8 @@ import type {
|
|
|
13
12
|
|
|
14
13
|
import type { BeraConfig, ChainId } from "@berachain/config";
|
|
15
14
|
|
|
15
|
+
import type { SWRConfiguration, SWRResponse } from "@berachain/utils/pkg/swr";
|
|
16
|
+
|
|
16
17
|
import type { ContractName } from "../enum/contracts";
|
|
17
18
|
import type { TransactionActionType } from "../enum/txnEnum";
|
|
18
19
|
import type {
|
|
@@ -20,9 +21,7 @@ import type {
|
|
|
20
21
|
TxnEventKeys,
|
|
21
22
|
} from "../hooks/useContractWrite/types";
|
|
22
23
|
|
|
23
|
-
export type DefaultHookOptions = {
|
|
24
|
-
opts?: SWRConfiguration & { isEnabled?: boolean };
|
|
25
|
-
};
|
|
24
|
+
export type DefaultHookOptions = SWRConfiguration & { isEnabled?: boolean };
|
|
26
25
|
|
|
27
26
|
export type DefaultHookReturnType<T = any> = Omit<
|
|
28
27
|
SWRResponse<T, any, any>,
|
package/src/types/pol.d.ts
CHANGED
|
@@ -55,10 +55,24 @@ export interface UserVaultInfo {
|
|
|
55
55
|
|
|
56
56
|
export type StakedBeraAsset = {
|
|
57
57
|
token: TokenWithMetadata;
|
|
58
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Staking APR, or `undefined` when unavailable (e.g. the APR backend is
|
|
60
|
+
* down). `undefined` lets the UI render a "—" placeholder instead of a
|
|
61
|
+
* misleading "0%".
|
|
62
|
+
*/
|
|
63
|
+
apr: number | undefined;
|
|
59
64
|
stakedAmount: number;
|
|
60
|
-
|
|
65
|
+
/**
|
|
66
|
+
* USD value of the staked amount, or `undefined` when the token price is
|
|
67
|
+
* unavailable (e.g. the price backend is down). `undefined` lets the UI
|
|
68
|
+
* render a "—" placeholder instead of a misleading "$0.00".
|
|
69
|
+
*/
|
|
70
|
+
stakedAmountUsd: number | undefined;
|
|
61
71
|
earnedAmount: number;
|
|
62
|
-
|
|
72
|
+
/**
|
|
73
|
+
* USD value of the earned amount, or `undefined` when the token price is
|
|
74
|
+
* unavailable. See {@link stakedAmountUsd}.
|
|
75
|
+
*/
|
|
76
|
+
earnedAmountUsd: number | undefined;
|
|
63
77
|
isLoadingEarnings?: boolean;
|
|
64
78
|
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polyfill for `AbortSignal.any`.
|
|
3
|
+
*
|
|
4
|
+
* `AbortSignal.any` ships in Chrome 116+, Safari 17.4+, Firefox 124+. Older
|
|
5
|
+
* environments — notably Android WebViews bundled with old Chromium (e.g.
|
|
6
|
+
* Chrome Mobile WebView 114) — lack it, and third-party libraries that call it
|
|
7
|
+
* (e.g. @pythnetwork/hermes-client) throw "AbortSignal.any is not a function".
|
|
8
|
+
*
|
|
9
|
+
* This installs a spec-compatible-enough fallback: it returns a controller's
|
|
10
|
+
* signal that aborts as soon as any of the input signals abort (propagating the
|
|
11
|
+
* abort reason). It is idempotent and a no-op when the native API exists.
|
|
12
|
+
*/
|
|
13
|
+
export function polyfillAbortSignalAny(): void {
|
|
14
|
+
if (typeof AbortSignal === "undefined") return;
|
|
15
|
+
if (typeof (AbortSignal as { any?: unknown }).any === "function") return;
|
|
16
|
+
|
|
17
|
+
(
|
|
18
|
+
AbortSignal as unknown as { any: (signals: AbortSignal[]) => AbortSignal }
|
|
19
|
+
).any = (signals: AbortSignal[]): AbortSignal => {
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
|
|
22
|
+
// Phase 1: if any signal is already aborted, short-circuit before attaching
|
|
23
|
+
// any listeners (attaching to the others would leave dangling listeners
|
|
24
|
+
// that never fire — the leak the WeakRef/FinalizationRegistry versions guard
|
|
25
|
+
// against; checking first avoids it without that machinery).
|
|
26
|
+
for (const signal of signals) {
|
|
27
|
+
if (signal.aborted) {
|
|
28
|
+
controller.abort(signal.reason);
|
|
29
|
+
return controller.signal;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Phase 2: forward the first abort, then detach every listener so none
|
|
34
|
+
// outlive the combined signal. Safe for our short-lived usage (per-request
|
|
35
|
+
// fetch signals that settle and are collected together).
|
|
36
|
+
const listeners: Array<() => void> = [];
|
|
37
|
+
const cleanup = () => {
|
|
38
|
+
for (let i = 0; i < signals.length; i++) {
|
|
39
|
+
signals[i].removeEventListener("abort", listeners[i]);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
for (const signal of signals) {
|
|
43
|
+
const onAbort = () => {
|
|
44
|
+
if (!controller.signal.aborted) controller.abort(signal.reason);
|
|
45
|
+
cleanup();
|
|
46
|
+
};
|
|
47
|
+
listeners.push(onAbort);
|
|
48
|
+
signal.addEventListener("abort", onAbort);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return controller.signal;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { polyfillAbortSignalAny } from "./polyfillAbortSignalAny.js";
|
|
4
|
+
|
|
5
|
+
describe("polyfillAbortSignalAny", () => {
|
|
6
|
+
const original = (AbortSignal as { any?: unknown }).any;
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
// restore whatever the runtime had (native or undefined)
|
|
10
|
+
(AbortSignal as { any?: unknown }).any = original;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("does not overwrite a native AbortSignal.any", () => {
|
|
14
|
+
const native = () => new AbortController().signal;
|
|
15
|
+
(AbortSignal as { any?: unknown }).any = native;
|
|
16
|
+
polyfillAbortSignalAny();
|
|
17
|
+
expect((AbortSignal as { any?: unknown }).any).toBe(native);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("installs a fallback when AbortSignal.any is missing", () => {
|
|
21
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
22
|
+
polyfillAbortSignalAny();
|
|
23
|
+
expect(typeof (AbortSignal as { any?: unknown }).any).toBe("function");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("aborts the combined signal when one input aborts", () => {
|
|
27
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
28
|
+
polyfillAbortSignalAny();
|
|
29
|
+
|
|
30
|
+
const a = new AbortController();
|
|
31
|
+
const b = new AbortController();
|
|
32
|
+
const combined = (
|
|
33
|
+
AbortSignal as unknown as { any: (s: AbortSignal[]) => AbortSignal }
|
|
34
|
+
).any([a.signal, b.signal]);
|
|
35
|
+
|
|
36
|
+
expect(combined.aborted).toBe(false);
|
|
37
|
+
b.abort("boom");
|
|
38
|
+
expect(combined.aborted).toBe(true);
|
|
39
|
+
expect(combined.reason).toBe("boom");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("removes listeners from all inputs once the combined signal aborts", () => {
|
|
43
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
44
|
+
polyfillAbortSignalAny();
|
|
45
|
+
|
|
46
|
+
const a = new AbortController();
|
|
47
|
+
const b = new AbortController();
|
|
48
|
+
const removed: AbortSignal[] = [];
|
|
49
|
+
for (const c of [a, b]) {
|
|
50
|
+
const orig = c.signal.removeEventListener.bind(c.signal);
|
|
51
|
+
c.signal.removeEventListener = ((...args: Parameters<typeof orig>) => {
|
|
52
|
+
removed.push(c.signal);
|
|
53
|
+
return orig(...args);
|
|
54
|
+
}) as typeof orig;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
(AbortSignal as unknown as { any: (s: AbortSignal[]) => AbortSignal }).any([
|
|
58
|
+
a.signal,
|
|
59
|
+
b.signal,
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
a.abort("x");
|
|
63
|
+
// both inputs should have had their abort listener detached, not just the firing one
|
|
64
|
+
expect(removed).toContain(a.signal);
|
|
65
|
+
expect(removed).toContain(b.signal);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("is already aborted if an input is already aborted", () => {
|
|
69
|
+
(AbortSignal as { any?: unknown }).any = undefined;
|
|
70
|
+
polyfillAbortSignalAny();
|
|
71
|
+
|
|
72
|
+
const a = new AbortController();
|
|
73
|
+
a.abort("early");
|
|
74
|
+
const combined = (
|
|
75
|
+
AbortSignal as unknown as { any: (s: AbortSignal[]) => AbortSignal }
|
|
76
|
+
).any([a.signal]);
|
|
77
|
+
|
|
78
|
+
expect(combined.aborted).toBe(true);
|
|
79
|
+
expect(combined.reason).toBe("early");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
File without changes
|