|
478 | 478 | ): Promise<boolean> => {
|
479 | 479 | if (!currentAccount?.address) {
|
480 | 480 | console.error("Cannot initialize Lit session: Missing account address");
|
| 481 | + toast.error("Decryption initialization failed", { |
| 482 | + description: "Wallet connection required for decrypted requests" |
| 483 | + }); |
481 | 484 | return false;
|
482 | 485 | }
|
483 | 486 |
|
484 | 487 | if (!cipherProvider) {
|
485 | 488 | console.error("Cannot initialize Lit session: Missing cipher provider");
|
| 489 | + toast.error("Decryption initialization failed", { |
| 490 | + description: "Encryption service not available" |
| 491 | + }); |
486 | 492 | return false;
|
487 | 493 | }
|
488 | 494 |
|
|
504 | 510 | const parsedSig = JSON.parse(storedSig);
|
505 | 511 |
|
506 | 512 | if (parsedSig.address?.toLowerCase() === currentAccount.address?.toLowerCase()) {
|
507 |
| - // Use the stored session key and signature to restore the session |
508 |
| - await cipherProvider.enableDecryption(true); |
| 513 | + cipherProvider.enableDecryption(true); |
509 | 514 | sliderValueForDecryption = "on";
|
510 | 515 |
|
511 | 516 | // Ensure our UI state reflects the storage state
|
|
516 | 521 | } else {
|
517 | 522 | console.log("Stored signature address doesn't match current account, resetting");
|
518 | 523 | resetDecryptionState();
|
| 524 | + toast.info("Decryption session reset", { |
| 525 | + description: "Previous session belonged to a different wallet address" |
| 526 | + }); |
519 | 527 | }
|
520 | 528 | } catch (sessionError) {
|
521 | 529 | console.error("Failed to restore Lit session:", sessionError);
|
522 | 530 | resetDecryptionState();
|
| 531 | + toast.error("Failed to restore decryption session", { |
| 532 | + description: "Try toggling decryption off and on again" |
| 533 | + }); |
523 | 534 | }
|
524 | 535 | } else {
|
525 | 536 | console.log("Incomplete session data, cannot restore Lit session");
|
526 | 537 | }
|
527 | 538 | } catch (error) {
|
528 | 539 | console.error("Failed to initialize Lit session:", error);
|
529 | 540 | resetDecryptionState();
|
| 541 | + toast.error("Decryption initialization failed", { |
| 542 | + description: error instanceof Error ? error.message : "Unknown error occurred" |
| 543 | + }); |
530 | 544 | }
|
531 | 545 | return false;
|
532 | 546 | };
|
|
895 | 909 | loadSessionSignatures = localStorage?.getItem("lit-wallet-sig") === null;
|
896 | 910 |
|
897 | 911 | if (loadSessionSignatures) {
|
898 |
| - await cipherProvider?.getSessionSignatures( |
899 |
| - signer, |
900 |
| - currentAccount.address, |
901 |
| - window.location.host, |
902 |
| - "Sign in to Lit Protocol through Request Network" |
903 |
| - ); |
| 912 | + try { |
| 913 | + await cipherProvider?.getSessionSignatures( |
| 914 | + signer, |
| 915 | + currentAccount.address, |
| 916 | + window.location.host, |
| 917 | + "Sign in to Lit Protocol through Request Network" |
| 918 | + ); |
| 919 | + } catch (sigError) { |
| 920 | + console.error("Failed to get session signatures:", sigError); |
| 921 | + toast.error("Signature request failed", { |
| 922 | + description: "Couldn't obtain needed signatures for decryption" |
| 923 | + }); |
| 924 | + resetDecryptionState(); |
| 925 | + return; |
| 926 | + } |
904 | 927 | }
|
905 | 928 |
|
906 |
| - await cipherProvider?.enableDecryption(true); |
| 929 | + // No await needed - enableDecryption is not async |
| 930 | + cipherProvider?.enableDecryption(true); |
907 | 931 | localStorage?.setItem("isDecryptionEnabled", "true");
|
908 | 932 | }
|
909 | 933 | } catch (error) {
|
910 | 934 | console.error("Failed to enable decryption:", error);
|
911 |
| - toast.error("Failed to enable decryption."); |
| 935 | + toast.error("Failed to enable decryption", { |
| 936 | + description: error instanceof Error ? |
| 937 | + error.message : |
| 938 | + "Make sure your wallet is connected and try again" |
| 939 | + }); |
912 | 940 | resetDecryptionState();
|
913 | 941 | return;
|
914 | 942 | } finally {
|
|
930 | 958 | selectedNetworks = previousNetworks; // Restore selection
|
931 | 959 | } catch (error) {
|
932 | 960 | console.error("Error loading requests:", error);
|
933 |
| - toast.error("Failed to load requests"); |
| 961 | + toast.error("Failed to load requests", { |
| 962 | + description: error instanceof Error ? |
| 963 | + error.message : |
| 964 | + "Check your connection and try again" |
| 965 | + }); |
934 | 966 | } finally {
|
935 | 967 | loading = false;
|
936 | 968 | }
|
|
0 commit comments