import { defineStore } from 'pinia' import { ref, computed } from 'vue' import type { WalletState } from '@/interface' export const useNeptuneStore = defineStore('neptune', () => { // ===== STATE ===== const wallet = ref({ seedPhrase: null, receiverId: null, viewKey: null, address: null, network: 'testnet', balance: null, utxos: [], }) const isLoading = ref(false) const error = ref(null) // ===== SETTERS ===== const setSeedPhrase = (seedPhrase: string[] | null) => { wallet.value.seedPhrase = seedPhrase } const setReceiverId = (receiverId: string | null) => { wallet.value.receiverId = receiverId } const setViewKey = (viewKey: string | null) => { wallet.value.viewKey = viewKey } const setAddress = (address: string | null) => { wallet.value.address = address } const setNetwork = (network: 'mainnet' | 'testnet') => { wallet.value.network = network } const setBalance = (balance: string | null) => { wallet.value.balance = balance } const setUtxos = (utxos: any[]) => { wallet.value.utxos = utxos } const setLoading = (loading: boolean) => { isLoading.value = loading } const setError = (err: string | null) => { error.value = err } const setWallet = (walletData: Partial) => { wallet.value = { ...wallet.value, ...walletData } } const clearWallet = () => { wallet.value = { seedPhrase: null, receiverId: null, viewKey: null, address: null, network: 'testnet', balance: null, utxos: [], } error.value = null } // ===== GETTERS ===== const getWallet = computed(() => wallet.value) const getSeedPhrase = computed(() => wallet.value.seedPhrase) const getReceiverId = computed(() => wallet.value.receiverId) const getViewKey = computed(() => wallet.value.viewKey) const getAddress = computed(() => wallet.value.address) const getNetwork = computed(() => wallet.value.network) const getBalance = computed(() => wallet.value.balance) const getUtxos = computed(() => wallet.value.utxos) const hasWallet = computed(() => wallet.value.address !== null) const getLoading = computed(() => isLoading.value) const getError = computed(() => error.value) return { getWallet, getSeedPhrase, getReceiverId, getViewKey, getAddress, getNetwork, getBalance, getUtxos, hasWallet, getLoading, getError, setSeedPhrase, setReceiverId, setViewKey, setAddress, setNetwork, setBalance, setUtxos, setLoading, setError, setWallet, clearWallet, } })