@agg-build/hooks 1.0.2 → 1.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/README.md +1 -1
- package/dist/{chunk-V6VNA7MX.mjs → chunk-553OI6M2.mjs} +565 -89
- package/dist/{chunk-NOYHQUW2.mjs → chunk-CWEJLBYY.mjs} +66 -11
- package/dist/{chunk-EB64HHYM.mjs → chunk-JWPZNCGY.mjs} +1 -1
- package/dist/deposit.d.mts +8 -2
- package/dist/deposit.d.ts +8 -2
- package/dist/deposit.js +215 -76
- package/dist/deposit.mjs +119 -66
- package/dist/index.d.mts +712 -42
- package/dist/index.d.ts +712 -42
- package/dist/index.js +1405 -357
- package/dist/index.mjs +681 -163
- package/dist/{use-sync-balances-B1_8tBKw.d.ts → use-sync-balances-CeD8qZWP.d.mts} +5 -2
- package/dist/{use-sync-balances-B1_8tBKw.d.mts → use-sync-balances-CeD8qZWP.d.ts} +5 -2
- package/dist/withdraw.d.mts +27 -3
- package/dist/withdraw.d.ts +27 -3
- package/dist/withdraw.js +178 -26
- package/dist/withdraw.mjs +4 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -82,8 +82,10 @@ __export(src_exports, {
|
|
|
82
82
|
MarketStatus: () => MarketStatus,
|
|
83
83
|
MatchStatus: () => MatchStatus,
|
|
84
84
|
MatchType: () => MatchType,
|
|
85
|
-
QueryClient: () =>
|
|
86
|
-
QueryClientProvider: () =>
|
|
85
|
+
QueryClient: () => import_react_query37.QueryClient,
|
|
86
|
+
QueryClientProvider: () => import_react_query37.QueryClientProvider,
|
|
87
|
+
RedeemRejectedError: () => RedeemRejectedError,
|
|
88
|
+
TradeSide: () => TradeSide,
|
|
87
89
|
TurnstileChallengeError: () => import_sdk4.TurnstileChallengeError,
|
|
88
90
|
Venue: () => Venue,
|
|
89
91
|
computeClosedPositionTotals: () => computeClosedPositionTotals,
|
|
@@ -98,9 +100,13 @@ __export(src_exports, {
|
|
|
98
100
|
getWalletAddressFromUserProfile: () => getWalletAddressFromUserProfile,
|
|
99
101
|
invalidateBalanceQueries: () => invalidateBalanceQueries,
|
|
100
102
|
invalidatePositionQueries: () => invalidatePositionQueries,
|
|
103
|
+
invalidateUserActivityQueries: () => invalidateUserActivityQueries,
|
|
104
|
+
invalidateUserMoneyState: () => invalidateUserMoneyState,
|
|
105
|
+
mergeBestPricesPreferringLive: () => mergeBestPricesPreferringLive,
|
|
101
106
|
optimizedImageUrl: () => optimizedImageUrl,
|
|
102
107
|
parseEmail: () => parseEmail,
|
|
103
108
|
parseEmailStrict: () => parseEmailStrict,
|
|
109
|
+
rangeToSeconds: () => rangeToSeconds,
|
|
104
110
|
requestAggAuthChooserOpen: () => requestAggAuthChooserOpen,
|
|
105
111
|
resolveAggUiLabels: () => resolveAggUiLabels,
|
|
106
112
|
resolveDefaultTradingMarket: () => resolveDefaultMarket,
|
|
@@ -108,6 +114,7 @@ __export(src_exports, {
|
|
|
108
114
|
resolveMarketTradingState: () => resolveMarketTradingState,
|
|
109
115
|
resolveMarketWinningOutcome: () => resolveMarketWinningOutcome,
|
|
110
116
|
resolveOrderEligibility: () => resolveOrderEligibility,
|
|
117
|
+
resolveRollingWindow: () => resolveRollingWindow,
|
|
111
118
|
resolveTradingStateKind: () => resolveTradingStateKind,
|
|
112
119
|
sortVenues: () => sortVenues,
|
|
113
120
|
timeRangeToInterval: () => timeRangeToInterval,
|
|
@@ -138,6 +145,7 @@ __export(src_exports, {
|
|
|
138
145
|
useGeoBlock: () => useGeoBlock,
|
|
139
146
|
useLabels: () => useLabels,
|
|
140
147
|
useLinkAccount: () => useLinkAccount,
|
|
148
|
+
useLiveBestPrices: () => useLiveBestPrices,
|
|
141
149
|
useLiveCandleOverlay: () => useLiveCandleOverlay,
|
|
142
150
|
useLiveCandles: () => useLiveCandles,
|
|
143
151
|
useLiveMarket: () => useLiveMarket,
|
|
@@ -147,6 +155,7 @@ __export(src_exports, {
|
|
|
147
155
|
useManagedBalances: () => useManagedBalances,
|
|
148
156
|
useMarketChart: () => useMarketChart,
|
|
149
157
|
useMarketOrderbook: () => useMarketOrderbook,
|
|
158
|
+
useMarketSearch: () => useMarketSearch,
|
|
150
159
|
useMidpoints: () => useMidpoints,
|
|
151
160
|
useOnBalanceUpdate: () => useOnBalanceUpdate,
|
|
152
161
|
useOnOrderSubmitted: () => useOnOrderSubmitted,
|
|
@@ -156,17 +165,21 @@ __export(src_exports, {
|
|
|
156
165
|
useOrderbookQuote: () => useOrderbookQuote,
|
|
157
166
|
useOrders: () => useOrders,
|
|
158
167
|
usePositions: () => usePositions,
|
|
159
|
-
useQueryClient: () =>
|
|
168
|
+
useQueryClient: () => import_react_query37.useQueryClient,
|
|
160
169
|
useQuoteManaged: () => useQuoteManaged,
|
|
161
170
|
useRampQuotes: () => useRampQuotes,
|
|
162
171
|
useRampSession: () => useRampSession,
|
|
163
172
|
useRedeem: () => useRedeem,
|
|
164
173
|
useRedeemEligibleCount: () => useRedeemEligibleCount,
|
|
174
|
+
useRedeemLifecycle: () => useRedeemLifecycle,
|
|
175
|
+
useRedeemLifecycles: () => useRedeemLifecycles,
|
|
176
|
+
useRollingChartWindow: () => useRollingChartWindow,
|
|
165
177
|
useSdkLabels: () => useSdkLabels,
|
|
166
178
|
useSdkUiConfig: () => useSdkUiConfig,
|
|
167
179
|
useSearch: () => useSearch,
|
|
168
180
|
useSmartRoute: () => useSmartRoute,
|
|
169
181
|
useSyncBalances: () => useSyncBalances,
|
|
182
|
+
useTradableVenues: () => useTradableVenues,
|
|
170
183
|
useUserActivity: () => useUserActivity,
|
|
171
184
|
useUserHoldings: () => useUserHoldings,
|
|
172
185
|
useVenueEvent: () => useVenueEvent,
|
|
@@ -175,9 +188,11 @@ __export(src_exports, {
|
|
|
175
188
|
useVenueMarkets: () => useVenueMarkets,
|
|
176
189
|
useViewportMidpoints: () => useViewportMidpoints,
|
|
177
190
|
useVisibleIds: () => useVisibleIds,
|
|
191
|
+
useWithdrawEstimate: () => useWithdrawEstimate,
|
|
178
192
|
useWithdrawFlow: () => useWithdrawFlow,
|
|
179
193
|
useWithdrawManaged: () => useWithdrawManaged,
|
|
180
|
-
useWithdrawalLifecycle: () => useWithdrawalLifecycle
|
|
194
|
+
useWithdrawalLifecycle: () => useWithdrawalLifecycle,
|
|
195
|
+
userActivityQueryKeys: () => userActivityQueryKeys
|
|
181
196
|
});
|
|
182
197
|
module.exports = __toCommonJS(src_exports);
|
|
183
198
|
|
|
@@ -303,7 +318,7 @@ var getVenueOrder = (venue) => {
|
|
|
303
318
|
var sortVenues = (venues) => [...venues].sort((a, b) => getVenueOrder(a) - getVenueOrder(b));
|
|
304
319
|
|
|
305
320
|
// src/index.ts
|
|
306
|
-
var
|
|
321
|
+
var import_react_query37 = require("@tanstack/react-query");
|
|
307
322
|
|
|
308
323
|
// src/candle-store.ts
|
|
309
324
|
var import_sdk = require("@agg-build/sdk");
|
|
@@ -437,7 +452,7 @@ var createAuthCallbackSession = (tokens) => {
|
|
|
437
452
|
};
|
|
438
453
|
};
|
|
439
454
|
var executeWalletAuthFlow = (input) => __async(null, null, function* () {
|
|
440
|
-
var _a, _b;
|
|
455
|
+
var _a, _b, _c, _d;
|
|
441
456
|
const address = input.options.address.trim();
|
|
442
457
|
const chain = (_a = input.options.chain) != null ? _a : "ethereum";
|
|
443
458
|
const provider = chain === "solana" ? "siws" : "siwe";
|
|
@@ -460,14 +475,14 @@ var executeWalletAuthFlow = (input) => __async(null, null, function* () {
|
|
|
460
475
|
uri: location.uri,
|
|
461
476
|
nonce: startResult.nonce,
|
|
462
477
|
chainId: typeof input.options.chainId === "string" ? input.options.chainId : "mainnet",
|
|
463
|
-
statement: input.options.statement
|
|
478
|
+
statement: (_c = startResult.statement) != null ? _c : input.options.statement
|
|
464
479
|
}) : input.client.buildSiweMessage({
|
|
465
480
|
domain: location.domain,
|
|
466
481
|
address,
|
|
467
482
|
uri: location.uri,
|
|
468
483
|
nonce: startResult.nonce,
|
|
469
484
|
chainId: typeof input.options.chainId === "number" ? input.options.chainId : void 0,
|
|
470
|
-
statement: input.options.statement
|
|
485
|
+
statement: (_d = startResult.statement) != null ? _d : input.options.statement
|
|
471
486
|
});
|
|
472
487
|
const signature = yield input.options.signMessage(message);
|
|
473
488
|
const result = yield input.client.verify({ message, signature });
|
|
@@ -648,6 +663,12 @@ var enUsLabels = {
|
|
|
648
663
|
max: "Max",
|
|
649
664
|
tokenLabel: "Receive token",
|
|
650
665
|
networkLabel: "Receive network",
|
|
666
|
+
estimatedFees: "Est. fees",
|
|
667
|
+
networkReserve: "Network reserve",
|
|
668
|
+
networkReserveTooltipAria: "Network reserve details",
|
|
669
|
+
networkReserveTooltipLineOne: "This reserve helps cover network and bridge costs.",
|
|
670
|
+
networkReserveTooltipLineTwo: "Any unused amount stays in your balance.",
|
|
671
|
+
youReceive: "You'll receive",
|
|
651
672
|
confirm: "Confirm withdrawal",
|
|
652
673
|
successTitle: "Withdrawal submitted",
|
|
653
674
|
successDescription: (tokenSymbol) => `Your ${tokenSymbol} withdrawal is being processed and will arrive shortly.`,
|
|
@@ -656,12 +677,16 @@ var enUsLabels = {
|
|
|
656
677
|
// terminal status — otherwise a finished withdrawal would keep showing
|
|
657
678
|
// "submitted / processing" forever and force the user to hard-refresh.
|
|
658
679
|
successTitleCompleted: "Withdrawal complete",
|
|
659
|
-
successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol}
|
|
680
|
+
successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol} has been successfully sent to your wallet.`,
|
|
660
681
|
successTitlePartial: "Withdrawal partially completed",
|
|
661
|
-
successDescriptionPartial: (
|
|
682
|
+
successDescriptionPartial: () => "Part of your withdrawal was completed successfully, but the remaining funds failed to transfer and were returned to your balance.",
|
|
662
683
|
successTitleFailed: "Withdrawal failed",
|
|
663
|
-
successDescriptionFailed: (
|
|
684
|
+
successDescriptionFailed: () => "We couldn't complete your withdrawal. Your funds were returned to your balance.",
|
|
685
|
+
retry: "Try Again",
|
|
686
|
+
close: "Close",
|
|
687
|
+
loadingDescription: "This may take a few minutes. You can safely close this window and check the status later in your activity.",
|
|
664
688
|
summary: {
|
|
689
|
+
requestedWithdrawal: "Requested withdrawal",
|
|
665
690
|
// The response is `pricingStatus: "unquoted"` — we don't know net
|
|
666
691
|
// output until on-chain settlement. Calling this "Amount received"
|
|
667
692
|
// would imply receipt before the lifecycle has confirmed. Keep it
|
|
@@ -679,6 +704,12 @@ var enUsLabels = {
|
|
|
679
704
|
completed: "Withdrawal complete.",
|
|
680
705
|
partial: "Withdrawal partially completed \u2014 see details below.",
|
|
681
706
|
failed: "Withdrawal failed.",
|
|
707
|
+
loadingSteps: {
|
|
708
|
+
preparing: "Preparing funds",
|
|
709
|
+
bridging: "Bridging between networks",
|
|
710
|
+
sending: "Sending to your wallet",
|
|
711
|
+
confirming: "Waiting for network confirmation"
|
|
712
|
+
},
|
|
682
713
|
steps: {
|
|
683
714
|
bridge: (sourceChainName, destChainName) => `Bridging from ${sourceChainName} to ${destChainName}`,
|
|
684
715
|
transfer: (destChainName) => `Transferring on ${destChainName}`
|
|
@@ -734,24 +765,66 @@ var enUsLabels = {
|
|
|
734
765
|
externalWallet: "Deposit from external wallet",
|
|
735
766
|
card: "Deposit with card"
|
|
736
767
|
},
|
|
768
|
+
depositStatusTitles: {
|
|
769
|
+
connectedWallet: {
|
|
770
|
+
pending: "Processing deposit from connected wallet",
|
|
771
|
+
completed: "Successful deposit from connected wallet",
|
|
772
|
+
failed: "Failed deposit from connected wallet",
|
|
773
|
+
canceled: "Canceled deposit from connected wallet"
|
|
774
|
+
},
|
|
775
|
+
externalWallet: {
|
|
776
|
+
pending: "Processing deposit from external wallet",
|
|
777
|
+
completed: "Successful deposit from external wallet",
|
|
778
|
+
failed: "Failed deposit from external wallet",
|
|
779
|
+
canceled: "Canceled deposit from external wallet"
|
|
780
|
+
},
|
|
781
|
+
card: {
|
|
782
|
+
pending: "Processing deposit with card",
|
|
783
|
+
completed: "Successful deposit with card",
|
|
784
|
+
failed: "Failed deposit with card",
|
|
785
|
+
canceled: "Canceled deposit with card"
|
|
786
|
+
}
|
|
787
|
+
},
|
|
788
|
+
withdrawalStatusTitles: {
|
|
789
|
+
pending: "Processing withdrawal",
|
|
790
|
+
completed: "Successful withdrawal",
|
|
791
|
+
failed: "Failed withdrawal",
|
|
792
|
+
canceled: "Canceled withdrawal"
|
|
793
|
+
},
|
|
737
794
|
// Activity-row title for any withdrawal regardless of lifecycle
|
|
738
|
-
// state
|
|
739
|
-
//
|
|
740
|
-
//
|
|
795
|
+
// state — render the asset rather than implying success. The
|
|
796
|
+
// ActivityRow renders a separate status chip when the row is
|
|
797
|
+
// failed. Retained for partner overrides that still want a
|
|
798
|
+
// status-agnostic title.
|
|
741
799
|
withdrawalTitle: (tokenSymbol) => `Withdraw ${tokenSymbol}`
|
|
742
800
|
},
|
|
743
801
|
positions: {
|
|
802
|
+
activeFilter: "Active",
|
|
803
|
+
closedFilter: "Closed",
|
|
804
|
+
marketHeader: "Market",
|
|
744
805
|
totalTradedHeader: "Total traded",
|
|
806
|
+
currentValueHeader: "Current value",
|
|
807
|
+
statusHeader: "Status",
|
|
808
|
+
resolutionHeader: "Resolution",
|
|
809
|
+
payoutHeader: "Payout",
|
|
810
|
+
resultHeader: "Result",
|
|
745
811
|
amountWonHeader: "Amount won",
|
|
746
812
|
claimHeader: "Claim",
|
|
747
813
|
claim: "Claim",
|
|
748
814
|
claimed: "Claimed",
|
|
749
815
|
pending: "Pending",
|
|
816
|
+
open: "Open",
|
|
750
817
|
won: "Won",
|
|
751
818
|
lost: "Lost",
|
|
819
|
+
sold: "Sold",
|
|
752
820
|
resolved: "Resolved",
|
|
753
821
|
marketClosed: "Market closed",
|
|
754
|
-
closed: "Closed"
|
|
822
|
+
closed: "Closed",
|
|
823
|
+
searchPlaceholder: "Search...",
|
|
824
|
+
noResults: "No results",
|
|
825
|
+
avgPrefix: "avg",
|
|
826
|
+
nowPrefix: "now",
|
|
827
|
+
finalPrefix: "final"
|
|
755
828
|
}
|
|
756
829
|
},
|
|
757
830
|
eventList: {
|
|
@@ -889,7 +962,7 @@ var enUsLabels = {
|
|
|
889
962
|
settlementEmpty: "No settlement details available.",
|
|
890
963
|
disclaimer: "By trading, you agree to the Terms of Use of each exchange.",
|
|
891
964
|
geoBlockTermsLink: "Terms of Use",
|
|
892
|
-
geoBlockGenericMessage: "
|
|
965
|
+
geoBlockGenericMessage: "None of the venues for this market are available in your region. See ",
|
|
893
966
|
geoBlockVenueMessage: (venueLabel) => `Trading on ${venueLabel} is not available in your region. See `,
|
|
894
967
|
geoBlockMessageSuffix: " for more information.",
|
|
895
968
|
geoBlockModalAriaLabel: "Geo-restricted location",
|
|
@@ -943,6 +1016,7 @@ var enUsLabels = {
|
|
|
943
1016
|
noMarketSelected: "Select a market to place an order.",
|
|
944
1017
|
noOrderbooks: "No live orderbooks are available for this market right now.",
|
|
945
1018
|
quoteUnavailable: "Quote temporarily unavailable. Please try again.",
|
|
1019
|
+
quoteBalanceMismatch: "Quote balance mismatch. Try a different amount.",
|
|
946
1020
|
selectedVenueUnavailable: "The venue you selected is no longer available on this route. Review the updated options and try again.",
|
|
947
1021
|
engineUnavailable: "The routing engine is temporarily unavailable. Please try again in a moment.",
|
|
948
1022
|
insufficientInputAmount: "Trade amount is too small to cover bridging and execution costs. Increase your spend or deposit funds on the destination chain.",
|
|
@@ -969,10 +1043,18 @@ var enUsLabels = {
|
|
|
969
1043
|
splitOrderDescription: "We split your order for the best price:",
|
|
970
1044
|
viewAllRoutes: (count) => `View all (${count})`,
|
|
971
1045
|
venueUnavailableInRegion: "Unavailable in your region",
|
|
1046
|
+
platformFee: "0% platform fees",
|
|
1047
|
+
estimatedFees: "Estimated fees",
|
|
1048
|
+
estimatedFeesTooltipAria: "Estimated fees breakdown",
|
|
1049
|
+
feeBreakdownVenueFees: "Venue fees",
|
|
1050
|
+
feeBreakdownBridgeFees: "Bridge fees",
|
|
1051
|
+
feeBreakdownExecutionGas: "Execution gas",
|
|
1052
|
+
feeBreakdownTotalFees: "Total fees",
|
|
972
1053
|
toWin: (tab) => tab === "buy" ? "To win" : "Payout",
|
|
973
1054
|
buyingOutcome: (label) => `Buying ${label}`,
|
|
974
1055
|
sellingOutcome: (label) => `Selling ${label}`,
|
|
975
1056
|
findingBestRoute: "Finding the best route...",
|
|
1057
|
+
checkingBalance: "Checking balance",
|
|
976
1058
|
submittingOrderProgress: "Submitting order...",
|
|
977
1059
|
orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
|
|
978
1060
|
executingOnVenue: (venueLabel) => `Executing on ${venueLabel}...`,
|
|
@@ -1231,6 +1313,7 @@ var defaultAggUiSearchConfig = {
|
|
|
1231
1313
|
var defaultAggUiConfig = {
|
|
1232
1314
|
enableLogs: false,
|
|
1233
1315
|
enableWebsocketsLogs: false,
|
|
1316
|
+
enableDebug: false,
|
|
1234
1317
|
general: {
|
|
1235
1318
|
locale: DEFAULT_LOCALE,
|
|
1236
1319
|
theme: "light",
|
|
@@ -1240,6 +1323,7 @@ var defaultAggUiConfig = {
|
|
|
1240
1323
|
features: {
|
|
1241
1324
|
enableAnimations: true,
|
|
1242
1325
|
enableLiveUpdates: true,
|
|
1326
|
+
showFeesBreakdown: false,
|
|
1243
1327
|
enableGradients: false
|
|
1244
1328
|
},
|
|
1245
1329
|
market: {
|
|
@@ -1267,7 +1351,7 @@ var mergeAggUiSearchConfig = (config) => {
|
|
|
1267
1351
|
};
|
|
1268
1352
|
};
|
|
1269
1353
|
var mergeAggUiConfig = (persisted, config) => {
|
|
1270
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K;
|
|
1354
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N;
|
|
1271
1355
|
const locale = (_d = (_c = (_a = config == null ? void 0 : config.general) == null ? void 0 : _a.locale) != null ? _c : (_b = persisted.general) == null ? void 0 : _b.locale) != null ? _d : DEFAULT_LOCALE;
|
|
1272
1356
|
const theme = (_h = (_g = (_e = config == null ? void 0 : config.general) == null ? void 0 : _e.theme) != null ? _g : (_f = persisted.general) == null ? void 0 : _f.theme) != null ? _h : defaultAggUiConfig.general.theme;
|
|
1273
1357
|
const formatters = createFormatters(locale);
|
|
@@ -1275,31 +1359,33 @@ var mergeAggUiConfig = (persisted, config) => {
|
|
|
1275
1359
|
return {
|
|
1276
1360
|
enableLogs: (_i = config == null ? void 0 : config.enableLogs) != null ? _i : defaultAggUiConfig.enableLogs,
|
|
1277
1361
|
enableWebsocketsLogs: (_j = config == null ? void 0 : config.enableWebsocketsLogs) != null ? _j : defaultAggUiConfig.enableWebsocketsLogs,
|
|
1362
|
+
enableDebug: (_k = config == null ? void 0 : config.enableDebug) != null ? _k : defaultAggUiConfig.enableDebug,
|
|
1278
1363
|
general: {
|
|
1279
1364
|
locale,
|
|
1280
1365
|
theme,
|
|
1281
|
-
rootClassName: (
|
|
1282
|
-
labels: mergeAggUiLabels(defaultLabels, (
|
|
1366
|
+
rootClassName: (_m = (_l = config == null ? void 0 : config.general) == null ? void 0 : _l.rootClassName) != null ? _m : defaultAggUiConfig.general.rootClassName,
|
|
1367
|
+
labels: mergeAggUiLabels(defaultLabels, (_n = config == null ? void 0 : config.general) == null ? void 0 : _n.labels)
|
|
1283
1368
|
},
|
|
1284
1369
|
features: {
|
|
1285
|
-
enableAnimations: (
|
|
1286
|
-
enableLiveUpdates: (
|
|
1287
|
-
|
|
1370
|
+
enableAnimations: (_p = (_o = config == null ? void 0 : config.features) == null ? void 0 : _o.enableAnimations) != null ? _p : defaultAggUiConfig.features.enableAnimations,
|
|
1371
|
+
enableLiveUpdates: (_r = (_q = config == null ? void 0 : config.features) == null ? void 0 : _q.enableLiveUpdates) != null ? _r : defaultAggUiConfig.features.enableLiveUpdates,
|
|
1372
|
+
showFeesBreakdown: (_t = (_s = config == null ? void 0 : config.features) == null ? void 0 : _s.showFeesBreakdown) != null ? _t : defaultAggUiConfig.features.showFeesBreakdown,
|
|
1373
|
+
enableGradients: (_v = (_u = config == null ? void 0 : config.features) == null ? void 0 : _u.enableGradients) != null ? _v : defaultAggUiConfig.features.enableGradients
|
|
1288
1374
|
},
|
|
1289
1375
|
market: {
|
|
1290
|
-
arbitrageThreshold: (
|
|
1376
|
+
arbitrageThreshold: (_x = (_w = config == null ? void 0 : config.market) == null ? void 0 : _w.arbitrageThreshold) != null ? _x : defaultAggUiConfig.market.arbitrageThreshold
|
|
1291
1377
|
},
|
|
1292
1378
|
chart: {
|
|
1293
|
-
defaultChartTimeRange: (
|
|
1294
|
-
selectedChartTimeRange: (
|
|
1379
|
+
defaultChartTimeRange: (_z = (_y = config == null ? void 0 : config.chart) == null ? void 0 : _y.defaultChartTimeRange) != null ? _z : defaultAggUiConfig.chart.defaultChartTimeRange,
|
|
1380
|
+
selectedChartTimeRange: (_D = (_C = (_A = persisted.chart) == null ? void 0 : _A.selectedChartTimeRange) != null ? _C : (_B = config == null ? void 0 : config.chart) == null ? void 0 : _B.defaultChartTimeRange) != null ? _D : defaultAggUiConfig.chart.defaultChartTimeRange,
|
|
1295
1381
|
setSelectedChartTimeRange: defaultAggUiConfig.chart.setSelectedChartTimeRange
|
|
1296
1382
|
},
|
|
1297
1383
|
formatting: {
|
|
1298
|
-
formatNumber: (
|
|
1299
|
-
formatPercent: (
|
|
1300
|
-
formatCurrency: (
|
|
1301
|
-
formatCompactCurrency: (
|
|
1302
|
-
formatDate: (
|
|
1384
|
+
formatNumber: (_F = (_E = config == null ? void 0 : config.formatting) == null ? void 0 : _E.formatNumber) != null ? _F : formatters.formatNumber,
|
|
1385
|
+
formatPercent: (_H = (_G = config == null ? void 0 : config.formatting) == null ? void 0 : _G.formatPercent) != null ? _H : formatters.formatPercent,
|
|
1386
|
+
formatCurrency: (_J = (_I = config == null ? void 0 : config.formatting) == null ? void 0 : _I.formatCurrency) != null ? _J : formatters.formatCurrency,
|
|
1387
|
+
formatCompactCurrency: (_L = (_K = config == null ? void 0 : config.formatting) == null ? void 0 : _K.formatCompactCurrency) != null ? _L : formatters.formatCompactCurrency,
|
|
1388
|
+
formatDate: (_N = (_M = config == null ? void 0 : config.formatting) == null ? void 0 : _M.formatDate) != null ? _N : formatters.formatDate
|
|
1303
1389
|
},
|
|
1304
1390
|
search: mergeAggUiSearchConfig(config == null ? void 0 : config.search),
|
|
1305
1391
|
walletActions: config == null ? void 0 : config.walletActions,
|
|
@@ -1601,6 +1687,26 @@ var shouldInvalidateBalancesForOrderEvent = (event, currentUserId) => {
|
|
|
1601
1687
|
if (!currentUserId) return true;
|
|
1602
1688
|
return event.userId === currentUserId;
|
|
1603
1689
|
};
|
|
1690
|
+
var userActivityQueryKeys = {
|
|
1691
|
+
all: () => ["user-activity"]
|
|
1692
|
+
};
|
|
1693
|
+
var invalidateUserActivityQueries = (queryClient, options) => {
|
|
1694
|
+
var _a;
|
|
1695
|
+
const strategy = (_a = options == null ? void 0 : options.strategy) != null ? _a : "remove";
|
|
1696
|
+
if (strategy === "remove") {
|
|
1697
|
+
queryClient.removeQueries({ queryKey: userActivityQueryKeys.all() });
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
queryClient.invalidateQueries({
|
|
1701
|
+
queryKey: userActivityQueryKeys.all(),
|
|
1702
|
+
refetchType: "all"
|
|
1703
|
+
});
|
|
1704
|
+
};
|
|
1705
|
+
var invalidateUserMoneyState = (queryClient, options) => {
|
|
1706
|
+
invalidateBalanceQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
|
|
1707
|
+
invalidatePositionQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
|
|
1708
|
+
invalidateUserActivityQueries(queryClient, { strategy: options == null ? void 0 : options.activityStrategy });
|
|
1709
|
+
};
|
|
1604
1710
|
|
|
1605
1711
|
// src/core/providers/balance-provider.tsx
|
|
1606
1712
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -1609,6 +1715,7 @@ var CHAIN_LABELS = {
|
|
|
1609
1715
|
10: "Optimism",
|
|
1610
1716
|
56: "BNB",
|
|
1611
1717
|
137: "Polygon",
|
|
1718
|
+
1337: "Hyperliquid",
|
|
1612
1719
|
8453: "Base",
|
|
1613
1720
|
42161: "Arbitrum",
|
|
1614
1721
|
43114: "Avalanche",
|
|
@@ -1648,7 +1755,9 @@ function AggBalanceProvider({ children }) {
|
|
|
1648
1755
|
return client.getManagedBalances();
|
|
1649
1756
|
}),
|
|
1650
1757
|
enabled: Boolean(client && isAuthenticated),
|
|
1651
|
-
staleTime:
|
|
1758
|
+
staleTime: 60 * 1e3,
|
|
1759
|
+
refetchOnWindowFocus: "always",
|
|
1760
|
+
refetchOnReconnect: "always"
|
|
1652
1761
|
});
|
|
1653
1762
|
const managedBalancesData = balancesQuery.data;
|
|
1654
1763
|
const managedBalances = (0, import_react3.useMemo)(
|
|
@@ -1808,6 +1917,7 @@ var import_react6 = require("react");
|
|
|
1808
1917
|
var import_react_query2 = require("@tanstack/react-query");
|
|
1809
1918
|
|
|
1810
1919
|
// src/market-data/chart-cache.ts
|
|
1920
|
+
var MAX_CACHE_RETENTION_SECONDS = 7 * 30 * 24 * 60 * 60 + 14 * 24 * 60 * 60;
|
|
1811
1921
|
var getIntervalSeconds = (interval) => {
|
|
1812
1922
|
switch (interval) {
|
|
1813
1923
|
case "1m":
|
|
@@ -1826,12 +1936,41 @@ var createVenueData = (venue, outcomeIds = []) => ({
|
|
|
1826
1936
|
candles: [],
|
|
1827
1937
|
liveCandle: null,
|
|
1828
1938
|
lineValue: void 0,
|
|
1829
|
-
lastTrade: null
|
|
1939
|
+
lastTrade: null,
|
|
1940
|
+
lastUpdateTs: null
|
|
1830
1941
|
});
|
|
1942
|
+
var pruneCandlesBefore = (candles, cutoffTs) => {
|
|
1943
|
+
if (cutoffTs <= 0) return candles;
|
|
1944
|
+
let firstKeptIndex = 0;
|
|
1945
|
+
while (firstKeptIndex < candles.length && candles[firstKeptIndex].time < cutoffTs) {
|
|
1946
|
+
firstKeptIndex += 1;
|
|
1947
|
+
}
|
|
1948
|
+
if (firstKeptIndex === 0) return candles;
|
|
1949
|
+
return candles.slice(firstKeptIndex);
|
|
1950
|
+
};
|
|
1951
|
+
var promoteClosedLiveCandle = (candles, liveCandle, expectedCandleTime) => {
|
|
1952
|
+
if (!liveCandle || liveCandle.time >= expectedCandleTime) {
|
|
1953
|
+
return { candles, promoted: false };
|
|
1954
|
+
}
|
|
1955
|
+
if (candles.some((candle) => candle.time === liveCandle.time)) {
|
|
1956
|
+
return { candles, promoted: false };
|
|
1957
|
+
}
|
|
1958
|
+
return { candles: sortCandles([...candles, liveCandle]), promoted: true };
|
|
1959
|
+
};
|
|
1960
|
+
var resolveMaxLastUpdateTs = (venues) => {
|
|
1961
|
+
let max = null;
|
|
1962
|
+
for (const venueData of Object.values(venues)) {
|
|
1963
|
+
if (venueData.lastUpdateTs != null && (max == null || venueData.lastUpdateTs > max)) {
|
|
1964
|
+
max = venueData.lastUpdateTs;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
return max;
|
|
1968
|
+
};
|
|
1831
1969
|
var sortCandles = (candles) => {
|
|
1832
1970
|
return [...candles].sort((left, right) => left.time - right.time);
|
|
1833
1971
|
};
|
|
1834
1972
|
var createMarketChartData = (params) => {
|
|
1973
|
+
var _a;
|
|
1835
1974
|
const candles = sortCandles(
|
|
1836
1975
|
params.response.data.map((candle) => ({
|
|
1837
1976
|
time: Math.floor(candle.t / 1e3),
|
|
@@ -1844,6 +1983,7 @@ var createMarketChartData = (params) => {
|
|
|
1844
1983
|
}))
|
|
1845
1984
|
);
|
|
1846
1985
|
const lastCandle = candles[candles.length - 1];
|
|
1986
|
+
const lastUpdateTs = (_a = lastCandle == null ? void 0 : lastCandle.time) != null ? _a : null;
|
|
1847
1987
|
const venues = {
|
|
1848
1988
|
[params.response.venue]: {
|
|
1849
1989
|
venue: params.response.venue,
|
|
@@ -1851,7 +1991,8 @@ var createMarketChartData = (params) => {
|
|
|
1851
1991
|
candles,
|
|
1852
1992
|
liveCandle: null,
|
|
1853
1993
|
lineValue: lastCandle == null ? void 0 : lastCandle.close,
|
|
1854
|
-
lastTrade: null
|
|
1994
|
+
lastTrade: null,
|
|
1995
|
+
lastUpdateTs
|
|
1855
1996
|
}
|
|
1856
1997
|
};
|
|
1857
1998
|
return {
|
|
@@ -1861,7 +2002,8 @@ var createMarketChartData = (params) => {
|
|
|
1861
2002
|
interval: params.interval,
|
|
1862
2003
|
startTs: params.startTs,
|
|
1863
2004
|
endTs: params.endTs,
|
|
1864
|
-
venues
|
|
2005
|
+
venues,
|
|
2006
|
+
lastUpdateTs
|
|
1865
2007
|
};
|
|
1866
2008
|
};
|
|
1867
2009
|
var mergeMarketChartData = (params) => {
|
|
@@ -1895,9 +2037,75 @@ var mergeMarketChartData = (params) => {
|
|
|
1895
2037
|
interval: params.interval,
|
|
1896
2038
|
startTs: params.startTs,
|
|
1897
2039
|
endTs: params.endTs,
|
|
1898
|
-
venues
|
|
2040
|
+
venues,
|
|
2041
|
+
lastUpdateTs: resolveMaxLastUpdateTs(venues)
|
|
1899
2042
|
};
|
|
1900
2043
|
};
|
|
2044
|
+
var applyMidpointToMarketChart = (data, update) => {
|
|
2045
|
+
var _a;
|
|
2046
|
+
if (!data || !Number.isFinite(update.midpoint)) {
|
|
2047
|
+
return data;
|
|
2048
|
+
}
|
|
2049
|
+
const targetVenueEntry = Object.entries(data.venues).find(
|
|
2050
|
+
([, venueData]) => venueData.outcomeIds.includes(update.outcomeId)
|
|
2051
|
+
);
|
|
2052
|
+
if (!targetVenueEntry && data.marketId !== update.outcomeId) {
|
|
2053
|
+
return data;
|
|
2054
|
+
}
|
|
2055
|
+
const [targetVenueName, currentVenue] = targetVenueEntry != null ? targetVenueEntry : [
|
|
2056
|
+
data.primaryVenue,
|
|
2057
|
+
(_a = data.venues[data.primaryVenue]) != null ? _a : createVenueData(data.primaryVenue, [update.outcomeId])
|
|
2058
|
+
];
|
|
2059
|
+
const intervalSeconds = getIntervalSeconds(data.interval);
|
|
2060
|
+
const expectedCandleTime = update.timestamp - update.timestamp % intervalSeconds;
|
|
2061
|
+
let liveCandle = currentVenue.liveCandle;
|
|
2062
|
+
const { candles: promotedCandles } = promoteClosedLiveCandle(
|
|
2063
|
+
currentVenue.candles,
|
|
2064
|
+
liveCandle,
|
|
2065
|
+
expectedCandleTime
|
|
2066
|
+
);
|
|
2067
|
+
const nextCandles = pruneCandlesBefore(
|
|
2068
|
+
promotedCandles,
|
|
2069
|
+
update.timestamp - MAX_CACHE_RETENTION_SECONDS
|
|
2070
|
+
);
|
|
2071
|
+
if (liveCandle && liveCandle.time === expectedCandleTime) {
|
|
2072
|
+
if (liveCandle.source === "trade") {
|
|
2073
|
+
liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
|
|
2074
|
+
close: update.midpoint
|
|
2075
|
+
});
|
|
2076
|
+
} else {
|
|
2077
|
+
liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
|
|
2078
|
+
close: update.midpoint,
|
|
2079
|
+
high: Math.max(liveCandle.high, update.midpoint),
|
|
2080
|
+
low: Math.min(liveCandle.low, update.midpoint),
|
|
2081
|
+
source: "midpoint"
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
} else {
|
|
2085
|
+
liveCandle = {
|
|
2086
|
+
time: expectedCandleTime,
|
|
2087
|
+
open: update.midpoint,
|
|
2088
|
+
high: update.midpoint,
|
|
2089
|
+
low: update.midpoint,
|
|
2090
|
+
close: update.midpoint,
|
|
2091
|
+
volume: 0,
|
|
2092
|
+
source: "midpoint"
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
const nextVenues = __spreadProps(__spreadValues({}, data.venues), {
|
|
2096
|
+
[targetVenueName]: __spreadProps(__spreadValues({}, currentVenue), {
|
|
2097
|
+
outcomeIds: currentVenue.outcomeIds.includes(update.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, update.outcomeId],
|
|
2098
|
+
candles: nextCandles,
|
|
2099
|
+
liveCandle,
|
|
2100
|
+
lineValue: update.midpoint,
|
|
2101
|
+
lastUpdateTs: update.timestamp
|
|
2102
|
+
})
|
|
2103
|
+
});
|
|
2104
|
+
return __spreadProps(__spreadValues({}, data), {
|
|
2105
|
+
venues: nextVenues,
|
|
2106
|
+
lastUpdateTs: resolveMaxLastUpdateTs(nextVenues)
|
|
2107
|
+
});
|
|
2108
|
+
};
|
|
1901
2109
|
var applyTradeToMarketChart = (data, trade) => {
|
|
1902
2110
|
var _a, _b, _c;
|
|
1903
2111
|
if (!data || data.marketId !== trade.outcomeId) {
|
|
@@ -1907,6 +2115,15 @@ var applyTradeToMarketChart = (data, trade) => {
|
|
|
1907
2115
|
const intervalSeconds = getIntervalSeconds(data.interval);
|
|
1908
2116
|
const expectedCandleTime = trade.timestamp - trade.timestamp % intervalSeconds;
|
|
1909
2117
|
let liveCandle = currentVenue.liveCandle;
|
|
2118
|
+
const { candles: promotedCandles } = promoteClosedLiveCandle(
|
|
2119
|
+
currentVenue.candles,
|
|
2120
|
+
liveCandle,
|
|
2121
|
+
expectedCandleTime
|
|
2122
|
+
);
|
|
2123
|
+
const nextCandles = pruneCandlesBefore(
|
|
2124
|
+
promotedCandles,
|
|
2125
|
+
trade.timestamp - MAX_CACHE_RETENTION_SECONDS
|
|
2126
|
+
);
|
|
1910
2127
|
if (liveCandle && liveCandle.time === expectedCandleTime) {
|
|
1911
2128
|
liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
|
|
1912
2129
|
close: trade.price,
|
|
@@ -1926,16 +2143,20 @@ var applyTradeToMarketChart = (data, trade) => {
|
|
|
1926
2143
|
source: "trade"
|
|
1927
2144
|
};
|
|
1928
2145
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
2146
|
+
const nextVenues = __spreadProps(__spreadValues({}, data.venues), {
|
|
2147
|
+
[trade.venue]: __spreadProps(__spreadValues({}, currentVenue), {
|
|
2148
|
+
outcomeIds: currentVenue.outcomeIds.includes(trade.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, trade.outcomeId],
|
|
2149
|
+
candles: nextCandles,
|
|
2150
|
+
liveCandle,
|
|
2151
|
+
lineValue: (_c = liveCandle == null ? void 0 : liveCandle.close) != null ? _c : trade.price,
|
|
2152
|
+
lastTrade: trade,
|
|
2153
|
+
lastUpdateTs: trade.timestamp
|
|
1937
2154
|
})
|
|
1938
2155
|
});
|
|
2156
|
+
return __spreadProps(__spreadValues({}, data), {
|
|
2157
|
+
venues: nextVenues,
|
|
2158
|
+
lastUpdateTs: resolveMaxLastUpdateTs(nextVenues)
|
|
2159
|
+
});
|
|
1939
2160
|
};
|
|
1940
2161
|
|
|
1941
2162
|
// src/market-data/live-cache.ts
|
|
@@ -2126,7 +2347,15 @@ var marketDataKeys = {
|
|
|
2126
2347
|
orderbook: (marketId, selectionKey, depth) => ["market-data", "orderbook", marketId, selectionKey != null ? selectionKey : null, depth != null ? depth : null],
|
|
2127
2348
|
orderbookPrefix: (marketId) => marketId == null ? ["market-data", "orderbook"] : ["market-data", "orderbook", marketId],
|
|
2128
2349
|
orderbookQuote: (marketId, side, size) => ["market-data", "orderbook-quote", marketId, side, size],
|
|
2129
|
-
|
|
2350
|
+
/**
|
|
2351
|
+
* Stable per `{marketId, interval, rangeKey}`. Deliberately excludes the
|
|
2352
|
+
* concrete `startTs`/`endTs` of the rolling window — those advance every
|
|
2353
|
+
* candle bucket, and including them would mint a fresh key on every
|
|
2354
|
+
* rollover, defeating React Query's cache on tab/page revisits. The
|
|
2355
|
+
* current window is passed to `queryFn` via closure instead, and
|
|
2356
|
+
* `refetchInterval` advances the data under the stable key.
|
|
2357
|
+
*/
|
|
2358
|
+
chart: (marketId, interval, rangeKey, countBack) => ["market-data", "chart", marketId, interval, rangeKey, countBack != null ? countBack : null],
|
|
2130
2359
|
chartPrefix: (marketId, interval) => {
|
|
2131
2360
|
if (!marketId) return ["market-data", "chart"];
|
|
2132
2361
|
if (!interval) return ["market-data", "chart", marketId];
|
|
@@ -2371,6 +2600,9 @@ function AggWebSocketProvider({ children }) {
|
|
|
2371
2600
|
const invalidatePositionCaches = (0, import_react6.useCallback)(() => {
|
|
2372
2601
|
invalidatePositionQueries(queryClient);
|
|
2373
2602
|
}, [queryClient]);
|
|
2603
|
+
const invalidateActivityCaches = (0, import_react6.useCallback)(() => {
|
|
2604
|
+
invalidateUserActivityQueries(queryClient);
|
|
2605
|
+
}, [queryClient]);
|
|
2374
2606
|
const callbacks = (0, import_react6.useMemo)(
|
|
2375
2607
|
() => ({
|
|
2376
2608
|
onSnapshot: (marketId, book) => {
|
|
@@ -2389,6 +2621,14 @@ function AggWebSocketProvider({ children }) {
|
|
|
2389
2621
|
syncLiveQuery(marketId, (previous) => withLiveOrderbook(previous, book, "snapshot"));
|
|
2390
2622
|
if (book.midpoint != null) {
|
|
2391
2623
|
getOrCreateBuilder(marketId).addMidpoint(book.midpoint, book.timestamp);
|
|
2624
|
+
syncChartQueries(
|
|
2625
|
+
marketId,
|
|
2626
|
+
(_queryKey, previous) => applyMidpointToMarketChart(previous, {
|
|
2627
|
+
outcomeId: marketId,
|
|
2628
|
+
midpoint: book.midpoint,
|
|
2629
|
+
timestamp: book.timestamp
|
|
2630
|
+
})
|
|
2631
|
+
);
|
|
2392
2632
|
}
|
|
2393
2633
|
},
|
|
2394
2634
|
onDelta: (marketId, book) => {
|
|
@@ -2434,6 +2674,14 @@ function AggWebSocketProvider({ children }) {
|
|
|
2434
2674
|
});
|
|
2435
2675
|
if (book.midpoint != null) {
|
|
2436
2676
|
getOrCreateBuilder(marketId).addMidpoint(book.midpoint, book.timestamp);
|
|
2677
|
+
syncChartQueries(
|
|
2678
|
+
marketId,
|
|
2679
|
+
(_queryKey, previous) => applyMidpointToMarketChart(previous, {
|
|
2680
|
+
outcomeId: marketId,
|
|
2681
|
+
midpoint: book.midpoint,
|
|
2682
|
+
timestamp: book.timestamp
|
|
2683
|
+
})
|
|
2684
|
+
);
|
|
2437
2685
|
}
|
|
2438
2686
|
},
|
|
2439
2687
|
onTrade: (trade) => {
|
|
@@ -2471,6 +2719,7 @@ function AggWebSocketProvider({ children }) {
|
|
|
2471
2719
|
onBalanceUpdate: (msg) => {
|
|
2472
2720
|
if (isClientAuthenticated) {
|
|
2473
2721
|
invalidateBalanceCaches();
|
|
2722
|
+
invalidateActivityCaches();
|
|
2474
2723
|
}
|
|
2475
2724
|
for (const listener of balanceUpdateListenersRef.current) {
|
|
2476
2725
|
listener(msg);
|
|
@@ -2536,6 +2785,7 @@ function AggWebSocketProvider({ children }) {
|
|
|
2536
2785
|
[
|
|
2537
2786
|
client,
|
|
2538
2787
|
enableWebsocketsLogs,
|
|
2788
|
+
invalidateActivityCaches,
|
|
2539
2789
|
invalidateBalanceCaches,
|
|
2540
2790
|
invalidatePositionCaches,
|
|
2541
2791
|
isClientAuthenticated,
|
|
@@ -2672,9 +2922,26 @@ var resolveTradingStateKind = (status) => {
|
|
|
2672
2922
|
return "closed";
|
|
2673
2923
|
};
|
|
2674
2924
|
var resolveMarketWinningOutcome = (market) => {
|
|
2675
|
-
var _a;
|
|
2925
|
+
var _a, _b, _c, _d;
|
|
2676
2926
|
if (!market) return null;
|
|
2677
|
-
|
|
2927
|
+
const localWinningOutcome = (_a = market.venueMarketOutcomes.find((outcome) => outcome.winner === true)) != null ? _a : null;
|
|
2928
|
+
if (localWinningOutcome) return localWinningOutcome;
|
|
2929
|
+
const matchedVenueMarkets = (_b = market.matchedVenueMarkets) != null ? _b : [];
|
|
2930
|
+
if (!matchedVenueMarkets.length) return null;
|
|
2931
|
+
for (const outcome of market.venueMarketOutcomes) {
|
|
2932
|
+
const matchedRefs = (_c = outcome.matchedVenueMarketOutcomes) != null ? _c : [];
|
|
2933
|
+
for (const ref of matchedRefs) {
|
|
2934
|
+
const matchedMarket = matchedVenueMarkets.find((item) => item.id === ref.venueMarketId);
|
|
2935
|
+
if (!matchedMarket) continue;
|
|
2936
|
+
const matchedOutcome = (_d = matchedMarket.venueMarketOutcomes) == null ? void 0 : _d.find(
|
|
2937
|
+
(item) => item.id === ref.venueMarketOutcomeId
|
|
2938
|
+
);
|
|
2939
|
+
if ((matchedOutcome == null ? void 0 : matchedOutcome.winner) === true) {
|
|
2940
|
+
return outcome;
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
return null;
|
|
2678
2945
|
};
|
|
2679
2946
|
var AFFIRMATIVE_WINNER_LABELS = /* @__PURE__ */ new Set(["yes", "up", "buy", "long", "true"]);
|
|
2680
2947
|
var isAffirmativeWinnerLabel = (label) => {
|
|
@@ -2862,51 +3129,50 @@ function findOutcomeAcrossMarkets(event, outcomeId) {
|
|
|
2862
3129
|
}
|
|
2863
3130
|
return null;
|
|
2864
3131
|
}
|
|
3132
|
+
var TradeSide = {
|
|
3133
|
+
Buy: "buy",
|
|
3134
|
+
Sell: "sell"
|
|
3135
|
+
};
|
|
2865
3136
|
function tradingReducer(state, action) {
|
|
2866
|
-
var _a, _b;
|
|
3137
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2867
3138
|
switch (action.type) {
|
|
2868
3139
|
case "INITIALIZE_EVENT": {
|
|
2869
3140
|
if (!action.event) {
|
|
2870
|
-
return { event: null, market: null, outcome: null };
|
|
3141
|
+
return { event: null, market: null, outcome: null, tradeSide: TradeSide.Buy };
|
|
2871
3142
|
}
|
|
2872
|
-
const market = resolveDefaultMarket(action.event);
|
|
2873
3143
|
return {
|
|
2874
3144
|
event: action.event,
|
|
2875
|
-
market,
|
|
2876
|
-
outcome:
|
|
3145
|
+
market: null,
|
|
3146
|
+
outcome: null,
|
|
3147
|
+
tradeSide: TradeSide.Buy
|
|
2877
3148
|
};
|
|
2878
3149
|
}
|
|
2879
3150
|
case "SYNC_EVENT": {
|
|
2880
|
-
const
|
|
2881
|
-
const
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
if (preservedMarketState.isTradingDisabled) {
|
|
2885
|
-
const tradableAlternative = resolveDefaultMarket(nextEvent);
|
|
2886
|
-
if (tradableAlternative && resolveMarketTradingState(tradableAlternative).isOpen) {
|
|
2887
|
-
return {
|
|
2888
|
-
event: nextEvent,
|
|
2889
|
-
market: tradableAlternative,
|
|
2890
|
-
outcome: resolveDefaultOutcome(tradableAlternative)
|
|
2891
|
-
};
|
|
2892
|
-
}
|
|
2893
|
-
}
|
|
2894
|
-
const preservedOutcome = state.outcome ? findOutcomeById(preservedMarket, state.outcome.id) : null;
|
|
3151
|
+
const previousMarketId = (_b = (_a = state.market) == null ? void 0 : _a.id) != null ? _b : null;
|
|
3152
|
+
const previousOutcomeId = (_d = (_c = state.outcome) == null ? void 0 : _c.id) != null ? _d : null;
|
|
3153
|
+
const syncedMarket = previousMarketId ? findMarketById(action.event, previousMarketId) : null;
|
|
3154
|
+
if (!syncedMarket || resolveMarketTradingState(syncedMarket).isTradingDisabled) {
|
|
2895
3155
|
return {
|
|
2896
|
-
event:
|
|
2897
|
-
market:
|
|
2898
|
-
outcome:
|
|
3156
|
+
event: action.event,
|
|
3157
|
+
market: null,
|
|
3158
|
+
outcome: null,
|
|
3159
|
+
tradeSide: (_e = state.tradeSide) != null ? _e : TradeSide.Buy
|
|
2899
3160
|
};
|
|
2900
3161
|
}
|
|
2901
|
-
const
|
|
3162
|
+
const syncedOutcome = previousOutcomeId ? findOutcomeById(syncedMarket, previousOutcomeId) : null;
|
|
2902
3163
|
return {
|
|
2903
|
-
event:
|
|
2904
|
-
market:
|
|
2905
|
-
outcome:
|
|
3164
|
+
event: action.event,
|
|
3165
|
+
market: syncedMarket,
|
|
3166
|
+
outcome: syncedOutcome,
|
|
3167
|
+
tradeSide: (_f = state.tradeSide) != null ? _f : TradeSide.Buy
|
|
2906
3168
|
};
|
|
2907
3169
|
}
|
|
3170
|
+
case "SET_TRADE_SIDE": {
|
|
3171
|
+
if (((_g = state.tradeSide) != null ? _g : TradeSide.Buy) === action.tradeSide) return state;
|
|
3172
|
+
return __spreadProps(__spreadValues({}, state), { tradeSide: action.tradeSide });
|
|
3173
|
+
}
|
|
2908
3174
|
case "SELECT_MARKET": {
|
|
2909
|
-
const market = (
|
|
3175
|
+
const market = (_i = (_h = findMarketById(state.event, action.marketId)) != null ? _h : action.market) != null ? _i : null;
|
|
2910
3176
|
if (!market) return state;
|
|
2911
3177
|
if (resolveMarketTradingState(market).kind === "resolved") return state;
|
|
2912
3178
|
return __spreadProps(__spreadValues({}, state), {
|
|
@@ -2915,6 +3181,9 @@ function tradingReducer(state, action) {
|
|
|
2915
3181
|
});
|
|
2916
3182
|
}
|
|
2917
3183
|
case "SELECT_OUTCOME": {
|
|
3184
|
+
if (((_j = state.outcome) == null ? void 0 : _j.id) === action.outcomeId) {
|
|
3185
|
+
return state;
|
|
3186
|
+
}
|
|
2918
3187
|
if (state.market) {
|
|
2919
3188
|
const outcomeInCurrentMarket = findOutcomeById(state.market, action.outcomeId);
|
|
2920
3189
|
if (outcomeInCurrentMarket) {
|
|
@@ -2966,7 +3235,8 @@ function logAction(actionType, payload, prev, next, enableLogs) {
|
|
|
2966
3235
|
var initialState = {
|
|
2967
3236
|
event: null,
|
|
2968
3237
|
market: null,
|
|
2969
|
-
outcome: null
|
|
3238
|
+
outcome: null,
|
|
3239
|
+
tradeSide: TradeSide.Buy
|
|
2970
3240
|
};
|
|
2971
3241
|
var EventTradingContext = (0, import_react7.createContext)(void 0);
|
|
2972
3242
|
var useEventTradingContext = () => {
|
|
@@ -2976,9 +3246,15 @@ var EventTradingProvider = ({
|
|
|
2976
3246
|
children,
|
|
2977
3247
|
enableLogs = false
|
|
2978
3248
|
}) => {
|
|
3249
|
+
var _a, _b;
|
|
2979
3250
|
const [state, rawDispatch] = (0, import_react7.useReducer)(tradingReducer, initialState);
|
|
2980
3251
|
const stateRef = (0, import_react7.useRef)(state);
|
|
3252
|
+
const pendingAtomicSelectionRef = (0, import_react7.useRef)(null);
|
|
2981
3253
|
stateRef.current = state;
|
|
3254
|
+
const pendingAtomicSelection = pendingAtomicSelectionRef.current;
|
|
3255
|
+
if (pendingAtomicSelection && ((_a = state.market) == null ? void 0 : _a.id) === pendingAtomicSelection.marketId && ((_b = state.outcome) == null ? void 0 : _b.id) === pendingAtomicSelection.outcomeId) {
|
|
3256
|
+
pendingAtomicSelectionRef.current = null;
|
|
3257
|
+
}
|
|
2982
3258
|
const dispatch = (0, import_react7.useCallback)(
|
|
2983
3259
|
(action) => {
|
|
2984
3260
|
const prev = stateRef.current;
|
|
@@ -3001,24 +3277,45 @@ var EventTradingProvider = ({
|
|
|
3001
3277
|
[dispatch]
|
|
3002
3278
|
);
|
|
3003
3279
|
const selectOutcome = (0, import_react7.useCallback)(
|
|
3004
|
-
(outcomeId) =>
|
|
3280
|
+
(outcomeId) => {
|
|
3281
|
+
var _a2, _b2;
|
|
3282
|
+
if (((_a2 = stateRef.current.outcome) == null ? void 0 : _a2.id) === outcomeId) return;
|
|
3283
|
+
if (((_b2 = pendingAtomicSelectionRef.current) == null ? void 0 : _b2.outcomeId) === outcomeId) return;
|
|
3284
|
+
dispatch({ type: "SELECT_OUTCOME", outcomeId });
|
|
3285
|
+
},
|
|
3005
3286
|
[dispatch]
|
|
3006
3287
|
);
|
|
3007
3288
|
const selectMarketAndOutcome = (0, import_react7.useCallback)(
|
|
3008
|
-
(marketId, outcomeId) =>
|
|
3289
|
+
(marketId, outcomeId) => {
|
|
3290
|
+
var _a2, _b2, _c, _d;
|
|
3291
|
+
if (((_a2 = stateRef.current.market) == null ? void 0 : _a2.id) === marketId && ((_b2 = stateRef.current.outcome) == null ? void 0 : _b2.id) === outcomeId) {
|
|
3292
|
+
return;
|
|
3293
|
+
}
|
|
3294
|
+
if (((_c = pendingAtomicSelectionRef.current) == null ? void 0 : _c.marketId) === marketId && ((_d = pendingAtomicSelectionRef.current) == null ? void 0 : _d.outcomeId) === outcomeId) {
|
|
3295
|
+
return;
|
|
3296
|
+
}
|
|
3297
|
+
pendingAtomicSelectionRef.current = { marketId, outcomeId };
|
|
3298
|
+
dispatch({ type: "SELECT_MARKET_AND_OUTCOME", marketId, outcomeId });
|
|
3299
|
+
},
|
|
3300
|
+
[dispatch]
|
|
3301
|
+
);
|
|
3302
|
+
const setTradeSide = (0, import_react7.useCallback)(
|
|
3303
|
+
(tradeSide) => dispatch({ type: "SET_TRADE_SIDE", tradeSide }),
|
|
3009
3304
|
[dispatch]
|
|
3010
3305
|
);
|
|
3011
3306
|
const value = (0, import_react7.useMemo)(
|
|
3012
3307
|
() => {
|
|
3013
|
-
var
|
|
3308
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
3014
3309
|
return {
|
|
3015
3310
|
selectedEvent: state.event,
|
|
3016
3311
|
selectedMarket: state.market,
|
|
3017
3312
|
selectedOutcome: state.outcome,
|
|
3018
|
-
selectedEventId: (
|
|
3313
|
+
selectedEventId: (_b2 = (_a2 = state.event) == null ? void 0 : _a2.id) != null ? _b2 : null,
|
|
3019
3314
|
selectedMarketId: (_d = (_c = state.market) == null ? void 0 : _c.id) != null ? _d : null,
|
|
3020
3315
|
selectedOutcomeId: (_f = (_e = state.outcome) == null ? void 0 : _e.id) != null ? _f : null,
|
|
3021
3316
|
selectedVenue: (_h = (_g = state.market) == null ? void 0 : _g.venue) != null ? _h : null,
|
|
3317
|
+
tradeSide: (_i = state.tradeSide) != null ? _i : TradeSide.Buy,
|
|
3318
|
+
setTradeSide,
|
|
3022
3319
|
initializeFromEvent,
|
|
3023
3320
|
syncEvent,
|
|
3024
3321
|
selectMarket,
|
|
@@ -3026,7 +3323,15 @@ var EventTradingProvider = ({
|
|
|
3026
3323
|
selectMarketAndOutcome
|
|
3027
3324
|
};
|
|
3028
3325
|
},
|
|
3029
|
-
[
|
|
3326
|
+
[
|
|
3327
|
+
state,
|
|
3328
|
+
initializeFromEvent,
|
|
3329
|
+
syncEvent,
|
|
3330
|
+
selectMarket,
|
|
3331
|
+
selectOutcome,
|
|
3332
|
+
selectMarketAndOutcome,
|
|
3333
|
+
setTradeSide
|
|
3334
|
+
]
|
|
3030
3335
|
);
|
|
3031
3336
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EventTradingContext.Provider, { value, children });
|
|
3032
3337
|
};
|
|
@@ -3229,7 +3534,7 @@ function useRampSession() {
|
|
|
3229
3534
|
}
|
|
3230
3535
|
|
|
3231
3536
|
// src/withdraw/use-withdraw-flow.ts
|
|
3232
|
-
var
|
|
3537
|
+
var import_react13 = require("react");
|
|
3233
3538
|
|
|
3234
3539
|
// src/execution/use-quote-managed.ts
|
|
3235
3540
|
var import_react_query6 = require("@tanstack/react-query");
|
|
@@ -3269,7 +3574,7 @@ function useWithdrawManaged(options) {
|
|
|
3269
3574
|
mutationFn: (params) => client.withdrawManaged(params),
|
|
3270
3575
|
onSuccess: (data) => {
|
|
3271
3576
|
var _a;
|
|
3272
|
-
|
|
3577
|
+
invalidateUserMoneyState(queryClient);
|
|
3273
3578
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
3274
3579
|
},
|
|
3275
3580
|
onError: options == null ? void 0 : options.onError
|
|
@@ -3381,7 +3686,7 @@ function useSyncBalances(options) {
|
|
|
3381
3686
|
mutationFn: () => client.syncManagedBalances(),
|
|
3382
3687
|
onSuccess: () => {
|
|
3383
3688
|
var _a;
|
|
3384
|
-
|
|
3689
|
+
invalidateUserMoneyState(queryClient);
|
|
3385
3690
|
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
|
|
3386
3691
|
},
|
|
3387
3692
|
onError: options == null ? void 0 : options.onError
|
|
@@ -3463,6 +3768,12 @@ function useExecutionProgress({
|
|
|
3463
3768
|
event: mappedEvent,
|
|
3464
3769
|
filledAmountRaw: msg.filledAmountRaw,
|
|
3465
3770
|
remainingAmountRaw: msg.remainingAmountRaw,
|
|
3771
|
+
actualSharesRaw: msg.actualSharesRaw,
|
|
3772
|
+
actualToWinRaw: msg.actualToWinRaw,
|
|
3773
|
+
quotedSharesRaw: msg.quotedSharesRaw,
|
|
3774
|
+
quotedToWinRaw: msg.quotedToWinRaw,
|
|
3775
|
+
executionPriceRaw: msg.executionPriceRaw,
|
|
3776
|
+
quotedPriceRaw: msg.quotedPriceRaw,
|
|
3466
3777
|
errorReason: event === "bridge_ws_subscribe_failed" ? (_a = msg.errorReason) != null ? _a : "Bridge event subscription failed." : msg.errorReason,
|
|
3467
3778
|
timestamp: msg.timestamp
|
|
3468
3779
|
};
|
|
@@ -3541,15 +3852,29 @@ function useExecutionProgress({
|
|
|
3541
3852
|
});
|
|
3542
3853
|
return;
|
|
3543
3854
|
}
|
|
3855
|
+
const buildFailedProgress = (prev) => {
|
|
3856
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3857
|
+
const seq = (_b2 = (_a2 = msg.sequence) != null ? _a2 : prev == null ? void 0 : prev.currentSequence) != null ? _b2 : 0;
|
|
3858
|
+
const stepType = (_d = (_c2 = msg.stepType) != null ? _c2 : prev == null ? void 0 : prev.currentStepType) != null ? _d : null;
|
|
3859
|
+
const baseStepTypes = (_e = prev == null ? void 0 : prev.stepTypes) != null ? _e : {};
|
|
3860
|
+
const stepTypes = seq && stepType ? __spreadProps(__spreadValues({}, baseStepTypes), { [seq]: stepType }) : baseStepTypes;
|
|
3861
|
+
return {
|
|
3862
|
+
dagRunId: (_g = (_f = msg.dagRunId) != null ? _f : prev == null ? void 0 : prev.dagRunId) != null ? _g : "",
|
|
3863
|
+
totalSteps: (_i = (_h = msg.totalSteps) != null ? _h : prev == null ? void 0 : prev.totalSteps) != null ? _i : 0,
|
|
3864
|
+
currentSequence: seq,
|
|
3865
|
+
currentStepType: stepType,
|
|
3866
|
+
completedSequences: (_j = prev == null ? void 0 : prev.completedSequences) != null ? _j : [],
|
|
3867
|
+
stepTypes,
|
|
3868
|
+
status: "failed",
|
|
3869
|
+
errorReason: (_l = (_k = msg.errorReason) != null ? _k : prev == null ? void 0 : prev.errorReason) != null ? _l : null
|
|
3870
|
+
};
|
|
3871
|
+
};
|
|
3872
|
+
if (event === "step_failed") {
|
|
3873
|
+
setDagProgress((prev) => buildFailedProgress(prev));
|
|
3874
|
+
return;
|
|
3875
|
+
}
|
|
3544
3876
|
if (event === "dag_failed") {
|
|
3545
|
-
setDagProgress((prev) =>
|
|
3546
|
-
var _a2;
|
|
3547
|
-
if (!prev) return prev;
|
|
3548
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
3549
|
-
status: "failed",
|
|
3550
|
-
errorReason: (_a2 = msg.errorReason) != null ? _a2 : null
|
|
3551
|
-
});
|
|
3552
|
-
});
|
|
3877
|
+
setDagProgress((prev) => buildFailedProgress(prev));
|
|
3553
3878
|
return;
|
|
3554
3879
|
}
|
|
3555
3880
|
}, []);
|
|
@@ -3574,7 +3899,7 @@ function useExecutionProgress({
|
|
|
3574
3899
|
}
|
|
3575
3900
|
};
|
|
3576
3901
|
const reconcile = () => __async(null, null, function* () {
|
|
3577
|
-
var _a, _b, _c;
|
|
3902
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
3578
3903
|
if (cancelled || pollInFlightRef.current) return;
|
|
3579
3904
|
const pending = orderIds.filter((id) => !terminalOrderIdsRef.current.has(id));
|
|
3580
3905
|
if (pending.length === 0) {
|
|
@@ -3606,7 +3931,13 @@ function useExecutionProgress({
|
|
|
3606
3931
|
venue: (_a = order.venue) != null ? _a : "",
|
|
3607
3932
|
event: mapped,
|
|
3608
3933
|
filledAmountRaw: (_b = order.filledAmountRaw) != null ? _b : void 0,
|
|
3609
|
-
|
|
3934
|
+
actualSharesRaw: (_c = order.actualSharesRaw) != null ? _c : void 0,
|
|
3935
|
+
actualToWinRaw: (_d = order.actualToWinRaw) != null ? _d : void 0,
|
|
3936
|
+
quotedSharesRaw: (_e = order.quotedSharesRaw) != null ? _e : void 0,
|
|
3937
|
+
quotedToWinRaw: (_f = order.quotedToWinRaw) != null ? _f : void 0,
|
|
3938
|
+
executionPriceRaw: (_g = order.executionPrice) != null ? _g : void 0,
|
|
3939
|
+
quotedPriceRaw: (_h = order.quotedPriceRaw) != null ? _h : void 0,
|
|
3940
|
+
errorReason: (_i = order.errorMessage) != null ? _i : void 0,
|
|
3610
3941
|
timestamp: new Date(order.updatedAt).getTime() || Date.now()
|
|
3611
3942
|
});
|
|
3612
3943
|
}
|
|
@@ -3686,11 +4017,27 @@ var computeClosedPositionTotals = (group) => {
|
|
|
3686
4017
|
|
|
3687
4018
|
// src/execution/use-redeem.ts
|
|
3688
4019
|
var import_react_query13 = require("@tanstack/react-query");
|
|
4020
|
+
var RedeemRejectedError = class extends Error {
|
|
4021
|
+
constructor(message, response) {
|
|
4022
|
+
super(message);
|
|
4023
|
+
this.name = "RedeemRejectedError";
|
|
4024
|
+
this.response = response;
|
|
4025
|
+
}
|
|
4026
|
+
};
|
|
4027
|
+
var isLegRejected = (status) => status === "ineligible" || status === "rejected";
|
|
3689
4028
|
var useRedeem = () => {
|
|
3690
4029
|
const client = useAggClient();
|
|
3691
4030
|
const queryClient = (0, import_react_query13.useQueryClient)();
|
|
3692
4031
|
return (0, import_react_query13.useMutation)({
|
|
3693
|
-
mutationFn: (body) =>
|
|
4032
|
+
mutationFn: (body) => __async(null, null, function* () {
|
|
4033
|
+
const response = yield client.redeem(body);
|
|
4034
|
+
if (response.results.length > 0 && response.results.every((r) => isLegRejected(r.status))) {
|
|
4035
|
+
const reasons = response.results.map((r) => r.reason).filter((r) => Boolean(r));
|
|
4036
|
+
const message = reasons.length > 0 ? reasons.join("; ") : "Redeem rejected";
|
|
4037
|
+
throw new RedeemRejectedError(message, response);
|
|
4038
|
+
}
|
|
4039
|
+
return response;
|
|
4040
|
+
}),
|
|
3694
4041
|
onSuccess: () => {
|
|
3695
4042
|
queryClient.invalidateQueries({ queryKey: executionKeys.positionsPrefix() });
|
|
3696
4043
|
queryClient.invalidateQueries({ queryKey: executionKeys.balances() });
|
|
@@ -3741,6 +4088,144 @@ var useRedeemEligibleCount = () => {
|
|
|
3741
4088
|
return (_a = query.data) != null ? _a : 0;
|
|
3742
4089
|
};
|
|
3743
4090
|
|
|
4091
|
+
// src/execution/use-redeem-lifecycle.ts
|
|
4092
|
+
var import_react12 = require("react");
|
|
4093
|
+
|
|
4094
|
+
// src/execution/use-redeem-lifecycles.ts
|
|
4095
|
+
var import_react11 = require("react");
|
|
4096
|
+
var computeDerivedState = (legs, expectedCount) => {
|
|
4097
|
+
const legCount = Object.keys(legs).length;
|
|
4098
|
+
let allTerminal = legCount === expectedCount;
|
|
4099
|
+
let allConfirmed = allTerminal;
|
|
4100
|
+
let anyFailed = false;
|
|
4101
|
+
let errorMessage = null;
|
|
4102
|
+
for (const leg of Object.values(legs)) {
|
|
4103
|
+
if (leg.status === "submitted") allTerminal = false;
|
|
4104
|
+
if (leg.status !== "confirmed") allConfirmed = false;
|
|
4105
|
+
if (leg.status === "failed") {
|
|
4106
|
+
anyFailed = true;
|
|
4107
|
+
if (errorMessage === null && leg.errorMessage) errorMessage = leg.errorMessage;
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
return {
|
|
4111
|
+
terminal: allTerminal,
|
|
4112
|
+
allConfirmed: allTerminal && allConfirmed,
|
|
4113
|
+
anyFailed,
|
|
4114
|
+
errorMessage
|
|
4115
|
+
};
|
|
4116
|
+
};
|
|
4117
|
+
var seedState = (input) => {
|
|
4118
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4119
|
+
const legs = {};
|
|
4120
|
+
for (const id of (_a = input.preFailedOutcomeIds) != null ? _a : []) {
|
|
4121
|
+
legs[id] = {
|
|
4122
|
+
status: "failed",
|
|
4123
|
+
txHash: null,
|
|
4124
|
+
errorMessage: (_c = (_b = input.preFailedReasons) == null ? void 0 : _b[id]) != null ? _c : null
|
|
4125
|
+
};
|
|
4126
|
+
}
|
|
4127
|
+
for (const id of (_d = input.preConfirmedOutcomeIds) != null ? _d : []) {
|
|
4128
|
+
legs[id] = {
|
|
4129
|
+
status: "confirmed",
|
|
4130
|
+
txHash: (_f = (_e = input.preConfirmedTxHashes) == null ? void 0 : _e[id]) != null ? _f : null,
|
|
4131
|
+
errorMessage: null
|
|
4132
|
+
};
|
|
4133
|
+
}
|
|
4134
|
+
const expectedCount = input.expectedOutcomeIds.length + ((_h = (_g = input.preFailedOutcomeIds) == null ? void 0 : _g.length) != null ? _h : 0) + ((_j = (_i = input.preConfirmedOutcomeIds) == null ? void 0 : _i.length) != null ? _j : 0);
|
|
4135
|
+
const derived = computeDerivedState(legs, expectedCount);
|
|
4136
|
+
return {
|
|
4137
|
+
pending: !derived.terminal,
|
|
4138
|
+
terminal: derived.terminal,
|
|
4139
|
+
allConfirmed: derived.allConfirmed,
|
|
4140
|
+
anyFailed: derived.anyFailed,
|
|
4141
|
+
errorMessage: derived.errorMessage,
|
|
4142
|
+
legs
|
|
4143
|
+
};
|
|
4144
|
+
};
|
|
4145
|
+
function useRedeemLifecycles(inputs) {
|
|
4146
|
+
const inputsByRedeemId = (0, import_react11.useMemo)(() => {
|
|
4147
|
+
const map = {};
|
|
4148
|
+
for (const input of inputs) {
|
|
4149
|
+
map[input.redeemId] = input;
|
|
4150
|
+
}
|
|
4151
|
+
return map;
|
|
4152
|
+
}, [inputs]);
|
|
4153
|
+
const [stateMap, setStateMap] = (0, import_react11.useState)(() => {
|
|
4154
|
+
const next = {};
|
|
4155
|
+
for (const [id, input] of Object.entries(inputsByRedeemId)) {
|
|
4156
|
+
next[id] = seedState(input);
|
|
4157
|
+
}
|
|
4158
|
+
return next;
|
|
4159
|
+
});
|
|
4160
|
+
(0, import_react11.useEffect)(() => {
|
|
4161
|
+
setStateMap((prev) => {
|
|
4162
|
+
let changed = false;
|
|
4163
|
+
const next = {};
|
|
4164
|
+
for (const [id, input] of Object.entries(inputsByRedeemId)) {
|
|
4165
|
+
const existing = prev[id];
|
|
4166
|
+
if (existing) {
|
|
4167
|
+
next[id] = existing;
|
|
4168
|
+
} else {
|
|
4169
|
+
next[id] = seedState(input);
|
|
4170
|
+
changed = true;
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
if (Object.keys(next).length !== Object.keys(prev).length) changed = true;
|
|
4174
|
+
return changed ? next : prev;
|
|
4175
|
+
});
|
|
4176
|
+
}, [inputsByRedeemId]);
|
|
4177
|
+
useOnRedeemEvent(
|
|
4178
|
+
(0, import_react11.useMemo)(() => {
|
|
4179
|
+
if (Object.keys(inputsByRedeemId).length === 0) return null;
|
|
4180
|
+
return (event) => {
|
|
4181
|
+
const input = inputsByRedeemId[event.redeemId];
|
|
4182
|
+
if (!input) return;
|
|
4183
|
+
setStateMap((prev) => {
|
|
4184
|
+
var _a, _b, _c, _d;
|
|
4185
|
+
const existing = prev[event.redeemId];
|
|
4186
|
+
if (!existing) return prev;
|
|
4187
|
+
const nextLegs = __spreadProps(__spreadValues({}, existing.legs), {
|
|
4188
|
+
[event.venueMarketOutcomeId]: {
|
|
4189
|
+
status: event.status,
|
|
4190
|
+
txHash: event.txHash,
|
|
4191
|
+
errorMessage: event.errorMessage
|
|
4192
|
+
}
|
|
4193
|
+
});
|
|
4194
|
+
const expectedCount = input.expectedOutcomeIds.length + ((_b = (_a = input.preFailedOutcomeIds) == null ? void 0 : _a.length) != null ? _b : 0) + ((_d = (_c = input.preConfirmedOutcomeIds) == null ? void 0 : _c.length) != null ? _d : 0);
|
|
4195
|
+
const derived = computeDerivedState(nextLegs, expectedCount);
|
|
4196
|
+
const nextState = {
|
|
4197
|
+
pending: !derived.terminal,
|
|
4198
|
+
terminal: derived.terminal,
|
|
4199
|
+
allConfirmed: derived.allConfirmed,
|
|
4200
|
+
anyFailed: derived.anyFailed,
|
|
4201
|
+
errorMessage: derived.errorMessage,
|
|
4202
|
+
legs: nextLegs
|
|
4203
|
+
};
|
|
4204
|
+
return __spreadProps(__spreadValues({}, prev), { [event.redeemId]: nextState });
|
|
4205
|
+
});
|
|
4206
|
+
};
|
|
4207
|
+
}, [inputsByRedeemId])
|
|
4208
|
+
);
|
|
4209
|
+
return stateMap;
|
|
4210
|
+
}
|
|
4211
|
+
|
|
4212
|
+
// src/execution/use-redeem-lifecycle.ts
|
|
4213
|
+
var INITIAL_STATE = {
|
|
4214
|
+
pending: true,
|
|
4215
|
+
terminal: false,
|
|
4216
|
+
allConfirmed: false,
|
|
4217
|
+
anyFailed: false,
|
|
4218
|
+
errorMessage: null,
|
|
4219
|
+
legs: {}
|
|
4220
|
+
};
|
|
4221
|
+
function useRedeemLifecycle(input) {
|
|
4222
|
+
var _a;
|
|
4223
|
+
const inputs = (0, import_react12.useMemo)(() => input ? [input] : [], [input]);
|
|
4224
|
+
const map = useRedeemLifecycles(inputs);
|
|
4225
|
+
if (!input) return INITIAL_STATE;
|
|
4226
|
+
return (_a = map[input.redeemId]) != null ? _a : INITIAL_STATE;
|
|
4227
|
+
}
|
|
4228
|
+
|
|
3744
4229
|
// src/withdraw/use-withdraw-flow.ts
|
|
3745
4230
|
var EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
3746
4231
|
var SOLANA_ADDRESS_REGEX = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
@@ -3756,7 +4241,9 @@ var WITHDRAWAL_SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([
|
|
|
3756
4241
|
// Base
|
|
3757
4242
|
56,
|
|
3758
4243
|
// BNB
|
|
3759
|
-
SOLANA_CHAIN_ID
|
|
4244
|
+
SOLANA_CHAIN_ID,
|
|
4245
|
+
1337
|
|
4246
|
+
// Hyperliquid
|
|
3760
4247
|
]);
|
|
3761
4248
|
var isValidDestinationAddress = (address, chainId) => {
|
|
3762
4249
|
if (chainId === SOLANA_CHAIN_ID) return SOLANA_ADDRESS_REGEX.test(address);
|
|
@@ -3807,20 +4294,20 @@ function useWithdrawFlow(options) {
|
|
|
3807
4294
|
const withdrawMutation = useWithdrawManaged();
|
|
3808
4295
|
const syncBalances = useSyncBalances();
|
|
3809
4296
|
const ws = useAggWebSocket();
|
|
3810
|
-
(0,
|
|
4297
|
+
(0, import_react13.useEffect)(() => {
|
|
3811
4298
|
if (!open) return;
|
|
3812
4299
|
syncBalances.mutate(void 0, {
|
|
3813
4300
|
onError: () => {
|
|
3814
4301
|
}
|
|
3815
4302
|
});
|
|
3816
4303
|
}, [open]);
|
|
3817
|
-
const [withdrawDestination, setWithdrawDestination] = (0,
|
|
3818
|
-
const [withdrawAmount, setWithdrawAmount] = (0,
|
|
3819
|
-
const [withdrawToken, setWithdrawToken] = (0,
|
|
3820
|
-
const [withdrawNetwork, setWithdrawNetwork] = (0,
|
|
3821
|
-
const [withdrawSummary, setWithdrawSummary] = (0,
|
|
3822
|
-
const [withdrawalId, setWithdrawalId] = (0,
|
|
3823
|
-
const networkOptions = (0,
|
|
4304
|
+
const [withdrawDestination, setWithdrawDestination] = (0, import_react13.useState)("");
|
|
4305
|
+
const [withdrawAmount, setWithdrawAmount] = (0, import_react13.useState)("");
|
|
4306
|
+
const [withdrawToken, setWithdrawToken] = (0, import_react13.useState)("USDC");
|
|
4307
|
+
const [withdrawNetwork, setWithdrawNetwork] = (0, import_react13.useState)("");
|
|
4308
|
+
const [withdrawSummary, setWithdrawSummary] = (0, import_react13.useState)(DEFAULT_WITHDRAW_SUMMARY);
|
|
4309
|
+
const [withdrawalId, setWithdrawalId] = (0, import_react13.useState)(null);
|
|
4310
|
+
const networkOptions = (0, import_react13.useMemo)(
|
|
3824
4311
|
() => (supportedChains != null ? supportedChains : []).filter((chain) => WITHDRAWAL_SUPPORTED_CHAIN_IDS.has(chain.chainId)).map((chain) => ({
|
|
3825
4312
|
value: String(chain.chainId),
|
|
3826
4313
|
label: chain.name
|
|
@@ -3828,13 +4315,13 @@ function useWithdrawFlow(options) {
|
|
|
3828
4315
|
[supportedChains]
|
|
3829
4316
|
);
|
|
3830
4317
|
const resolvedWithdrawNetwork = withdrawNetwork || ((_a = networkOptions[0]) == null ? void 0 : _a.value) || "";
|
|
3831
|
-
(0,
|
|
4318
|
+
(0, import_react13.useEffect)(() => {
|
|
3832
4319
|
if (!networkOptions.length) return;
|
|
3833
4320
|
if (!withdrawNetwork || !networkOptions.some((option) => option.value === withdrawNetwork)) {
|
|
3834
4321
|
setWithdrawNetwork(networkOptions[0].value);
|
|
3835
4322
|
}
|
|
3836
4323
|
}, [networkOptions, withdrawNetwork]);
|
|
3837
|
-
const tokenOptions = (0,
|
|
4324
|
+
const tokenOptions = (0, import_react13.useMemo)(() => {
|
|
3838
4325
|
var _a2, _b2, _c;
|
|
3839
4326
|
const selectedChainId = Number(resolvedWithdrawNetwork);
|
|
3840
4327
|
const supportedTokensForNetwork = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens) != null ? _b2 : [];
|
|
@@ -3845,17 +4332,17 @@ function useWithdrawFlow(options) {
|
|
|
3845
4332
|
}));
|
|
3846
4333
|
}, [balances, resolvedWithdrawNetwork, supportedChains]);
|
|
3847
4334
|
const resolvedWithdrawToken = tokenOptions.some((option) => option.value === withdrawToken) ? withdrawToken : ((_b = tokenOptions[0]) == null ? void 0 : _b.value) || "";
|
|
3848
|
-
(0,
|
|
4335
|
+
(0, import_react13.useEffect)(() => {
|
|
3849
4336
|
if (!tokenOptions.length) return;
|
|
3850
4337
|
if (!tokenOptions.some((option) => option.value === withdrawToken)) {
|
|
3851
4338
|
setWithdrawToken(tokenOptions[0].value);
|
|
3852
4339
|
}
|
|
3853
4340
|
}, [tokenOptions, withdrawToken]);
|
|
3854
|
-
const selectedCashEntry = (0,
|
|
4341
|
+
const selectedCashEntry = (0, import_react13.useMemo)(
|
|
3855
4342
|
() => balances == null ? void 0 : balances.cash.find((cashEntry) => cashEntry.tokenSymbol === resolvedWithdrawToken),
|
|
3856
4343
|
[balances, resolvedWithdrawToken]
|
|
3857
4344
|
);
|
|
3858
|
-
const selectedTokenDecimals = (0,
|
|
4345
|
+
const selectedTokenDecimals = (0, import_react13.useMemo)(() => {
|
|
3859
4346
|
var _a2, _b2, _c, _d;
|
|
3860
4347
|
const selectedChainId = Number(resolvedWithdrawNetwork);
|
|
3861
4348
|
return (_d = (_c = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens.find((token) => token.symbol === resolvedWithdrawToken)) == null ? void 0 : _b2.decimals) != null ? _c : selectedCashEntry == null ? void 0 : selectedCashEntry.decimals) != null ? _d : 6;
|
|
@@ -3865,18 +4352,18 @@ function useWithdrawFlow(options) {
|
|
|
3865
4352
|
selectedCashEntry == null ? void 0 : selectedCashEntry.decimals,
|
|
3866
4353
|
supportedChains
|
|
3867
4354
|
]);
|
|
3868
|
-
const exactBalance = (0,
|
|
4355
|
+
const exactBalance = (0, import_react13.useMemo)(() => {
|
|
3869
4356
|
if (!selectedCashEntry) return "0";
|
|
3870
4357
|
return formatRawTokenAmount(selectedCashEntry.totalRaw, selectedCashEntry.decimals);
|
|
3871
4358
|
}, [selectedCashEntry]);
|
|
3872
|
-
const balanceDisplay = (0,
|
|
4359
|
+
const balanceDisplay = (0, import_react13.useMemo)(() => {
|
|
3873
4360
|
if (!selectedCashEntry) return `0.00 ${resolvedWithdrawToken || withdrawToken}`;
|
|
3874
4361
|
return `${formatRawTokenAmountForDisplay(
|
|
3875
4362
|
selectedCashEntry.totalRaw,
|
|
3876
4363
|
selectedCashEntry.decimals
|
|
3877
4364
|
)} ${resolvedWithdrawToken}`;
|
|
3878
4365
|
}, [resolvedWithdrawToken, selectedCashEntry, withdrawToken]);
|
|
3879
|
-
const resetFlowState = (0,
|
|
4366
|
+
const resetFlowState = (0, import_react13.useCallback)(() => {
|
|
3880
4367
|
setWithdrawDestination("");
|
|
3881
4368
|
setWithdrawAmount("");
|
|
3882
4369
|
setWithdrawToken("USDC");
|
|
@@ -3884,17 +4371,17 @@ function useWithdrawFlow(options) {
|
|
|
3884
4371
|
setWithdrawSummary(DEFAULT_WITHDRAW_SUMMARY);
|
|
3885
4372
|
setWithdrawalId(null);
|
|
3886
4373
|
}, []);
|
|
3887
|
-
const handleWithdrawOpenChange = (0,
|
|
4374
|
+
const handleWithdrawOpenChange = (0, import_react13.useCallback)(
|
|
3888
4375
|
(isOpen) => {
|
|
3889
4376
|
if (!isOpen) resetFlowState();
|
|
3890
4377
|
onOpenChange(isOpen);
|
|
3891
4378
|
},
|
|
3892
4379
|
[onOpenChange, resetFlowState]
|
|
3893
4380
|
);
|
|
3894
|
-
(0,
|
|
4381
|
+
(0, import_react13.useEffect)(() => {
|
|
3895
4382
|
if (!open) resetFlowState();
|
|
3896
4383
|
}, [open, resetFlowState]);
|
|
3897
|
-
const handleWithdrawProvider = (0,
|
|
4384
|
+
const handleWithdrawProvider = (0, import_react13.useCallback)(() => __async(null, null, function* () {
|
|
3898
4385
|
var _a2, _b2;
|
|
3899
4386
|
const destinationChainId = Number(resolvedWithdrawNetwork);
|
|
3900
4387
|
const trimmedDestination = withdrawDestination.trim();
|
|
@@ -3980,25 +4467,73 @@ function useWithdrawFlow(options) {
|
|
|
3980
4467
|
onWithdrawAmountChange: setWithdrawAmount,
|
|
3981
4468
|
onWithdrawTokenChange: setWithdrawToken,
|
|
3982
4469
|
onWithdrawNetworkChange: setWithdrawNetwork,
|
|
3983
|
-
onMaxClick: (0,
|
|
4470
|
+
onMaxClick: (0, import_react13.useCallback)(() => {
|
|
3984
4471
|
setWithdrawAmount(exactBalance === "0" ? "0" : exactBalance);
|
|
3985
4472
|
}, [exactBalance]),
|
|
3986
|
-
onSelectWithdrawProvider: (0,
|
|
4473
|
+
onSelectWithdrawProvider: (0, import_react13.useCallback)(
|
|
3987
4474
|
(_providerId) => __async(null, null, function* () {
|
|
3988
4475
|
return handleWithdrawProvider();
|
|
3989
4476
|
}),
|
|
3990
4477
|
[handleWithdrawProvider]
|
|
3991
4478
|
),
|
|
3992
|
-
onDoneWithdraw: (0,
|
|
4479
|
+
onDoneWithdraw: (0, import_react13.useCallback)(() => handleWithdrawOpenChange(false), [handleWithdrawOpenChange])
|
|
3993
4480
|
};
|
|
3994
4481
|
}
|
|
3995
4482
|
|
|
4483
|
+
// src/withdraw/use-withdraw-estimate.ts
|
|
4484
|
+
var import_react14 = require("react");
|
|
4485
|
+
function useWithdrawEstimate({
|
|
4486
|
+
amount,
|
|
4487
|
+
selectedToken,
|
|
4488
|
+
selectedNetwork
|
|
4489
|
+
}) {
|
|
4490
|
+
return (0, import_react14.useMemo)(() => {
|
|
4491
|
+
const numAmount = Number(amount);
|
|
4492
|
+
if (!amount || isNaN(numAmount) || numAmount <= 0 || !selectedToken || !selectedNetwork) {
|
|
4493
|
+
return null;
|
|
4494
|
+
}
|
|
4495
|
+
const network = selectedNetwork.toLowerCase();
|
|
4496
|
+
let feeVal = 0.1;
|
|
4497
|
+
let reserveVal = 0.2;
|
|
4498
|
+
if (network === "1" || network === "mainnet" || network === "ethereum") {
|
|
4499
|
+
feeVal = 1.22;
|
|
4500
|
+
reserveVal = 0.3;
|
|
4501
|
+
} else if (network === "137" || network === "polygon") {
|
|
4502
|
+
feeVal = 0.05;
|
|
4503
|
+
reserveVal = 0.15;
|
|
4504
|
+
} else if (network === "42161" || network === "arbitrum") {
|
|
4505
|
+
feeVal = 0.05;
|
|
4506
|
+
reserveVal = 0.15;
|
|
4507
|
+
} else if (network === "8453" || network === "base") {
|
|
4508
|
+
feeVal = 0.05;
|
|
4509
|
+
reserveVal = 0.15;
|
|
4510
|
+
} else if (network === "56" || network === "bnb" || network === "bsc") {
|
|
4511
|
+
feeVal = 0.1;
|
|
4512
|
+
reserveVal = 0.2;
|
|
4513
|
+
} else if (network === "792703809" || network === "solana") {
|
|
4514
|
+
feeVal = 0.01;
|
|
4515
|
+
reserveVal = 0.04;
|
|
4516
|
+
} else if (network === "1337" || network === "hyperliquid") {
|
|
4517
|
+
feeVal = 0.02;
|
|
4518
|
+
reserveVal = 0.08;
|
|
4519
|
+
}
|
|
4520
|
+
const youReceiveVal = Math.max(0, numAmount - feeVal);
|
|
4521
|
+
return {
|
|
4522
|
+
estimatedFees: `~$${feeVal.toFixed(2)}`,
|
|
4523
|
+
networkReserve: `~$${reserveVal.toFixed(2)}`,
|
|
4524
|
+
youReceive: `~${youReceiveVal.toFixed(2)} ${selectedToken}`
|
|
4525
|
+
};
|
|
4526
|
+
}, [amount, selectedToken, selectedNetwork]);
|
|
4527
|
+
}
|
|
4528
|
+
|
|
3996
4529
|
// src/withdraw/use-withdrawal-lifecycle.ts
|
|
3997
|
-
var
|
|
4530
|
+
var import_react15 = require("react");
|
|
3998
4531
|
var import_react_query15 = require("@tanstack/react-query");
|
|
3999
|
-
var
|
|
4532
|
+
var INITIAL_STATE2 = {
|
|
4000
4533
|
pending: true,
|
|
4001
4534
|
status: null,
|
|
4535
|
+
requestedAmountRaw: null,
|
|
4536
|
+
completedAmountRaw: null,
|
|
4002
4537
|
terminal: false,
|
|
4003
4538
|
lastLeg: null,
|
|
4004
4539
|
legs: [],
|
|
@@ -4029,14 +4564,16 @@ var mergeLegs = (prev, snapshot, delta) => {
|
|
|
4029
4564
|
return next;
|
|
4030
4565
|
};
|
|
4031
4566
|
var restToLifecycleState = (response) => {
|
|
4032
|
-
var _a;
|
|
4567
|
+
var _a, _b;
|
|
4033
4568
|
return {
|
|
4034
4569
|
pending: false,
|
|
4035
4570
|
status: response.status,
|
|
4571
|
+
requestedAmountRaw: response.requested.amountRaw,
|
|
4572
|
+
completedAmountRaw: (_a = response.completedAmountRaw) != null ? _a : null,
|
|
4036
4573
|
terminal: response.status === "completed" || response.status === "partial" || response.status === "failed",
|
|
4037
4574
|
lastLeg: null,
|
|
4038
4575
|
legs: response.legs.map(restLegToWsLeg),
|
|
4039
|
-
errorMessage: (
|
|
4576
|
+
errorMessage: (_b = response.errorMessage) != null ? _b : null,
|
|
4040
4577
|
// No server timestamp on the REST response — we use 0 as "older than any
|
|
4041
4578
|
// WS timestamp" so a subsequent WS event always wins. Callers that read
|
|
4042
4579
|
// `timestamp` should treat 0/null interchangeably as "unset".
|
|
@@ -4047,14 +4584,14 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
4047
4584
|
const client = useAggClient();
|
|
4048
4585
|
const wsConnected = useAggWebSocketConnectionState();
|
|
4049
4586
|
const queryClient = (0, import_react_query15.useQueryClient)();
|
|
4050
|
-
const [state, setState] = (0,
|
|
4051
|
-
const stateRef = (0,
|
|
4587
|
+
const [state, setState] = (0, import_react15.useState)(INITIAL_STATE2);
|
|
4588
|
+
const stateRef = (0, import_react15.useRef)(state);
|
|
4052
4589
|
stateRef.current = state;
|
|
4053
|
-
const balanceRefetchedForRef = (0,
|
|
4054
|
-
(0,
|
|
4055
|
-
setState(
|
|
4590
|
+
const balanceRefetchedForRef = (0, import_react15.useRef)(null);
|
|
4591
|
+
(0, import_react15.useEffect)(() => {
|
|
4592
|
+
setState(INITIAL_STATE2);
|
|
4056
4593
|
}, [withdrawalId]);
|
|
4057
|
-
(0,
|
|
4594
|
+
(0, import_react15.useEffect)(() => {
|
|
4058
4595
|
if (!withdrawalId) return;
|
|
4059
4596
|
let cancelled = false;
|
|
4060
4597
|
(() => __async(null, null, function* () {
|
|
@@ -4073,17 +4610,19 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
4073
4610
|
cancelled = true;
|
|
4074
4611
|
};
|
|
4075
4612
|
}, [client, withdrawalId, wsConnected]);
|
|
4076
|
-
const handler = (0,
|
|
4613
|
+
const handler = (0, import_react15.useMemo)(() => {
|
|
4077
4614
|
if (!withdrawalId) return null;
|
|
4078
4615
|
return (msg) => {
|
|
4079
4616
|
if (msg.withdrawalId !== withdrawalId) return;
|
|
4080
4617
|
setState((prev) => {
|
|
4081
|
-
var _a, _b;
|
|
4618
|
+
var _a, _b, _c, _d;
|
|
4082
4619
|
return {
|
|
4083
4620
|
pending: false,
|
|
4084
4621
|
status: msg.status,
|
|
4622
|
+
requestedAmountRaw: (_a = msg.requestedAmountRaw) != null ? _a : prev.requestedAmountRaw,
|
|
4623
|
+
completedAmountRaw: (_b = msg.completedAmountRaw) != null ? _b : prev.completedAmountRaw,
|
|
4085
4624
|
terminal: msg.terminal,
|
|
4086
|
-
lastLeg: (
|
|
4625
|
+
lastLeg: (_c = msg.leg) != null ? _c : null,
|
|
4087
4626
|
// `legs[]` is the cumulative server-known truth. Snapshots
|
|
4088
4627
|
// (`pending` / terminal rollup) carry a full `legs[]` and replace
|
|
4089
4628
|
// it. Intermediate per-leg deltas carry only `leg` (no `legs[]`)
|
|
@@ -4091,23 +4630,23 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
4091
4630
|
// (sourceChainId, destChainId, type) so the timeline UI doesn't
|
|
4092
4631
|
// collapse to empty between snapshots.
|
|
4093
4632
|
legs: mergeLegs(prev.legs, msg.legs, msg.leg),
|
|
4094
|
-
errorMessage: (
|
|
4633
|
+
errorMessage: (_d = msg.errorMessage) != null ? _d : null,
|
|
4095
4634
|
timestamp: msg.timestamp
|
|
4096
4635
|
};
|
|
4097
4636
|
});
|
|
4098
4637
|
};
|
|
4099
4638
|
}, [withdrawalId]);
|
|
4100
4639
|
useOnWithdrawalLifecycle(handler);
|
|
4101
|
-
(0,
|
|
4640
|
+
(0, import_react15.useEffect)(() => {
|
|
4102
4641
|
if (!withdrawalId) return;
|
|
4103
4642
|
if (!state.terminal) return;
|
|
4104
4643
|
if (balanceRefetchedForRef.current === withdrawalId) return;
|
|
4105
4644
|
balanceRefetchedForRef.current = withdrawalId;
|
|
4106
|
-
|
|
4645
|
+
invalidateUserMoneyState(queryClient);
|
|
4107
4646
|
client.syncManagedBalances().catch(() => {
|
|
4108
4647
|
});
|
|
4109
4648
|
}, [client, queryClient, state.terminal, withdrawalId]);
|
|
4110
|
-
const reset = (0,
|
|
4649
|
+
const reset = (0, import_react15.useCallback)(() => setState(INITIAL_STATE2), []);
|
|
4111
4650
|
return { state, reset };
|
|
4112
4651
|
}
|
|
4113
4652
|
|
|
@@ -4115,7 +4654,7 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
4115
4654
|
var import_sdk4 = require("@agg-build/sdk");
|
|
4116
4655
|
|
|
4117
4656
|
// src/use-geo-block.ts
|
|
4118
|
-
var
|
|
4657
|
+
var import_react16 = require("react");
|
|
4119
4658
|
var DEFAULT_STATE = {
|
|
4120
4659
|
isLocationBlocked: false,
|
|
4121
4660
|
isTradingBlocked: false,
|
|
@@ -4123,7 +4662,7 @@ var DEFAULT_STATE = {
|
|
|
4123
4662
|
};
|
|
4124
4663
|
function useGeoBlock() {
|
|
4125
4664
|
var _a, _b;
|
|
4126
|
-
const authContext = (0,
|
|
4665
|
+
const authContext = (0, import_react16.useContext)(AggAuthContext);
|
|
4127
4666
|
if (process.env.NEXT_PUBLIC_GEO_BLOCK_DISABLE === "true") return DEFAULT_STATE;
|
|
4128
4667
|
const isBlocked = (_b = (_a = authContext == null ? void 0 : authContext.user) == null ? void 0 : _a.isLocationBlocked) != null ? _b : false;
|
|
4129
4668
|
if (!isBlocked) return DEFAULT_STATE;
|
|
@@ -4135,7 +4674,7 @@ function useGeoBlock() {
|
|
|
4135
4674
|
}
|
|
4136
4675
|
|
|
4137
4676
|
// src/use-agg-auth.ts
|
|
4138
|
-
var
|
|
4677
|
+
var import_react17 = require("react");
|
|
4139
4678
|
function useAggAuth(options = {}) {
|
|
4140
4679
|
const {
|
|
4141
4680
|
isAuthenticated,
|
|
@@ -4145,7 +4684,7 @@ function useAggAuth(options = {}) {
|
|
|
4145
4684
|
signIn: signInWithProvider,
|
|
4146
4685
|
signOut
|
|
4147
4686
|
} = useAggAuthContext();
|
|
4148
|
-
const signIn = (0,
|
|
4687
|
+
const signIn = (0, import_react17.useCallback)(
|
|
4149
4688
|
(statement) => __async(null, null, function* () {
|
|
4150
4689
|
if (!options.signMessage) {
|
|
4151
4690
|
throw new Error(
|
|
@@ -4169,11 +4708,11 @@ function useAggAuth(options = {}) {
|
|
|
4169
4708
|
}
|
|
4170
4709
|
|
|
4171
4710
|
// src/use-link-account.ts
|
|
4172
|
-
var
|
|
4711
|
+
var import_react18 = require("react");
|
|
4173
4712
|
function useLinkAccount() {
|
|
4174
4713
|
const client = useAggClient();
|
|
4175
|
-
const [isLoading, setIsLoading] = (0,
|
|
4176
|
-
const [error, setError] = (0,
|
|
4714
|
+
const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
|
|
4715
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
4177
4716
|
const run = (fn) => {
|
|
4178
4717
|
setIsLoading(true);
|
|
4179
4718
|
setError(null);
|
|
@@ -4183,11 +4722,11 @@ function useLinkAccount() {
|
|
|
4183
4722
|
throw err;
|
|
4184
4723
|
}).finally(() => setIsLoading(false));
|
|
4185
4724
|
};
|
|
4186
|
-
const startLink = (0,
|
|
4725
|
+
const startLink = (0, import_react18.useCallback)(
|
|
4187
4726
|
(body) => run(() => client.linkAccount(body)),
|
|
4188
4727
|
[client]
|
|
4189
4728
|
);
|
|
4190
|
-
const confirmLink = (0,
|
|
4729
|
+
const confirmLink = (0, import_react18.useCallback)(
|
|
4191
4730
|
(token) => run(() => client.linkAccountConfirm(token)),
|
|
4192
4731
|
[client]
|
|
4193
4732
|
);
|
|
@@ -4233,10 +4772,10 @@ function useCategories(options) {
|
|
|
4233
4772
|
}
|
|
4234
4773
|
|
|
4235
4774
|
// src/use-debounced-value.ts
|
|
4236
|
-
var
|
|
4775
|
+
var import_react19 = require("react");
|
|
4237
4776
|
function useDebouncedValue(value, delay) {
|
|
4238
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
4239
|
-
(0,
|
|
4777
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react19.useState)(value);
|
|
4778
|
+
(0, import_react19.useEffect)(() => {
|
|
4240
4779
|
const timeoutId = window.setTimeout(() => {
|
|
4241
4780
|
setDebouncedValue(value);
|
|
4242
4781
|
}, delay);
|
|
@@ -4252,11 +4791,22 @@ var import_react_query17 = require("@tanstack/react-query");
|
|
|
4252
4791
|
function useExecutionOrders(options = {}) {
|
|
4253
4792
|
var _a, _b;
|
|
4254
4793
|
const client = useAggClient();
|
|
4255
|
-
const {
|
|
4794
|
+
const {
|
|
4795
|
+
status,
|
|
4796
|
+
orderId,
|
|
4797
|
+
quoteId,
|
|
4798
|
+
limit = 50,
|
|
4799
|
+
enabled = true,
|
|
4800
|
+
refetchIntervalMs = false
|
|
4801
|
+
} = options;
|
|
4256
4802
|
const query = (0, import_react_query17.useInfiniteQuery)({
|
|
4257
|
-
|
|
4803
|
+
// quoteId + orderId are part of the cache key — different filters
|
|
4804
|
+
// produce different result sets, so they have to vary the key.
|
|
4805
|
+
queryKey: ["execution-orders", status != null ? status : "all", quoteId != null ? quoteId : null, orderId != null ? orderId : null, limit],
|
|
4258
4806
|
queryFn: ({ pageParam }) => client.getExecutionOrders({
|
|
4259
4807
|
status,
|
|
4808
|
+
orderId,
|
|
4809
|
+
quoteId,
|
|
4260
4810
|
limit,
|
|
4261
4811
|
cursor: pageParam
|
|
4262
4812
|
}),
|
|
@@ -4278,10 +4828,36 @@ function useExecutionOrders(options = {}) {
|
|
|
4278
4828
|
|
|
4279
4829
|
// src/use-user-activity.ts
|
|
4280
4830
|
var import_react_query18 = require("@tanstack/react-query");
|
|
4831
|
+
var DEFAULT_PENDING_REFETCH_INTERVAL_MS = 15e3;
|
|
4832
|
+
var PENDING_ACTIVITY_STATUSES = /* @__PURE__ */ new Set([
|
|
4833
|
+
"pending",
|
|
4834
|
+
// trade pre-fill lifecycle
|
|
4835
|
+
"signing",
|
|
4836
|
+
"pending_bridge",
|
|
4837
|
+
"submitting",
|
|
4838
|
+
"submitted",
|
|
4839
|
+
// withdrawal lifecycle
|
|
4840
|
+
"bridging",
|
|
4841
|
+
"transferring"
|
|
4842
|
+
]);
|
|
4843
|
+
var hasPendingActivity = (pages) => {
|
|
4844
|
+
if (!pages) return false;
|
|
4845
|
+
for (const page of pages) {
|
|
4846
|
+
for (const item of page.data) {
|
|
4847
|
+
if (PENDING_ACTIVITY_STATUSES.has(item.status.toLowerCase())) return true;
|
|
4848
|
+
}
|
|
4849
|
+
}
|
|
4850
|
+
return false;
|
|
4851
|
+
};
|
|
4281
4852
|
function useUserActivity(options = {}) {
|
|
4282
4853
|
var _a, _b;
|
|
4283
4854
|
const client = useAggClient();
|
|
4284
|
-
const {
|
|
4855
|
+
const {
|
|
4856
|
+
type,
|
|
4857
|
+
limit = 50,
|
|
4858
|
+
enabled = true,
|
|
4859
|
+
pendingRefetchIntervalMs = DEFAULT_PENDING_REFETCH_INTERVAL_MS
|
|
4860
|
+
} = options;
|
|
4285
4861
|
const query = (0, import_react_query18.useInfiniteQuery)({
|
|
4286
4862
|
queryKey: ["user-activity", type != null ? type : "all", limit],
|
|
4287
4863
|
queryFn: ({ pageParam }) => client.getUserActivity({
|
|
@@ -4294,7 +4870,17 @@ function useUserActivity(options = {}) {
|
|
|
4294
4870
|
var _a2;
|
|
4295
4871
|
return lastPage.hasMore ? (_a2 = lastPage.nextCursor) != null ? _a2 : void 0 : void 0;
|
|
4296
4872
|
},
|
|
4297
|
-
enabled
|
|
4873
|
+
enabled,
|
|
4874
|
+
// Keep the previously-loaded pages visible while a refetch is in
|
|
4875
|
+
// flight (typically after a deposit / withdraw cache invalidation).
|
|
4876
|
+
// Without this the feed flashes to the skeleton mid-session, which
|
|
4877
|
+
// is worse UX than briefly showing slightly-stale rows.
|
|
4878
|
+
placeholderData: import_react_query18.keepPreviousData,
|
|
4879
|
+
refetchInterval: (q) => {
|
|
4880
|
+
if (pendingRefetchIntervalMs === false) return false;
|
|
4881
|
+
const data = q.state.data;
|
|
4882
|
+
return hasPendingActivity(data == null ? void 0 : data.pages) ? pendingRefetchIntervalMs : false;
|
|
4883
|
+
}
|
|
4298
4884
|
});
|
|
4299
4885
|
const activities = (_b = (_a = query.data) == null ? void 0 : _a.pages.flatMap((page) => page.data)) != null ? _b : [];
|
|
4300
4886
|
const hasNextPage = !!query.hasNextPage;
|
|
@@ -4305,13 +4891,13 @@ function useUserActivity(options = {}) {
|
|
|
4305
4891
|
}
|
|
4306
4892
|
|
|
4307
4893
|
// src/use-external-id.ts
|
|
4308
|
-
var
|
|
4894
|
+
var import_react20 = require("react");
|
|
4309
4895
|
function useExternalId(options = {}) {
|
|
4310
4896
|
const client = useAggClient();
|
|
4311
4897
|
const { onSuccess, onError: onErrorCb } = options;
|
|
4312
|
-
const [isLoading, setIsLoading] = (0,
|
|
4313
|
-
const [error, setError] = (0,
|
|
4314
|
-
const linkExternalId = (0,
|
|
4898
|
+
const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
|
|
4899
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
4900
|
+
const linkExternalId = (0, import_react20.useCallback)(
|
|
4315
4901
|
(assertion) => __async(null, null, function* () {
|
|
4316
4902
|
setIsLoading(true);
|
|
4317
4903
|
setError(null);
|
|
@@ -4362,17 +4948,17 @@ function useExecutionPositions(options = {}) {
|
|
|
4362
4948
|
}
|
|
4363
4949
|
|
|
4364
4950
|
// src/use-live-candle-overlay.ts
|
|
4365
|
-
var
|
|
4951
|
+
var import_react24 = require("react");
|
|
4366
4952
|
|
|
4367
4953
|
// src/use-live-candles.ts
|
|
4368
|
-
var
|
|
4954
|
+
var import_react23 = require("react");
|
|
4369
4955
|
var import_sdk3 = require("@agg-build/sdk");
|
|
4370
4956
|
|
|
4371
4957
|
// src/use-market-chart.ts
|
|
4372
4958
|
var import_react_query20 = require("@tanstack/react-query");
|
|
4373
4959
|
|
|
4374
4960
|
// src/market-data/subscription.ts
|
|
4375
|
-
var
|
|
4961
|
+
var import_react21 = require("react");
|
|
4376
4962
|
function useMarketDataSubscription({
|
|
4377
4963
|
marketId,
|
|
4378
4964
|
additionalMarketIds,
|
|
@@ -4381,7 +4967,7 @@ function useMarketDataSubscription({
|
|
|
4381
4967
|
trades = false
|
|
4382
4968
|
}) {
|
|
4383
4969
|
const ws = useAggWebSocket();
|
|
4384
|
-
const allIds = (0,
|
|
4970
|
+
const allIds = (0, import_react21.useMemo)(() => {
|
|
4385
4971
|
const ids = /* @__PURE__ */ new Set();
|
|
4386
4972
|
if (marketId) ids.add(marketId);
|
|
4387
4973
|
if (additionalMarketIds) {
|
|
@@ -4392,7 +4978,7 @@ function useMarketDataSubscription({
|
|
|
4392
4978
|
return [...ids];
|
|
4393
4979
|
}, [marketId, additionalMarketIds]);
|
|
4394
4980
|
const stableKey = allIds.join("|");
|
|
4395
|
-
(0,
|
|
4981
|
+
(0, import_react21.useEffect)(() => {
|
|
4396
4982
|
if (!ws || !allIds.length || !enabled || !orderbook && !trades) return;
|
|
4397
4983
|
const unsubscribers = [];
|
|
4398
4984
|
for (const id of allIds) {
|
|
@@ -4429,24 +5015,23 @@ function useMarketChart(options) {
|
|
|
4429
5015
|
endTs = null,
|
|
4430
5016
|
countBack = null,
|
|
4431
5017
|
enabled = true,
|
|
4432
|
-
live
|
|
5018
|
+
live,
|
|
5019
|
+
refetchIntervalMs = null,
|
|
5020
|
+
rangeKey
|
|
4433
5021
|
} = options;
|
|
5022
|
+
const resolvedRangeKey = rangeKey != null ? rangeKey : interval;
|
|
4434
5023
|
const liveEnabled = live != null ? live : enableLiveUpdates;
|
|
4435
5024
|
const outcomeIds = (() => {
|
|
4436
5025
|
const ids = /* @__PURE__ */ new Set();
|
|
4437
|
-
if (marketId)
|
|
4438
|
-
ids.add(marketId);
|
|
4439
|
-
}
|
|
5026
|
+
if (marketId) ids.add(marketId);
|
|
4440
5027
|
if (venueMarketIds) {
|
|
4441
5028
|
for (const venueMarketId of venueMarketIds) {
|
|
4442
|
-
if (venueMarketId)
|
|
4443
|
-
ids.add(venueMarketId);
|
|
4444
|
-
}
|
|
5029
|
+
if (venueMarketId) ids.add(venueMarketId);
|
|
4445
5030
|
}
|
|
4446
5031
|
}
|
|
4447
|
-
return [...ids];
|
|
5032
|
+
return [...ids].sort();
|
|
4448
5033
|
})();
|
|
4449
|
-
const primaryOutcomeId = (_a =
|
|
5034
|
+
const primaryOutcomeId = (_a = marketId != null ? marketId : venueMarketIds == null ? void 0 : venueMarketIds.find(Boolean)) != null ? _a : null;
|
|
4450
5035
|
const isQueryEnabled = enabled && outcomeIds.length > 0 && endTs != null && (startTs != null || countBack != null);
|
|
4451
5036
|
useMarketDataSubscription({
|
|
4452
5037
|
marketId: primaryOutcomeId,
|
|
@@ -4457,7 +5042,11 @@ function useMarketChart(options) {
|
|
|
4457
5042
|
});
|
|
4458
5043
|
const queries = (0, import_react_query20.useQueries)({
|
|
4459
5044
|
queries: outcomeIds.map((outcomeId) => ({
|
|
4460
|
-
|
|
5045
|
+
// Cache key is intentionally time-free. The rolling window's
|
|
5046
|
+
// startTs/endTs advance on every bucket but the user expects the same
|
|
5047
|
+
// chart on revisit — see comment on `marketDataKeys.chart`. queryFn
|
|
5048
|
+
// closes over the current window so refetches still fetch fresh data.
|
|
5049
|
+
queryKey: marketDataKeys.chart(outcomeId, interval, resolvedRangeKey, countBack),
|
|
4461
5050
|
queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
|
|
4462
5051
|
const response = yield client.getChartBars(
|
|
4463
5052
|
{
|
|
@@ -4478,11 +5067,17 @@ function useMarketChart(options) {
|
|
|
4478
5067
|
});
|
|
4479
5068
|
}),
|
|
4480
5069
|
enabled: isQueryEnabled,
|
|
4481
|
-
|
|
4482
|
-
|
|
5070
|
+
// Treat data as fresh for one bucket — within that window the
|
|
5071
|
+
// existing entry serves remounts without a refetch, and the
|
|
5072
|
+
// `refetchInterval` below schedules the next bucket's refresh.
|
|
5073
|
+
staleTime: refetchIntervalMs != null && refetchIntervalMs > 0 ? refetchIntervalMs : 3e4,
|
|
5074
|
+
// 60 min — survives typical tab/page revisits without re-fetching.
|
|
5075
|
+
gcTime: 60 * 6e4,
|
|
4483
5076
|
refetchOnWindowFocus: false,
|
|
4484
5077
|
retry: 1,
|
|
4485
|
-
placeholderData: import_react_query20.keepPreviousData
|
|
5078
|
+
placeholderData: import_react_query20.keepPreviousData,
|
|
5079
|
+
refetchInterval: refetchIntervalMs != null && refetchIntervalMs > 0 ? refetchIntervalMs : false,
|
|
5080
|
+
refetchIntervalInBackground: false
|
|
4486
5081
|
}))
|
|
4487
5082
|
});
|
|
4488
5083
|
const successfulDatasets = queries.flatMap((query) => {
|
|
@@ -4511,13 +5106,13 @@ function useMarketChart(options) {
|
|
|
4511
5106
|
}
|
|
4512
5107
|
|
|
4513
5108
|
// src/use-live-market-stores.ts
|
|
4514
|
-
var
|
|
5109
|
+
var import_react22 = require("react");
|
|
4515
5110
|
function useLiveMarketStores(venueMarketIds) {
|
|
4516
5111
|
const ws = useAggWebSocket();
|
|
4517
|
-
const [, forceRender] = (0,
|
|
4518
|
-
const subsRef = (0,
|
|
4519
|
-
const stableKey = (0,
|
|
4520
|
-
(0,
|
|
5112
|
+
const [, forceRender] = (0, import_react22.useReducer)((c) => c + 1, 0);
|
|
5113
|
+
const subsRef = (0, import_react22.useRef)(/* @__PURE__ */ new Map());
|
|
5114
|
+
const stableKey = (0, import_react22.useMemo)(() => venueMarketIds.slice().sort().join("|"), [venueMarketIds]);
|
|
5115
|
+
(0, import_react22.useEffect)(() => {
|
|
4521
5116
|
if (!ws || venueMarketIds.length === 0) return;
|
|
4522
5117
|
const current = subsRef.current;
|
|
4523
5118
|
const desired = new Set(venueMarketIds);
|
|
@@ -4554,7 +5149,7 @@ function candleToLive(c, source) {
|
|
|
4554
5149
|
function useLiveCandles(options) {
|
|
4555
5150
|
var _a;
|
|
4556
5151
|
const { market, interval = "5m", mode = "venue", startTs, endTs } = options;
|
|
4557
|
-
const venueMarketIds = (0,
|
|
5152
|
+
const venueMarketIds = (0, import_react23.useMemo)(() => {
|
|
4558
5153
|
if (!market) return [];
|
|
4559
5154
|
if (mode === "venue") return [market.id];
|
|
4560
5155
|
const ids = [market.id];
|
|
@@ -4574,7 +5169,7 @@ function useLiveCandles(options) {
|
|
|
4574
5169
|
endTs: endTs != null ? endTs : null,
|
|
4575
5170
|
enabled: !!restMarketId && startTs != null && endTs != null
|
|
4576
5171
|
});
|
|
4577
|
-
const liveData = (0,
|
|
5172
|
+
const liveData = (0, import_react23.useMemo)(() => {
|
|
4578
5173
|
if (builders2.length === 0) return { closed: [], forming: null };
|
|
4579
5174
|
if (mode === "venue" || builders2.length === 1) {
|
|
4580
5175
|
return {
|
|
@@ -4587,7 +5182,7 @@ function useLiveCandles(options) {
|
|
|
4587
5182
|
forming: (0, import_sdk3.mergeCandles)(builders2.map((b) => b.getForming(interval)))
|
|
4588
5183
|
};
|
|
4589
5184
|
}, [builders2, interval, mode]);
|
|
4590
|
-
const candles = (0,
|
|
5185
|
+
const candles = (0, import_react23.useMemo)(() => {
|
|
4591
5186
|
const byTime = /* @__PURE__ */ new Map();
|
|
4592
5187
|
if (chartData) {
|
|
4593
5188
|
const venueEntries = Object.values(chartData.venues);
|
|
@@ -4612,7 +5207,7 @@ function useLiveCandles(options) {
|
|
|
4612
5207
|
merged.sort((a, b) => a.time - b.time);
|
|
4613
5208
|
return merged;
|
|
4614
5209
|
}, [chartData, liveData.closed]);
|
|
4615
|
-
const liveCandle = (0,
|
|
5210
|
+
const liveCandle = (0, import_react23.useMemo)(() => {
|
|
4616
5211
|
if (!liveData.forming) return null;
|
|
4617
5212
|
return candleToLive(liveData.forming, "live");
|
|
4618
5213
|
}, [liveData.forming]);
|
|
@@ -4660,7 +5255,7 @@ function useLiveCandleOverlay(options) {
|
|
|
4660
5255
|
startTs,
|
|
4661
5256
|
endTs
|
|
4662
5257
|
});
|
|
4663
|
-
const scaleCandle = (0,
|
|
5258
|
+
const scaleCandle = (0, import_react24.useCallback)(
|
|
4664
5259
|
(candle) => ({
|
|
4665
5260
|
time: candle.time,
|
|
4666
5261
|
open: candle.o * scale,
|
|
@@ -4671,8 +5266,8 @@ function useLiveCandleOverlay(options) {
|
|
|
4671
5266
|
}),
|
|
4672
5267
|
[scale]
|
|
4673
5268
|
);
|
|
4674
|
-
const scaledCandles = (0,
|
|
4675
|
-
const liveCandle = (0,
|
|
5269
|
+
const scaledCandles = (0, import_react24.useMemo)(() => rawCandles.map(scaleCandle), [rawCandles, scaleCandle]);
|
|
5270
|
+
const liveCandle = (0, import_react24.useMemo)(() => rawLive ? scaleCandle(rawLive) : null, [rawLive, scaleCandle]);
|
|
4676
5271
|
return {
|
|
4677
5272
|
liveCandle,
|
|
4678
5273
|
scaledCandles,
|
|
@@ -4683,7 +5278,7 @@ function useLiveCandleOverlay(options) {
|
|
|
4683
5278
|
}
|
|
4684
5279
|
|
|
4685
5280
|
// src/use-event-orderbook-data.ts
|
|
4686
|
-
var
|
|
5281
|
+
var import_react25 = require("react");
|
|
4687
5282
|
function extractSelectedOutcomeIds(selectedMarket) {
|
|
4688
5283
|
var _a, _b, _c;
|
|
4689
5284
|
if (!selectedMarket) return [];
|
|
@@ -4703,17 +5298,17 @@ function useEventOrderbookData(venueMarkets, selectedMarketId) {
|
|
|
4703
5298
|
const {
|
|
4704
5299
|
features: { enableLiveUpdates }
|
|
4705
5300
|
} = useAggUiConfig();
|
|
4706
|
-
const selectedMarket = (0,
|
|
5301
|
+
const selectedMarket = (0, import_react25.useMemo)(() => {
|
|
4707
5302
|
var _a;
|
|
4708
5303
|
if (!selectedMarketId || !(venueMarkets == null ? void 0 : venueMarkets.length)) return null;
|
|
4709
5304
|
return (_a = venueMarkets.find((m) => m.id === selectedMarketId)) != null ? _a : null;
|
|
4710
5305
|
}, [venueMarkets, selectedMarketId]);
|
|
4711
|
-
const selectedOutcomeIds = (0,
|
|
5306
|
+
const selectedOutcomeIds = (0, import_react25.useMemo)(
|
|
4712
5307
|
() => extractSelectedOutcomeIds(selectedMarket),
|
|
4713
5308
|
[selectedMarket]
|
|
4714
5309
|
);
|
|
4715
5310
|
const selectedKey = selectedOutcomeIds.join("|");
|
|
4716
|
-
(0,
|
|
5311
|
+
(0, import_react25.useEffect)(() => {
|
|
4717
5312
|
if (!ws || !enableLiveUpdates || !selectedOutcomeIds.length) return;
|
|
4718
5313
|
const unsubscribers = selectedOutcomeIds.map((id) => ws.subscribe(id, "orderbook"));
|
|
4719
5314
|
return () => {
|
|
@@ -4805,7 +5400,7 @@ function useLiveMarket(canonicalMarketId) {
|
|
|
4805
5400
|
}
|
|
4806
5401
|
|
|
4807
5402
|
// src/use-live-outcome-prices.ts
|
|
4808
|
-
var
|
|
5403
|
+
var import_react26 = require("react");
|
|
4809
5404
|
var import_react_query22 = require("@tanstack/react-query");
|
|
4810
5405
|
var EMPTY_PRICES = /* @__PURE__ */ new Map();
|
|
4811
5406
|
var buildMidpointFingerprint = (outcomeIds, queries) => {
|
|
@@ -4821,7 +5416,7 @@ function useLiveOutcomePrices(venueMarkets) {
|
|
|
4821
5416
|
const {
|
|
4822
5417
|
features: { enableLiveUpdates }
|
|
4823
5418
|
} = useAggUiConfig();
|
|
4824
|
-
const outcomeIds = (0,
|
|
5419
|
+
const outcomeIds = (0, import_react26.useMemo)(() => {
|
|
4825
5420
|
var _a;
|
|
4826
5421
|
if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
|
|
4827
5422
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -4843,11 +5438,11 @@ function useLiveOutcomePrices(venueMarkets) {
|
|
|
4843
5438
|
}))
|
|
4844
5439
|
});
|
|
4845
5440
|
const fingerprint = buildMidpointFingerprint(outcomeIds, queries);
|
|
4846
|
-
const prevRef = (0,
|
|
5441
|
+
const prevRef = (0, import_react26.useRef)({
|
|
4847
5442
|
fingerprint: "",
|
|
4848
5443
|
prices: EMPTY_PRICES
|
|
4849
5444
|
});
|
|
4850
|
-
const data = (0,
|
|
5445
|
+
const data = (0, import_react26.useMemo)(() => {
|
|
4851
5446
|
var _a, _b, _c, _d;
|
|
4852
5447
|
if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return EMPTY_PRICES;
|
|
4853
5448
|
if (fingerprint === prevRef.current.fingerprint) {
|
|
@@ -4880,6 +5475,128 @@ function findLivePriceById(livePrices, id) {
|
|
|
4880
5475
|
return livePrices.get(id);
|
|
4881
5476
|
}
|
|
4882
5477
|
|
|
5478
|
+
// src/use-live-best-prices.ts
|
|
5479
|
+
var import_react27 = require("react");
|
|
5480
|
+
var import_react_query23 = require("@tanstack/react-query");
|
|
5481
|
+
var EMPTY = /* @__PURE__ */ new Map();
|
|
5482
|
+
var extractOutcomeBestPrices = (state) => {
|
|
5483
|
+
var _a, _b;
|
|
5484
|
+
const ob = state == null ? void 0 : state.orderbook;
|
|
5485
|
+
if (!ob) return {};
|
|
5486
|
+
const bestBid = (_a = ob.bids[0]) == null ? void 0 : _a.price;
|
|
5487
|
+
const bestAsk = (_b = ob.asks[0]) == null ? void 0 : _b.price;
|
|
5488
|
+
return {
|
|
5489
|
+
bestBid: bestBid != null ? bestBid : void 0,
|
|
5490
|
+
bestAsk: bestAsk != null ? bestAsk : void 0
|
|
5491
|
+
};
|
|
5492
|
+
};
|
|
5493
|
+
var buildFingerprint = (outcomeIds, queries) => {
|
|
5494
|
+
var _a, _b, _c, _d;
|
|
5495
|
+
const parts = [];
|
|
5496
|
+
for (let i = 0; i < outcomeIds.length; i++) {
|
|
5497
|
+
const ob = (_b = (_a = queries[i]) == null ? void 0 : _a.data) == null ? void 0 : _b.orderbook;
|
|
5498
|
+
const bid = (_c = ob == null ? void 0 : ob.bids[0]) == null ? void 0 : _c.price;
|
|
5499
|
+
const ask = (_d = ob == null ? void 0 : ob.asks[0]) == null ? void 0 : _d.price;
|
|
5500
|
+
parts.push(`${outcomeIds[i]}:${bid != null ? bid : "_"}:${ask != null ? ask : "_"}`);
|
|
5501
|
+
}
|
|
5502
|
+
return parts.join("|");
|
|
5503
|
+
};
|
|
5504
|
+
function useLiveBestPrices(venueMarkets) {
|
|
5505
|
+
const {
|
|
5506
|
+
features: { enableLiveUpdates }
|
|
5507
|
+
} = useAggUiConfig();
|
|
5508
|
+
const outcomeIds = (0, import_react27.useMemo)(() => {
|
|
5509
|
+
var _a, _b;
|
|
5510
|
+
if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
|
|
5511
|
+
const ids = /* @__PURE__ */ new Set();
|
|
5512
|
+
for (const vm of venueMarkets) {
|
|
5513
|
+
for (const outcome of (_a = vm.venueMarketOutcomes) != null ? _a : []) {
|
|
5514
|
+
if (outcome.id) ids.add(outcome.id);
|
|
5515
|
+
for (const ref of (_b = outcome.matchedVenueMarketOutcomes) != null ? _b : []) {
|
|
5516
|
+
if (ref.venueMarketOutcomeId) ids.add(ref.venueMarketOutcomeId);
|
|
5517
|
+
}
|
|
5518
|
+
}
|
|
5519
|
+
}
|
|
5520
|
+
return [...ids].sort();
|
|
5521
|
+
}, [venueMarkets]);
|
|
5522
|
+
const queries = (0, import_react_query23.useQueries)({
|
|
5523
|
+
queries: outcomeIds.map((id) => ({
|
|
5524
|
+
queryKey: marketDataKeys.live(id),
|
|
5525
|
+
queryFn: () => createMarketLiveState(id),
|
|
5526
|
+
enabled: false,
|
|
5527
|
+
staleTime: Infinity,
|
|
5528
|
+
gcTime: 5 * 6e4,
|
|
5529
|
+
initialData: () => createMarketLiveState(id)
|
|
5530
|
+
}))
|
|
5531
|
+
});
|
|
5532
|
+
const fingerprint = buildFingerprint(outcomeIds, queries);
|
|
5533
|
+
const prevRef = (0, import_react27.useRef)({
|
|
5534
|
+
fingerprint: "",
|
|
5535
|
+
result: EMPTY
|
|
5536
|
+
});
|
|
5537
|
+
return (0, import_react27.useMemo)(() => {
|
|
5538
|
+
var _a, _b, _c, _d;
|
|
5539
|
+
if (!(venueMarkets == null ? void 0 : venueMarkets.length) || !enableLiveUpdates) return EMPTY;
|
|
5540
|
+
if (fingerprint === prevRef.current.fingerprint) return prevRef.current.result;
|
|
5541
|
+
const perOutcome = /* @__PURE__ */ new Map();
|
|
5542
|
+
for (let i = 0; i < outcomeIds.length; i++) {
|
|
5543
|
+
const state = (_a = queries[i]) == null ? void 0 : _a.data;
|
|
5544
|
+
const best = extractOutcomeBestPrices(state);
|
|
5545
|
+
if (best.bestBid != null || best.bestAsk != null) {
|
|
5546
|
+
perOutcome.set(outcomeIds[i], best);
|
|
5547
|
+
}
|
|
5548
|
+
}
|
|
5549
|
+
if (perOutcome.size === 0) {
|
|
5550
|
+
prevRef.current = { fingerprint, result: EMPTY };
|
|
5551
|
+
return EMPTY;
|
|
5552
|
+
}
|
|
5553
|
+
const result = new Map(perOutcome);
|
|
5554
|
+
for (const vm of venueMarkets) {
|
|
5555
|
+
for (const outcome of (_b = vm.venueMarketOutcomes) != null ? _b : []) {
|
|
5556
|
+
const refs = (_c = outcome.matchedVenueMarketOutcomes) != null ? _c : [];
|
|
5557
|
+
if (!refs.length) continue;
|
|
5558
|
+
const group = [outcome.id, ...refs.map((ref) => ref.venueMarketOutcomeId)];
|
|
5559
|
+
let groupBestAsk;
|
|
5560
|
+
let groupBestBid;
|
|
5561
|
+
for (const id of group) {
|
|
5562
|
+
const entry = perOutcome.get(id);
|
|
5563
|
+
if (!entry) continue;
|
|
5564
|
+
if (entry.bestAsk != null && (groupBestAsk == null || entry.bestAsk < groupBestAsk)) {
|
|
5565
|
+
groupBestAsk = entry.bestAsk;
|
|
5566
|
+
}
|
|
5567
|
+
if (entry.bestBid != null && (groupBestBid == null || entry.bestBid > groupBestBid)) {
|
|
5568
|
+
groupBestBid = entry.bestBid;
|
|
5569
|
+
}
|
|
5570
|
+
}
|
|
5571
|
+
if (groupBestAsk == null && groupBestBid == null) continue;
|
|
5572
|
+
for (const id of group) {
|
|
5573
|
+
const prev = (_d = result.get(id)) != null ? _d : {};
|
|
5574
|
+
const nextBid = groupBestBid != null ? groupBestBid : prev.bestBid;
|
|
5575
|
+
const nextAsk = groupBestAsk != null ? groupBestAsk : prev.bestAsk;
|
|
5576
|
+
if (nextBid == null && nextAsk == null) continue;
|
|
5577
|
+
result.set(id, __spreadValues(__spreadValues({}, nextBid != null ? { bestBid: nextBid } : {}), nextAsk != null ? { bestAsk: nextAsk } : {}));
|
|
5578
|
+
}
|
|
5579
|
+
}
|
|
5580
|
+
}
|
|
5581
|
+
prevRef.current = { fingerprint, result };
|
|
5582
|
+
return result;
|
|
5583
|
+
}, [venueMarkets, enableLiveUpdates, fingerprint, outcomeIds, queries]);
|
|
5584
|
+
}
|
|
5585
|
+
function mergeBestPricesPreferringLive(rest, live) {
|
|
5586
|
+
var _a, _b, _c;
|
|
5587
|
+
if (!live.size) return rest != null ? rest : EMPTY;
|
|
5588
|
+
if (!rest || !rest.size) return live;
|
|
5589
|
+
const merged = new Map(rest);
|
|
5590
|
+
for (const [id, liveEntry] of live) {
|
|
5591
|
+
const prev = (_a = merged.get(id)) != null ? _a : {};
|
|
5592
|
+
merged.set(id, {
|
|
5593
|
+
bestBid: (_b = liveEntry.bestBid) != null ? _b : prev.bestBid,
|
|
5594
|
+
bestAsk: (_c = liveEntry.bestAsk) != null ? _c : prev.bestAsk
|
|
5595
|
+
});
|
|
5596
|
+
}
|
|
5597
|
+
return merged;
|
|
5598
|
+
}
|
|
5599
|
+
|
|
4883
5600
|
// src/use-live-trades.ts
|
|
4884
5601
|
function useLiveTrades(canonicalMarketId) {
|
|
4885
5602
|
const {
|
|
@@ -4896,19 +5613,146 @@ function useLiveTrades(canonicalMarketId) {
|
|
|
4896
5613
|
}
|
|
4897
5614
|
|
|
4898
5615
|
// src/use-midpoints.ts
|
|
4899
|
-
var
|
|
4900
|
-
var
|
|
5616
|
+
var import_react_query24 = require("@tanstack/react-query");
|
|
5617
|
+
var import_react28 = require("react");
|
|
4901
5618
|
var normalizeVenueMarketIds = (venueMarkets) => {
|
|
4902
|
-
|
|
4903
|
-
|
|
5619
|
+
var _a;
|
|
5620
|
+
const ids = /* @__PURE__ */ new Set();
|
|
5621
|
+
for (const market of venueMarkets != null ? venueMarkets : []) {
|
|
5622
|
+
if (market.id) ids.add(market.id);
|
|
5623
|
+
for (const sibling of (_a = market.matchedVenueMarkets) != null ? _a : []) {
|
|
5624
|
+
if (sibling.id) ids.add(sibling.id);
|
|
5625
|
+
}
|
|
5626
|
+
}
|
|
5627
|
+
return [...ids].sort((left, right) => left.localeCompare(right));
|
|
5628
|
+
};
|
|
5629
|
+
var normalizeOutcomeLabel = (label) => {
|
|
5630
|
+
return typeof label === "string" ? label.trim().toLowerCase() : "";
|
|
5631
|
+
};
|
|
5632
|
+
var resolveBestMidpointCandidateOutcomeIds = (venueMarkets) => {
|
|
5633
|
+
var _a, _b;
|
|
5634
|
+
if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
|
|
5635
|
+
const candidateIds = [];
|
|
5636
|
+
for (const market of venueMarkets) {
|
|
5637
|
+
const outcomes = (_a = market.venueMarketOutcomes) != null ? _a : [];
|
|
5638
|
+
const yesOutcome = outcomes.find((outcome) => normalizeOutcomeLabel(outcome.label) === "yes");
|
|
5639
|
+
if (yesOutcome == null ? void 0 : yesOutcome.id) {
|
|
5640
|
+
candidateIds.push(yesOutcome.id);
|
|
5641
|
+
continue;
|
|
5642
|
+
}
|
|
5643
|
+
const firstOutcomeId = (_b = outcomes[0]) == null ? void 0 : _b.id;
|
|
5644
|
+
if (firstOutcomeId) {
|
|
5645
|
+
candidateIds.push(firstOutcomeId);
|
|
5646
|
+
}
|
|
5647
|
+
}
|
|
5648
|
+
return [...new Set(candidateIds)];
|
|
5649
|
+
};
|
|
5650
|
+
var resolveSiblingOutcomeMidpoint = (matched, ref) => {
|
|
5651
|
+
var _a, _b;
|
|
5652
|
+
if (!(matched == null ? void 0 : matched.length)) return null;
|
|
5653
|
+
const sibling = matched.find((m) => m.venueMarketId === ref.venueMarketId);
|
|
5654
|
+
if (!((_a = sibling == null ? void 0 : sibling.outcomes) == null ? void 0 : _a.length)) return null;
|
|
5655
|
+
const sibOutcome = sibling.outcomes.find(
|
|
5656
|
+
(o) => o.venueMarketOutcomeId === ref.venueMarketOutcomeId
|
|
4904
5657
|
);
|
|
5658
|
+
if ((sibOutcome == null ? void 0 : sibOutcome.midpoint) == null) return null;
|
|
5659
|
+
return { midpoint: sibOutcome.midpoint, venue: (_b = sibling.venue) != null ? _b : null };
|
|
5660
|
+
};
|
|
5661
|
+
var extractBestPrices = (data, venueMarkets) => {
|
|
5662
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
5663
|
+
const bestPrices = /* @__PURE__ */ new Map();
|
|
5664
|
+
const venuesByOutcome = /* @__PURE__ */ new Map();
|
|
5665
|
+
if (!(data == null ? void 0 : data.length)) return { bestPrices, bestPriceVenuesByOutcomeId: venuesByOutcome };
|
|
5666
|
+
const setEntry = (outcomeId, next) => {
|
|
5667
|
+
const prev = bestPrices.get(outcomeId);
|
|
5668
|
+
const merged = __spreadValues({}, prev != null ? prev : {});
|
|
5669
|
+
if (next.bestBid != null) merged.bestBid = next.bestBid;
|
|
5670
|
+
if (next.bestAsk != null) merged.bestAsk = next.bestAsk;
|
|
5671
|
+
if (merged.bestBid != null || merged.bestAsk != null) bestPrices.set(outcomeId, merged);
|
|
5672
|
+
const prevVenues = venuesByOutcome.get(outcomeId);
|
|
5673
|
+
const mergedVenues = __spreadValues({}, prevVenues != null ? prevVenues : {});
|
|
5674
|
+
if (next.bestBidVenue != null) mergedVenues.bestBidVenue = next.bestBidVenue;
|
|
5675
|
+
if (next.bestAskVenue != null) mergedVenues.bestAskVenue = next.bestAskVenue;
|
|
5676
|
+
if (mergedVenues.bestBidVenue || mergedVenues.bestAskVenue) {
|
|
5677
|
+
venuesByOutcome.set(outcomeId, mergedVenues);
|
|
5678
|
+
}
|
|
5679
|
+
};
|
|
5680
|
+
for (const item of data) {
|
|
5681
|
+
const venue = (_a = item.venue) != null ? _a : null;
|
|
5682
|
+
for (const o of (_b = item.outcomes) != null ? _b : []) {
|
|
5683
|
+
if (o.bestBid != null || o.bestAsk != null) {
|
|
5684
|
+
setEntry(o.venueMarketOutcomeId, {
|
|
5685
|
+
bestBid: o.bestBid,
|
|
5686
|
+
bestAsk: o.bestAsk,
|
|
5687
|
+
bestBidVenue: o.bestBid != null ? venue : null,
|
|
5688
|
+
bestAskVenue: o.bestAsk != null ? venue : null
|
|
5689
|
+
});
|
|
5690
|
+
}
|
|
5691
|
+
}
|
|
5692
|
+
}
|
|
5693
|
+
for (const item of data) {
|
|
5694
|
+
for (const m of (_c = item.matched) != null ? _c : []) {
|
|
5695
|
+
const venue = (_d = m.venue) != null ? _d : null;
|
|
5696
|
+
for (const o of (_e = m.outcomes) != null ? _e : []) {
|
|
5697
|
+
if (bestPrices.has(o.venueMarketOutcomeId)) continue;
|
|
5698
|
+
if (o.bestBid != null || o.bestAsk != null) {
|
|
5699
|
+
setEntry(o.venueMarketOutcomeId, {
|
|
5700
|
+
bestBid: o.bestBid,
|
|
5701
|
+
bestAsk: o.bestAsk,
|
|
5702
|
+
bestBidVenue: o.bestBid != null ? venue : null,
|
|
5703
|
+
bestAskVenue: o.bestAsk != null ? venue : null
|
|
5704
|
+
});
|
|
5705
|
+
}
|
|
5706
|
+
}
|
|
5707
|
+
}
|
|
5708
|
+
}
|
|
5709
|
+
if (venueMarkets == null ? void 0 : venueMarkets.length) {
|
|
5710
|
+
for (const market of venueMarkets) {
|
|
5711
|
+
for (const outcome of (_f = market.venueMarketOutcomes) != null ? _f : []) {
|
|
5712
|
+
const refs = (_g = outcome.matchedVenueMarketOutcomes) != null ? _g : [];
|
|
5713
|
+
if (!refs.length) continue;
|
|
5714
|
+
const group = [outcome.id, ...refs.map((ref) => ref.venueMarketOutcomeId)];
|
|
5715
|
+
let bestAsk;
|
|
5716
|
+
let bestBid;
|
|
5717
|
+
let bestAskVenue;
|
|
5718
|
+
let bestBidVenue;
|
|
5719
|
+
for (const id of group) {
|
|
5720
|
+
const entry = bestPrices.get(id);
|
|
5721
|
+
const venues = venuesByOutcome.get(id);
|
|
5722
|
+
if (!entry) continue;
|
|
5723
|
+
if (entry.bestAsk != null && (bestAsk == null || entry.bestAsk < bestAsk)) {
|
|
5724
|
+
bestAsk = entry.bestAsk;
|
|
5725
|
+
bestAskVenue = (_h = venues == null ? void 0 : venues.bestAskVenue) != null ? _h : bestAskVenue;
|
|
5726
|
+
}
|
|
5727
|
+
if (entry.bestBid != null && (bestBid == null || entry.bestBid > bestBid)) {
|
|
5728
|
+
bestBid = entry.bestBid;
|
|
5729
|
+
bestBidVenue = (_i = venues == null ? void 0 : venues.bestBidVenue) != null ? _i : bestBidVenue;
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5732
|
+
if (bestAsk == null && bestBid == null) continue;
|
|
5733
|
+
for (const id of group) {
|
|
5734
|
+
setEntry(id, {
|
|
5735
|
+
bestBid,
|
|
5736
|
+
bestAsk,
|
|
5737
|
+
bestBidVenue,
|
|
5738
|
+
bestAskVenue
|
|
5739
|
+
});
|
|
5740
|
+
}
|
|
5741
|
+
}
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
return { bestPrices, bestPriceVenuesByOutcomeId: venuesByOutcome };
|
|
4905
5745
|
};
|
|
4906
5746
|
function useMidpoints(venueMarkets) {
|
|
4907
5747
|
const client = useAggClient();
|
|
4908
|
-
const ids = (0,
|
|
4909
|
-
const
|
|
5748
|
+
const ids = (0, import_react28.useMemo)(() => normalizeVenueMarketIds(venueMarkets), [venueMarkets]);
|
|
5749
|
+
const bestMidpointCandidateOutcomeIds = (0, import_react28.useMemo)(
|
|
5750
|
+
() => resolveBestMidpointCandidateOutcomeIds(venueMarkets),
|
|
5751
|
+
[venueMarkets]
|
|
5752
|
+
);
|
|
5753
|
+
const { data, isLoading } = (0, import_react_query24.useQuery)({
|
|
4910
5754
|
queryKey: ["midpoints", ids],
|
|
4911
|
-
queryFn: () => client.getMidpoints(ids),
|
|
5755
|
+
queryFn: () => client.getMidpoints(ids, { bestPrice: true }),
|
|
4912
5756
|
enabled: ids.length > 0,
|
|
4913
5757
|
staleTime: Infinity,
|
|
4914
5758
|
gcTime: 30 * 6e4,
|
|
@@ -4916,73 +5760,156 @@ function useMidpoints(venueMarkets) {
|
|
|
4916
5760
|
refetchOnWindowFocus: false,
|
|
4917
5761
|
refetchOnReconnect: false
|
|
4918
5762
|
});
|
|
4919
|
-
const result = (0,
|
|
4920
|
-
var _a, _b, _c, _d, _e
|
|
5763
|
+
const result = (0, import_react28.useMemo)(() => {
|
|
5764
|
+
var _a, _b, _c, _d, _e;
|
|
4921
5765
|
const map = /* @__PURE__ */ new Map();
|
|
4922
5766
|
const venueMap = /* @__PURE__ */ new Map();
|
|
4923
5767
|
if (!(data == null ? void 0 : data.data) || !venueMarkets) return { map, venueMap };
|
|
5768
|
+
const itemByMarketId = new Map(data.data.map((item) => [item.venueMarketId, item]));
|
|
4924
5769
|
for (const item of data.data) {
|
|
4925
|
-
if ((_a = item.outcomes) == null ? void 0 : _a.length)
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
if (bestMatchedMidpoint == null || m.midpoint < bestMatchedMidpoint) {
|
|
4947
|
-
bestMatchedMidpoint = m.midpoint;
|
|
4948
|
-
bestMatchedVenue = (_d = m.venue) != null ? _d : null;
|
|
4949
|
-
}
|
|
4950
|
-
}
|
|
4951
|
-
if (bestMatchedMidpoint != null && (primaryYesMidpoint == null || bestMatchedMidpoint < primaryYesMidpoint)) {
|
|
4952
|
-
for (const outcome of market.venueMarketOutcomes) {
|
|
4953
|
-
const isYes = ((_e = outcome.label) == null ? void 0 : _e.toLowerCase()) === "yes";
|
|
4954
|
-
map.set(outcome.id, isYes ? bestMatchedMidpoint : 1 - bestMatchedMidpoint);
|
|
4955
|
-
if (bestMatchedVenue) venueMap.set(outcome.id, bestMatchedVenue);
|
|
4956
|
-
}
|
|
4957
|
-
}
|
|
5770
|
+
if (!((_a = item.outcomes) == null ? void 0 : _a.length)) continue;
|
|
5771
|
+
for (const o of item.outcomes) {
|
|
5772
|
+
if (o.midpoint == null) continue;
|
|
5773
|
+
map.set(o.venueMarketOutcomeId, o.midpoint);
|
|
5774
|
+
if (item.venue) venueMap.set(o.venueMarketOutcomeId, item.venue);
|
|
5775
|
+
}
|
|
5776
|
+
}
|
|
5777
|
+
for (const market of venueMarkets) {
|
|
5778
|
+
const item = itemByMarketId.get(market.id);
|
|
5779
|
+
if (!item) continue;
|
|
5780
|
+
for (const outcome of market.venueMarketOutcomes) {
|
|
5781
|
+
const refs = (_b = outcome.matchedVenueMarketOutcomes) != null ? _b : [];
|
|
5782
|
+
if (!refs.length) continue;
|
|
5783
|
+
let best = (_c = map.get(outcome.id)) != null ? _c : null;
|
|
5784
|
+
let bestVenue = (_d = item.venue) != null ? _d : null;
|
|
5785
|
+
for (const ref of refs) {
|
|
5786
|
+
const sib = resolveSiblingOutcomeMidpoint(item.matched, ref);
|
|
5787
|
+
if (sib == null) continue;
|
|
5788
|
+
if (best == null || sib.midpoint < best) {
|
|
5789
|
+
best = sib.midpoint;
|
|
5790
|
+
bestVenue = (_e = sib.venue) != null ? _e : bestVenue;
|
|
4958
5791
|
}
|
|
4959
5792
|
}
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
const market = venueMarkets.find((vm) => vm.id === item.venueMarketId);
|
|
4964
|
-
if (!market) continue;
|
|
4965
|
-
for (const outcome of market.venueMarketOutcomes) {
|
|
4966
|
-
const isYes = ((_f = outcome.label) == null ? void 0 : _f.toLowerCase()) === "yes";
|
|
4967
|
-
map.set(outcome.id, isYes ? item.midpoint : 1 - item.midpoint);
|
|
4968
|
-
if (item.venue) venueMap.set(outcome.id, item.venue);
|
|
5793
|
+
if (best != null) {
|
|
5794
|
+
map.set(outcome.id, best);
|
|
5795
|
+
if (bestVenue) venueMap.set(outcome.id, bestVenue);
|
|
4969
5796
|
}
|
|
4970
5797
|
}
|
|
4971
5798
|
}
|
|
4972
5799
|
return { map, venueMap };
|
|
4973
5800
|
}, [data, venueMarkets]);
|
|
5801
|
+
const { bestMidpoint, bestMidpointVenue } = (0, import_react28.useMemo)(() => {
|
|
5802
|
+
let value;
|
|
5803
|
+
let venue;
|
|
5804
|
+
for (const outcomeId of bestMidpointCandidateOutcomeIds) {
|
|
5805
|
+
const midpoint = result.map.get(outcomeId);
|
|
5806
|
+
if (midpoint == null) continue;
|
|
5807
|
+
if (value == null || midpoint < value) {
|
|
5808
|
+
value = midpoint;
|
|
5809
|
+
venue = result.venueMap.get(outcomeId);
|
|
5810
|
+
}
|
|
5811
|
+
}
|
|
5812
|
+
if (value == null) {
|
|
5813
|
+
for (const [outcomeId, midpoint] of result.map) {
|
|
5814
|
+
if (value == null || midpoint < value) {
|
|
5815
|
+
value = midpoint;
|
|
5816
|
+
venue = result.venueMap.get(outcomeId);
|
|
5817
|
+
}
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
return { bestMidpoint: value, bestMidpointVenue: venue };
|
|
5821
|
+
}, [bestMidpointCandidateOutcomeIds, result.map, result.venueMap]);
|
|
5822
|
+
const { bestPrices, bestPriceVenuesByOutcomeId } = (0, import_react28.useMemo)(
|
|
5823
|
+
() => extractBestPrices(data == null ? void 0 : data.data, venueMarkets),
|
|
5824
|
+
[data == null ? void 0 : data.data, venueMarkets]
|
|
5825
|
+
);
|
|
4974
5826
|
return {
|
|
4975
5827
|
prices: result.map,
|
|
5828
|
+
bestMidpointsByOutcomeId: result.map,
|
|
4976
5829
|
venueByOutcomeId: result.venueMap,
|
|
4977
|
-
|
|
5830
|
+
bestPrices,
|
|
5831
|
+
bestPriceVenuesByOutcomeId,
|
|
5832
|
+
isLoading: isLoading && ids.length > 0,
|
|
5833
|
+
bestMidpoint,
|
|
5834
|
+
bestMidpointVenue
|
|
4978
5835
|
};
|
|
4979
5836
|
}
|
|
4980
5837
|
|
|
5838
|
+
// src/use-tradable-venues.ts
|
|
5839
|
+
var import_react29 = require("react");
|
|
5840
|
+
function useTradableVenues(venueMarkets) {
|
|
5841
|
+
const { prices, isLoading } = useMidpoints(venueMarkets);
|
|
5842
|
+
const tradableVenues = (0, import_react29.useMemo)(() => {
|
|
5843
|
+
var _a;
|
|
5844
|
+
if (isLoading) return null;
|
|
5845
|
+
if (!venueMarkets || venueMarkets.length === 0) return /* @__PURE__ */ new Set();
|
|
5846
|
+
const set = /* @__PURE__ */ new Set();
|
|
5847
|
+
for (const market of venueMarkets) {
|
|
5848
|
+
const outcomes = (_a = market.venueMarketOutcomes) != null ? _a : [];
|
|
5849
|
+
for (const outcome of outcomes) {
|
|
5850
|
+
if (prices.has(outcome.id)) {
|
|
5851
|
+
set.add(market.venue);
|
|
5852
|
+
break;
|
|
5853
|
+
}
|
|
5854
|
+
}
|
|
5855
|
+
}
|
|
5856
|
+
return set;
|
|
5857
|
+
}, [venueMarkets, prices, isLoading]);
|
|
5858
|
+
return { tradableVenues, isLoading };
|
|
5859
|
+
}
|
|
5860
|
+
|
|
5861
|
+
// src/use-rolling-chart-window.ts
|
|
5862
|
+
var import_react30 = require("react");
|
|
5863
|
+
var RANGE_SECONDS_BY_RANGE = {
|
|
5864
|
+
"1H": 60 * 60,
|
|
5865
|
+
"6H": 6 * 60 * 60,
|
|
5866
|
+
"1D": 24 * 60 * 60,
|
|
5867
|
+
"1W": 7 * 24 * 60 * 60,
|
|
5868
|
+
"1M": 30 * 24 * 60 * 60,
|
|
5869
|
+
ALL: 6 * 30 * 24 * 60 * 60
|
|
5870
|
+
};
|
|
5871
|
+
var rangeToSeconds = (range) => RANGE_SECONDS_BY_RANGE[range];
|
|
5872
|
+
var resolveRollingWindow = (params) => {
|
|
5873
|
+
var _a;
|
|
5874
|
+
const interval = (_a = params.interval) != null ? _a : timeRangeToInterval(params.range);
|
|
5875
|
+
const intervalSeconds = getIntervalSeconds(interval);
|
|
5876
|
+
const rangeSeconds = rangeToSeconds(params.range);
|
|
5877
|
+
const endTs = Math.ceil(params.nowSec / intervalSeconds) * intervalSeconds;
|
|
5878
|
+
return {
|
|
5879
|
+
range: params.range,
|
|
5880
|
+
interval,
|
|
5881
|
+
rangeSeconds,
|
|
5882
|
+
intervalSeconds,
|
|
5883
|
+
nowSec: params.nowSec,
|
|
5884
|
+
endTs,
|
|
5885
|
+
startTs: endTs - rangeSeconds,
|
|
5886
|
+
refetchIntervalMs: intervalSeconds * 1e3
|
|
5887
|
+
};
|
|
5888
|
+
};
|
|
5889
|
+
var useRollingChartWindow = (options) => {
|
|
5890
|
+
var _a;
|
|
5891
|
+
const tickMs = (_a = options.tickMs) != null ? _a : 1e3;
|
|
5892
|
+
const optionsNowMs = options.nowMs;
|
|
5893
|
+
const nowMs = (0, import_react30.useMemo)(() => optionsNowMs != null ? optionsNowMs : (() => Date.now()), [optionsNowMs]);
|
|
5894
|
+
const [nowSec, setNowSec] = (0, import_react30.useState)(() => Math.floor(nowMs() / 1e3));
|
|
5895
|
+
(0, import_react30.useEffect)(() => {
|
|
5896
|
+
setNowSec(Math.floor(nowMs() / 1e3));
|
|
5897
|
+
const handle = setInterval(() => {
|
|
5898
|
+
setNowSec(Math.floor(nowMs() / 1e3));
|
|
5899
|
+
}, tickMs);
|
|
5900
|
+
return () => clearInterval(handle);
|
|
5901
|
+
}, [tickMs, nowMs]);
|
|
5902
|
+
return (0, import_react30.useMemo)(
|
|
5903
|
+
() => resolveRollingWindow({ range: options.range, nowSec, interval: options.interval }),
|
|
5904
|
+
[options.range, options.interval, nowSec]
|
|
5905
|
+
);
|
|
5906
|
+
};
|
|
5907
|
+
|
|
4981
5908
|
// src/use-market-orderbook.ts
|
|
4982
|
-
var
|
|
5909
|
+
var import_react_query25 = require("@tanstack/react-query");
|
|
4983
5910
|
function useMarketOrderbook(options) {
|
|
4984
5911
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4985
|
-
const queryClient = (0,
|
|
5912
|
+
const queryClient = (0, import_react_query25.useQueryClient)();
|
|
4986
5913
|
const ws = useAggWebSocket();
|
|
4987
5914
|
const isConnected = useAggWebSocketConnectionState();
|
|
4988
5915
|
const {
|
|
@@ -4999,7 +5926,7 @@ function useMarketOrderbook(options) {
|
|
|
4999
5926
|
enabled: enabled && !!selectedOutcomeId,
|
|
5000
5927
|
orderbook: true
|
|
5001
5928
|
});
|
|
5002
|
-
const liveQueries = (0,
|
|
5929
|
+
const liveQueries = (0, import_react_query25.useQueries)({
|
|
5003
5930
|
queries: subscriptionIds.map((subscriptionId) => ({
|
|
5004
5931
|
queryKey: marketDataKeys.live(subscriptionId),
|
|
5005
5932
|
queryFn: () => createMarketLiveState(subscriptionId),
|
|
@@ -5065,7 +5992,7 @@ function useMarketOrderbook(options) {
|
|
|
5065
5992
|
}
|
|
5066
5993
|
|
|
5067
5994
|
// src/use-order-book.ts
|
|
5068
|
-
var
|
|
5995
|
+
var import_react_query26 = require("@tanstack/react-query");
|
|
5069
5996
|
function useOrderBook(options) {
|
|
5070
5997
|
const client = useAggClient();
|
|
5071
5998
|
const { orderbooks, enabled = true, canonicalMarketId } = options;
|
|
@@ -5078,7 +6005,7 @@ function useOrderBook(options) {
|
|
|
5078
6005
|
venueMarketOutcomeId: outcome.id
|
|
5079
6006
|
})) : void 0
|
|
5080
6007
|
});
|
|
5081
|
-
const batchedResult = (0,
|
|
6008
|
+
const batchedResult = (0, import_react_query26.useQuery)({
|
|
5082
6009
|
queryKey: requestedVenueMarketIds.length ? ["orderbooks", requestedVenueMarketIds, null] : ["orderbooks", "__disabled__", null],
|
|
5083
6010
|
queryFn: ({ signal }) => client.getOrderbooks(
|
|
5084
6011
|
{
|
|
@@ -5091,7 +6018,7 @@ function useOrderBook(options) {
|
|
|
5091
6018
|
gcTime: 5 * 6e4,
|
|
5092
6019
|
refetchOnWindowFocus: false,
|
|
5093
6020
|
retry: 1,
|
|
5094
|
-
placeholderData:
|
|
6021
|
+
placeholderData: import_react_query26.keepPreviousData
|
|
5095
6022
|
});
|
|
5096
6023
|
const data = (() => {
|
|
5097
6024
|
var _a, _b;
|
|
@@ -5146,7 +6073,7 @@ function useOrderBook(options) {
|
|
|
5146
6073
|
}
|
|
5147
6074
|
|
|
5148
6075
|
// src/use-orderbook-quote.ts
|
|
5149
|
-
var
|
|
6076
|
+
var import_react_query27 = require("@tanstack/react-query");
|
|
5150
6077
|
var QUOTE_DEBOUNCE_MS = 300;
|
|
5151
6078
|
var createUnavailableOrderbookError = (message, code, retryable) => {
|
|
5152
6079
|
const error = new Error(message);
|
|
@@ -5208,7 +6135,7 @@ function useOrderbookQuote(options) {
|
|
|
5208
6135
|
const { marketId, side, size, enabled = true } = options;
|
|
5209
6136
|
const debouncedSize = useDebouncedValue(size, QUOTE_DEBOUNCE_MS);
|
|
5210
6137
|
const shouldFetch = enabled && !!marketId && debouncedSize > 0;
|
|
5211
|
-
const query = (0,
|
|
6138
|
+
const query = (0, import_react_query27.useQuery)({
|
|
5212
6139
|
queryKey: marketId ? marketDataKeys.orderbookQuote(marketId, side, debouncedSize) : ["market-data", "orderbook-quote", "__disabled__"],
|
|
5213
6140
|
queryFn: () => __async(null, null, function* () {
|
|
5214
6141
|
var _a2, _b, _c, _d;
|
|
@@ -5239,7 +6166,7 @@ function useOrderbookQuote(options) {
|
|
|
5239
6166
|
staleTime: 1e4,
|
|
5240
6167
|
gcTime: 5 * 6e4,
|
|
5241
6168
|
retry: 1,
|
|
5242
|
-
placeholderData:
|
|
6169
|
+
placeholderData: import_react_query27.keepPreviousData
|
|
5243
6170
|
});
|
|
5244
6171
|
return {
|
|
5245
6172
|
data: (_a = query.data) != null ? _a : null,
|
|
@@ -5250,12 +6177,12 @@ function useOrderbookQuote(options) {
|
|
|
5250
6177
|
}
|
|
5251
6178
|
|
|
5252
6179
|
// src/use-orders.ts
|
|
5253
|
-
var
|
|
6180
|
+
var import_react_query28 = require("@tanstack/react-query");
|
|
5254
6181
|
function useOrders(options = {}) {
|
|
5255
6182
|
var _a, _b, _c, _d;
|
|
5256
6183
|
const client = useAggClient();
|
|
5257
6184
|
const { userId, status, limit = 50, offset = 0, enabled = true } = options;
|
|
5258
|
-
const query = (0,
|
|
6185
|
+
const query = (0, import_react_query28.useQuery)({
|
|
5259
6186
|
queryKey: ["orders", userId != null ? userId : "me", status != null ? status : "all", limit, offset],
|
|
5260
6187
|
queryFn: () => client.getOrders({
|
|
5261
6188
|
userId,
|
|
@@ -5272,16 +6199,16 @@ function useOrders(options = {}) {
|
|
|
5272
6199
|
}
|
|
5273
6200
|
|
|
5274
6201
|
// src/use-search.ts
|
|
5275
|
-
var
|
|
5276
|
-
var
|
|
6202
|
+
var import_react_query29 = require("@tanstack/react-query");
|
|
6203
|
+
var import_react31 = require("react");
|
|
5277
6204
|
function useSearch(options) {
|
|
5278
6205
|
var _a, _b, _c;
|
|
5279
|
-
const client = (0,
|
|
5280
|
-
const queryClient = (0,
|
|
5281
|
-
const [fallbackQueryClient] = (0,
|
|
5282
|
-
const { q, type, categoryIds, limit = 20, enabled = true } = options;
|
|
6206
|
+
const client = (0, import_react31.useContext)(AggClientContext);
|
|
6207
|
+
const queryClient = (0, import_react31.useContext)(import_react_query29.QueryClientContext);
|
|
6208
|
+
const [fallbackQueryClient] = (0, import_react31.useState)(() => new import_react_query29.QueryClient());
|
|
6209
|
+
const { q, type, categoryIds, limit = 20, enabled = true, deep = false } = options;
|
|
5283
6210
|
const isEnabled = enabled && q.length > 0;
|
|
5284
|
-
(0,
|
|
6211
|
+
(0, import_react31.useEffect)(() => {
|
|
5285
6212
|
if (queryClient) return void 0;
|
|
5286
6213
|
fallbackQueryClient.mount();
|
|
5287
6214
|
return () => {
|
|
@@ -5291,9 +6218,11 @@ function useSearch(options) {
|
|
|
5291
6218
|
if (isEnabled && !client) {
|
|
5292
6219
|
throw new Error("useSearch must be used within an <AggProvider>");
|
|
5293
6220
|
}
|
|
5294
|
-
const query = (0,
|
|
6221
|
+
const query = (0, import_react_query29.useInfiniteQuery)(
|
|
5295
6222
|
{
|
|
5296
|
-
|
|
6223
|
+
// deep is part of the key — TanStack treats deep vs light as
|
|
6224
|
+
// independent queries so users can have both modes cached side-by-side.
|
|
6225
|
+
queryKey: ["search", q, type, (_a = categoryIds == null ? void 0 : categoryIds.join(",")) != null ? _a : "", limit, deep],
|
|
5297
6226
|
queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
|
|
5298
6227
|
if (!client) {
|
|
5299
6228
|
throw new Error("useSearch must be used within an <AggProvider>");
|
|
@@ -5303,7 +6232,8 @@ function useSearch(options) {
|
|
|
5303
6232
|
type,
|
|
5304
6233
|
categoryIds,
|
|
5305
6234
|
limit,
|
|
5306
|
-
cursor: pageParam
|
|
6235
|
+
cursor: pageParam,
|
|
6236
|
+
deep
|
|
5307
6237
|
});
|
|
5308
6238
|
return res;
|
|
5309
6239
|
}),
|
|
@@ -5313,7 +6243,7 @@ function useSearch(options) {
|
|
|
5313
6243
|
if (!lastPage.hasMore) return void 0;
|
|
5314
6244
|
return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
|
|
5315
6245
|
},
|
|
5316
|
-
placeholderData:
|
|
6246
|
+
placeholderData: import_react_query29.keepPreviousData,
|
|
5317
6247
|
enabled: isEnabled && !!client
|
|
5318
6248
|
},
|
|
5319
6249
|
queryClient != null ? queryClient : fallbackQueryClient
|
|
@@ -5331,8 +6261,95 @@ function useSearch(options) {
|
|
|
5331
6261
|
};
|
|
5332
6262
|
}
|
|
5333
6263
|
|
|
6264
|
+
// src/use-market-search.ts
|
|
6265
|
+
var import_react32 = require("react");
|
|
6266
|
+
function useMarketSearch(options) {
|
|
6267
|
+
var _a;
|
|
6268
|
+
const {
|
|
6269
|
+
type,
|
|
6270
|
+
categoryIds,
|
|
6271
|
+
limit = 20,
|
|
6272
|
+
debounceMs = 200,
|
|
6273
|
+
enableSuggestions = true,
|
|
6274
|
+
minLength = 1
|
|
6275
|
+
} = options;
|
|
6276
|
+
const [query, setQueryState] = (0, import_react32.useState)("");
|
|
6277
|
+
const [submittedQuery, setSubmittedQuery] = (0, import_react32.useState)(null);
|
|
6278
|
+
const debouncedQuery = useDebouncedValue(query, debounceMs);
|
|
6279
|
+
const trimmedDebounced = debouncedQuery.trim();
|
|
6280
|
+
const suggestionsEnabled = enableSuggestions && trimmedDebounced.length >= minLength;
|
|
6281
|
+
const suggestionsQuery = useSearch({
|
|
6282
|
+
q: trimmedDebounced,
|
|
6283
|
+
type,
|
|
6284
|
+
categoryIds,
|
|
6285
|
+
limit,
|
|
6286
|
+
enabled: suggestionsEnabled,
|
|
6287
|
+
deep: false
|
|
6288
|
+
});
|
|
6289
|
+
const submittedQ = (_a = submittedQuery == null ? void 0 : submittedQuery.trim()) != null ? _a : "";
|
|
6290
|
+
const resultsQuery = useSearch({
|
|
6291
|
+
q: submittedQ,
|
|
6292
|
+
type,
|
|
6293
|
+
categoryIds,
|
|
6294
|
+
limit,
|
|
6295
|
+
enabled: submittedQ.length > 0,
|
|
6296
|
+
deep: true
|
|
6297
|
+
});
|
|
6298
|
+
const setQuery = (0, import_react32.useCallback)((value) => {
|
|
6299
|
+
setQueryState(value);
|
|
6300
|
+
}, []);
|
|
6301
|
+
const submit = (0, import_react32.useCallback)(
|
|
6302
|
+
(q) => {
|
|
6303
|
+
const target = (q != null ? q : query).trim();
|
|
6304
|
+
if (target.length === 0) return;
|
|
6305
|
+
setSubmittedQuery(target);
|
|
6306
|
+
},
|
|
6307
|
+
[query]
|
|
6308
|
+
);
|
|
6309
|
+
const clear = (0, import_react32.useCallback)(() => {
|
|
6310
|
+
setQueryState("");
|
|
6311
|
+
setSubmittedQuery(null);
|
|
6312
|
+
}, []);
|
|
6313
|
+
return {
|
|
6314
|
+
/** Current input value (controlled). */
|
|
6315
|
+
query,
|
|
6316
|
+
/** Update the input value. Triggers the debounced typeahead. */
|
|
6317
|
+
setQuery,
|
|
6318
|
+
/** The query value that produced the current `results`, or null if none. */
|
|
6319
|
+
submittedQuery,
|
|
6320
|
+
/** Fire a deep search. Use this on Enter / Search button. */
|
|
6321
|
+
submit,
|
|
6322
|
+
/** Reset both input and results state. */
|
|
6323
|
+
clear,
|
|
6324
|
+
/**
|
|
6325
|
+
* Typeahead state. Backed by a light /search call (no reranker).
|
|
6326
|
+
* `data` is paginated like `useSearch.data` (flattened across pages).
|
|
6327
|
+
*/
|
|
6328
|
+
suggestions: {
|
|
6329
|
+
data: suggestionsQuery.data,
|
|
6330
|
+
isLoading: suggestionsQuery.isLoading,
|
|
6331
|
+
isError: suggestionsQuery.isError,
|
|
6332
|
+
error: suggestionsQuery.error
|
|
6333
|
+
},
|
|
6334
|
+
/**
|
|
6335
|
+
* Full-page results state. Backed by a deep /search call (reranker on).
|
|
6336
|
+
* Cursor pagination is exposed via `fetchNextPage` / `hasNextPage`.
|
|
6337
|
+
*/
|
|
6338
|
+
results: {
|
|
6339
|
+
data: resultsQuery.data,
|
|
6340
|
+
isLoading: resultsQuery.isLoading,
|
|
6341
|
+
isError: resultsQuery.isError,
|
|
6342
|
+
error: resultsQuery.error,
|
|
6343
|
+
hasNextPage: resultsQuery.hasNextPage,
|
|
6344
|
+
fetchNextPage: resultsQuery.fetchNextPage,
|
|
6345
|
+
isFetchingNextPage: resultsQuery.isFetchingNextPage
|
|
6346
|
+
}
|
|
6347
|
+
};
|
|
6348
|
+
}
|
|
6349
|
+
|
|
5334
6350
|
// src/use-smart-route.ts
|
|
5335
|
-
var
|
|
6351
|
+
var import_react_query30 = require("@tanstack/react-query");
|
|
6352
|
+
var SMART_ROUTE_STALE_TIME_MS = 2e4;
|
|
5336
6353
|
function useSmartRoute(options) {
|
|
5337
6354
|
var _a, _b;
|
|
5338
6355
|
const client = useAggClient();
|
|
@@ -5347,10 +6364,12 @@ function useSmartRoute(options) {
|
|
|
5347
6364
|
chainBalances,
|
|
5348
6365
|
slipCapBps,
|
|
5349
6366
|
compareVenues,
|
|
5350
|
-
|
|
6367
|
+
deepEstimate,
|
|
6368
|
+
enabled = true,
|
|
6369
|
+
staleTimeMs = SMART_ROUTE_STALE_TIME_MS
|
|
5351
6370
|
} = options;
|
|
5352
6371
|
const resolvedVenueMarketOutcomeId = (_a = venueMarketOutcomeId != null ? venueMarketOutcomeId : venueMarketId) != null ? _a : outcomeId;
|
|
5353
|
-
const query = (0,
|
|
6372
|
+
const query = (0, import_react_query30.useQuery)({
|
|
5354
6373
|
queryKey: [
|
|
5355
6374
|
"smart-route",
|
|
5356
6375
|
resolvedVenueMarketOutcomeId,
|
|
@@ -5360,7 +6379,8 @@ function useSmartRoute(options) {
|
|
|
5360
6379
|
sellShares != null ? sellShares : null,
|
|
5361
6380
|
chainBalances ? JSON.stringify(chainBalances) : null,
|
|
5362
6381
|
slipCapBps != null ? slipCapBps : null,
|
|
5363
|
-
compareVenues != null ? compareVenues : false
|
|
6382
|
+
compareVenues != null ? compareVenues : false,
|
|
6383
|
+
deepEstimate != null ? deepEstimate : false
|
|
5364
6384
|
],
|
|
5365
6385
|
queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
|
|
5366
6386
|
return client.getSmartRoute(
|
|
@@ -5372,17 +6392,19 @@ function useSmartRoute(options) {
|
|
|
5372
6392
|
sellShares,
|
|
5373
6393
|
chainBalances,
|
|
5374
6394
|
slipCapBps,
|
|
5375
|
-
compareVenues
|
|
6395
|
+
compareVenues,
|
|
6396
|
+
deepEstimate
|
|
5376
6397
|
},
|
|
5377
6398
|
{ signal }
|
|
5378
6399
|
);
|
|
5379
6400
|
}),
|
|
5380
6401
|
enabled: enabled && !!resolvedVenueMarketOutcomeId && ((maxSpend != null ? maxSpend : 0) > 0 || (sellShares != null ? sellShares : 0) > 0),
|
|
5381
|
-
staleTime:
|
|
6402
|
+
staleTime: staleTimeMs,
|
|
6403
|
+
refetchInterval: staleTimeMs > 0 ? staleTimeMs : false,
|
|
5382
6404
|
gcTime: 6e4,
|
|
5383
6405
|
refetchOnWindowFocus: false,
|
|
5384
6406
|
retry: 1,
|
|
5385
|
-
placeholderData:
|
|
6407
|
+
placeholderData: import_react_query30.keepPreviousData
|
|
5386
6408
|
});
|
|
5387
6409
|
const error = query.error;
|
|
5388
6410
|
return {
|
|
@@ -5395,12 +6417,12 @@ function useSmartRoute(options) {
|
|
|
5395
6417
|
}
|
|
5396
6418
|
|
|
5397
6419
|
// src/use-user-holdings.ts
|
|
5398
|
-
var
|
|
6420
|
+
var import_react_query31 = require("@tanstack/react-query");
|
|
5399
6421
|
function useUserHoldings(options) {
|
|
5400
6422
|
var _a, _b;
|
|
5401
6423
|
const client = useAggClient();
|
|
5402
6424
|
const { venue, venueMarketId, venueEventId, enabled = true } = options;
|
|
5403
|
-
const query = (0,
|
|
6425
|
+
const query = (0, import_react_query31.useInfiniteQuery)({
|
|
5404
6426
|
queryKey: ["user-holdings", venue, venueMarketId, venueEventId],
|
|
5405
6427
|
queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
|
|
5406
6428
|
return client.getUserHoldings({
|
|
@@ -5426,15 +6448,15 @@ function useUserHoldings(options) {
|
|
|
5426
6448
|
}
|
|
5427
6449
|
|
|
5428
6450
|
// src/use-enriched-venue-event.ts
|
|
5429
|
-
var
|
|
6451
|
+
var import_react34 = require("react");
|
|
5430
6452
|
|
|
5431
6453
|
// src/use-venue-event.ts
|
|
5432
|
-
var
|
|
6454
|
+
var import_react_query32 = require("@tanstack/react-query");
|
|
5433
6455
|
function useVenueEvent(options) {
|
|
5434
6456
|
var _a;
|
|
5435
6457
|
const client = useAggClient();
|
|
5436
6458
|
const { eventId, enabled = true } = options;
|
|
5437
|
-
const query = (0,
|
|
6459
|
+
const query = (0, import_react_query32.useQuery)({
|
|
5438
6460
|
queryKey: ["venue-event", eventId],
|
|
5439
6461
|
queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
|
|
5440
6462
|
return client.getVenueEventById(eventId, { signal });
|
|
@@ -5453,13 +6475,13 @@ function useVenueEvent(options) {
|
|
|
5453
6475
|
}
|
|
5454
6476
|
|
|
5455
6477
|
// src/use-venue-markets.ts
|
|
5456
|
-
var
|
|
5457
|
-
var
|
|
6478
|
+
var import_react_query33 = require("@tanstack/react-query");
|
|
6479
|
+
var import_react33 = require("react");
|
|
5458
6480
|
function useVenueMarkets(options) {
|
|
5459
6481
|
var _a, _b, _c, _d, _e;
|
|
5460
|
-
const client = (0,
|
|
5461
|
-
const queryClient = (0,
|
|
5462
|
-
const [fallbackQueryClient] = (0,
|
|
6482
|
+
const client = (0, import_react33.useContext)(AggClientContext);
|
|
6483
|
+
const queryClient = (0, import_react33.useContext)(import_react_query33.QueryClientContext);
|
|
6484
|
+
const [fallbackQueryClient] = (0, import_react33.useState)(() => new import_react_query33.QueryClient());
|
|
5463
6485
|
const venue = options == null ? void 0 : options.venue;
|
|
5464
6486
|
const venueEventId = options == null ? void 0 : options.venueEventId;
|
|
5465
6487
|
const search = options == null ? void 0 : options.search;
|
|
@@ -5470,7 +6492,7 @@ function useVenueMarkets(options) {
|
|
|
5470
6492
|
const limit = (_b = options == null ? void 0 : options.limit) != null ? _b : 20;
|
|
5471
6493
|
const sortBy = options == null ? void 0 : options.sortBy;
|
|
5472
6494
|
const sortDir = options == null ? void 0 : options.sortDir;
|
|
5473
|
-
(0,
|
|
6495
|
+
(0, import_react33.useEffect)(() => {
|
|
5474
6496
|
if (queryClient) return void 0;
|
|
5475
6497
|
fallbackQueryClient.mount();
|
|
5476
6498
|
return () => {
|
|
@@ -5480,7 +6502,7 @@ function useVenueMarkets(options) {
|
|
|
5480
6502
|
if (enabled && !client) {
|
|
5481
6503
|
throw new Error("useVenueMarkets must be used within an <AggProvider>");
|
|
5482
6504
|
}
|
|
5483
|
-
const query = (0,
|
|
6505
|
+
const query = (0, import_react_query33.useInfiniteQuery)(
|
|
5484
6506
|
{
|
|
5485
6507
|
queryKey: [
|
|
5486
6508
|
"venue-markets",
|
|
@@ -5550,7 +6572,7 @@ function useEnrichedVenueEvent(options) {
|
|
|
5550
6572
|
sortBy: "yesPrice",
|
|
5551
6573
|
sortDir: "desc"
|
|
5552
6574
|
});
|
|
5553
|
-
const enrichedEvent = (0,
|
|
6575
|
+
const enrichedEvent = (0, import_react34.useMemo)(() => {
|
|
5554
6576
|
if (!event) return void 0;
|
|
5555
6577
|
if (markets.length === 0) return event;
|
|
5556
6578
|
return mergeEventWithFullMarkets(event, markets);
|
|
@@ -5564,13 +6586,13 @@ function useEnrichedVenueEvent(options) {
|
|
|
5564
6586
|
}
|
|
5565
6587
|
|
|
5566
6588
|
// src/use-venue-events.ts
|
|
5567
|
-
var
|
|
5568
|
-
var
|
|
6589
|
+
var import_react_query34 = require("@tanstack/react-query");
|
|
6590
|
+
var import_react35 = require("react");
|
|
5569
6591
|
function useVenueEvents(options) {
|
|
5570
6592
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5571
|
-
const client = (0,
|
|
5572
|
-
const queryClient = (0,
|
|
5573
|
-
const [fallbackQueryClient] = (0,
|
|
6593
|
+
const client = (0, import_react35.useContext)(AggClientContext);
|
|
6594
|
+
const queryClient = (0, import_react35.useContext)(import_react_query34.QueryClientContext);
|
|
6595
|
+
const [fallbackQueryClient] = (0, import_react35.useState)(() => new import_react_query34.QueryClient());
|
|
5574
6596
|
const venues = options == null ? void 0 : options.venues;
|
|
5575
6597
|
const search = options == null ? void 0 : options.search;
|
|
5576
6598
|
const categoryIds = options == null ? void 0 : options.categoryIds;
|
|
@@ -5585,7 +6607,7 @@ function useVenueEvents(options) {
|
|
|
5585
6607
|
const maxYesPrice = options == null ? void 0 : options.maxYesPrice;
|
|
5586
6608
|
const endDateFrom = options == null ? void 0 : options.endDateFrom;
|
|
5587
6609
|
const initialPages = options == null ? void 0 : options.initialPages;
|
|
5588
|
-
(0,
|
|
6610
|
+
(0, import_react35.useEffect)(() => {
|
|
5589
6611
|
if (queryClient) return void 0;
|
|
5590
6612
|
fallbackQueryClient.mount();
|
|
5591
6613
|
return () => {
|
|
@@ -5595,7 +6617,7 @@ function useVenueEvents(options) {
|
|
|
5595
6617
|
if (enabled && !client) {
|
|
5596
6618
|
throw new Error("useVenueEvents must be used within an <AggProvider>");
|
|
5597
6619
|
}
|
|
5598
|
-
const query = (0,
|
|
6620
|
+
const query = (0, import_react_query34.useInfiniteQuery)(
|
|
5599
6621
|
{
|
|
5600
6622
|
queryKey: [
|
|
5601
6623
|
queryKeyScope,
|
|
@@ -5638,13 +6660,13 @@ function useVenueEvents(options) {
|
|
|
5638
6660
|
return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
|
|
5639
6661
|
},
|
|
5640
6662
|
// TODO: RMIK - Comment out to show skeletons on category switch
|
|
5641
|
-
placeholderData:
|
|
6663
|
+
placeholderData: import_react_query34.keepPreviousData,
|
|
5642
6664
|
enabled: enabled && !!client
|
|
5643
6665
|
},
|
|
5644
6666
|
queryClient != null ? queryClient : fallbackQueryClient
|
|
5645
6667
|
);
|
|
5646
|
-
const prefetchedRef = (0,
|
|
5647
|
-
(0,
|
|
6668
|
+
const prefetchedRef = (0, import_react35.useRef)(false);
|
|
6669
|
+
(0, import_react35.useEffect)(() => {
|
|
5648
6670
|
var _a2, _b2;
|
|
5649
6671
|
if (prefetchedRef.current) return;
|
|
5650
6672
|
if (!initialPages || initialPages <= 1) return;
|
|
@@ -5662,7 +6684,7 @@ function useVenueEvents(options) {
|
|
|
5662
6684
|
query.hasNextPage,
|
|
5663
6685
|
query.fetchNextPage
|
|
5664
6686
|
]);
|
|
5665
|
-
const events = (0,
|
|
6687
|
+
const events = (0, import_react35.useMemo)(
|
|
5666
6688
|
() => {
|
|
5667
6689
|
var _a2, _b2;
|
|
5668
6690
|
return (_b2 = (_a2 = query.data) == null ? void 0 : _a2.pages.flatMap((page) => page.data)) != null ? _b2 : [];
|
|
@@ -5680,7 +6702,7 @@ function useVenueEvents(options) {
|
|
|
5680
6702
|
}
|
|
5681
6703
|
|
|
5682
6704
|
// src/use-venue-market-midpoints.ts
|
|
5683
|
-
var
|
|
6705
|
+
var import_react_query35 = require("@tanstack/react-query");
|
|
5684
6706
|
var MAX_VENUE_MARKET_IDS_PER_REQUEST = 200;
|
|
5685
6707
|
var normalizeVenueMarketIds2 = (venueMarketIds) => {
|
|
5686
6708
|
return [
|
|
@@ -5716,7 +6738,7 @@ function useVenueMarketMidpoints(options) {
|
|
|
5716
6738
|
const client = useAggClient();
|
|
5717
6739
|
const enabled = (_a = options.enabled) != null ? _a : true;
|
|
5718
6740
|
const requestedVenueMarketIds = normalizeVenueMarketIds2(options.venueMarketIds);
|
|
5719
|
-
const query = (0,
|
|
6741
|
+
const query = (0, import_react_query35.useQuery)({
|
|
5720
6742
|
queryKey: requestedVenueMarketIds.length ? ["venue-market-midpoints", requestedVenueMarketIds] : ["venue-market-midpoints", "__disabled__"],
|
|
5721
6743
|
queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
|
|
5722
6744
|
const venueMarketIdChunks = chunkVenueMarketIds(requestedVenueMarketIds);
|
|
@@ -5725,7 +6747,7 @@ function useVenueMarketMidpoints(options) {
|
|
|
5725
6747
|
}
|
|
5726
6748
|
const chunkResponses = yield Promise.all(
|
|
5727
6749
|
venueMarketIdChunks.map((venueMarketIds) => {
|
|
5728
|
-
return client.getMidpoints({ venueMarketIds }, { signal });
|
|
6750
|
+
return client.getMidpoints({ venueMarketIds, bestPrice: true }, { signal });
|
|
5729
6751
|
})
|
|
5730
6752
|
);
|
|
5731
6753
|
return mergeMidpointResponses(chunkResponses);
|
|
@@ -5735,7 +6757,7 @@ function useVenueMarketMidpoints(options) {
|
|
|
5735
6757
|
gcTime: 5 * 6e4,
|
|
5736
6758
|
refetchOnWindowFocus: false,
|
|
5737
6759
|
retry: 1,
|
|
5738
|
-
placeholderData:
|
|
6760
|
+
placeholderData: import_react_query35.keepPreviousData
|
|
5739
6761
|
});
|
|
5740
6762
|
const midpointRows = (_c = (_b = query.data) == null ? void 0 : _b.data) != null ? _c : [];
|
|
5741
6763
|
const midpointsByVenueMarketId = mapMidpointsByVenueMarketId(midpointRows);
|
|
@@ -5770,60 +6792,68 @@ function computePriceGaps(input) {
|
|
|
5770
6792
|
}
|
|
5771
6793
|
|
|
5772
6794
|
// src/use-viewport-midpoints.ts
|
|
5773
|
-
var
|
|
5774
|
-
var
|
|
5775
|
-
|
|
5776
|
-
if (!
|
|
5777
|
-
const
|
|
5778
|
-
|
|
6795
|
+
var import_react36 = require("react");
|
|
6796
|
+
var buildOutcomeMidpointMap = (outcomes) => {
|
|
6797
|
+
const m = /* @__PURE__ */ new Map();
|
|
6798
|
+
if (!outcomes) return m;
|
|
6799
|
+
for (const o of outcomes) {
|
|
6800
|
+
if (o.midpoint != null) m.set(o.venueMarketOutcomeId, o.midpoint);
|
|
6801
|
+
}
|
|
6802
|
+
return m;
|
|
5779
6803
|
};
|
|
5780
6804
|
var resolveUncachedVisibleMarketIds = (visibleMarkets, cache, inFlightIds) => {
|
|
6805
|
+
var _a;
|
|
6806
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5781
6807
|
const idsToFetch = [];
|
|
6808
|
+
const consider = (id) => {
|
|
6809
|
+
if (!id) return;
|
|
6810
|
+
if (seen.has(id)) return;
|
|
6811
|
+
if (inFlightIds.has(id)) return;
|
|
6812
|
+
if (cache.has(id)) return;
|
|
6813
|
+
seen.add(id);
|
|
6814
|
+
idsToFetch.push(id);
|
|
6815
|
+
};
|
|
5782
6816
|
for (const market of visibleMarkets) {
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
6817
|
+
consider(market.id);
|
|
6818
|
+
for (const sibling of (_a = market.matchedVenueMarkets) != null ? _a : []) {
|
|
6819
|
+
consider(sibling.id);
|
|
6820
|
+
}
|
|
5786
6821
|
}
|
|
5787
6822
|
return idsToFetch;
|
|
5788
6823
|
};
|
|
5789
6824
|
var buildCachedMidpointEntries = (requestedVenueMarketIds, rows) => {
|
|
5790
|
-
var _a
|
|
6825
|
+
var _a;
|
|
5791
6826
|
const rowsByVenueMarketId = new Map(rows.map((item) => [item.venueMarketId, item]));
|
|
5792
6827
|
const nextCacheEntries = /* @__PURE__ */ new Map();
|
|
5793
6828
|
for (const venueMarketId of requestedVenueMarketIds) {
|
|
5794
6829
|
const item = rowsByVenueMarketId.get(venueMarketId);
|
|
5795
|
-
const yesMidpoint = resolveYesMidpoint(item == null ? void 0 : item.outcomes);
|
|
5796
6830
|
nextCacheEntries.set(venueMarketId, __spreadProps(__spreadValues({}, (item == null ? void 0 : item.venue) ? { venue: item.venue } : {}), {
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
midpoint: (_a2 = matched.midpoint) != null ? _a2 : null,
|
|
5804
|
-
spread: (_b2 = matched.spread) != null ? _b2 : null
|
|
5805
|
-
}, matched.venue ? { venue: matched.venue } : {});
|
|
5806
|
-
})
|
|
6831
|
+
ownOutcomes: buildOutcomeMidpointMap(item == null ? void 0 : item.outcomes),
|
|
6832
|
+
matched: ((_a = item == null ? void 0 : item.matched) != null ? _a : []).map((sib) => __spreadProps(__spreadValues({
|
|
6833
|
+
venueMarketId: sib.venueMarketId
|
|
6834
|
+
}, sib.venue ? { venue: sib.venue } : {}), {
|
|
6835
|
+
outcomes: buildOutcomeMidpointMap(sib.outcomes)
|
|
6836
|
+
}))
|
|
5807
6837
|
}));
|
|
5808
6838
|
}
|
|
5809
6839
|
return nextCacheEntries;
|
|
5810
6840
|
};
|
|
5811
6841
|
function useViewportMidpoints(visibleMarkets) {
|
|
5812
6842
|
const client = useAggClient();
|
|
5813
|
-
const [cache, setCache] = (0,
|
|
5814
|
-
const inFlightRef = (0,
|
|
5815
|
-
const visibleRef = (0,
|
|
6843
|
+
const [cache, setCache] = (0, import_react36.useState)(() => /* @__PURE__ */ new Map());
|
|
6844
|
+
const inFlightRef = (0, import_react36.useRef)(/* @__PURE__ */ new Set());
|
|
6845
|
+
const visibleRef = (0, import_react36.useRef)(visibleMarkets);
|
|
5816
6846
|
visibleRef.current = visibleMarkets;
|
|
5817
|
-
const visibleFp = (0,
|
|
6847
|
+
const visibleFp = (0, import_react36.useMemo)(
|
|
5818
6848
|
() => [...new Set(visibleMarkets.map((m) => m.id))].sort().join("|"),
|
|
5819
6849
|
[visibleMarkets]
|
|
5820
6850
|
);
|
|
5821
|
-
(0,
|
|
6851
|
+
(0, import_react36.useEffect)(() => {
|
|
5822
6852
|
const toFetch = resolveUncachedVisibleMarketIds(visibleRef.current, cache, inFlightRef.current);
|
|
5823
6853
|
if (!toFetch.length) return;
|
|
5824
6854
|
let cancelled = false;
|
|
5825
6855
|
for (const id of toFetch) inFlightRef.current.add(id);
|
|
5826
|
-
client.getMidpoints(toFetch).then((resp) => {
|
|
6856
|
+
client.getMidpoints(toFetch, { bestPrice: true }).then((resp) => {
|
|
5827
6857
|
var _a;
|
|
5828
6858
|
if (cancelled) return;
|
|
5829
6859
|
const nextCacheEntries = buildCachedMidpointEntries(toFetch, (_a = resp.data) != null ? _a : []);
|
|
@@ -5842,29 +6872,31 @@ function useViewportMidpoints(visibleMarkets) {
|
|
|
5842
6872
|
cancelled = true;
|
|
5843
6873
|
};
|
|
5844
6874
|
}, [visibleFp, cache]);
|
|
5845
|
-
const { prices, venueByOutcomeId } = (0,
|
|
5846
|
-
var _a, _b, _c, _d
|
|
6875
|
+
const { prices, venueByOutcomeId } = (0, import_react36.useMemo)(() => {
|
|
6876
|
+
var _a, _b, _c, _d;
|
|
5847
6877
|
const map = /* @__PURE__ */ new Map();
|
|
5848
6878
|
const venueMap = /* @__PURE__ */ new Map();
|
|
5849
6879
|
for (const market of visibleMarkets) {
|
|
5850
6880
|
const entry = cache.get(market.id);
|
|
5851
6881
|
if (!entry) continue;
|
|
5852
|
-
|
|
5853
|
-
let midVenue = (_a = entry.venue) != null ? _a : market.venue;
|
|
5854
|
-
for (const m of entry.matched) {
|
|
5855
|
-
const matchedFromCache = (_b = cache.get(m.venueMarketId)) == null ? void 0 : _b.midpoint;
|
|
5856
|
-
const candidateMidpoint = matchedFromCache != null ? matchedFromCache : m.midpoint;
|
|
5857
|
-
if (candidateMidpoint == null) continue;
|
|
5858
|
-
if (mid == null || candidateMidpoint < mid) {
|
|
5859
|
-
mid = candidateMidpoint;
|
|
5860
|
-
midVenue = (_e = (_d = (_c = cache.get(m.venueMarketId)) == null ? void 0 : _c.venue) != null ? _d : m.venue) != null ? _e : market.venue;
|
|
5861
|
-
}
|
|
5862
|
-
}
|
|
5863
|
-
if (mid == null) continue;
|
|
6882
|
+
const ownVenue = (_a = entry.venue) != null ? _a : market.venue;
|
|
5864
6883
|
for (const outcome of market.venueMarketOutcomes) {
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
6884
|
+
let best = (_b = entry.ownOutcomes.get(outcome.id)) != null ? _b : null;
|
|
6885
|
+
let bestVenue = best != null ? ownVenue : null;
|
|
6886
|
+
for (const ref of (_c = outcome.matchedVenueMarketOutcomes) != null ? _c : []) {
|
|
6887
|
+
const sib = entry.matched.find((m) => m.venueMarketId === ref.venueMarketId);
|
|
6888
|
+
if (!sib) continue;
|
|
6889
|
+
const sibMidpoint = sib.outcomes.get(ref.venueMarketOutcomeId);
|
|
6890
|
+
if (sibMidpoint == null) continue;
|
|
6891
|
+
if (best == null || sibMidpoint < best) {
|
|
6892
|
+
best = sibMidpoint;
|
|
6893
|
+
bestVenue = (_d = sib.venue) != null ? _d : bestVenue;
|
|
6894
|
+
}
|
|
6895
|
+
}
|
|
6896
|
+
if (best != null) {
|
|
6897
|
+
map.set(outcome.id, best);
|
|
6898
|
+
if (bestVenue) venueMap.set(outcome.id, bestVenue);
|
|
6899
|
+
}
|
|
5868
6900
|
}
|
|
5869
6901
|
}
|
|
5870
6902
|
return { prices: map, venueByOutcomeId: venueMap };
|
|
@@ -5873,15 +6905,15 @@ function useViewportMidpoints(visibleMarkets) {
|
|
|
5873
6905
|
}
|
|
5874
6906
|
|
|
5875
6907
|
// src/use-visible-ids.ts
|
|
5876
|
-
var
|
|
6908
|
+
var import_react37 = require("react");
|
|
5877
6909
|
function useVisibleIds(options = {}) {
|
|
5878
6910
|
const { rootMargin = "0px", threshold = 0 } = options;
|
|
5879
|
-
const [visibleIds, setVisibleIds] = (0,
|
|
5880
|
-
const observerRef = (0,
|
|
5881
|
-
const elementsRef = (0,
|
|
5882
|
-
const elementIdRef = (0,
|
|
5883
|
-
const callbackRefsRef = (0,
|
|
5884
|
-
(0,
|
|
6911
|
+
const [visibleIds, setVisibleIds] = (0, import_react37.useState)(() => /* @__PURE__ */ new Set());
|
|
6912
|
+
const observerRef = (0, import_react37.useRef)(null);
|
|
6913
|
+
const elementsRef = (0, import_react37.useRef)(/* @__PURE__ */ new Map());
|
|
6914
|
+
const elementIdRef = (0, import_react37.useRef)(/* @__PURE__ */ new WeakMap());
|
|
6915
|
+
const callbackRefsRef = (0, import_react37.useRef)(/* @__PURE__ */ new Map());
|
|
6916
|
+
(0, import_react37.useEffect)(() => {
|
|
5885
6917
|
if (typeof IntersectionObserver === "undefined") return;
|
|
5886
6918
|
const observer = new IntersectionObserver(
|
|
5887
6919
|
(entries) => {
|
|
@@ -5913,7 +6945,7 @@ function useVisibleIds(options = {}) {
|
|
|
5913
6945
|
observerRef.current = null;
|
|
5914
6946
|
};
|
|
5915
6947
|
}, [rootMargin, threshold]);
|
|
5916
|
-
const register = (0,
|
|
6948
|
+
const register = (0, import_react37.useCallback)((id) => {
|
|
5917
6949
|
const existing = callbackRefsRef.current.get(id);
|
|
5918
6950
|
if (existing) return existing;
|
|
5919
6951
|
const callback = (el) => {
|
|
@@ -5946,12 +6978,12 @@ function useVisibleIds(options = {}) {
|
|
|
5946
6978
|
}
|
|
5947
6979
|
|
|
5948
6980
|
// src/use-app-config.ts
|
|
5949
|
-
var
|
|
6981
|
+
var import_react_query36 = require("@tanstack/react-query");
|
|
5950
6982
|
var FIVE_MINUTES = 5 * 60 * 1e3;
|
|
5951
6983
|
function useAppConfig() {
|
|
5952
|
-
var _a, _b, _c, _d, _e, _f;
|
|
6984
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5953
6985
|
const client = useAggClient();
|
|
5954
|
-
const query = (0,
|
|
6986
|
+
const query = (0, import_react_query36.useQuery)({
|
|
5955
6987
|
queryKey: ["agg", "app-config"],
|
|
5956
6988
|
queryFn: () => client.getAppConfig(),
|
|
5957
6989
|
staleTime: FIVE_MINUTES
|
|
@@ -5960,6 +6992,7 @@ function useAppConfig() {
|
|
|
5960
6992
|
disabledVenues: (_b = (_a = query.data) == null ? void 0 : _a.disabledVenues) != null ? _b : [],
|
|
5961
6993
|
disabledCategoryPresets: (_d = (_c = query.data) == null ? void 0 : _c.disabledCategoryPresets) != null ? _d : [],
|
|
5962
6994
|
earlyAccessEnabled: (_f = (_e = query.data) == null ? void 0 : _e.earlyAccessEnabled) != null ? _f : false,
|
|
6995
|
+
authOptions: (_h = (_g = query.data) == null ? void 0 : _g.authOptions) != null ? _h : [],
|
|
5963
6996
|
isLoading: query.isLoading,
|
|
5964
6997
|
error: query.error
|
|
5965
6998
|
};
|
|
@@ -5980,6 +7013,8 @@ function useAppConfig() {
|
|
|
5980
7013
|
MatchType,
|
|
5981
7014
|
QueryClient,
|
|
5982
7015
|
QueryClientProvider,
|
|
7016
|
+
RedeemRejectedError,
|
|
7017
|
+
TradeSide,
|
|
5983
7018
|
TurnstileChallengeError,
|
|
5984
7019
|
Venue,
|
|
5985
7020
|
computeClosedPositionTotals,
|
|
@@ -5994,9 +7029,13 @@ function useAppConfig() {
|
|
|
5994
7029
|
getWalletAddressFromUserProfile,
|
|
5995
7030
|
invalidateBalanceQueries,
|
|
5996
7031
|
invalidatePositionQueries,
|
|
7032
|
+
invalidateUserActivityQueries,
|
|
7033
|
+
invalidateUserMoneyState,
|
|
7034
|
+
mergeBestPricesPreferringLive,
|
|
5997
7035
|
optimizedImageUrl,
|
|
5998
7036
|
parseEmail,
|
|
5999
7037
|
parseEmailStrict,
|
|
7038
|
+
rangeToSeconds,
|
|
6000
7039
|
requestAggAuthChooserOpen,
|
|
6001
7040
|
resolveAggUiLabels,
|
|
6002
7041
|
resolveDefaultTradingMarket,
|
|
@@ -6004,6 +7043,7 @@ function useAppConfig() {
|
|
|
6004
7043
|
resolveMarketTradingState,
|
|
6005
7044
|
resolveMarketWinningOutcome,
|
|
6006
7045
|
resolveOrderEligibility,
|
|
7046
|
+
resolveRollingWindow,
|
|
6007
7047
|
resolveTradingStateKind,
|
|
6008
7048
|
sortVenues,
|
|
6009
7049
|
timeRangeToInterval,
|
|
@@ -6034,6 +7074,7 @@ function useAppConfig() {
|
|
|
6034
7074
|
useGeoBlock,
|
|
6035
7075
|
useLabels,
|
|
6036
7076
|
useLinkAccount,
|
|
7077
|
+
useLiveBestPrices,
|
|
6037
7078
|
useLiveCandleOverlay,
|
|
6038
7079
|
useLiveCandles,
|
|
6039
7080
|
useLiveMarket,
|
|
@@ -6043,6 +7084,7 @@ function useAppConfig() {
|
|
|
6043
7084
|
useManagedBalances,
|
|
6044
7085
|
useMarketChart,
|
|
6045
7086
|
useMarketOrderbook,
|
|
7087
|
+
useMarketSearch,
|
|
6046
7088
|
useMidpoints,
|
|
6047
7089
|
useOnBalanceUpdate,
|
|
6048
7090
|
useOnOrderSubmitted,
|
|
@@ -6058,11 +7100,15 @@ function useAppConfig() {
|
|
|
6058
7100
|
useRampSession,
|
|
6059
7101
|
useRedeem,
|
|
6060
7102
|
useRedeemEligibleCount,
|
|
7103
|
+
useRedeemLifecycle,
|
|
7104
|
+
useRedeemLifecycles,
|
|
7105
|
+
useRollingChartWindow,
|
|
6061
7106
|
useSdkLabels,
|
|
6062
7107
|
useSdkUiConfig,
|
|
6063
7108
|
useSearch,
|
|
6064
7109
|
useSmartRoute,
|
|
6065
7110
|
useSyncBalances,
|
|
7111
|
+
useTradableVenues,
|
|
6066
7112
|
useUserActivity,
|
|
6067
7113
|
useUserHoldings,
|
|
6068
7114
|
useVenueEvent,
|
|
@@ -6071,7 +7117,9 @@ function useAppConfig() {
|
|
|
6071
7117
|
useVenueMarkets,
|
|
6072
7118
|
useViewportMidpoints,
|
|
6073
7119
|
useVisibleIds,
|
|
7120
|
+
useWithdrawEstimate,
|
|
6074
7121
|
useWithdrawFlow,
|
|
6075
7122
|
useWithdrawManaged,
|
|
6076
|
-
useWithdrawalLifecycle
|
|
7123
|
+
useWithdrawalLifecycle,
|
|
7124
|
+
userActivityQueryKeys
|
|
6077
7125
|
});
|