From e504b1f7e21dd1291dc2d25c541e2a89510ca869 Mon Sep 17 00:00:00 2001 From: padreug Date: Fri, 5 Sep 2025 04:02:22 +0200 Subject: [PATCH] Enhance market module with authentication service integration - Inject AuthService into useMarket for improved user authentication checks. - Add error handling for missing AuthService and RelayHub to ensure proper module installation. - Update comments to clarify the use of pubkey from either nostrStore or AuthService, indicating a need for confirmation on the preferred source. - Refactor NostrmarketService to utilize injected RelayHub, improving error handling and code clarity. --- src/modules/market/composables/useMarket.ts | 7 +++++++ src/modules/market/services/nostrmarketService.ts | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modules/market/composables/useMarket.ts b/src/modules/market/composables/useMarket.ts index 776aca8..78a10d7 100644 --- a/src/modules/market/composables/useMarket.ts +++ b/src/modules/market/composables/useMarket.ts @@ -16,11 +16,16 @@ export function useMarket() { const nostrStore = useNostrStore() const marketStore = useMarketStore() const relayHub = injectService(SERVICE_TOKENS.RELAY_HUB) as any + const authService = injectService(SERVICE_TOKENS.AUTH_SERVICE) as any if (!relayHub) { throw new Error('RelayHub not available. Make sure base module is installed.') } + if (!authService) { + throw new Error('AuthService not available. Make sure base module is installed.') + } + // State const isLoading = ref(false) const error = ref(null) @@ -48,6 +53,7 @@ export function useMarket() { // Load market from naddr // Parse naddr to get market data + // TODO: Confirm if this should use nostrStore.account?.pubkey or authService.user.value?.pubkey const marketData = { identifier: naddr.split(':')[2] || 'default', pubkey: naddr.split(':')[1] || nostrStore.account?.pubkey || '' @@ -469,6 +475,7 @@ export function useMarket() { // Load market data console.log('🛒 Loading basic market data...') + // TODO: Confirm if this should use nostrStore.account?.pubkey or authService.user.value?.pubkey await loadMarketData({ identifier: 'default', pubkey: nostrStore.account?.pubkey || '' diff --git a/src/modules/market/services/nostrmarketService.ts b/src/modules/market/services/nostrmarketService.ts index 51a6a8a..0c74a67 100644 --- a/src/modules/market/services/nostrmarketService.ts +++ b/src/modules/market/services/nostrmarketService.ts @@ -1,5 +1,5 @@ import { finalizeEvent, type EventTemplate, nip04 } from 'nostr-tools' -import { relayHub } from '@/lib/nostr/relayHub' +import { injectService, SERVICE_TOKENS } from '@/core/di-container' import { auth } from '@/composables/useAuth' import type { Stall, Product, Order } from '@/stores/market' @@ -68,6 +68,14 @@ export interface NostrmarketOrderStatus { } export class NostrmarketService { + private get relayHub() { + const hub = injectService(SERVICE_TOKENS.RELAY_HUB) + if (!hub) { + throw new Error('RelayHub not available. Make sure base module is installed.') + } + return hub + } + /** * Convert hex string to Uint8Array (browser-compatible) */ @@ -150,7 +158,7 @@ export class NostrmarketService { const prvkeyBytes = this.hexToUint8Array(prvkey) const event = finalizeEvent(eventTemplate, prvkeyBytes) - const result = await relayHub.publishEvent(event) + const result = await this.relayHub.publishEvent(event) console.log('Stall published to nostrmarket:', { stallId: stall.id, @@ -193,7 +201,7 @@ export class NostrmarketService { const prvkeyBytes = this.hexToUint8Array(prvkey) const event = finalizeEvent(eventTemplate, prvkeyBytes) - const result = await relayHub.publishEvent(event) + const result = await this.relayHub.publishEvent(event) console.log('Product published to nostrmarket:', { productId: product.id,