diff --git a/app/app.py b/app/app.py index 4525e7d..8cfd8dd 100644 --- a/app/app.py +++ b/app/app.py @@ -10,6 +10,38 @@ app = Flask(__name__, static_folder="static") def show_wallet_form(): return render_template("index.html") +# Route to get the current RPC configuration +@app.route("/get_rpc_config", methods=["GET"]) +def get_rpc_config(): + return jsonify( + { + "rpcHost": request.cookies.get("rpcHost"), + "rpcPort": request.cookies.get("rpcPort"), + "rpcUser": request.cookies.get("rpcUser"), + "rpcPassword": request.cookies.get("rpcPassword"), + } + ) + + +# Route to update the RPC configuration +@app.route("/update_rpc_config", methods=["POST"]) +def update_rpc_config(): + try: + # Extract RPC config from the POST request + rpc_host = request.form["rpcHost"] + rpc_port = request.form["rpcPort"] + rpc_user = request.form["rpcUser"] + rpc_password = request.form["rpcPassword"] + + # Update localStorage with the new values + response = jsonify({"message": "RPC configuration updated successfully."}) + response.set_cookie("rpcHost", value=rpc_host) + response.set_cookie("rpcPort", value=rpc_port) + response.set_cookie("rpcUser", value=rpc_user) + response.set_cookie("rpcPassword", value=rpc_password) + return response + except Exception as e: + return jsonify({"message": f"Error updating RPC configuration: {str(e)}"}) @app.route("/create_wallet", methods=["POST"]) def handle_create_wallet(): @@ -50,41 +82,12 @@ def list_wallets(): error_message = "An Exception occurred: " + str(general_exception) return jsonify({"error": error_message}) # Return JSON error response +@app.route("/set_active_wallet", methods=["POST"]) +def set_active_wallet(): + wallet_name = request.form["walletName"] + return jsonify({"message": f"Active wallet set to '{wallet_name}'."}) - -# Route to get the current RPC configuration -@app.route("/get_rpc_config", methods=["GET"]) -def get_rpc_config(): - return jsonify( - { - "rpcHost": request.cookies.get("rpcHost"), - "rpcPort": request.cookies.get("rpcPort"), - "rpcUser": request.cookies.get("rpcUser"), - "rpcPassword": request.cookies.get("rpcPassword"), - } - ) - - -# Route to update the RPC configuration -@app.route("/update_rpc_config", methods=["POST"]) -def update_rpc_config(): - try: - # Extract RPC config from the POST request - rpc_host = request.form["rpcHost"] - rpc_port = request.form["rpcPort"] - rpc_user = request.form["rpcUser"] - rpc_password = request.form["rpcPassword"] - - # Update localStorage with the new values - response = jsonify({"message": "RPC configuration updated successfully."}) - response.set_cookie("rpcHost", value=rpc_host) - response.set_cookie("rpcPort", value=rpc_port) - response.set_cookie("rpcUser", value=rpc_user) - response.set_cookie("rpcPassword", value=rpc_password) - return response - except Exception as e: - return jsonify({"message": f"Error updating RPC configuration: {str(e)}"}) - +active_wallet = {} # Store active wallets in memory if __name__ == "__main__": app.run(debug=True) \ No newline at end of file diff --git a/app/static/java/fetchWallets.js b/app/static/java/fetchWallets.js new file mode 100644 index 0000000..e7ccc9b --- /dev/null +++ b/app/static/java/fetchWallets.js @@ -0,0 +1,29 @@ +// Function to fetch wallets and display them +function fetchWallets() { + fetch('/wallets') + .then(response => response.json()) + .then(data => { + const wallets = data.wallets; + + // Display wallets in the frontend (e.g., as a list or dropdown) + const walletsList = document.getElementById('walletList'); + walletsList.innerHTML = ''; + + wallets.forEach(wallet => { + const walletItem = document.createElement('div'); + walletItem.textContent = wallet; + walletItem.classList.add('wallet-item'); + + // Add event listener to set the wallet as active on click + walletItem.addEventListener('click', () => setActiveWallet(wallet)); + + walletsList.appendChild(walletItem); + }); + }) + .catch(error => { + console.error('Error:', error); + }); +} + +// Call fetchWallets function on page load to get and display wallets +document.addEventListener('DOMContentLoaded', fetchWallets); \ No newline at end of file diff --git a/app/static/java/setActiveWallet.js b/app/static/java/setActiveWallet.js new file mode 100644 index 0000000..9901bb6 --- /dev/null +++ b/app/static/java/setActiveWallet.js @@ -0,0 +1,20 @@ +// Function to set the active wallet in localStorage +function setActiveWallet(walletName) { + localStorage.setItem('activeWallet', walletName); + + // Optionally, update UI to highlight/select the active wallet + // For example, you can add a CSS class to highlight the selected wallet + + // Send the selected wallet to the backend to set it as active + fetch('/set_active_wallet', { + method: 'POST', + body: new URLSearchParams({ walletName }) + }) + .then(response => response.json()) + .then(data => { + console.log(data.message); // Log success message from the backend + }) + .catch(error => { + console.error('Error:', error); + }); +} \ No newline at end of file diff --git a/app/static/java/walletFormResponse.js b/app/static/java/walletFormResponse.js index 78b1f36..bbfaf40 100644 --- a/app/static/java/walletFormResponse.js +++ b/app/static/java/walletFormResponse.js @@ -14,4 +14,4 @@ document.getElementById('walletForm').addEventListener('submit', function(event) .catch(error => { console.error('Error:', error); }); -}); \ No newline at end of file +}); diff --git a/app/static/java/walletList.js b/app/static/java/walletList.js deleted file mode 100644 index 009a57b..0000000 --- a/app/static/java/walletList.js +++ /dev/null @@ -1,21 +0,0 @@ -window.onload = function () { - fetch("/wallets") - .then((response) => response.json()) - .then((data) => { - const walletList = document.getElementById("walletList"); - if (data.wallets && data.wallets.length > 0) { - const wallets = data.wallets; - const walletsHTML = wallets - .map((wallet) => `
${wallet}
`) - .join(""); - walletList.innerHTML = walletsHTML; - } else { - walletList.innerHTML = "No wallets found.
"; - } - }) - .catch((error) => { - console.error("Error fetching wallet list:", error); - const walletList = document.getElementById("walletList"); - walletList.innerHTML = "Error fetching wallets.
"; - }); - }; \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html index c03bb24..c4943ef 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -86,7 +86,7 @@