diff --git a/account.py b/account.py index 89f5ba8..200f66a 100644 --- a/account.py +++ b/account.py @@ -32,7 +32,6 @@ def check_account(cookie: str): info = hsw.getAccountInfo(account, 'default') if 'error' in info: return False - return account def check_password(cookie: str, password: str): @@ -49,6 +48,40 @@ def check_password(cookie: str, password: str): return False return True +def createWallet(account: str, password: str): + # Create the account + # Python wrapper doesn't support this yet + response = requests.put(f"http://x:{APIKEY}@localhost:12039/wallet/{account}") + print(response) + print(response.json()) + + if response.status_code != 200: + return { + "error": { + "message": "Error creating account" + } + } + + # Get seed + seed = hsw.getMasterHDKey(account) + seed = seed['mnemonic']['phrase'] + + + # Encrypt the wallet (python wrapper doesn't support this yet) + response = requests.post(f"http://x:{APIKEY}@localhost:12039/wallet/{account}/passphrase", + json={"passphrase": password}) + print(response) + + return { + "seed": seed, + "account": account, + "password": password + } + +def listWallets(): + # List the wallets + response = hsw.listWallets() + return response def getBalance(account: str): # Get the total balance @@ -493,6 +526,92 @@ def revoke(account,domain): "message": str(e) } } + + + +#region settingsAPIs +def rescan(): + try: + response = hsw.walletRescan(0) + return response + except Exception as e: + return { + "error": { + "message": str(e) + } + } + +def resendTXs(): + try: + response = hsw.walletResend() + return response + except Exception as e: + return { + "error": { + "message": str(e) + } + } + + + +def zapTXs(account): + age = 60 * 20 # 20 minutes + + account_name = check_account(account) + + if account_name == False: + return { + "error": { + "message": "Invalid account" + } + } + + try: + response = requests.post(f"http://x:{APIKEY}@localhost:12039/wallet/{account_name}/zap", + json={"age": age, + "account": "default" + }) + return response + except Exception as e: + return { + "error": { + "message": str(e) + } + } + + +def getxPub(account): + account_name = check_account(account) + + if account_name == False: + return { + "error": { + "message": "Invalid account" + } + } + + + try: + print(account_name) + response = hsw.getAccountInfo(account_name,"default") + if 'error' in response: + return { + "error": { + "message": response['error']['message'] + } + } + return response['accountKey'] + + return response + except Exception as e: + return { + "error": { + "message": str(e) + } + } + + +#endregion def generateReport(account): domains = getDomains(account) diff --git a/main.py b/main.py index 5b1ccd8..b7e9288 100644 --- a/main.py +++ b/main.py @@ -289,7 +289,6 @@ def search(): state = 'AVAILABLE' next = "Available Now" elif state == "REVOKED": - state = 'AVAILABLE' next = "Available Now" elif state == 'OPENING': next = "Bidding opens in ~" + str(domain['info']['stats']['blocksUntilBidding']) + " blocks" @@ -685,7 +684,6 @@ def auction(domain): if search_term in own_domains: next_action = f'Manage' elif state == "REVOKED": - state = 'AVAILABLE' next = "Available Now" next_action = f'Open Auction' elif state == 'OPENING': @@ -821,6 +819,62 @@ def reveal_auction(domain): return redirect("/success?tx=" + response['hash']) +#region settings +@app.route('/settings') +def settings(): + # Check if the user is logged in + if request.cookies.get("account") is None: + return redirect("/login") + + account = account_module.check_account(request.cookies.get("account")) + if not account: + return redirect("/logout") + + error = request.args.get("error") + if error == None: + error = "" + success = request.args.get("success") + if success == None: + success = "" + + return render_template("settings.html", account=account,sync=account_module.getNodeSync(), + error=error,success=success) + +@app.route('/settings/') +def settings_action(action): + # Check if the user is logged in + if request.cookies.get("account") is None: + return redirect("/login") + + account = account_module.check_account(request.cookies.get("account")) + if not account: + return redirect("/logout") + + if action == "rescan": + resp = account_module.rescan() + if 'error' in resp: + return redirect("/settings?error=" + str(resp['error'])) + return redirect("/settings?success=Resent transactions") + elif action == "resend": + resp = account_module.resendTXs() + if 'error' in resp: + return redirect("/settings?error=" + str(resp['error'])) + return redirect("/settings?success=Resent transactions") + + + elif action == "zap": + resp = account_module.zapTXs(request.cookies.get("account")) + if 'error' in resp: + return redirect("/settings?error=" + str(resp['error'])) + return redirect("/settings?success=Zapped transactions") + elif action == "xpub": + return render_template("message.html", account=account,sync=account_module.getNodeSync(), + title="xPub Key",content=account_module.getxPub(request.cookies.get("account"))) + + return redirect("/settings?error=Invalid action") + + +#endregion #endregion @@ -864,6 +918,48 @@ def logout(): response.set_cookie("account", "", expires=0) return response +@app.route('/register', methods=["POST"]) +def register(): + # Get the account and password + account = request.form.get("name") + password = request.form.get("password") + repeatPassword = request.form.get("password_repeat") + + # Check if the passwords match + if password != repeatPassword: + return render_template("register.html", + error="Passwords do not match", + name=account,password=password,password_repeat=repeatPassword) + + # Check if the account is valid + if account.count(":") > 0: + return render_template("register.html", + error="Invalid account", + name=account,password=password,password_repeat=repeatPassword) + + # List wallets + wallets = account_module.listWallets() + if account in wallets: + return render_template("register.html", + error="Account already exists", + name=account,password=password,password_repeat=repeatPassword) + + # Create the account + response = account_module.createWallet(account,password) + + if 'error' in response: + return render_template("register.html", + error=response['error'], + name=account,password=password,password_repeat=repeatPassword) + + + # Set the cookie + response = make_response(render_template("message.html", sync=account_module.getNodeSync(), + title="Account Created", + content="Your account has been created. Here is your seed phrase. Please write it down and keep it safe as it will not be shown again

