feat: Add dashboard widget
This commit is contained in:
parent
5ee5f518a4
commit
0a074a4bbf
@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import account
|
import account
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
# Plugin Data
|
# Plugin Data
|
||||||
info = {
|
info = {
|
||||||
@ -23,9 +25,55 @@ functions = {
|
|||||||
"type": "list"
|
"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):
|
def balance(params, authentication):
|
||||||
wallets = account.listWallets()
|
wallets = account.listWallets()
|
||||||
balances = []
|
balances = []
|
||||||
@ -39,4 +87,49 @@ def balance(params, authentication):
|
|||||||
|
|
||||||
balances.append(f"Total: Available: {available:,.2f} HNS, Total: {total:,.2f} HNS")
|
balances.append(f"Total: Available: {available:,.2f} HNS, Total: {total:,.2f} HNS")
|
||||||
|
|
||||||
return {"result": balances}
|
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<br>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<br>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"}
|
Loading…
Reference in New Issue
Block a user