Skip to content

Commit 82dd1a3

Browse files
committed
feat: improve toast messages
1. **Removed unnecessary awaits for `enableDecryption`**: - The `cipherProvider.enableDecryption()` method is not asynchronous, so I removed the `await` before these calls in the `initializeLitSession`, `loadRequests`, and other functions. 2. **Added user-friendly error toasts**: - Added more descriptive toast messages for common error scenarios in the Lit Protocol initialization - Added informative toast when a decryption session is reset due to address mismatch - Improved error messages in the `loadRequests` function 3. **Enhanced error handling**: - Added specific try/catch block for session signature requests - Provided more context in error messages to help users understand what went wrong - Made error messages more actionable with suggestions on how to resolve issues 4. **Improved error descriptions**: - Using the actual error message when available - Providing helpful fallback messages when the error doesn't have a message property - Including user-friendly suggestions for resolving common issues
1 parent d65b963 commit 82dd1a3

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

packages/invoice-dashboard/src/lib/view-requests.svelte

+43-11
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,17 @@
478478
): Promise<boolean> => {
479479
if (!currentAccount?.address) {
480480
console.error("Cannot initialize Lit session: Missing account address");
481+
toast.error("Decryption initialization failed", {
482+
description: "Wallet connection required for decrypted requests"
483+
});
481484
return false;
482485
}
483486
484487
if (!cipherProvider) {
485488
console.error("Cannot initialize Lit session: Missing cipher provider");
489+
toast.error("Decryption initialization failed", {
490+
description: "Encryption service not available"
491+
});
486492
return false;
487493
}
488494
@@ -504,8 +510,7 @@
504510
const parsedSig = JSON.parse(storedSig);
505511
506512
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);
509514
sliderValueForDecryption = "on";
510515
511516
// Ensure our UI state reflects the storage state
@@ -516,17 +521,26 @@
516521
} else {
517522
console.log("Stored signature address doesn't match current account, resetting");
518523
resetDecryptionState();
524+
toast.info("Decryption session reset", {
525+
description: "Previous session belonged to a different wallet address"
526+
});
519527
}
520528
} catch (sessionError) {
521529
console.error("Failed to restore Lit session:", sessionError);
522530
resetDecryptionState();
531+
toast.error("Failed to restore decryption session", {
532+
description: "Try toggling decryption off and on again"
533+
});
523534
}
524535
} else {
525536
console.log("Incomplete session data, cannot restore Lit session");
526537
}
527538
} catch (error) {
528539
console.error("Failed to initialize Lit session:", error);
529540
resetDecryptionState();
541+
toast.error("Decryption initialization failed", {
542+
description: error instanceof Error ? error.message : "Unknown error occurred"
543+
});
530544
}
531545
return false;
532546
};
@@ -895,20 +909,34 @@
895909
loadSessionSignatures = localStorage?.getItem("lit-wallet-sig") === null;
896910
897911
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+
}
904927
}
905928
906-
await cipherProvider?.enableDecryption(true);
929+
// No await needed - enableDecryption is not async
930+
cipherProvider?.enableDecryption(true);
907931
localStorage?.setItem("isDecryptionEnabled", "true");
908932
}
909933
} catch (error) {
910934
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+
});
912940
resetDecryptionState();
913941
return;
914942
} finally {
@@ -930,7 +958,11 @@
930958
selectedNetworks = previousNetworks; // Restore selection
931959
} catch (error) {
932960
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+
});
934966
} finally {
935967
loading = false;
936968
}

0 commit comments

Comments
 (0)