@pear-protocol/symmio-client 0.2.32 → 0.2.33
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 +21 -4
- package/dist/react/index.d.ts +21 -4
- package/dist/react/index.js +52 -41
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +52 -41
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -39,8 +39,12 @@ declare function useSymmAuth(params?: UseSymmAuthParams): {
|
|
|
39
39
|
accessToken: string | null;
|
|
40
40
|
authToken: string | null;
|
|
41
41
|
isAuthenticated: boolean;
|
|
42
|
-
refresh: (accountAddress?: Address
|
|
43
|
-
|
|
42
|
+
refresh: (accountAddress?: Address, options?: {
|
|
43
|
+
force?: boolean;
|
|
44
|
+
}) => Promise<string | null>;
|
|
45
|
+
refreshAuth: (accountAddress?: Address, options?: {
|
|
46
|
+
force?: boolean;
|
|
47
|
+
}) => Promise<string | null>;
|
|
44
48
|
clear: () => void;
|
|
45
49
|
};
|
|
46
50
|
|
|
@@ -8504,6 +8508,12 @@ declare function useSymmBalances(params: {
|
|
|
8504
8508
|
query?: SymmQueryConfig;
|
|
8505
8509
|
}): _tanstack_react_query.UseQueryResult<node_modules__pear_protocol_symm_core_dist_types.BalanceInfoResponse, Error>;
|
|
8506
8510
|
|
|
8511
|
+
type SymmTradeAuthParams = {
|
|
8512
|
+
address?: Address;
|
|
8513
|
+
chainId?: number;
|
|
8514
|
+
walletClient?: WalletClient;
|
|
8515
|
+
siweDomain?: string;
|
|
8516
|
+
};
|
|
8507
8517
|
/**
|
|
8508
8518
|
* Use case: Open a basket position through SYMM core API.
|
|
8509
8519
|
*/
|
|
@@ -8513,7 +8523,9 @@ declare function useSymmOpenBasketMutation(options?: {
|
|
|
8513
8523
|
/**
|
|
8514
8524
|
* Use case: Close a position with automatic auth-token resolution.
|
|
8515
8525
|
*/
|
|
8516
|
-
declare function useSymmClosePositionMutation(
|
|
8526
|
+
declare function useSymmClosePositionMutation(paramsOrOptions?: SymmTradeAuthParams | {
|
|
8527
|
+
mutation?: SymmMutationConfig<unknown, Error, ClosePositionRequest>;
|
|
8528
|
+
}, maybeOptions?: {
|
|
8517
8529
|
mutation?: SymmMutationConfig<unknown, Error, ClosePositionRequest>;
|
|
8518
8530
|
}): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, ClosePositionRequest, unknown>;
|
|
8519
8531
|
/**
|
|
@@ -8533,7 +8545,12 @@ declare function useSymmCancelOpenMutation(options?: {
|
|
|
8533
8545
|
/**
|
|
8534
8546
|
* Use case: Update position settings with automatic auth-token resolution.
|
|
8535
8547
|
*/
|
|
8536
|
-
declare function useSymmUpdatePositionMutation(
|
|
8548
|
+
declare function useSymmUpdatePositionMutation(paramsOrOptions?: SymmTradeAuthParams | {
|
|
8549
|
+
mutation?: SymmMutationConfig<unknown, Error, {
|
|
8550
|
+
positionId: string;
|
|
8551
|
+
request: UpdatePositionRequest;
|
|
8552
|
+
}>;
|
|
8553
|
+
}, maybeOptions?: {
|
|
8537
8554
|
mutation?: SymmMutationConfig<unknown, Error, {
|
|
8538
8555
|
positionId: string;
|
|
8539
8556
|
request: UpdatePositionRequest;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -39,8 +39,12 @@ declare function useSymmAuth(params?: UseSymmAuthParams): {
|
|
|
39
39
|
accessToken: string | null;
|
|
40
40
|
authToken: string | null;
|
|
41
41
|
isAuthenticated: boolean;
|
|
42
|
-
refresh: (accountAddress?: Address
|
|
43
|
-
|
|
42
|
+
refresh: (accountAddress?: Address, options?: {
|
|
43
|
+
force?: boolean;
|
|
44
|
+
}) => Promise<string | null>;
|
|
45
|
+
refreshAuth: (accountAddress?: Address, options?: {
|
|
46
|
+
force?: boolean;
|
|
47
|
+
}) => Promise<string | null>;
|
|
44
48
|
clear: () => void;
|
|
45
49
|
};
|
|
46
50
|
|
|
@@ -8504,6 +8508,12 @@ declare function useSymmBalances(params: {
|
|
|
8504
8508
|
query?: SymmQueryConfig;
|
|
8505
8509
|
}): _tanstack_react_query.UseQueryResult<node_modules__pear_protocol_symm_core_dist_types.BalanceInfoResponse, Error>;
|
|
8506
8510
|
|
|
8511
|
+
type SymmTradeAuthParams = {
|
|
8512
|
+
address?: Address;
|
|
8513
|
+
chainId?: number;
|
|
8514
|
+
walletClient?: WalletClient;
|
|
8515
|
+
siweDomain?: string;
|
|
8516
|
+
};
|
|
8507
8517
|
/**
|
|
8508
8518
|
* Use case: Open a basket position through SYMM core API.
|
|
8509
8519
|
*/
|
|
@@ -8513,7 +8523,9 @@ declare function useSymmOpenBasketMutation(options?: {
|
|
|
8513
8523
|
/**
|
|
8514
8524
|
* Use case: Close a position with automatic auth-token resolution.
|
|
8515
8525
|
*/
|
|
8516
|
-
declare function useSymmClosePositionMutation(
|
|
8526
|
+
declare function useSymmClosePositionMutation(paramsOrOptions?: SymmTradeAuthParams | {
|
|
8527
|
+
mutation?: SymmMutationConfig<unknown, Error, ClosePositionRequest>;
|
|
8528
|
+
}, maybeOptions?: {
|
|
8517
8529
|
mutation?: SymmMutationConfig<unknown, Error, ClosePositionRequest>;
|
|
8518
8530
|
}): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, ClosePositionRequest, unknown>;
|
|
8519
8531
|
/**
|
|
@@ -8533,7 +8545,12 @@ declare function useSymmCancelOpenMutation(options?: {
|
|
|
8533
8545
|
/**
|
|
8534
8546
|
* Use case: Update position settings with automatic auth-token resolution.
|
|
8535
8547
|
*/
|
|
8536
|
-
declare function useSymmUpdatePositionMutation(
|
|
8548
|
+
declare function useSymmUpdatePositionMutation(paramsOrOptions?: SymmTradeAuthParams | {
|
|
8549
|
+
mutation?: SymmMutationConfig<unknown, Error, {
|
|
8550
|
+
positionId: string;
|
|
8551
|
+
request: UpdatePositionRequest;
|
|
8552
|
+
}>;
|
|
8553
|
+
}, maybeOptions?: {
|
|
8537
8554
|
mutation?: SymmMutationConfig<unknown, Error, {
|
|
8538
8555
|
positionId: string;
|
|
8539
8556
|
request: UpdatePositionRequest;
|
package/dist/react/index.js
CHANGED
|
@@ -616,7 +616,6 @@ async function login(chainId, params) {
|
|
|
616
616
|
// src/react/auth.ts
|
|
617
617
|
var TOKEN_STORAGE_PREFIX = "symm_access_token";
|
|
618
618
|
var TOKEN_STORAGE_VERSION = 1;
|
|
619
|
-
var tokenCache = /* @__PURE__ */ new Map();
|
|
620
619
|
function cacheKey(address, chainId) {
|
|
621
620
|
return `${address}:${chainId}`;
|
|
622
621
|
}
|
|
@@ -654,20 +653,11 @@ function writeStoredToken(address, chainId, cached) {
|
|
|
654
653
|
}
|
|
655
654
|
}
|
|
656
655
|
function getCachedToken(address, chainId) {
|
|
657
|
-
const cached = tokenCache.get(cacheKey(address, chainId));
|
|
658
|
-
if (cached && Date.now() < cached.expiresAt) {
|
|
659
|
-
return cached.token;
|
|
660
|
-
}
|
|
661
|
-
if (cached) {
|
|
662
|
-
tokenCache.delete(cacheKey(address, chainId));
|
|
663
|
-
}
|
|
664
656
|
const stored = readStoredToken(address, chainId);
|
|
665
657
|
if (!stored) return null;
|
|
666
|
-
tokenCache.set(cacheKey(address, chainId), stored);
|
|
667
658
|
return stored.token;
|
|
668
659
|
}
|
|
669
660
|
function clearCachedToken(address, chainId) {
|
|
670
|
-
tokenCache.delete(cacheKey(address, chainId));
|
|
671
661
|
if (typeof window !== "undefined") {
|
|
672
662
|
window.localStorage.removeItem(storageKey(address, chainId));
|
|
673
663
|
}
|
|
@@ -700,7 +690,6 @@ async function fetchAccessToken(walletClient, signerAddress, accountAddress, cha
|
|
|
700
690
|
token: accessToken,
|
|
701
691
|
expiresAt: expiresAt - 6e4
|
|
702
692
|
};
|
|
703
|
-
tokenCache.set(cacheKey(accountAddress, chainId), cachedToken);
|
|
704
693
|
writeStoredToken(accountAddress, chainId, cachedToken);
|
|
705
694
|
return accessToken;
|
|
706
695
|
}
|
|
@@ -743,7 +732,7 @@ function useSymmAuth(params) {
|
|
|
743
732
|
const chainId = params?.chainId ?? ctx.chainId ?? 42161;
|
|
744
733
|
const walletClient = params?.walletClient ?? ctx.walletClient;
|
|
745
734
|
const siweDomain = params?.siweDomain;
|
|
746
|
-
const
|
|
735
|
+
const token = useSymmAuthStore((state) => {
|
|
747
736
|
if (address) {
|
|
748
737
|
return state.tokensByKey[symmAuthTokenKey(address, chainId)] ?? null;
|
|
749
738
|
}
|
|
@@ -754,29 +743,32 @@ function useSymmAuth(params) {
|
|
|
754
743
|
const clearToken = useSymmAuthStore((state) => state.clearToken);
|
|
755
744
|
const previousAddressRef = react.useRef(address);
|
|
756
745
|
const previousChainIdRef = react.useRef(chainId);
|
|
746
|
+
const refreshAuthRef = react.useRef(async () => null);
|
|
757
747
|
const refreshAuth = react.useCallback(
|
|
758
|
-
async (accountAddress) => {
|
|
748
|
+
async (accountAddress, options) => {
|
|
759
749
|
if (!walletClient || !address) return null;
|
|
760
750
|
const resolvedAccountAddress = accountAddress ?? address;
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
751
|
+
if (!options?.force) {
|
|
752
|
+
const inStore = getToken(resolvedAccountAddress, chainId);
|
|
753
|
+
if (inStore) {
|
|
754
|
+
return inStore;
|
|
755
|
+
}
|
|
756
|
+
const cached = getCachedToken(resolvedAccountAddress, chainId);
|
|
757
|
+
if (cached) {
|
|
758
|
+
setToken(resolvedAccountAddress, chainId, cached);
|
|
759
|
+
return cached;
|
|
760
|
+
}
|
|
769
761
|
}
|
|
770
762
|
try {
|
|
771
|
-
const
|
|
763
|
+
const token2 = await fetchAccessToken(
|
|
772
764
|
walletClient,
|
|
773
765
|
address,
|
|
774
766
|
resolvedAccountAddress,
|
|
775
767
|
chainId,
|
|
776
768
|
siweDomain
|
|
777
769
|
);
|
|
778
|
-
setToken(resolvedAccountAddress, chainId,
|
|
779
|
-
return
|
|
770
|
+
setToken(resolvedAccountAddress, chainId, token2);
|
|
771
|
+
return token2;
|
|
780
772
|
} catch {
|
|
781
773
|
clearToken(resolvedAccountAddress, chainId);
|
|
782
774
|
return null;
|
|
@@ -784,6 +776,7 @@ function useSymmAuth(params) {
|
|
|
784
776
|
},
|
|
785
777
|
[walletClient, address, chainId, siweDomain, getToken, setToken, clearToken]
|
|
786
778
|
);
|
|
779
|
+
refreshAuthRef.current = refreshAuth;
|
|
787
780
|
const clearAuth = react.useCallback(() => {
|
|
788
781
|
if (address) {
|
|
789
782
|
clearCachedToken(address, chainId);
|
|
@@ -797,24 +790,22 @@ function useSymmAuth(params) {
|
|
|
797
790
|
const chainChanged = previousChainId !== chainId;
|
|
798
791
|
previousAddressRef.current = address;
|
|
799
792
|
previousChainIdRef.current = chainId;
|
|
800
|
-
if (!address
|
|
793
|
+
if (!address) {
|
|
801
794
|
return;
|
|
802
795
|
}
|
|
803
796
|
if (previousAddress && (addressChanged || chainChanged)) {
|
|
804
797
|
clearCachedToken(previousAddress, previousChainId);
|
|
805
798
|
clearToken(previousAddress, previousChainId);
|
|
806
799
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
setToken(address, chainId, cached);
|
|
810
|
-
} else {
|
|
811
|
-
clearToken(address, chainId);
|
|
800
|
+
if (!walletClient) {
|
|
801
|
+
return;
|
|
812
802
|
}
|
|
813
|
-
|
|
803
|
+
void refreshAuthRef.current(address);
|
|
804
|
+
}, [address, walletClient, chainId, clearToken]);
|
|
814
805
|
return {
|
|
815
|
-
accessToken,
|
|
816
|
-
authToken:
|
|
817
|
-
isAuthenticated: !!
|
|
806
|
+
accessToken: token,
|
|
807
|
+
authToken: token,
|
|
808
|
+
isAuthenticated: !!token,
|
|
818
809
|
refresh: refreshAuth,
|
|
819
810
|
refreshAuth,
|
|
820
811
|
clear: clearAuth
|
|
@@ -25036,10 +25027,28 @@ function useSymmBalances(params) {
|
|
|
25036
25027
|
enabled: internalEnabled && (params.query?.enabled ?? true)
|
|
25037
25028
|
});
|
|
25038
25029
|
}
|
|
25039
|
-
function
|
|
25030
|
+
function splitTradeHookArgs(paramsOrOptions, options) {
|
|
25031
|
+
if (paramsOrOptions && "mutation" in paramsOrOptions) {
|
|
25032
|
+
return {
|
|
25033
|
+
params: {},
|
|
25034
|
+
options: paramsOrOptions
|
|
25035
|
+
};
|
|
25036
|
+
}
|
|
25037
|
+
return {
|
|
25038
|
+
params: paramsOrOptions ?? {},
|
|
25039
|
+
options
|
|
25040
|
+
};
|
|
25041
|
+
}
|
|
25042
|
+
function useResolveTradeAuthToken(params = {}) {
|
|
25040
25043
|
const context = useSymmContext();
|
|
25041
|
-
const
|
|
25042
|
-
const
|
|
25044
|
+
const address = params.address ?? context.address;
|
|
25045
|
+
const chainId = params.chainId ?? context.chainId;
|
|
25046
|
+
const { refreshAuth } = useSymmAuth({
|
|
25047
|
+
address,
|
|
25048
|
+
chainId,
|
|
25049
|
+
walletClient: params.walletClient,
|
|
25050
|
+
siweDomain: params.siweDomain
|
|
25051
|
+
});
|
|
25043
25052
|
const refreshAuthFromContext = context.refreshAuth;
|
|
25044
25053
|
return react.useCallback(
|
|
25045
25054
|
async (providedAuthToken, accountAddress) => {
|
|
@@ -25077,10 +25086,11 @@ function useSymmOpenBasketMutation(options) {
|
|
|
25077
25086
|
}
|
|
25078
25087
|
});
|
|
25079
25088
|
}
|
|
25080
|
-
function useSymmClosePositionMutation(
|
|
25089
|
+
function useSymmClosePositionMutation(paramsOrOptions, maybeOptions) {
|
|
25081
25090
|
const { symmCoreClient } = useSymmContext();
|
|
25082
25091
|
const queryClient = reactQuery.useQueryClient();
|
|
25083
|
-
const
|
|
25092
|
+
const { params, options } = splitTradeHookArgs(paramsOrOptions, maybeOptions);
|
|
25093
|
+
const resolveAuthToken = useResolveTradeAuthToken(params);
|
|
25084
25094
|
return reactQuery.useMutation({
|
|
25085
25095
|
...withSymmMutationConfig(options?.mutation, {
|
|
25086
25096
|
onSuccess: () => {
|
|
@@ -25134,10 +25144,11 @@ function useSymmCancelOpenMutation(options) {
|
|
|
25134
25144
|
}
|
|
25135
25145
|
});
|
|
25136
25146
|
}
|
|
25137
|
-
function useSymmUpdatePositionMutation(
|
|
25147
|
+
function useSymmUpdatePositionMutation(paramsOrOptions, maybeOptions) {
|
|
25138
25148
|
const { symmCoreClient } = useSymmContext();
|
|
25139
25149
|
const queryClient = reactQuery.useQueryClient();
|
|
25140
|
-
const
|
|
25150
|
+
const { params, options } = splitTradeHookArgs(paramsOrOptions, maybeOptions);
|
|
25151
|
+
const resolveAuthToken = useResolveTradeAuthToken(params);
|
|
25141
25152
|
return reactQuery.useMutation({
|
|
25142
25153
|
...withSymmMutationConfig(options?.mutation, {
|
|
25143
25154
|
onSuccess: () => {
|