@pear-protocol/symmio-client 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/index.d.mts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +251 -155
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +251 -155
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/provider.js +193 -0
- package/dist/react/provider.js.map +1 -1
- package/dist/react/provider.mjs +194 -1
- package/dist/react/provider.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -8559,6 +8559,7 @@ type SymmTradeAuthParams = {
|
|
|
8559
8559
|
address?: Address;
|
|
8560
8560
|
chainId?: number;
|
|
8561
8561
|
};
|
|
8562
|
+
|
|
8562
8563
|
type OpenBasketMutationRequest = WithOptionalAuthToken<OpenBasketPositionRequest>;
|
|
8563
8564
|
type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest>;
|
|
8564
8565
|
type CloseAllPositionsMutationRequest = WithOptionalAuthToken<Parameters<NonNullable<ReturnType<typeof useSymmContext>['symmCoreClient']>['positions']['closeAll']>[0]>;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -8559,6 +8559,7 @@ type SymmTradeAuthParams = {
|
|
|
8559
8559
|
address?: Address;
|
|
8560
8560
|
chainId?: number;
|
|
8561
8561
|
};
|
|
8562
|
+
|
|
8562
8563
|
type OpenBasketMutationRequest = WithOptionalAuthToken<OpenBasketPositionRequest>;
|
|
8563
8564
|
type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest>;
|
|
8564
8565
|
type CloseAllPositionsMutationRequest = WithOptionalAuthToken<Parameters<NonNullable<ReturnType<typeof useSymmContext>['symmCoreClient']>['positions']['closeAll']>[0]>;
|
package/dist/react/index.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var symmCore = require('@pear-protocol/symm-core');
|
|
6
6
|
var zustand = require('zustand');
|
|
7
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
8
7
|
var reactQuery = require('@tanstack/react-query');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
9
|
var siwe = require('siwe');
|
|
10
10
|
var viem = require('viem');
|
|
11
11
|
|
|
@@ -490,6 +490,193 @@ function useBinanceWs(params) {
|
|
|
490
490
|
};
|
|
491
491
|
}, [symmCoreClient, chainId, subscribeSymbol, unsubscribeSymbol]);
|
|
492
492
|
}
|
|
493
|
+
|
|
494
|
+
// src/react/query-keys.ts
|
|
495
|
+
var symmKeys = {
|
|
496
|
+
all: ["symm"],
|
|
497
|
+
balancesRoot: ["symm", "balances"],
|
|
498
|
+
accountSummaryRoot: ["symm", "accountSummary"],
|
|
499
|
+
accountDataRoot: ["symm", "accountData"],
|
|
500
|
+
approvalRoot: ["symm", "approval"],
|
|
501
|
+
positionsRoot: ["symm", "positions"],
|
|
502
|
+
openOrdersRoot: ["symm", "openOrders"],
|
|
503
|
+
tradeHistoryRoot: ["symm", "tradeHistory"],
|
|
504
|
+
portfolioRoot: ["symm", "portfolio"],
|
|
505
|
+
tpslOrdersRoot: ["symm", "tpslOrders"],
|
|
506
|
+
twapOrdersRoot: ["symm", "twapOrders"],
|
|
507
|
+
triggerOrdersRoot: ["symm", "triggerOrders"],
|
|
508
|
+
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
509
|
+
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
510
|
+
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
511
|
+
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
512
|
+
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
513
|
+
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
514
|
+
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
515
|
+
auth: (accountAddress, chainId, signerAddress) => ["symm", "auth", accountAddress, chainId, signerAddress],
|
|
516
|
+
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
517
|
+
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
518
|
+
positions: (params) => ["symm", "positions", params],
|
|
519
|
+
openOrders: (params) => ["symm", "openOrders", params],
|
|
520
|
+
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
521
|
+
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
522
|
+
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
523
|
+
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
524
|
+
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
525
|
+
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
526
|
+
markets: (chainId, search, pageSize) => ["symm", "markets", chainId, search, pageSize],
|
|
527
|
+
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
528
|
+
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
529
|
+
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
530
|
+
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
531
|
+
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
532
|
+
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
533
|
+
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
534
|
+
portfolio: (params) => ["symm", "portfolio", params],
|
|
535
|
+
notifications: (params) => ["symm", "notifications", params],
|
|
536
|
+
unreadCount: (params) => ["symm", "unreadCount", params],
|
|
537
|
+
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
538
|
+
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
539
|
+
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
540
|
+
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
541
|
+
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
542
|
+
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
543
|
+
};
|
|
544
|
+
var useSymmWsStore = zustand.create((set) => ({
|
|
545
|
+
isConnected: false,
|
|
546
|
+
setConnected: (isConnected) => set({ isConnected })
|
|
547
|
+
}));
|
|
548
|
+
|
|
549
|
+
// src/react/hooks/use-symm-ws.ts
|
|
550
|
+
function asUnsubscribeFn(value) {
|
|
551
|
+
return typeof value === "function" ? value : null;
|
|
552
|
+
}
|
|
553
|
+
function useSymmWs(params = {}) {
|
|
554
|
+
const ctx = react.useContext(SymmContext);
|
|
555
|
+
const queryClient = reactQuery.useQueryClient();
|
|
556
|
+
const isConnected = useSymmWsStore((state) => state.isConnected);
|
|
557
|
+
const setConnected = useSymmWsStore((state) => state.setConnected);
|
|
558
|
+
const symmCoreClient = params.symmCoreClient ?? ctx?.symmCoreClient ?? null;
|
|
559
|
+
const accountAddress = params.accountAddress ?? ctx?.address;
|
|
560
|
+
const chainId = params.chainId ?? ctx?.chainId ?? 42161;
|
|
561
|
+
react.useEffect(() => {
|
|
562
|
+
if (!symmCoreClient || !accountAddress) {
|
|
563
|
+
setConnected(false);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const ws = symmCoreClient.ws;
|
|
567
|
+
const addr = accountAddress;
|
|
568
|
+
const unsubscribers = [];
|
|
569
|
+
let cancelled = false;
|
|
570
|
+
const removeOnConnect = ws.onConnect(() => {
|
|
571
|
+
setConnected(true);
|
|
572
|
+
});
|
|
573
|
+
const removeOnDisconnect = ws.onDisconnect(() => {
|
|
574
|
+
setConnected(false);
|
|
575
|
+
});
|
|
576
|
+
const removeOnError = asUnsubscribeFn(ws.onError?.(() => {
|
|
577
|
+
}));
|
|
578
|
+
const removeOnWelcome = asUnsubscribeFn(ws.onWelcome?.(() => {
|
|
579
|
+
}));
|
|
580
|
+
unsubscribers.push(removeOnConnect, removeOnDisconnect);
|
|
581
|
+
if (removeOnError) unsubscribers.push(removeOnError);
|
|
582
|
+
if (removeOnWelcome) unsubscribers.push(removeOnWelcome);
|
|
583
|
+
const positionsUnsub = asUnsubscribeFn(
|
|
584
|
+
ws.subscribeToPositions(addr, chainId, () => {
|
|
585
|
+
queryClient.invalidateQueries({
|
|
586
|
+
queryKey: symmKeys.positionsRoot
|
|
587
|
+
});
|
|
588
|
+
})
|
|
589
|
+
);
|
|
590
|
+
if (positionsUnsub) unsubscribers.push(positionsUnsub);
|
|
591
|
+
const openOrdersUnsub = asUnsubscribeFn(
|
|
592
|
+
ws.subscribeToOpenOrders(addr, chainId, () => {
|
|
593
|
+
queryClient.invalidateQueries({
|
|
594
|
+
queryKey: symmKeys.openOrdersRoot
|
|
595
|
+
});
|
|
596
|
+
})
|
|
597
|
+
);
|
|
598
|
+
if (openOrdersUnsub) unsubscribers.push(openOrdersUnsub);
|
|
599
|
+
const tradesUnsub = asUnsubscribeFn(
|
|
600
|
+
ws.subscribeToTrades(addr, chainId, () => {
|
|
601
|
+
queryClient.invalidateQueries({
|
|
602
|
+
queryKey: symmKeys.tradeHistoryRoot
|
|
603
|
+
});
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
if (tradesUnsub) unsubscribers.push(tradesUnsub);
|
|
607
|
+
const accountSummaryUnsub = asUnsubscribeFn(
|
|
608
|
+
ws.subscribeToAccountSummary(addr, chainId, () => {
|
|
609
|
+
queryClient.invalidateQueries({
|
|
610
|
+
queryKey: symmKeys.balances(accountAddress, chainId)
|
|
611
|
+
});
|
|
612
|
+
queryClient.invalidateQueries({
|
|
613
|
+
queryKey: symmKeys.accountSummary(accountAddress, chainId)
|
|
614
|
+
});
|
|
615
|
+
})
|
|
616
|
+
);
|
|
617
|
+
if (accountSummaryUnsub) unsubscribers.push(accountSummaryUnsub);
|
|
618
|
+
const notificationsUnsub = asUnsubscribeFn(
|
|
619
|
+
ws.subscribeToNotifications(addr, chainId, () => {
|
|
620
|
+
queryClient.invalidateQueries({
|
|
621
|
+
queryKey: symmKeys.notifications({ accountAddress, chainId })
|
|
622
|
+
});
|
|
623
|
+
queryClient.invalidateQueries({
|
|
624
|
+
queryKey: symmKeys.unreadCount({ accountAddress, chainId })
|
|
625
|
+
});
|
|
626
|
+
})
|
|
627
|
+
);
|
|
628
|
+
if (notificationsUnsub) unsubscribers.push(notificationsUnsub);
|
|
629
|
+
const tpslUnsub = asUnsubscribeFn(
|
|
630
|
+
ws.subscribeToTpsl(addr, chainId, () => {
|
|
631
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.tpslOrdersRoot });
|
|
632
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
|
|
633
|
+
})
|
|
634
|
+
);
|
|
635
|
+
if (tpslUnsub) unsubscribers.push(tpslUnsub);
|
|
636
|
+
const twapUnsub = asUnsubscribeFn(
|
|
637
|
+
ws.subscribeToTwapOrders(addr, chainId, () => {
|
|
638
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.twapOrdersRoot });
|
|
639
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
|
|
640
|
+
})
|
|
641
|
+
);
|
|
642
|
+
if (twapUnsub) unsubscribers.push(twapUnsub);
|
|
643
|
+
const triggerOrdersUnsub = asUnsubscribeFn(
|
|
644
|
+
ws.subscribeToTriggerOrders(addr, chainId, () => {
|
|
645
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.triggerOrdersRoot });
|
|
646
|
+
queryClient.invalidateQueries({ queryKey: symmKeys.openOrdersRoot });
|
|
647
|
+
})
|
|
648
|
+
);
|
|
649
|
+
if (triggerOrdersUnsub) unsubscribers.push(triggerOrdersUnsub);
|
|
650
|
+
const executionsUnsub = asUnsubscribeFn(
|
|
651
|
+
ws.subscribeToExecutions(addr, chainId, () => {
|
|
652
|
+
queryClient.invalidateQueries({
|
|
653
|
+
queryKey: symmKeys.positionsRoot
|
|
654
|
+
});
|
|
655
|
+
queryClient.invalidateQueries({
|
|
656
|
+
queryKey: symmKeys.portfolioRoot
|
|
657
|
+
});
|
|
658
|
+
})
|
|
659
|
+
);
|
|
660
|
+
if (executionsUnsub) unsubscribers.push(executionsUnsub);
|
|
661
|
+
void ws.connect().then(() => {
|
|
662
|
+
if (cancelled) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
}).catch(() => {
|
|
666
|
+
if (cancelled) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
setConnected(false);
|
|
670
|
+
});
|
|
671
|
+
return () => {
|
|
672
|
+
cancelled = true;
|
|
673
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
674
|
+
ws.disconnect();
|
|
675
|
+
setConnected(false);
|
|
676
|
+
};
|
|
677
|
+
}, [symmCoreClient, accountAddress, chainId, queryClient, setConnected]);
|
|
678
|
+
return { isConnected };
|
|
679
|
+
}
|
|
493
680
|
function SymmProvider({
|
|
494
681
|
chainId = 42161,
|
|
495
682
|
address,
|
|
@@ -522,6 +709,11 @@ function SymmProvider({
|
|
|
522
709
|
symmCoreClient,
|
|
523
710
|
chainId
|
|
524
711
|
});
|
|
712
|
+
useSymmWs({
|
|
713
|
+
symmCoreClient,
|
|
714
|
+
accountAddress: address,
|
|
715
|
+
chainId
|
|
716
|
+
});
|
|
525
717
|
return /* @__PURE__ */ jsxRuntime.jsx(SymmContext.Provider, { value, children });
|
|
526
718
|
}
|
|
527
719
|
|
|
@@ -704,57 +896,6 @@ async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress
|
|
|
704
896
|
return cachedToken;
|
|
705
897
|
}
|
|
706
898
|
|
|
707
|
-
// src/react/query-keys.ts
|
|
708
|
-
var symmKeys = {
|
|
709
|
-
all: ["symm"],
|
|
710
|
-
balancesRoot: ["symm", "balances"],
|
|
711
|
-
accountSummaryRoot: ["symm", "accountSummary"],
|
|
712
|
-
accountDataRoot: ["symm", "accountData"],
|
|
713
|
-
approvalRoot: ["symm", "approval"],
|
|
714
|
-
positionsRoot: ["symm", "positions"],
|
|
715
|
-
openOrdersRoot: ["symm", "openOrders"],
|
|
716
|
-
tradeHistoryRoot: ["symm", "tradeHistory"],
|
|
717
|
-
portfolioRoot: ["symm", "portfolio"],
|
|
718
|
-
tpslOrdersRoot: ["symm", "tpslOrders"],
|
|
719
|
-
twapOrdersRoot: ["symm", "twapOrders"],
|
|
720
|
-
triggerOrdersRoot: ["symm", "triggerOrders"],
|
|
721
|
-
accounts: (address, chainId) => ["symm", "accounts", address, chainId],
|
|
722
|
-
accountsApi: (address, chainId) => ["symm", "accountsApi", address, chainId],
|
|
723
|
-
accountsLength: (address, chainId) => ["symm", "accountsLength", address, chainId],
|
|
724
|
-
accountsWithPositions: (address, chainId) => ["symm", "accountsWithPositions", address, chainId],
|
|
725
|
-
accountSummary: (address, chainId) => ["symm", "accountSummary", address, chainId],
|
|
726
|
-
accountData: (address, chainId, upnl) => ["symm", "accountData", address, chainId, upnl],
|
|
727
|
-
signature: (address, chainId) => ["symm", "signature", address, chainId],
|
|
728
|
-
auth: (accountAddress, chainId, signerAddress) => ["symm", "auth", accountAddress, chainId, signerAddress],
|
|
729
|
-
approval: (owner, spender, chainId, token) => ["symm", "approval", owner, spender, chainId, token],
|
|
730
|
-
balances: (address, chainId) => ["symm", "balances", address, chainId],
|
|
731
|
-
positions: (params) => ["symm", "positions", params],
|
|
732
|
-
openOrders: (params) => ["symm", "openOrders", params],
|
|
733
|
-
tradeHistory: (params) => ["symm", "tradeHistory", params],
|
|
734
|
-
tpslOrders: (address, chainId) => ["symm", "tpslOrders", address, chainId],
|
|
735
|
-
tpslOrdersList: (params) => ["symm", "tpslOrders", params],
|
|
736
|
-
twapOrders: (address, chainId) => ["symm", "twapOrders", address, chainId],
|
|
737
|
-
triggerOrders: (params) => ["symm", "triggerOrders", params],
|
|
738
|
-
triggerConfig: (orderId) => ["symm", "triggerConfig", orderId],
|
|
739
|
-
markets: (chainId, search, pageSize) => ["symm", "markets", chainId, search, pageSize],
|
|
740
|
-
hedgerMarketById: (id, chainId) => ["symm", "hedgerMarketById", id, chainId],
|
|
741
|
-
hedgerMarketBySymbol: (symbol, chainId) => ["symm", "hedgerMarketBySymbol", symbol, chainId],
|
|
742
|
-
lockedParams: (marketName, leverage, chainId) => ["symm", "lockedParams", marketName, leverage, chainId],
|
|
743
|
-
hedgerMarkets: (request) => ["symm", "hedgerMarkets", request],
|
|
744
|
-
fundingRates: (chainId) => ["symm", "fundingRates", chainId],
|
|
745
|
-
fundingPayments: (params) => ["symm", "fundingPayments", params],
|
|
746
|
-
fundingHistory: (params) => ["symm", "fundingHistory", params],
|
|
747
|
-
portfolio: (params) => ["symm", "portfolio", params],
|
|
748
|
-
notifications: (params) => ["symm", "notifications", params],
|
|
749
|
-
unreadCount: (params) => ["symm", "unreadCount", params],
|
|
750
|
-
availableMargin: (address, chainId) => ["symm", "availableMargin", address, chainId],
|
|
751
|
-
pendingIds: (address, chainId) => ["symm", "pendingIds", address, chainId],
|
|
752
|
-
pendingInstantOpens: (accountAddress, chainId) => ["symm", "pendingInstantOpens", accountAddress, chainId],
|
|
753
|
-
twapOrder: (orderId) => ["symm", "twapOrder", orderId],
|
|
754
|
-
delegation: (account, target, selectors, chainId) => ["symm", "delegation", account, target, selectors, chainId],
|
|
755
|
-
chartMetadata: (symbolsKey, positionKey) => ["symm", "chartMetadata", symbolsKey, positionKey]
|
|
756
|
-
};
|
|
757
|
-
|
|
758
899
|
// src/react/auth-cache.ts
|
|
759
900
|
function getAuthQueryData(queryClient, accountAddress, chainId, signerAddress) {
|
|
760
901
|
return queryClient.getQueryData(
|
|
@@ -824,12 +965,6 @@ function clearAuthState(queryClient, accountAddress, chainId, signerAddress) {
|
|
|
824
965
|
}
|
|
825
966
|
|
|
826
967
|
// src/react/hooks/use-symm-auth.ts
|
|
827
|
-
function logSymmAuth(event, details) {
|
|
828
|
-
if (typeof window === "undefined") {
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
831
|
-
console.log("[symm-auth]", event, details ?? {});
|
|
832
|
-
}
|
|
833
968
|
function useSymmAuth(params) {
|
|
834
969
|
const context = useSymmContext();
|
|
835
970
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -843,20 +978,10 @@ function useSymmAuth(params) {
|
|
|
843
978
|
async (accountAddress, options) => {
|
|
844
979
|
const resolvedAccountAddress = accountAddress ?? activeAccountAddress;
|
|
845
980
|
if (!resolvedAccountAddress) {
|
|
846
|
-
logSymmAuth("refresh:skip-no-active-account", {
|
|
847
|
-
signerAddress: address,
|
|
848
|
-
chainId
|
|
849
|
-
});
|
|
850
981
|
return null;
|
|
851
982
|
}
|
|
852
983
|
if (!walletClient || !address) return null;
|
|
853
984
|
try {
|
|
854
|
-
logSymmAuth("refresh:fetch-start", {
|
|
855
|
-
signerAddress: address,
|
|
856
|
-
accountAddress: resolvedAccountAddress,
|
|
857
|
-
chainId,
|
|
858
|
-
force: options?.force ?? false
|
|
859
|
-
});
|
|
860
985
|
const tokenEntry = await resolveAuthTokenEntry({
|
|
861
986
|
queryClient,
|
|
862
987
|
walletClient,
|
|
@@ -867,20 +992,9 @@ function useSymmAuth(params) {
|
|
|
867
992
|
force: options?.force
|
|
868
993
|
});
|
|
869
994
|
const token2 = tokenEntry?.token ?? null;
|
|
870
|
-
logSymmAuth("refresh:fetch-success", {
|
|
871
|
-
signerAddress: address,
|
|
872
|
-
accountAddress: resolvedAccountAddress,
|
|
873
|
-
chainId
|
|
874
|
-
});
|
|
875
995
|
return token2;
|
|
876
996
|
} catch (error) {
|
|
877
997
|
clearPersistedAuthState(resolvedAccountAddress, chainId);
|
|
878
|
-
logSymmAuth("refresh:fetch-failed", {
|
|
879
|
-
signerAddress: address,
|
|
880
|
-
accountAddress: resolvedAccountAddress,
|
|
881
|
-
chainId,
|
|
882
|
-
error: error instanceof Error ? error.message : String(error)
|
|
883
|
-
});
|
|
884
998
|
return null;
|
|
885
999
|
}
|
|
886
1000
|
},
|
|
@@ -2128,9 +2242,53 @@ function useSymmApproveMutation(params, options) {
|
|
|
2128
2242
|
}
|
|
2129
2243
|
});
|
|
2130
2244
|
}
|
|
2245
|
+
function splitTradeHookArgs(paramsOrOptions, options) {
|
|
2246
|
+
if (paramsOrOptions && "mutation" in paramsOrOptions) {
|
|
2247
|
+
return {
|
|
2248
|
+
params: {},
|
|
2249
|
+
options: paramsOrOptions
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
return {
|
|
2253
|
+
params: paramsOrOptions ?? {},
|
|
2254
|
+
options
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
function useResolveTradeAuthToken(params = {}) {
|
|
2258
|
+
const context = useSymmContext();
|
|
2259
|
+
const queryClient = reactQuery.useQueryClient();
|
|
2260
|
+
const address = params.address ?? context.address;
|
|
2261
|
+
const chainId = params.chainId ?? context.chainId;
|
|
2262
|
+
return react.useCallback(
|
|
2263
|
+
async (providedAuthToken, accountAddress, overrideChainId) => {
|
|
2264
|
+
const resolvedChainId = overrideChainId ?? chainId;
|
|
2265
|
+
if (providedAuthToken) {
|
|
2266
|
+
return providedAuthToken;
|
|
2267
|
+
}
|
|
2268
|
+
const resolvedAccountAddress = accountAddress ?? address;
|
|
2269
|
+
if (!resolvedAccountAddress) {
|
|
2270
|
+
return null;
|
|
2271
|
+
}
|
|
2272
|
+
const inMemoryToken = getAuthTokenFromRuntimeCache(
|
|
2273
|
+
queryClient,
|
|
2274
|
+
resolvedAccountAddress,
|
|
2275
|
+
resolvedChainId,
|
|
2276
|
+
address
|
|
2277
|
+
);
|
|
2278
|
+
if (inMemoryToken) {
|
|
2279
|
+
return inMemoryToken;
|
|
2280
|
+
}
|
|
2281
|
+
return null;
|
|
2282
|
+
},
|
|
2283
|
+
[address, chainId, queryClient]
|
|
2284
|
+
);
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
// src/react/hooks/use-symm-cancel-close.ts
|
|
2131
2288
|
function useSymmCancelClose(options) {
|
|
2132
2289
|
const { symmCoreClient, chainId, address } = useSymmContext();
|
|
2133
2290
|
const queryClient = reactQuery.useQueryClient();
|
|
2291
|
+
const resolveAuthToken = useResolveTradeAuthToken({ address, chainId });
|
|
2134
2292
|
return reactQuery.useMutation({
|
|
2135
2293
|
...withSymmMutationConfig(options?.mutation, {
|
|
2136
2294
|
onSuccess: () => {
|
|
@@ -2147,14 +2305,12 @@ function useSymmCancelClose(options) {
|
|
|
2147
2305
|
if (!symmCoreClient) {
|
|
2148
2306
|
throw new Error("symm-core client not available");
|
|
2149
2307
|
}
|
|
2150
|
-
const resolvedAccountAddress = accountAddress ?? address;
|
|
2151
2308
|
const resolvedChainId = overrideChainId ?? chainId;
|
|
2152
|
-
const resolvedAuthToken =
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
resolvedChainId
|
|
2156
|
-
|
|
2157
|
-
) : null);
|
|
2309
|
+
const resolvedAuthToken = await resolveAuthToken(
|
|
2310
|
+
authToken,
|
|
2311
|
+
accountAddress,
|
|
2312
|
+
resolvedChainId
|
|
2313
|
+
);
|
|
2158
2314
|
if (!resolvedAuthToken) {
|
|
2159
2315
|
throw new Error("auth token is required to cancel a pending close");
|
|
2160
2316
|
}
|
|
@@ -2169,6 +2325,7 @@ function useSymmCancelClose(options) {
|
|
|
2169
2325
|
function useSymmCloseOrder(options) {
|
|
2170
2326
|
const { symmCoreClient, address, chainId } = useSymmContext();
|
|
2171
2327
|
const queryClient = reactQuery.useQueryClient();
|
|
2328
|
+
const resolveAuthToken = useResolveTradeAuthToken({ address, chainId });
|
|
2172
2329
|
return reactQuery.useMutation({
|
|
2173
2330
|
...withSymmMutationConfig(options?.mutation, {
|
|
2174
2331
|
onSuccess: () => {
|
|
@@ -2181,16 +2338,17 @@ function useSymmCloseOrder(options) {
|
|
|
2181
2338
|
throw new Error("symm-core client not available");
|
|
2182
2339
|
}
|
|
2183
2340
|
const typedRequest = request;
|
|
2184
|
-
const
|
|
2341
|
+
const authToken = await resolveAuthToken(
|
|
2342
|
+
typedRequest.authToken,
|
|
2343
|
+
typedRequest.accountAddress
|
|
2344
|
+
);
|
|
2345
|
+
if (!authToken) {
|
|
2346
|
+
throw new Error("auth token is required to close an order");
|
|
2347
|
+
}
|
|
2185
2348
|
return symmCoreClient.orders.close(request.id, {
|
|
2186
2349
|
kind: request.kind,
|
|
2187
2350
|
type: request.type,
|
|
2188
|
-
authToken
|
|
2189
|
-
queryClient,
|
|
2190
|
-
resolvedAccountAddress,
|
|
2191
|
-
chainId,
|
|
2192
|
-
address
|
|
2193
|
-
) ?? void 0 : void 0)
|
|
2351
|
+
authToken
|
|
2194
2352
|
});
|
|
2195
2353
|
}
|
|
2196
2354
|
});
|
|
@@ -25300,64 +25458,6 @@ function useSymmBalances(params) {
|
|
|
25300
25458
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25301
25459
|
});
|
|
25302
25460
|
}
|
|
25303
|
-
function logTradeAuth(event, details) {
|
|
25304
|
-
if (typeof window === "undefined") {
|
|
25305
|
-
return;
|
|
25306
|
-
}
|
|
25307
|
-
console.debug("[symm-trade]", event, details ?? {});
|
|
25308
|
-
}
|
|
25309
|
-
function splitTradeHookArgs(paramsOrOptions, options) {
|
|
25310
|
-
if (paramsOrOptions && "mutation" in paramsOrOptions) {
|
|
25311
|
-
return {
|
|
25312
|
-
params: {},
|
|
25313
|
-
options: paramsOrOptions
|
|
25314
|
-
};
|
|
25315
|
-
}
|
|
25316
|
-
return {
|
|
25317
|
-
params: paramsOrOptions ?? {},
|
|
25318
|
-
options
|
|
25319
|
-
};
|
|
25320
|
-
}
|
|
25321
|
-
function useResolveTradeAuthToken(params = {}) {
|
|
25322
|
-
const context = useSymmContext();
|
|
25323
|
-
const queryClient = reactQuery.useQueryClient();
|
|
25324
|
-
const address = params.address ?? context.address;
|
|
25325
|
-
const chainId = params.chainId ?? context.chainId;
|
|
25326
|
-
return react.useCallback(
|
|
25327
|
-
async (providedAuthToken, accountAddress) => {
|
|
25328
|
-
if (providedAuthToken) {
|
|
25329
|
-
logTradeAuth("resolve-auth:provided", {
|
|
25330
|
-
accountAddress,
|
|
25331
|
-
chainId
|
|
25332
|
-
});
|
|
25333
|
-
return providedAuthToken;
|
|
25334
|
-
}
|
|
25335
|
-
const resolvedAccountAddress = accountAddress ?? address;
|
|
25336
|
-
if (!resolvedAccountAddress) {
|
|
25337
|
-
return null;
|
|
25338
|
-
}
|
|
25339
|
-
const inMemoryToken = getAuthTokenFromRuntimeCache(
|
|
25340
|
-
queryClient,
|
|
25341
|
-
resolvedAccountAddress,
|
|
25342
|
-
chainId,
|
|
25343
|
-
address
|
|
25344
|
-
);
|
|
25345
|
-
if (inMemoryToken) {
|
|
25346
|
-
logTradeAuth("resolve-auth:store-hit", {
|
|
25347
|
-
accountAddress: resolvedAccountAddress,
|
|
25348
|
-
chainId
|
|
25349
|
-
});
|
|
25350
|
-
return inMemoryToken;
|
|
25351
|
-
}
|
|
25352
|
-
logTradeAuth("resolve-auth:miss", {
|
|
25353
|
-
accountAddress: resolvedAccountAddress,
|
|
25354
|
-
chainId
|
|
25355
|
-
});
|
|
25356
|
-
return null;
|
|
25357
|
-
},
|
|
25358
|
-
[address, chainId, queryClient]
|
|
25359
|
-
);
|
|
25360
|
-
}
|
|
25361
25461
|
function useSymmOpenBasketMutation(options) {
|
|
25362
25462
|
const { symmCoreClient } = useSymmContext();
|
|
25363
25463
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -26921,10 +27021,6 @@ function getSymmErrorMessage(error) {
|
|
|
26921
27021
|
if (error instanceof Error) return error.message;
|
|
26922
27022
|
return "An unexpected error occurred.";
|
|
26923
27023
|
}
|
|
26924
|
-
var useSymmWsStore = zustand.create((set) => ({
|
|
26925
|
-
isConnected: false,
|
|
26926
|
-
setConnected: (isConnected) => set({ isConnected })
|
|
26927
|
-
}));
|
|
26928
27024
|
|
|
26929
27025
|
exports.SymmProvider = SymmProvider;
|
|
26930
27026
|
exports.getSymmErrorMessage = getSymmErrorMessage;
|