@pear-protocol/symmio-client 0.2.39 → 0.2.40

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.
@@ -597,10 +597,24 @@ async function login(chainId, params) {
597
597
  body: JSON.stringify(body)
598
598
  });
599
599
  if (!response.ok) {
600
- const errorData = await response.json().catch(() => null);
601
- throw new Error(
602
- errorData?.error_message ?? `Login failed: ${response.statusText}`
603
- );
600
+ let errorMessage = "";
601
+ if (typeof response.text === "function") {
602
+ const rawBody = await response.text().catch(() => "");
603
+ if (rawBody) {
604
+ try {
605
+ const parsed = JSON.parse(rawBody);
606
+ errorMessage = parsed.error_message ?? parsed.message ?? parsed.detail ?? rawBody;
607
+ } catch {
608
+ errorMessage = rawBody;
609
+ }
610
+ }
611
+ }
612
+ if (!errorMessage && typeof response.json === "function") {
613
+ const errorData = await response.json().catch(() => null);
614
+ errorMessage = errorData?.error_message ?? errorData?.message ?? errorData?.detail ?? "";
615
+ }
616
+ const reason = errorMessage || response.statusText;
617
+ throw new Error(reason ? `Login failed: ${reason}` : "Login failed");
604
618
  }
605
619
  const data = await response.json();
606
620
  if (!data.access_token) {
@@ -664,15 +678,15 @@ function clearCachedToken(address, chainId) {
664
678
  }
665
679
  async function fetchAccessToken(walletClient, signerAddress, accountAddress, chainId, domain) {
666
680
  const resolvedDomain = domain ?? (typeof window !== "undefined" ? window.location.host : "localhost");
667
- const uri = typeof window !== "undefined" ? window.location.origin : `https://${resolvedDomain}`;
681
+ const hedgerLoginUrl = new URL("login", getHedgerBaseUrl(chainId)).href;
668
682
  const nonce = await getNonce(chainId, accountAddress);
669
683
  const { message, issuedAt, expirationTime } = createSiweMessage({
670
684
  address: signerAddress,
671
- statement: "Sign in to Symm Protocol",
685
+ statement: `msg: ${accountAddress}`,
672
686
  chainId,
673
687
  nonce,
674
688
  domain: resolvedDomain,
675
- uri
689
+ uri: hedgerLoginUrl
676
690
  });
677
691
  const signature = await walletClient.signMessage({
678
692
  account: signerAddress,
@@ -826,12 +840,6 @@ function useSymmAuth(params) {
826
840
  clearToken(address, chainId);
827
841
  }
828
842
  }, [address, chainId, clearToken]);
829
- console.log("symm auth", {
830
- address,
831
- chainId,
832
- walletClient,
833
- symmCoreClient
834
- });
835
843
  react.useEffect(() => {
836
844
  const previousAddress = previousAddressRef.current;
837
845
  const previousChainId = previousChainIdRef.current;
@@ -851,28 +859,12 @@ function useSymmAuth(params) {
851
859
  previousAddress,
852
860
  previousChainId
853
861
  });
854
- console.log("bootstrap:dependencies", {
855
- address,
856
- chainId,
857
- hasWalletClient: !!walletClient,
858
- hasSymmCoreClient: !!symmCoreClient,
859
- hasRefreshAuth: !!refreshAuthRef.current,
860
- addressChanged,
861
- chainChanged,
862
- previousAddress,
863
- previousChainId
864
- });
865
862
  if (!address) {
866
863
  logSymmAuth("bootstrap:skip-no-address", {
867
864
  chainId,
868
865
  hasWalletClient: !!walletClient,
869
866
  hasSymmCoreClient: !!symmCoreClient
870
867
  });
871
- console.log("bootstrap:skip-no-address", {
872
- chainId,
873
- hasWalletClient: !!walletClient,
874
- hasSymmCoreClient: !!symmCoreClient
875
- });
876
868
  return;
877
869
  }
878
870
  const userAddress = address;
@@ -888,13 +880,6 @@ function useSymmAuth(params) {
888
880
  hasSymmCoreClient: !!symmCoreClient,
889
881
  hasRefreshAuth: !!refreshAuthRef.current
890
882
  });
891
- console.log("bootstrap:run", {
892
- userAddress,
893
- chainId,
894
- hasWalletClient: !!walletClient,
895
- hasSymmCoreClient: !!symmCoreClient,
896
- hasRefreshAuth: !!refreshAuthRef.current
897
- });
898
883
  let targets = [userAddress];
899
884
  if (symmCoreClient) {
900
885
  try {
@@ -911,22 +896,12 @@ function useSymmAuth(params) {
911
896
  chainId,
912
897
  subaccounts
913
898
  });
914
- console.log("bootstrap:subaccounts-resolved", {
915
- userAddress,
916
- chainId,
917
- subaccounts
918
- });
919
899
  } catch (error) {
920
900
  logSymmAuth("bootstrap:subaccounts-failed", {
921
901
  userAddress,
922
902
  chainId,
923
903
  error: error instanceof Error ? error.message : String(error)
924
904
  });
925
- console.log("bootstrap:subaccounts-failed", {
926
- userAddress,
927
- chainId,
928
- error: error instanceof Error ? error.message : String(error)
929
- });
930
905
  }
931
906
  }
932
907
  const uniqueTargets = [...new Set(targets)].filter(