@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.mjs
CHANGED
|
@@ -831,28 +831,54 @@ async function login(chainId, params) {
|
|
|
831
831
|
var TOKEN_STORAGE_PREFIX = "symm_access_token";
|
|
832
832
|
var TOKEN_STORAGE_VERSION = 1;
|
|
833
833
|
function cacheKey(address, chainId) {
|
|
834
|
-
return `${address}:${chainId}`;
|
|
834
|
+
return `${address.toLowerCase()}:${chainId}`;
|
|
835
835
|
}
|
|
836
836
|
function storageKey(address, chainId) {
|
|
837
837
|
return `${TOKEN_STORAGE_PREFIX}:${TOKEN_STORAGE_VERSION}:${cacheKey(address, chainId)}`;
|
|
838
838
|
}
|
|
839
|
+
function findStorageKey(address, chainId) {
|
|
840
|
+
const canonicalKey = storageKey(address, chainId);
|
|
841
|
+
if (typeof window === "undefined") return canonicalKey;
|
|
842
|
+
if (window.localStorage.getItem(canonicalKey) != null) {
|
|
843
|
+
return canonicalKey;
|
|
844
|
+
}
|
|
845
|
+
const normalizedKey = canonicalKey.toLowerCase();
|
|
846
|
+
for (let index = 0; index < window.localStorage.length; index += 1) {
|
|
847
|
+
const key = window.localStorage.key(index);
|
|
848
|
+
if (key?.toLowerCase() === normalizedKey) {
|
|
849
|
+
return key;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return canonicalKey;
|
|
853
|
+
}
|
|
854
|
+
function removeStoredTokenKeys(address, chainId) {
|
|
855
|
+
if (typeof window === "undefined") return;
|
|
856
|
+
const normalizedKey = storageKey(address, chainId).toLowerCase();
|
|
857
|
+
for (let index = window.localStorage.length - 1; index >= 0; index -= 1) {
|
|
858
|
+
const key = window.localStorage.key(index);
|
|
859
|
+
if (key?.toLowerCase() === normalizedKey) {
|
|
860
|
+
window.localStorage.removeItem(key);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
839
864
|
function getCachedTokenEntry(address, chainId) {
|
|
840
865
|
if (typeof window === "undefined") return null;
|
|
866
|
+
const key = findStorageKey(address, chainId);
|
|
841
867
|
try {
|
|
842
|
-
const raw = window.localStorage.getItem(
|
|
868
|
+
const raw = window.localStorage.getItem(key);
|
|
843
869
|
if (!raw) return null;
|
|
844
870
|
const parsed = JSON.parse(raw);
|
|
845
871
|
if (!parsed || typeof parsed.token !== "string" || typeof parsed.expiresAt !== "number") {
|
|
846
|
-
window.localStorage.removeItem(
|
|
872
|
+
window.localStorage.removeItem(key);
|
|
847
873
|
return null;
|
|
848
874
|
}
|
|
849
875
|
if (Date.now() >= parsed.expiresAt) {
|
|
850
|
-
window.localStorage.removeItem(
|
|
876
|
+
window.localStorage.removeItem(key);
|
|
851
877
|
return null;
|
|
852
878
|
}
|
|
853
879
|
return parsed;
|
|
854
880
|
} catch {
|
|
855
|
-
window.localStorage.removeItem(
|
|
881
|
+
window.localStorage.removeItem(key);
|
|
856
882
|
return null;
|
|
857
883
|
}
|
|
858
884
|
}
|
|
@@ -867,9 +893,7 @@ function writeStoredToken(address, chainId, cached) {
|
|
|
867
893
|
}
|
|
868
894
|
}
|
|
869
895
|
function clearCachedToken(address, chainId) {
|
|
870
|
-
|
|
871
|
-
window.localStorage.removeItem(storageKey(address, chainId));
|
|
872
|
-
}
|
|
896
|
+
removeStoredTokenKeys(address, chainId);
|
|
873
897
|
}
|
|
874
898
|
async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress, chainId, domain) {
|
|
875
899
|
const resolvedDomain = domain ?? (typeof window !== "undefined" ? window.location.hostname : "localhost");
|
|
@@ -903,7 +927,7 @@ async function fetchAccessTokenEntry(walletClient, signerAddress, accountAddress
|
|
|
903
927
|
return cachedToken;
|
|
904
928
|
}
|
|
905
929
|
function authStoreKey(accountAddress, chainId, signerAddress) {
|
|
906
|
-
return `${accountAddress}:${chainId}:${signerAddress ?? ""}`;
|
|
930
|
+
return `${accountAddress.toLowerCase()}:${chainId}:${signerAddress?.toLowerCase() ?? ""}`;
|
|
907
931
|
}
|
|
908
932
|
function getEntryFromSnapshot(state, accountAddress, chainId, signerAddress) {
|
|
909
933
|
const signerScoped = state.entries[authStoreKey(accountAddress, chainId, signerAddress)];
|
|
@@ -1130,7 +1154,6 @@ function useSymmAuth(params) {
|
|
|
1130
1154
|
isAuthenticated: !!token,
|
|
1131
1155
|
error,
|
|
1132
1156
|
signIn,
|
|
1133
|
-
refreshAuth: signIn,
|
|
1134
1157
|
clear: clearAuth
|
|
1135
1158
|
};
|
|
1136
1159
|
}
|
|
@@ -2345,14 +2368,15 @@ function splitTradeHookArgs(paramsOrOptions, options) {
|
|
|
2345
2368
|
function useResolveTradeAuthToken(params = {}) {
|
|
2346
2369
|
const context = useSymmContext();
|
|
2347
2370
|
const address = params.address ?? context.address;
|
|
2371
|
+
const defaultAccountAddress = params.accountAddress ?? address;
|
|
2348
2372
|
const chainId = params.chainId ?? context.chainId;
|
|
2349
2373
|
return useCallback(
|
|
2350
|
-
async (providedAuthToken,
|
|
2374
|
+
async (providedAuthToken, requestAccountAddress, overrideChainId) => {
|
|
2351
2375
|
const resolvedChainId = overrideChainId ?? chainId;
|
|
2352
2376
|
if (providedAuthToken) {
|
|
2353
2377
|
return providedAuthToken;
|
|
2354
2378
|
}
|
|
2355
|
-
const resolvedAccountAddress =
|
|
2379
|
+
const resolvedAccountAddress = requestAccountAddress ?? defaultAccountAddress;
|
|
2356
2380
|
if (!resolvedAccountAddress) {
|
|
2357
2381
|
return null;
|
|
2358
2382
|
}
|
|
@@ -2366,7 +2390,7 @@ function useResolveTradeAuthToken(params = {}) {
|
|
|
2366
2390
|
}
|
|
2367
2391
|
return null;
|
|
2368
2392
|
},
|
|
2369
|
-
[address, chainId]
|
|
2393
|
+
[address, defaultAccountAddress, chainId]
|
|
2370
2394
|
);
|
|
2371
2395
|
}
|
|
2372
2396
|
|
|
@@ -25615,7 +25639,8 @@ function useSymmClosePositionMutation(paramsOrOptions, maybeOptions) {
|
|
|
25615
25639
|
const typedRequest = request;
|
|
25616
25640
|
const authToken = await resolveAuthToken(
|
|
25617
25641
|
typedRequest.authToken,
|
|
25618
|
-
typedRequest.accountAddress
|
|
25642
|
+
typedRequest.accountAddress,
|
|
25643
|
+
typedRequest.chainId
|
|
25619
25644
|
);
|
|
25620
25645
|
if (!authToken) {
|
|
25621
25646
|
throw new Error("auth token is required to close a position");
|