utilities

package
v0.0.0-...-5e3cc78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppColors = DarkPalette

AppColors is now a pointer that we switch

View Source
var DarkPalette = ColorPalette{
	Background:  color.NRGBA{R: 20, G: 20, B: 20, A: 155},
	Text:        color.NRGBA{R: 255, G: 255, B: 255, A: 255},
	Error:       color.NRGBA{R: 225, G: 50, B: 50, A: 255},
	Success:     color.NRGBA{R: 76, G: 175, B: 80, A: 255},
	Title:       color.NRGBA{R: 255, G: 184, B: 0, A: 255},
	Button:      color.NRGBA{R: 100, G: 100, B: 100, A: 165},
	Info:        color.NRGBA{R: 0, G: 190, B: 255, A: 255},
	Warning:     color.NRGBA{R: 255, G: 184, B: 0, A: 255},
	Primary:     color.NRGBA{R: 0, G: 125, B: 255, A: 255},
	Secondary:   color.NRGBA{R: 110, G: 115, B: 125, A: 255},
	Light:       color.NRGBA{R: 20, G: 18, B: 25, A: 255},
	Dark:        color.NRGBA{R: 0, G: 0, B: 0, A: 255},
	Accent1:     color.NRGBA{R: 255, G: 184, B: 0, A: 255},
	Accent2:     color.NRGBA{R: 255, G: 184, B: 0, A: 255},
	Accent3:     color.NRGBA{R: 255, G: 184, B: 0, A: 255},
	Accent4:     color.NRGBA{R: 20, G: 20, B: 0, A: 255},
	Accent1Dark: color.NRGBA{R: 180, G: 130, B: 0, A: 255},
	Spread:      color.NRGBA{R: 255, G: 200, B: 0, A: 135},
}
View Source
var LightPalette = ColorPalette{
	Background:  color.NRGBA{R: 255, G: 255, B: 255, A: 255},
	Text:        color.NRGBA{R: 30, G: 30, B: 35, A: 255},
	Error:       color.NRGBA{R: 200, G: 30, B: 30, A: 255},
	Success:     color.NRGBA{R: 20, G: 120, B: 50, A: 255},
	Title:       color.NRGBA{R: 160, G: 110, B: 0, A: 255},
	Button:      color.NRGBA{R: 235, G: 235, B: 240, A: 255},
	Info:        color.NRGBA{R: 180, G: 130, B: 0, A: 255},
	Warning:     color.NRGBA{R: 180, G: 130, B: 0, A: 255},
	Primary:     color.NRGBA{R: 60, G: 60, B: 70, A: 255},
	Secondary:   color.NRGBA{R: 100, G: 100, B: 110, A: 255},
	Light:       color.NRGBA{R: 255, G: 255, B: 255, A: 255},
	Dark:        color.NRGBA{R: 248, G: 248, B: 250, A: 255},
	Accent1:     color.NRGBA{R: 210, G: 150, B: 0, A: 255},
	Accent2:     color.NRGBA{R: 60, G: 60, B: 70, A: 255},
	Accent3:     color.NRGBA{R: 210, G: 150, B: 0, A: 255},
	Accent4:     color.NRGBA{R: 248, G: 248, B: 250, A: 255},
	Accent1Dark: color.NRGBA{R: 160, G: 110, B: 0, A: 255},
	Spread:      color.NRGBA{R: 180, G: 130, B: 0, A: 180},
}

Functions

func CalculateDistance

func CalculateDistance(lat1, lon1, lat2, lon2 float64) float64

CalculateDistance returns the distance (in km) between two coordinates using the Haversine formula.

func DeriveDRPCTarget

func DeriveDRPCTarget(apiURL string) string

DeriveDRPCTarget parses the given API URL, extracts the host, and appends a default port of 8081 for dRPC connections.

func DrawIconClose

func DrawIconClose(gtx layout.Context, col color.NRGBA) layout.Dimensions

DrawIconClose draws a Material-style close (X) icon.

func DrawIconMenu

