Created
June 26, 2025 03:56
-
-
Save learntheropes/7a9890a3e2c71f19e53c0a04a3df01b2 to your computer and use it in GitHub Desktop.
BTC price in multiple currencies widget for scriptable iOS app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bitcoin Price Widget using Yadio.io | |
| let widget = new ListWidget(); | |
| widget.setPadding(16, 16, 16, 16); | |
| widget.backgroundColor = new Color("#1a1a1a"); | |
| let title = widget.addText("₿ Bitcoin Price"); | |
| title.font = Font.boldSystemFont(16); | |
| title.textColor = Color.white(); | |
| widget.addSpacer(8); | |
| const currencies = ['PYG', 'ARS', 'EUR', 'USD']; | |
| try { | |
| // 1) fetch the whole JSON… | |
| let res = await new Request("https://api.yadio.io/exrates/btc").loadJSON(); | |
| // 2) extract the nested BTC object | |
| let rates = res.BTC || {}; | |
| for (let code of currencies) { | |
| let price = rates[code] != null | |
| ? Number(rates[code]).toLocaleString() | |
| : "N/A"; | |
| let line = widget.addText(`${code}: ${price}`); | |
| line.font = Font.mediumSystemFont(14); | |
| line.textColor = Color.white(); | |
| } | |
| } catch (e) { | |
| let err = widget.addText("Error fetching data"); | |
| err.font = Font.mediumSystemFont(14); | |
| err.textColor = Color.red(); | |
| console.error(e); | |
| } | |
| Script.setWidget(widget); | |
| Script.complete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment