@pear-protocol/symmio-client 0.3.11 → 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 -4
- package/dist/react/index.d.ts +6 -4
- package/dist/react/index.js +39 -13
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +39 -13
- 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)];
|
|
@@ -2344,14 +2368,15 @@ function splitTradeHookArgs(paramsOrOptions, options) {
|
|
|
2344
2368
|
function useResolveTradeAuthToken(params = {}) {
|
|
2345
2369
|
const context = useSymmContext();
|
|
2346
2370
|
const address = params.address ?? context.address;
|
|
2371
|
+
const defaultAccountAddress = params.accountAddress ?? address;
|
|
2347
2372
|
const chainId = params.chainId ?? context.chainId;
|
|
2348
2373
|
return useCallback(
|
|
2349
|
-
async (providedAuthToken,
|
|
2374
|
+
async (providedAuthToken, requestAccountAddress, overrideChainId) => {
|
|
2350
2375
|
const resolvedChainId = overrideChainId ?? chainId;
|
|
2351
2376
|
if (providedAuthToken) {
|
|
2352
2377
|
return providedAuthToken;
|
|
2353
2378
|
}
|
|
2354
|
-
const resolvedAccountAddress =
|
|
2379
|
+
const resolvedAccountAddress = requestAccountAddress ?? defaultAccountAddress;
|
|
2355
2380
|
if (!resolvedAccountAddress) {
|
|
2356
2381
|
return null;
|
|
2357
2382
|
}
|
|
@@ -2365,7 +2390,7 @@ function useResolveTradeAuthToken(params = {}) {
|
|
|
2365
2390
|
}
|
|
2366
2391
|
return null;
|
|
2367
2392
|
},
|
|
2368
|
-
[address, chainId]
|
|
2393
|
+
[address, defaultAccountAddress, chainId]
|
|
2369
2394
|
);
|
|
2370
2395
|
}
|
|
2371
2396
|
|
|
@@ -25614,7 +25639,8 @@ function useSymmClosePositionMutation(paramsOrOptions, maybeOptions) {
|
|
|
25614
25639
|
const typedRequest = request;
|
|
25615
25640
|
const authToken = await resolveAuthToken(
|
|
25616
25641
|
typedRequest.authToken,
|
|
25617
|
-
typedRequest.accountAddress
|
|
25642
|
+
typedRequest.accountAddress,
|
|
25643
|
+
typedRequest.chainId
|
|
25618
25644
|
);
|
|
25619
25645
|
if (!authToken) {
|
|
25620
25646
|
throw new Error("auth token is required to close a position");
|