func DrawIconMenu(gtx layout.Context, col color.NRGBA) layout.Dimensions

DrawIconMenu draws a Material-style hamburger menu icon.

func DrawIconSearch

func DrawIconSearch(gtx layout.Context, col color.NRGBA) layout.Dimensions

DrawIconSearch draws a Material-style search icon (magnifying glass).

func FetchAllRates

func FetchAllRates(window *app.Window, state *AppState, config AppConfig)

FetchAllRates initiates the concurrent fetching of exchange rates.

func FetchAllRatesRPC

func FetchAllRatesRPC(window *app.Window, state *AppState, apiURL string)

FetchAllRatesRPC performs a single dRPC call to fetch all rates for the given currency.

func FetchUserLocation

func FetchUserLocation() (float64, float64, error)

FetchUserLocation attempts to retrieve the user's location. On macOS, it tries to use CoreLocation via a temporary Swift script. Otherwise, it falls back to an IP-based location.

func GenerateFakeData

func GenerateFakeData(points int, basePrice float64, seed int64) []float64

GenerateFakeData creates a sine-wave like dataset for demo purposes.

func GetCachePath

func GetCachePath() string

GetCachePath returns the path to the cache file.

func GetFormattedDate

func GetFormattedDate(lang string, t time.Time) string

GetFormattedDate returns a date string localized for the given language (e.g. "24 Jan").

func GetFormattedDateTime

func GetFormattedDateTime(lang string, t time.Time) string

GetFormattedDateTime returns a date and time string localized (e.g. "24 Jan 15:30").

func GetTranslation

func GetTranslation(lang, key string) string

GetTranslation retrieves the translation for a given language and key. Defaults to English or returns the key if unavailable.

func InitTranslations

func InitTranslations()

InitTranslations loads the translations from the embedded filesystem and initializes the global translations map.

func LanguageModal

func LanguageModal(gtx layout.Context, window *app.Window, theme *material.Theme, state *AppState) layout.Dimensions

LanguageModal renders a modal for selecting a language using a modern grid-based card layout.

func LayoutRightPanel

func LayoutRightPanel(gtx layout.Context, window *app.Window, theme *material.Theme, state *AppState, config AppConfig) layout.Dimensions

LayoutRightPanel lays out the right-side panel of the application.

func LayoutSearchBar

func LayoutSearchBar(gtx layout.Context, window *app.Window, theme *material.Theme, state *AppState) layout.Dimensions

LayoutSearchBar renders a search bar component with a text editor and a Locate button, styled and responsive to the current state.

func LayoutUI

func LayoutUI(gtx layout.Context, window *app.Window, theme *material.Theme, state *AppState, config AppConfig)

LayoutUI - Main application layout

func LayoutVerticalCurrencyBar

func LayoutVerticalCurrencyBar(
	gtx layout.Context, window *app.Window,
	theme *material.Theme, state *AppState, config AppConfig) layout.Dimensions

LayoutVerticalCurrencyBar creates a vertical sidebar for currency selection with a given layout, window, theme, state, and config.

func LoadCache

func LoadCache(state *AppState)

LoadCache loads the application state from a local JSON file.

func LoadFontCollection

func LoadFontCollection() ([]font.FontFace, error)

LoadFontCollection loads a collection of font faces from predefined font files and returns them.

func ModalOverlay

func ModalOverlay(
	gtx layout.Context, window *app.Window,
	state *AppState, content layout.Widget) layout.Dimensions

ModalOverlay displays a centrally aligned modal overlay with optional content and handles dismissal on background click.

func SaveCache

func SaveCache(state *AppState)

SaveCache saves the current application state (cantors and rates) to a local JSON file.

func StartDRPCStream

func StartDRPCStream(window *app.Window, state *AppState, apiURL string)

StartDRPCStream establishes a connection to the dRPC server and processes streaming rate updates in real-time.

func UpdateStateWithRate

func UpdateStateWithRate(window *app.Window, state *AppState, rate *pb.RateResponse)

