Skip to content

Commit

Permalink
Release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Apr 4, 2023
1 parent f8965b3 commit 08957fd
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 130 deletions.
1 change: 1 addition & 0 deletions assets.tinybar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id": 31566704, "decimals": 6, "unit_name": "USDC", "name": "USDC"}]
619 changes: 503 additions & 116 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["aorumbayev <aorumbayev at pm.me>"]

[tool.poetry.dependencies]
python = "^3.10"
rumps = "^0.3.0"
rumps = "^0.4.0"
requests = "^2.26.0"
tinyman-py-sdk = {git = "https://github.com/tinymanorg/tinyman-py-sdk.git", rev = "main"}
py-algorand-sdk = "^1.8.0"
Expand Down
4 changes: 0 additions & 4 deletions src/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@
if _data
else [
USDC,
ASA(id=230946361, decimals=6, unit_name="GEMS", name="AlgoGems"),
ASA(id=27165954, decimals=6, unit_name="PLANETS", name="PLANET"),
ASA(id=287867876, decimals=6, unit_name="OPUL", name="OPULOUS"),
ASA(id=233939122, decimals=6, unit_name="AWT", name="ALGOWORLD TOKEN"),
]
)
8 changes: 8 additions & 0 deletions src/common/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import BaseModel


Expand All @@ -14,3 +16,9 @@ class ASA(BaseModel):
decimals: int
unit_name: str
name: str
creator: Optional[str] = None
manager: Optional[str] = None
reserve: Optional[str] = None
freeze: Optional[str] = None
total: Optional[int] = None
url: Optional[str] = None
69 changes: 60 additions & 9 deletions src/tinybar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import rumps
from algosdk.v2client.algod import AlgodClient
from tinyman.v1.client import TinymanClient, TinymanMainnetClient, TinymanTestnetClient
from tinyman.v2.client import (
BaseTinymanClient,
TinymanV2MainnetClient,
TinymanV2TestnetClient,
)

from src.common.constants import (
ALGO,
Expand All @@ -14,8 +18,6 @@
from src.common.models import ASA
from src.common.utils import save_tinybar_data

rumps.debug_mode(True)

ICON_PATH = "icon.png"
ALGOD_URL = "https://mainnet-api.algonode.cloud"

Expand All @@ -27,21 +29,24 @@ def __init__(self):
super(TinyBar, self).__init__(name="TinyBar")

### Clients setup
self.tinyman_client: TinymanClient = (
TinymanMainnetClient(
self.tinyman_client: BaseTinymanClient = (
TinymanV2MainnetClient(
algod,
)
if LEDGER_TYPE.lower() == "mainnet"
else TinymanTestnetClient()
else TinymanV2TestnetClient()
)

self.asas = TINYBAR_ASSETS_DB
self.asa: ASA = TINYBAR_ASSETS_DB[0]

### Menu setup
self.search_menuitem: rumps.MenuItem = rumps.MenuItem("🔎 Search")
self.search_menuitem: rumps.MenuItem = rumps.MenuItem("➕ Add ASA")
self.menu.add(self.search_menuitem)

self.explorer_menuitem: rumps.MenuItem = rumps.MenuItem("🔎 Explorer")
self.menu.add(self.explorer_menuitem)

for asa in self.asas:
self.menu.add(rumps.MenuItem(asa.unit_name, callback=self._changeAsa))

Expand All @@ -57,7 +62,7 @@ def _save_asa_data(self, asa: ASA):
self.asas.append(asa)
save_tinybar_data(TINYBAR_DATA_PATH, self.asas)

@rumps.clicked("🔎 Search")
@rumps.clicked("➕ Add ASA")
def search(self, sender):
window = rumps.Window(
f"Current: {self.asa.unit_name} ({self.asa.id})",
Expand All @@ -80,11 +85,57 @@ def search(self, sender):
self.title = "Invalid ASA, try again..."
self.asa = TINYBAR_ASSETS_DB[0]

@rumps.clicked("🔎 Explorer")
def search(self, sender):
window = rumps.Window(
f"Current: {self.asa.unit_name} ({self.asa.id})",
"Enter asset ID (aka ASA ID)...",
)
window.icon = ICON_PATH
response = window.run()

try:
asa_info = self.tinyman_client.algod.asset_info(int(response.text))
asa = ASA(
id=asa_info["index"],
decimals=asa_info["params"]["decimals"],
unit_name=asa_info["params"]["unit-name"],
name=asa_info["params"]["name"],
manager=asa_info["params"]["manager"],
reserve=asa_info["params"]["reserve"],
freeze=asa_info["params"]["freeze"],
creator=asa_info["params"]["creator"],
total=asa_info["params"]["total"],
url=asa_info["params"]["url"],
)
message = (
f"ID: {asa.id}\n"
f"Unit Name: {asa.unit_name}\n"
f"Name: {asa.name}\n"
f"Total: {asa.total}\n"
f"URL: {asa.url}\n"
f"Creator: {asa.creator}\n"
f"Reserve: {asa.reserve}\n"
f"Manager: {asa.freeze}\n"
f"Manager: {asa.manager}\n"
f"https://algoscan.app/asset/{asa.id}"
)
rumps.alert(
title="AlgoScan URL",
message=message,
ok=None,
cancel=None,
icon_path=ICON_PATH,
)
except Exception:
self.title = "Invalid ASA, try again..."
self.asa = TINYBAR_ASSETS_DB[0]

@rumps.clicked("ℹ️ About")
def about(self, _):
rumps.alert(
title="TinyBar App",
message="Version 0.3.2 - Dec 2022 by @aorumbayev\nhttps://github.com/aorumbayev/tinybar\n\nTracking TinyMan asset prices from your MacOS menu bar\nhas never been easier!\n\n* The base currency is ALGO, app always displays USDC equivalent to selected ALGO amount from selected ASA/ALGO pair.\n\n* Refresh rate is every 60 seconds.\n\nUpdates are currently manual, refer to repo to get latest...\n\nLicensed under MIT.\n\nrumps licensed under BSD 3-Clause.",
message="Version 0.4.0 - Apr 2023 by @aorumbayev\nhttps://github.com/aorumbayev/tinybar\n\nTracking TinyMan asset prices from your MacOS menu bar\nhas never been easier!\n\n* The base currency is ALGO, app always displays USDC equivalent to selected ALGO amount from selected ASA/ALGO pair.\n\n* Refresh rate is every 60 seconds.\n\nUpdates are currently manual, refer to repo to get latest...\n\nLicensed under MIT.\n\nrumps licensed under BSD 3-Clause.",
ok=None,
cancel=None,
icon_path=ICON_PATH,
Expand Down

0 comments on commit 08957fd

Please sign in to comment.