Files
dashtab/app/components/bitcoin-ticker.gjs
raucao 47906a0386 Add the bitcoin icon badge to the ticker
Match the OpenRouter widget's icon style: a small circular badge with the
bitcoin glyph in white before the price. Export the bitcoin glyph path and
transform from the integrations registry so the ticker and the avatar use
the same source.
2026-11-13 15:01:46 +04:00

97 lines
2.7 KiB
Plaintext

import Component from '@glimmer/component';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import { formFor } from '../config/integration-forms';
import {
BITCOIN_ICON_PATH,
BITCOIN_ICON_TRANSFORM,
} from '../config/integrations';
export default class BitcoinTickerComponent extends Component {
@service bitcoin;
@service modal;
get formattedPrice() {
if (this.bitcoin.price == null) {
return '—';
}
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0,
}).format(this.bitcoin.price);
}
get hasChange() {
return this.bitcoin.changePercent != null;
}
get isUp() {
return this.bitcoin.changePercent >= 0;
}
get changeClass() {
return this.isUp ? 'text-green-400' : 'text-red-400';
}
@action
openSettings() {
this.modal.open({
component: formFor('bitcoin'),
props: { mode: 'edit' },
size: 'md',
});
}
<template>
{{#if this.bitcoin.enabled}}
<button
type="button"
{{on "click" this.openSettings}}
aria-label="Edit Bitcoin ticker settings"
class="cursor-pointer rounded-lg text-center text-white text-shadow-md focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white/70"
>
<div class="flex items-center justify-center gap-1.5">
<span
data-test-bitcoin-icon
class="flex size-4 flex-none items-center justify-center rounded-full bg-[#F7931A]"
aria-hidden="true"
>
<svg
viewBox="0 0 24 24"
fill="currentColor"
class="size-2.5 text-white"
>
<path
d={{BITCOIN_ICON_PATH}}
transform={{BITCOIN_ICON_TRANSFORM}}
/>
</svg>
</span>
<span class="text-lg font-semibold">{{this.formattedPrice}}</span>
{{#if this.hasChange}}
<svg
viewBox="0 0 8 8"
fill="currentColor"
aria-hidden="true"
class="size-2 shrink-0 {{this.changeClass}}"
data-direction={{if this.isUp "up" "down"}}
>
{{#if this.isUp}}
<path d="M4 0 8 8H0z" />
{{else}}
<path d="M4 8 0 0h8z" />
{{/if}}
</svg>
<span class="sr-only">{{if this.isUp "up" "down"}}</span>
{{/if}}
</div>
{{#if this.bitcoin.error}}
<div class="text-xs text-red-300">{{this.bitcoin.error}}</div>
{{/if}}
</button>
{{/if}}
</template>
}