UpdateStateWithRate safely updates the application state with a new rate and triggers a UI refresh.

Types

type ApiCantorResponse

type ApiCantorResponse struct {
	ID          int     `json:"id"`
	DisplayName string  `json:"displayName"`
	Name        string  `json:"name"`
	Latitude    float64 `json:"latitude"`
	Longitude   float64 `json:"longitude"`
}

ApiCantorResponse for parsing JSON

type AppConfig

type AppConfig struct {
	APICantorsURL string
	APIRatesURL   string
	APIHistoryURL string
}

AppConfig stores app configuration

type AppState

type AppState struct {
	Vault          *CantorVault
	CantorsMu      sync.RWMutex
	Cantors        map[string]*CantorInfo
	History        *pb.HistoryResponse
	ChartAnimStart time.Time // Tracks when the chart data was last updated for animation
	LastFrameTime  time.Time
	IsLoadingStart time.Time
	IsLoading      atomic.Bool
	IsConnected    atomic.Bool
	Notifications  *Notification
	UI             UIState
}

AppState holds the overall state of the application.

type CachedData

type CachedData struct {
	Cantors map[string]*CantorInfo  `json:"cantors"`
	Rates   map[string]*CantorEntry `json:"rates"`
	SavedAt time.Time               `json:"savedAt"`
}

CachedData represents the cached application state.

type CantorEntry

type CantorEntry struct {
	URL      string
	Rate     ExchangeRates
	Error    string
	LoadedAt time.Time
}

CantorEntry represents data fetched from a single cantor.

type CantorInfo

type CantorInfo struct {
	ID          int
	DisplayName string
	Address     string
	Latitude    float64
	Longitude   float64
	Button      widget.Clickable `json:"-"`

	// Long Press Logic
	PressStart         time.Time `json:"-"`
	IsPressing         bool      `json:"-"`
	LongPressTriggered bool      `json:"-"`
}

CantorInfo holds information about a cantor.

type CantorItemArgs

type CantorItemArgs struct {
	Cantor      *CantorInfo
	DisplayName string
	BuyVal      string
	SellVal     string
	SpreadVal   string
	BuyColor    color.NRGBA
	SellColor   color.NRGBA
	Change24h   float64
	IsSelected  bool
	IsMobile    bool
}

CantorItemArgs holds arguments for rendering a cantor item row.

type CantorRowConfig

type CantorRowConfig struct {
	CantorID string
	BestBuy  float64
	BestSell float64
}

CantorRowConfig groups data required to render a single cantor row

type CantorVault

type CantorVault struct {
	Mu        sync.Mutex
	Rates     map[string]*CantorEntry
	LastEntry *CantorEntry
}

CantorVault stores the entries from all cantors

type ColorPalette

type ColorPalette struct {
	Background  color.NRGBA
	Text        color.NRGBA
	Error       color.NRGBA
	Success     color.NRGBA
	Title       color.NRGBA
	Button      color.NRGBA
	Info        color.NRGBA
	Warning     color.NRGBA
	Primary     color.NRGBA
	Secondary   color.NRGBA
	Light       color.NRGBA
	Dark        color.NRGBA
	Accent1     color.NRGBA
	Accent2     color.NRGBA
	Accent3     color.NRGBA
	Accent4     color.NRGBA
	Accent1Dark color.NRGBA
	Spread      color.NRGBA
}

ColorPalette AppColors Colors It defines the color palette used throughout the application.

type ExchangeRates

type ExchangeRates struct {
	BuyRate   string  `json:"buyRate"`
	SellRate  string  `json:"sellRate"`
	Change24h float64 `json:"change24h"`
}

ExchangeRates holds the buy and sell rates for a currency.

type GeoLocationResponse

type GeoLocationResponse struct {
	Lat float64 `json:"lat"`
	Lon float64 `json:"lon"`
}

GeoLocationResponse matches the response structure from ip-api.com

type HoverInfo

type HoverInfo struct {
	Active   bool
	Title    string
	Subtitle string
	Extra    string
}

