123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /* Import modules. */
- import { defineStore } from 'pinia'
- /* Import clipboard manager. */
- import './system/clipboard.ts'
- /* Initialize constants. */
- const UPDATE_TICKER_INTERVAL = 30000 // 30 seconds
- /**
- * 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'),
- /* Initialize notifications. */
- notif: {
- isShowing: false,
- icon: null,
- title: null,
- description: null,
- delay: 7000,
- },
- /**
- * 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,
- /**
- * Tickers
- *
- * Support for multiple exchange tickers across multiple currencies.
- */
- _tickers: null,
- }),
- getters: {
- nex() {
- if (!this._tickers?.NEXA) {
- return null
- }
- return this._tickers.NEXA.quote.USD.price
- },
- usd() {
- if (!this.nex) {
- return null
- }
- return this.nex * 10**6
- },
- locale() {
- if (!this._locale) {
- return null
- }
- return this._locale
- },
- },
- actions: {
- /**
- * Initialize Application
- *
- * Performs startup activities.
- */
- init() {
- this._appStarts++
- /* Validate tickers. */
- if (!this._tickers) {
- /* Initialize tickers. */
- this._tickers = {}
- }
- /* Initialize ticker interval. */
- setInterval(this.updateTicker, UPDATE_TICKER_INTERVAL)
- /* Update ticker. */
- this.updateTicker()
- if (this._locale === null) {
- /* Set (library) locale from (store) locale. */
- this._locale = navigator.language || navigator.userLanguage
- console.log(`User's preferred language is:`, this.locale)
- }
- /* Initialize (library) locale. */
- // const { locale } = useI18n()
- /* Set (library) locale. */
- // locale.value = this.locale
- },
- async updateTicker () {
- if (!this._tickers.NEXA) {
- this._tickers.NEXA = {}
- }
- this._tickers.NEXA = await $fetch('https://nexa.exchange/ticker')
- },
- },
- })
|