/* Import modules. */ import { defineStore } from 'pinia' /* Set constants. */ const TICKER_INTERVAL = 30000 /** * System Store */ export const useSystemStore = defineStore('system', { state: () => ({ /* Set constants. */ ONE_SAT: BigInt('1'), ONE_NEX: BigInt('100'), ONE_KEX: BigInt('100000'), ONE_MEX: BigInt('100000000'), ONE_META: BigInt('1000000000000000000'), /* Set Nexa Exchange API endpoint. */ NEXA_EXCHANGE_ENDPOINT: 'https://nexa.exchange', /* Initialize notifications. */ _notif: { isShowing: false, icon: null, title: null, description: null, delay: 7000, }, /** * Application Starts */ _appStarts: 0, /** * Application Version */ _appVersion: null, /** * Flags * * 1. Dark mode * 2. Unconfirmed transactions */ _flags: null, /** * Locale * * Controls the localization language. * (default is english) */ _locale: null, /** * Notices * * System notices that nag/remind the user of some important action or * information; which can be permanently disabled ("Do Not Show Again") * via checkbox and confirmation. * * NOTE: Unique 1-byte (hex) codes (up to 255) are used to reduce the size * of this storage field. */ _notices: null, _ticker: null, }), getters: { ticker(_state) { return _state._ticker }, usd(_state) { const usd = _state._ticker?.quote?.USD?.price const formatted = parseFloat((usd * 1000000.0).toFixed(4)) return formatted }, }, actions: { /** * Initialize Application * * Performs startup activities. */ init() { /* Increment application starts. */ this._appStarts++ /* Set ticker interval. */ setInterval(this.updateTicker, TICKER_INTERVAL) /* Initial ticker update. */ this.updateTicker() }, /** * Update Ticker */ async updateTicker() { this._ticker = await $fetch(this.NEXA_EXCHANGE_ENDPOINT + '/_ticker') .catch(err => console.error(err)) // console.info('SYSTEM (update ticker):', this.ticker) } }, })