HoverInfo holds data for the dynamic notch display

type IntroAnim

type IntroAnim struct {
	Active    bool
	StartTime time.Time
	Progress  float32
}

IntroAnim holds state for the intro animation.

type LineChart

type LineChart struct {
	Data       []float64
	Timestamps []int64 // Unix timestamps corresponding to Data points
	StartLabel string
	Tag        any // Tag for pointer events
}

LineChart holds the configuration for a simple line chart.

func (*LineChart) Layout

func (lc *LineChart) Layout(gtx layout.Context, window *app.Window, theme *material.Theme, alpha uint8, state *UIState) layout.Dimensions

Layout renders the line chart within the given constraints.

type MarketValueArgs

type MarketValueArgs struct {
	Label    string
	Value    string
	Color    color.NRGBA
	Change   float64
	IsMobile bool
}

MarketValueArgs holds arguments for rendering a market value display.

type MenuAnim struct {
	CurrentAlpha float32
	LastTime     time.Time
}

MenuAnim holds state for the mobile menu animation.

type ModalConfig

type ModalConfig struct {
	Title    string
	Options  []string
	Buttons  []widget.Clickable
	OnSelect func(string)
}

ModalConfig represents the configuration for a modal UI component.

type Notification

type Notification struct {
	Message string
	Type    string
	Timeout time.Time
}

Notification holds information about a notification banner.

type TimeframeButtonArgs

type TimeframeButtonArgs struct {
	Window *app.Window
	Config AppConfig
	Index  int
	TF     string
	Text   string
}

TimeframeButtonArgs holds arguments for rendering a timeframe selection button.

type UIState

type UIState struct {
	ModalOpen           string
	ModalAnimStart      time.Time
	LangModalButton     widget.Clickable
	CurrencyModalButton widget.Clickable
	ModalClick          widget.Clickable
	ModalList           widget.List
	ModalClose          widget.Clickable

	MobileMenuOpen       bool
	MobileMenuBtn        widget.Clickable
	MobileMenuBackdrop   widget.Clickable
	BgClick              widget.Clickable
	IsMobile             bool
	LayoutTransitionTime time.Time

	CurrencyList    widget.List
	SearchEditor    widget.Editor
	SearchText      string
	SearchActive    bool
	SearchClickable widget.Clickable
	FilteredIDs     []string

	ChartMode        string             // "BUY" or "SELL"
	ChartModeButtons []widget.Clickable // [0] -> Buy, [1] -> Sell
	ChartHoverTag    int                // Unique tag for chart input events
	ChartHoverX      float32
	ChartHoverActive bool

	UserLocation struct {
		Latitude  float64
		Longitude float64
		Active    bool
	}

	MaxDistance     float64
	DistanceSlider  widget.Float
	LocateButton    widget.Clickable
	StatusClickable widget.Clickable
	HoverInfo       HoverInfo
	NotchState      struct {
		CurrentAlpha   float32
		LastContent    HoverInfo
		LastTime       time.Time
		LastHoverTime  time.Time
		HoverStartTime time.Time
	}

	PulseState struct {
		ShowGainer bool      // True = Gainer, False = Loser
		LastSwitch time.Time // Last switch?
	}

	TopMovers struct {
		GainerID   string
		LoserID    string
		LastUpdate time.Time
	}

	IntroAnim IntroAnim
	MenuAnim  MenuAnim

	SelectedCantor        string
	SelectedLanguage      string
	LanguageOptions       []string
	CurrencyOptions       []string
	LanguageOptionButtons []widget.Clickable
	CurrencyOptionButtons []widget.Clickable

	Language string
	Currency string

	LightMode   bool
	ThemeButton widget.Clickable

	SortMode         string // "NAME", "BUY", "SELL", "DIST"
	SortButtons      []widget.Clickable
	Timeframe        string // "1D", "7D", "30D"
	TimeframeButtons []widget.Clickable

	CantorsList widget.List
}

UIState holds UI-specific state and widgets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL