@pear-protocol/symmio-client 0.3.10 → 0.3.12
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 +6 -7
- package/dist/react/index.d.ts +6 -7
- package/dist/react/index.js +39 -14
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +39 -14
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -46,9 +46,6 @@ declare function useSymmAuth(params?: UseSymmAuthParams): {
|
|
|
46
46
|
signIn: (accountAddress?: Address, options?: {
|
|
47
47
|
force?: boolean;
|
|
48
48
|
}) => Promise<string | null>;
|
|
49
|
-
refreshAuth: (accountAddress?: Address, options?: {
|
|
50
|
-
force?: boolean;
|
|
51
|
-
}) => Promise<string | null>;
|
|
52
49
|
clear: () => void;
|
|
53
50
|
};
|
|
54
51
|
|
|
@@ -8555,12 +8552,16 @@ declare function useSymmBalances(params: {
|
|
|
8555
8552
|
}): _tanstack_react_query.UseQueryResult<node_modules__pear_protocol_symm_core_dist_types.BalanceInfoResponse, Error>;
|
|
8556
8553
|
|
|
8557
8554
|
type SymmTradeAuthParams = {
|
|
8555
|
+
accountAddress?: Address;
|
|
8558
8556
|
address?: Address;
|
|
8559
8557
|
chainId?: number;
|
|
8560
8558
|
};
|
|
8561
8559
|
|
|
8562
8560
|
type OpenBasketMutationRequest = WithOptionalAuthToken<OpenBasketPositionRequest>;
|
|
8563
|
-
type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest
|
|
8561
|
+
type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest> & {
|
|
8562
|
+
accountAddress?: Address;
|
|
8563
|
+
chainId?: number;
|
|
8564
|
+
};
|
|
8564
8565
|
type CloseAllPositionsMutationRequest = WithOptionalAuthToken<Parameters<NonNullable<ReturnType<typeof useSymmContext>['symmCoreClient']>['positions']['closeAll']>[0]>;
|
|
8565
8566
|
type UpdatePositionMutationRequest = WithOptionalAuthToken<UpdatePositionRequest>;
|
|
8566
8567
|
/**
|
|
@@ -8578,9 +8579,7 @@ declare function useSymmClosePositionMutation(paramsOrOptions?: SymmTradeAuthPar
|
|
|
8578
8579
|
mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
|
|
8579
8580
|
}, maybeOptions?: {
|
|
8580
8581
|
mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
|
|
8581
|
-
}): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error,
|
|
8582
|
-
authToken?: string | undefined;
|
|
8583
|
-
}, unknown>;
|
|
8582
|
+
}): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, ClosePositionMutationRequest, unknown>;
|
|
8584
8583
|
/**
|
|
8585
8584
|
* Use case: Close all open positions for the provided request scope.
|
|
8586
8585
|
*/
|
package/dist/react/index.d.ts
CHANGED
|
@@ -46,9 +46,6 @@ declare function useSymmAuth(params?: UseSymmAuthParams): {
|
|
|
46
46
|
signIn: (accountAddress?: Address, options?: {
|
|
47
47
|
force?: boolean;
|
|
48
48
|
}) => Promise<string | null>;
|
|
49
|
-
refreshAuth: (accountAddress?: Address, options?: {
|
|
50
|
-
force?: boolean;
|
|
51
|
-
}) => Promise<string | null>;
|
|
52
49
|
clear: () => void;
|
|
53
50
|
};
|
|
54
51
|
|
|
@@ -8555,12 +8552,16 @@ declare function useSymmBalances(params: {
|
|
|
8555
8552
|
}): _tanstack_react_query.UseQueryResult<node_modules__pear_protocol_symm_core_dist_types.BalanceInfoResponse, Error>;
|
|
8556
8553
|
|
|
8557
8554
|
type SymmTradeAuthParams = {
|
|
8555
|
+
accountAddress?: Address;
|
|
8558
8556
|
address?: Address;
|
|
8559
8557
|
chainId?: number;
|
|
8560
8558
|
};
|
|
8561
8559
|
|
|
8562
8560
|
type OpenBasketMutationRequest = WithOptionalAuthToken<OpenBasketPositionRequest>;
|
|
8563
|
-
type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest
|
|
8561
|
+
type ClosePositionMutationRequest = WithOptionalAuthToken<ClosePositionRequest> & {
|
|
8562
|
+
accountAddress?: Address;
|
|
8563
|
+
chainId?: number;
|
|
8564
|
+
};
|
|
8564
8565
|
type CloseAllPositionsMutationRequest = WithOptionalAuthToken<Parameters<NonNullable<ReturnType<typeof useSymmContext>['symmCoreClient']>['positions']['closeAll']>[0]>;
|
|
8565
8566
|
type UpdatePositionMutationRequest = WithOptionalAuthToken<UpdatePositionRequest>;
|
|
8566
8567
|
/**
|
|
@@ -8578,9 +8579,7 @@ declare function useSymmClosePositionMutation(paramsOrOptions?: SymmTradeAuthPar
|
|
|
8578
8579
|
mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
|
|
8579
8580
|
}, maybeOptions?: {
|
|
8580
8581
|
mutation?: SymmMutationConfig<unknown, Error, ClosePositionMutationRequest>;
|
|
8581
|
-
}): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error,
|
|
8582
|
-
authToken?: string | undefined;
|
|
8583
|
-
}, unknown>;
|
|
8582
|
+
}): _tanstack_react_query.UseMutationResult<_pear_protocol_symm_core.ClosePositionResponse | _pear_protocol_symm_core.CloseCommandResult, Error, ClosePositionMutationRequest, unknown>;
|
|
8584
8583
|
/**
|
|
8585
8584
|
* Use case: Close all open positions for the provided request scope.
|
|
8586
8585
|
*/
|
package/dist/react/index.js
CHANGED
|
@@ -833,28 +833,54 @@ async function login(chainId, params) {
|
|
|
833
833
|
var TOKEN_STORAGE_PREFIX = "symm_access_token";
|
|
834
834
|
var TOKEN_STORAGE_VERSION = 1;
|
|
835
835
|
function cacheKey(address, chainId) {
|
|
836
|
-
return `${address}:${chainId}`;
|
|
836
|
+
return `${address.toLowerCase()}:${chainId}`;
|
|
837
837
|
}
|
|
838
838
|
function storageKey(address, chainId) {
|
|
839
839
|
return `${TOKEN_STORAGE_PREFIX}:${TOKEN_STORAGE_VERSION}:${cacheKey(address, chainId)}`;
|
|
840
840
|
}
|
|
841
|
+
function findStorageKey(address, chainId) {
|
|
842
|
+
const canonicalKey = storageKey(address, chainId);
|
|
843
|
+
if (typeof window === "undefined") return canonicalKey;
|
|
844
|
+
if (window.localStorage.getItem(canonicalKey) != null) {
|
|
845
|
+
return canonicalKey;
|
|
846
|
+
}
|
|
847
|
+
const normalizedKey = canonicalKey.toLowerCase();
|
|
848
|
+
for (let index = 0; index < window.localStorage.length; index += 1) {
|
|
849
|
+
const key = window.localStorage.key(index);
|
|
850
|
+
if (key?.toLowerCase() === normalizedKey) {
|
|
851
|
+
return key;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return canonicalKey;
|
|
855
|
+
}
|
|
856
|
+
function removeStoredTokenKeys(address, chainId) {
|
|
857
|
+
if (typeof window === "undefined") return;
|
|
858
|
+
const normalizedKey = storageKey(address, chainId).toLowerCase();
|
|
859
|
+
for (let index = window.localStorage.length - 1; index >= 0; index -= 1) {
|
|
860
|
+
const key = window.localStorage.key(index);
|
|
861
|
+
if (key?.toLowerCase() === normalizedKey) {
|
|
862
|
+
window.localStorage.removeItem(key);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
841
866
|
function getCachedTokenEntry(address, chainId) {
|
|
842
867
|
if (typeof window === "undefined") return null;
|
|
868
|
+
const key = findStorageKey(address, chainId);
|
|
843
869
|
try {
|
|
844
|
-
const raw = window.localStorage.getItem(
|
|
870
|
+
const raw = window.localStorage.getItem(key);
|
|
845
871
|
if (!raw) return null;
|
|
846
872
|
const parsed = JSON.parse(raw);
|
|
847
873
|
if (!parsed || typeof parsed.token !== "string" || typeof parsed.expiresAt !== "number") {
|
|
848
|
-
window.localStorage.removeItem(
|
|
874
|
+
window.localStorage.removeItem(key);
|
|
849
875
|
return null;
|
|
850
876
|
}
|
|
851
877
|
if (Date.now() >= parsed.expiresAt) {
|
|
852
|
-
window.localStorage.removeItem(
|
|
878
|
+
window.localStorage.removeItem(key);
|
|
853
879
|
return null;
|
|
854
880
|
}
|
|
855
881
|
return parsed;
|
|
856
882
|
} catch {
|
|
857
|
-
window.localStorage.removeItem(
|
|
883
|
+
window.localStorage.removeItem(key);
|
|
858
884
|
return null;
|
|
859
885
|
}
|
|
860
886
|
}
|
|
@@ -869,9 +895,7 @@ function writeStoredToken(address, chainId, cached) {
|
|
|
869
895
|
}
|
|
870
896
|
}
|
|
871
897
|
function clearCachedToken(address, chainId) {
|
|
872
|
-
|
|
873
|
-
window.localStorage.removeItem(storageKey(address, chainId));
|
|
874
|
-
}
|
|
898
|
+
removeStoredTokenKeys(address, chainId);
|
|
875
899
|
}
|
|
876
900
|
async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress, chainId, domain) {
|
|
877
901
|
const resolvedDomain = domain ?? (typeof window !== "undefined" ? window.location.hostname : "localhost");
|
|
@@ -905,7 +929,7 @@ async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress
|
|
|
905
929
|
return cachedToken;
|
|
906
930
|
}
|
|
907
931
|
function authStoreKey(accountAddress, chainId, signerAddress) {
|
|
908
|
-
return `${accountAddress}:${chainId}:${signerAddress ?? ""}`;
|
|
932
|
+
return `${accountAddress.toLowerCase()}:${chainId}:${signerAddress?.toLowerCase() ?? ""}`;
|
|
909
933
|
}
|
|
910
934
|
function getEntryFromSnapshot(state, accountAddress, chainId, signerAddress) {
|
|
911
935
|
const signerScoped = state.entries[authStoreKey(accountAddress, chainId, signerAddress)];
|
|
@@ -1132,7 +1156,6 @@ function useSymmAuth(params) {
|
|
|
1132
1156
|
isAuthenticated: !!token,
|
|
1133
1157
|
error,
|
|
1134
1158
|
signIn,
|
|
1135
|
-
refreshAuth: signIn,
|
|
1136
1159
|
clear: clearAuth
|
|
1137
1160
|
};
|
|
1138
1161
|
}
|
|
@@ -2347,14 +2370,15 @@ function splitTradeHookArgs(paramsOrOptions, options) {
|
|
|
2347
2370
|
function useResolveTradeAuthToken(params = {}) {
|
|
2348
2371
|
const context = useSymmContext();
|
|
2349
2372
|
const address = params.address ?? context.address;
|
|
2373
|
+
const defaultAccountAddress = params.accountAddress ?? address;
|
|
2350
2374
|
const chainId = params.chainId ?? context.chainId;
|
|
2351
2375
|
return react.useCallback(
|
|
2352
|
-
async (providedAuthToken,
|
|
2376
|
+
async (providedAuthToken, requestAccountAddress, overrideChainId) => {
|
|
2353
2377
|
const resolvedChainId = overrideChainId ?? chainId;
|
|
2354
2378
|
if (providedAuthToken) {
|
|
2355
2379
|
return providedAuthToken;
|
|
2356
2380
|
}
|
|
2357
|
-
const resolvedAccountAddress =
|
|
2381
|
+
const resolvedAccountAddress = requestAccountAddress ?? defaultAccountAddress;
|
|
2358
2382
|
if (!resolvedAccountAddress) {
|
|
2359
2383
|
return null;
|
|
2360
2384
|
}
|
|
@@ -2368,7 +2392,7 @@ function useResolveTradeAuthToken(params = {}) {
|
|
|
2368
2392
|
}
|
|
2369
2393
|
return null;
|
|
2370
2394
|
},
|
|
2371
|
-
[address, chainId]
|
|
2395
|
+
[address, defaultAccountAddress, chainId]
|
|
2372
2396
|
);
|
|
2373
2397
|
}
|
|
2374
2398
|
|
|
@@ -25617,7 +25641,8 @@ function useSymmClosePositionMutation(paramsOrOptions, maybeOptions) {
|
|
|
25617
25641
|
const typedRequest = request;
|
|
25618
25642
|
const authToken = await resolveAuthToken(
|
|
25619
25643
|
typedRequest.authToken,
|
|
25620
|
-
typedRequest.accountAddress
|
|
25644
|
+
typedRequest.accountAddress,
|
|
25645
|
+
typedRequest.chainId
|
|
25621
25646
|
);
|
|
25622
25647
|
if (!authToken) {
|
|
25623
25648
|
throw new Error("auth token is required to close a position");
|