refactor: Simplify useMarket composable by removing unused client references and improving parameter naming
- Eliminate unnecessary Nostr client retrieval in publishProduct and publishStall functions. - Update parameter names in event processing functions for clarity, using underscores for unused parameters. - Clean up imports in useMarket.ts to streamline the codebase.
This commit is contained in:
parent
1fcc3706be
commit
8643eecfe7
3 changed files with 7 additions and 33 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { ref, computed, readonly } from 'vue'
|
import { ref, readonly } from 'vue'
|
||||||
import { useNostrStore } from '@/stores/nostr'
|
import { useNostrStore } from '@/stores/nostr'
|
||||||
import { useMarketStore, type Market, type Stall, type Product } from '@/stores/market'
|
import { useMarketStore, type Market, type Stall, type Product } from '@/stores/market'
|
||||||
import { config } from '@/lib/config'
|
import { config } from '@/lib/config'
|
||||||
|
|
@ -54,8 +54,6 @@ export function useMarket() {
|
||||||
const loadMarketData = async (marketData: any) => {
|
const loadMarketData = async (marketData: any) => {
|
||||||
try {
|
try {
|
||||||
console.log('Starting loadMarketData...')
|
console.log('Starting loadMarketData...')
|
||||||
// Get Nostr client
|
|
||||||
const client = nostrStore.getClient()
|
|
||||||
console.log('Got Nostr client')
|
console.log('Got Nostr client')
|
||||||
|
|
||||||
// Load market configuration
|
// Load market configuration
|
||||||
|
|
@ -193,7 +191,7 @@ export function useMarket() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Process each stall group, keeping only the most recent version
|
// Process each stall group, keeping only the most recent version
|
||||||
stallGroups.forEach((stallEvents, stallId) => {
|
stallGroups.forEach((stallEvents, _stallId) => {
|
||||||
// Sort by created_at timestamp (most recent first)
|
// Sort by created_at timestamp (most recent first)
|
||||||
stallEvents.sort((a, b) => b.event.created_at - a.event.created_at)
|
stallEvents.sort((a, b) => b.event.created_at - a.event.created_at)
|
||||||
|
|
||||||
|
|
@ -263,7 +261,7 @@ export function useMarket() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Process each product group, keeping only the most recent version
|
// Process each product group, keeping only the most recent version
|
||||||
productGroups.forEach((productEvents, productId) => {
|
productGroups.forEach((productEvents, _productId) => {
|
||||||
// Sort by created_at timestamp (most recent first)
|
// Sort by created_at timestamp (most recent first)
|
||||||
productEvents.sort((a, b) => b.event.created_at - a.event.created_at)
|
productEvents.sort((a, b) => b.event.created_at - a.event.created_at)
|
||||||
|
|
||||||
|
|
@ -476,20 +474,8 @@ export function useMarket() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const publishProduct = async (productData: any) => {
|
const publishProduct = async (_productData: any) => {
|
||||||
try {
|
try {
|
||||||
const client = nostrStore.getClient()
|
|
||||||
|
|
||||||
// Create unsigned event
|
|
||||||
const unsignedEvent = {
|
|
||||||
kind: MARKET_EVENT_KINDS.PRODUCT,
|
|
||||||
content: JSON.stringify(productData),
|
|
||||||
tags: [
|
|
||||||
['d', productData.id],
|
|
||||||
['t', 'product']
|
|
||||||
],
|
|
||||||
created_at: Math.floor(Date.now() / 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: This would need to be signed with the user's private key
|
// Note: This would need to be signed with the user's private key
|
||||||
// For now, we'll just log that this function needs to be implemented
|
// For now, we'll just log that this function needs to be implemented
|
||||||
|
|
@ -501,20 +487,8 @@ export function useMarket() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const publishStall = async (stallData: any) => {
|
const publishStall = async (_stallData: any) => {
|
||||||
try {
|
try {
|
||||||
const client = nostrStore.getClient()
|
|
||||||
|
|
||||||
// Create unsigned event
|
|
||||||
const unsignedEvent = {
|
|
||||||
kind: MARKET_EVENT_KINDS.STALL,
|
|
||||||
content: JSON.stringify(stallData),
|
|
||||||
tags: [
|
|
||||||
['d', stallData.id],
|
|
||||||
['t', 'stall']
|
|
||||||
],
|
|
||||||
created_at: Math.floor(Date.now() / 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: This would need to be signed with the user's private key
|
// Note: This would need to be signed with the user's private key
|
||||||
// For now, we'll just log that this function needs to be implemented
|
// For now, we'll just log that this function needs to be implemented
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,7 @@ export class NostrClient {
|
||||||
since?: number
|
since?: number
|
||||||
until?: number
|
until?: number
|
||||||
'#d'?: string[]
|
'#d'?: string[]
|
||||||
} = {}): Promise<Event[]> {
|
}): Promise<Event[]> {
|
||||||
const {
|
const {
|
||||||
kinds,
|
kinds,
|
||||||
authors,
|
authors,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref, computed, readonly } from 'vue'
|
import { ref, computed, readonly } from 'vue'
|
||||||
import { config } from '@/lib/config'
|
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
export interface Market {
|
export interface Market {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue