Skip to content

Commit

Permalink
Merge pull request #809 from tinymanorg/add-verified-asa-icons-automa…
Browse files Browse the repository at this point in the history
…tically

Add verified ASA icons to JSON files automatically at build step
  • Loading branch information
gokselcoban authored Nov 14, 2023
2 parents 4a163a8 + ef7bfa2 commit d147eee
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/upload-to-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- main
schedule:
# Schedule to run at midnight UTC
- cron: '0 0 * * *'

permissions:
id-token: write # This is required for requesting the JWT
Expand All @@ -28,6 +31,17 @@ jobs:
- name: Prepare build folder
run: INDEXER_TOKEN=${{ secrets.INDEXER_TOKEN }} npm run build

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Python dependencies
run: pip install requests

- name: Fetch verified asset icons (verified by Pera)
run: python fetch_verified_asa_icons.py

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_STORE
build/
node_modules
node_modules
*idea
57 changes: 57 additions & 0 deletions fetch_verified_asa_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import json
from pathlib import Path

import requests

current_dir = Path(__file__).parent
build_directory = current_dir / "build"
assets_file_path = build_directory / "assets.json"
icons_file_path = build_directory / "icons.json"

with open(assets_file_path) as file:
assets_data = json.load(file)

with open(icons_file_path) as file:
icons_data = json.load(file)


def process_assets(assets):
for asset in assets:
asset_id = str(asset["asset_id"])
if asset_id not in assets_data and asset["logo"]:
logo_url = asset["logo"] + "?format=png&height=256&width=256"

icons_data[asset_id] = logo_url

assets_data[asset_id] = {
"id": asset_id,
"name": asset["name"],
"unit_name": asset["unit_name"],
"url": "",
"decimals": asset["fraction_decimals"],
"total_amount": asset["total"],
"deleted": asset["is_deleted"],
"logo": {
"png": logo_url,
"svg": "",
},
}


response = requests.get("https://api.perawallet.app/v1/assets/?status=verified").json()
# Check and process the first page
if "results" in response:
process_assets(response["results"])

# Iterate over the next pages
while "next" in response and response["next"]:
response = requests.get(response["next"]).json()
if "results" in response:
process_assets(response["results"])


with open(assets_file_path, 'w') as file:
json.dump(assets_data, file)

with open(icons_file_path, 'w') as file:
json.dump(icons_data, file)

0 comments on commit d147eee

Please sign in to comment.