123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /* 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)
- }
- },
- })
|