setactivewallet implemented
This commit is contained in:
parent
c2bc4ac9b0
commit
bbd3abfacc
71
app/app.py
71
app/app.py
@ -10,6 +10,38 @@ app = Flask(__name__, static_folder="static")
|
|||||||
def show_wallet_form():
|
def show_wallet_form():
|
||||||
return render_template("index.html")
|
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"])
|
@app.route("/create_wallet", methods=["POST"])
|
||||||
def handle_create_wallet():
|
def handle_create_wallet():
|
||||||
@ -50,41 +82,12 @@ def list_wallets():
|
|||||||
error_message = "An Exception occurred: " + str(general_exception)
|
error_message = "An Exception occurred: " + str(general_exception)
|
||||||
return jsonify({"error": error_message}) # Return JSON error response
|
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}'."})
|
||||||
|
|
||||||
|
active_wallet = {} # Store active wallets in memory
|
||||||
# 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)}"})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
29
app/static/java/fetchWallets.js
Normal file
29
app/static/java/fetchWallets.js
Normal file
@ -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);
|
20
app/static/java/setActiveWallet.js
Normal file
20
app/static/java/setActiveWallet.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
}
|
@ -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) => `<p>${wallet}</p>`)
|
|
||||||
.join("");
|
|
||||||
walletList.innerHTML = walletsHTML;
|
|
||||||
} else {
|
|
||||||
walletList.innerHTML = "<p>No wallets found.</p>";
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Error fetching wallet list:", error);
|
|
||||||
const walletList = document.getElementById("walletList");
|
|
||||||
walletList.innerHTML = "<p>Error fetching wallets.</p>";
|
|
||||||
});
|
|
||||||
};
|
|
@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
<h1 class="mt-6 mb-4 ml-2 text-xl font-bold">Available Wallets</h1>
|
<h1 class="mt-6 mb-4 ml-2 text-xl font-bold">Available Wallets</h1>
|
||||||
<div id="walletList" class="ml-4"></div>
|
<div id="walletList" class="ml-4"></div>
|
||||||
<script src="{{ url_for('static', filename='java/walletList.js') }}"></script>
|
<script src="{{ url_for('static', filename='java/fetchWallets.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='java/setActiveWallet.js') }}"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user