Skip to content

Instantly share code, notes, and snippets.

@stevelacey
Last active November 25, 2020 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevelacey/c15234fa7080a5eabe800e46bae69f40 to your computer and use it in GitHub Desktop.
Save stevelacey/c15234fa7080a5eabe800e46bae69f40 to your computer and use it in GitHub Desktop.
const widget = new ListWidget()
widget.backgroundColor = Color.black()
const amount = (number) => '$' + new Intl.NumberFormat().format(Math.round(number))
const text = (text, fontSize) => {
const t = widget.addText(text)
t.font = new Font('Avenir-Heavy', fontSize)
t.textColor = Color.white()
}
const alias = {
'Freetrade': 'FT',
'TransferWise': 'TW',
}
data.balances.slice(0, 6).forEach(balance => {
balance.name = alias[balance.name] || balance.name
text(`${amount(balance.total)} ${balance.name}`, 12)
})
text(`${amount(data.total)} 🔥️`, 16)
Script.setWidget(widget)
Script.complete()
const widget = new ListWidget()
widget.backgroundColor = Color.black()
const amount = (number) => '$' + new Intl.NumberFormat().format(Math.round(number))
const text = (text, fontSize) => {
const t = widget.addText(text)
t.font = new Font('Avenir-Heavy', fontSize)
t.textColor = Color.white()
}
data.positions.sort((a, b) => b.total - a.total).slice(0, 18).forEach(position => {
text(`${amount(position.total)} ${position.name} (${position.symbol})`, 12)
})
Script.setWidget(widget)
Script.complete()
const request = new Request('https://path/to/some/json')
const data = await request.loadJSON()
const gist = new Request(`${args.widgetParameter}?v=${Math.round(new Date().getTime() / 1000)}`)
const script = await gist.loadString()
eval(script)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment