2025-06-22 00:21:09 +03:00

76 lines
2.4 KiB
JavaScript

import { w as writable } from "./index2.js";
const createWalletStore = () => {
const initialState = { publicKey: null, keyId: null };
console.log("Creating wallet store with initial state:", initialState);
const store = writable(initialState);
const { subscribe, set, update } = store;
return {
subscribe,
/**
* Registers a keypair in the browser's storage.
* @async
* @function register
* @param {Object} params - Parameters for the registration
* @param {string} params.publicKey - The public key to register
* @param {string} params.secretKey - The secret key to encrypt and store
* @param {string} params.pincode - The pincode to use for encryption
*/
register: async ({ publicKey, secretKey, pincode }) => {
console.log("Registering wallet with public key:", publicKey);
{
console.error("Cannot register wallet in SSR mode");
return;
}
},
/**
* Confirms the pincode for an encrypted keypair.
* @async
* @function confirmPincode
* @param {Object} params - Parameters for the confirmation
* @param {string} params.pincode - The pincode to confirm
*/
confirmPincode: async ({ pincode }) => {
console.log("Confirming pincode");
{
console.error("Cannot confirm pincode in SSR mode");
return;
}
},
/**
* Removes the wallet from the store and from localStorage.
* @function logout
*/
logout: () => {
console.log("Logging out wallet");
set({ publicKey: null, keyId: null });
console.log("Wallet logged out");
}
};
};
const walletStore = createWalletStore();
function navigateToDashboard() {
console.log("Direct navigation to dashboard initiated");
try {
window.location.href = "/redirect?to=/dashboard";
} catch (e) {
console.error("Failed to navigate to redirect page:", e);
try {
window.location.href = "/dashboard";
} catch (e2) {
console.error("Failed to navigate with location.href:", e2);
try {
window.location.replace("/dashboard");
} catch (e22) {
console.error("Failed to navigate with location.replace:", e22);
const link = document.createElement("a");
link.href = "/dashboard";
link.click();
}
}
}
}
walletStore.navigateToDashboard = navigateToDashboard;
export {
walletStore as w
};