diff --git a/multi-wallet.py b/multi-wallet.py index 575a7e1..1b70f43 100644 --- a/multi-wallet.py +++ b/multi-wallet.py @@ -1,5 +1,7 @@ import json import account +import os +import time # Plugin Data info = { @@ -23,9 +25,55 @@ functions = { "type": "list" } } + }, + "dash": { + "name": "Dashboard widget", + "type": "dashboard", + "description": "List total balance of all wallets on your dashboard", + "params": {}, + "returns": { + "result": + { + "name": "Total Holdings", + "type": "text" + } + } + }, + "enable": { + "name": "Enable Dashboard widget", + "type": "default", + "description": "Enable the dashboard widget", + "params": {}, + "returns": { + "result": + { + "name": "Result", + "type": "text" + } + } + }, + "disable": { + "name": "Disable Dashboard widget", + "type": "default", + "description": "Disable the dashboard widget", + "params": {}, + "returns": { + "result": + { + "name": "Result", + "type": "text" + } + } } } +if not os.path.exists("user_data/multiwallet.json"): + with open("user_data/multiwallet.json", "w") as f: + json.dump({ + "enabled": False, + "lastUpdate": 0 + }, f) + def balance(params, authentication): wallets = account.listWallets() balances = [] @@ -39,4 +87,49 @@ def balance(params, authentication): balances.append(f"Total: Available: {available:,.2f} HNS, Total: {total:,.2f} HNS") - return {"result": balances} \ No newline at end of file + return {"result": balances} + +def dash(params, authentication): + with open("user_data/multiwallet.json", "r") as f: + multiwallet = json.load(f) + + if multiwallet['enabled'] == False: + return {"result": None} + # Check time + currentTime = int(time.time()) + if currentTime - multiwallet['lastUpdate'] < 60*10: + return {"result": f"Available: {multiwallet['total']['available']:,.2f} HNS
Total: {multiwallet['total']['total']:,.2f} HNS"} + + wallets = account.listWallets() + total = 0 + available = 0 + for wallet in wallets: + info = account.getBalance(wallet) + total += info['total'] + available += info['available'] + + multiwallet['total'] = { + "available": available, + "total": total + } + multiwallet['lastUpdate'] = currentTime + with open("user_data/multiwallet.json", "w") as f: + json.dump(multiwallet, f) + + return {"result": f"Available: {available:,.2f} HNS
Total: {total:,.2f} HNS"} + +def enable(params, authentication): + with open("user_data/multiwallet.json", "r") as f: + multiwallet = json.load(f) + multiwallet['enabled'] = True + with open("user_data/multiwallet.json", "w") as f: + json.dump(multiwallet, f) + return {"result": "Success"} + +def disable(params, authentication): + with open("user_data/multiwallet.json", "r") as f: + multiwallet = json.load(f) + multiwallet['enabled'] = False + with open("user_data/multiwallet.json", "w") as f: + json.dump(multiwallet, f) + return {"result": "Success"} \ No newline at end of file