neptune-web-wallet/src/stores/neptuneStore.ts

125 lines
3.3 KiB
TypeScript
Raw Normal View History

2025-10-24 22:49:46 +07:00
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import type { WalletState } from '@/interface'
export const useNeptuneStore = defineStore('neptune', () => {
// ===== STATE =====
const wallet = ref<WalletState>({
seedPhrase: null,
password: null,
2025-10-24 22:49:46 +07:00
receiverId: null,
viewKey: null,
address: null,
network: 'testnet',
balance: null,
utxos: [],
})
const isLoading = ref(false)
const error = ref<string | null>(null)
// ===== SETTERS =====
const setSeedPhrase = (seedPhrase: string[] | null) => {
wallet.value.seedPhrase = seedPhrase
}
const setPassword = (password: string | null) => {
wallet.value.password = password
}
2025-10-24 22:49:46 +07:00
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<WalletState>) => {
wallet.value = { ...wallet.value, ...walletData }
}
const clearWallet = () => {
wallet.value = {
seedPhrase: null,
password: null,
2025-10-24 22:49:46 +07:00
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 getSeedPhraseString = computed(() => wallet.value.seedPhrase?.join(' ') || '')
const getPassword = computed(() => wallet.value.password)
2025-10-24 22:49:46 +07:00
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,
getSeedPhraseString,
getPassword,
2025-10-24 22:49:46 +07:00
getReceiverId,
getViewKey,
getAddress,
getNetwork,
getBalance,
getUtxos,
hasWallet,
getLoading,
getError,
setSeedPhrase,
setPassword,
2025-10-24 22:49:46 +07:00
setReceiverId,
setViewKey,
setAddress,
setNetwork,
setBalance,
setUtxos,
setLoading,
setError,
setWallet,
clearWallet,
}
})