" + response['seed'])) + response.set_cookie("account", account+":"+password) + return response + @app.route('/report') def report(): diff --git a/templates/404.html b/templates/404.html index 866f389..59334f2 100644 --- a/templates/404.html +++ b/templates/404.html @@ -30,6 +30,7 @@ +
diff --git a/templates/auction.html b/templates/auction.html index 68b07d5..efcea85 100644 --- a/templates/auction.html +++ b/templates/auction.html @@ -30,6 +30,7 @@ +
diff --git a/templates/confirm-password.html b/templates/confirm-password.html index d87534e..2939e6d 100644 --- a/templates/confirm-password.html +++ b/templates/confirm-password.html @@ -30,6 +30,7 @@ +
diff --git a/templates/confirm.html b/templates/confirm.html index b5db38a..ecd63f7 100644 --- a/templates/confirm.html +++ b/templates/confirm.html @@ -30,6 +30,7 @@ +
diff --git a/templates/index.html b/templates/index.html index 2854f08..c4a3fba 100644 --- a/templates/index.html +++ b/templates/index.html @@ -30,6 +30,7 @@ +
diff --git a/templates/login.html b/templates/login.html index cead225..b55e0f9 100644 --- a/templates/login.html +++ b/templates/login.html @@ -35,7 +35,7 @@

-
Create a wallet!
+
Create a wallet!
diff --git a/templates/manage.html b/templates/manage.html index 83fd6b4..cde165f 100644 --- a/templates/manage.html +++ b/templates/manage.html @@ -30,6 +30,7 @@ +
diff --git a/templates/message.html b/templates/message.html new file mode 100644 index 0000000..bc18201 --- /dev/null +++ b/templates/message.html @@ -0,0 +1,79 @@ + + + + + + + FireWallet + + + + + + + + + + + + + +
+ +
+
+ +
+

{{title}}

+

{{content|safe}}

+
+
+
+
+ +
+
+
+
+ + + + + \ No newline at end of file diff --git a/templates/receive.html b/templates/receive.html index 1feed34..04abd98 100644 --- a/templates/receive.html +++ b/templates/receive.html @@ -30,6 +30,7 @@ +
diff --git a/templates/register.html b/templates/register.html index 087339c..655396b 100644 --- a/templates/register.html +++ b/templates/register.html @@ -12,7 +12,6 @@ - @@ -22,28 +21,23 @@
diff --git a/templates/search.html b/templates/search.html index 57a77a9..3a5c9ab 100644 --- a/templates/search.html +++ b/templates/search.html @@ -30,6 +30,7 @@ +
diff --git a/templates/send.html b/templates/send.html index 76e6068..bc39855 100644 --- a/templates/send.html +++ b/templates/send.html @@ -30,6 +30,7 @@ +
diff --git a/templates/settings.html b/templates/settings.html new file mode 100644 index 0000000..401a9d8 --- /dev/null +++ b/templates/settings.html @@ -0,0 +1,117 @@ + + + + + + + Settings - FireWallet + + + + + + + + + + + + + +
+ +
+
+ +
+

{{error}}

+

{{success}}

+
+
+

Node Settings

+
Settings that affect all wallets
+
    +
  • +
    Rescan +

    Rescan

    Rescan the blockchain for transactions +
    +
  • +
  • +
    Resend +

    Resend unconfirmed transactions

    Resend any transactions that haven't been mined yet. +
    +
  • +
  • +
    Zap +

    Delete unconfirmed transactions

    This will only remove pending tx from the wallet older than 20 minutes (~ 2 blocks) +
    +
  • +
+
+
+
+
+
+
+

Wallet Settings

+
Settings that affect only current wallets
+
    +
  • +
    xPub +

    xPub Key

    Get your xPub key +
    +
  • +
+
+
+
+
+
+
+ +
+
+
+
+ + + + + \ No newline at end of file diff --git a/templates/success.html b/templates/success.html index 14d766f..df64a0c 100644 --- a/templates/success.html +++ b/templates/success.html @@ -30,6 +30,7 @@ +
diff --git a/templates/tx.html b/templates/tx.html index 887ff1b..03d463d 100644 --- a/templates/tx.html +++ b/templates/tx.html @@ -30,6 +30,7 @@ +