-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
async function connectWallet() { | ||
try { | ||
const starknet = window.starknet; | ||
const wallet = await starknet.enable(); | ||
|
||
if (wallet) { | ||
console.log("Wallet object:", wallet); // Logs the entire wallet object | ||
|
||
const walletAddress = starknet.selectedAddress; | ||
console.log("Wallet Address:", walletAddress); // Logs the wallet address | ||
alert(`Wallet connected: ${walletAddress}`); | ||
|
||
// Save wallet address in session | ||
const formData = new FormData(); | ||
formData.append("wallet_id", walletAddress); | ||
|
||
await fetch("/login", { | ||
method: "POST", | ||
body: formData | ||
}); | ||
|
||
// Redirect or reload the page after connection | ||
window.location.reload(); | ||
} else { | ||
alert("Connection failed. Please try again."); | ||
} | ||
} catch (error) { | ||
console.error("Error connecting wallet:", error); // Logs any error | ||
alert("An error occurred. Please check the console."); | ||
} | ||
} | ||
|
||
async function logout() { | ||
// Remove wallet_id from session and redirect to login page | ||
await fetch("/logout", { method: "POST" }); | ||
window.location.href = "/login"; | ||
} |