Enhance chat and market integration with message forwarding
- Make ChatService globally available for other modules, enabling market-related message handling. - Introduce a market message handler in ChatService to process market-related direct messages (DMs). - Update useMarket to register the market message handler with ChatService, streamlining order-related DM processing. - Refactor message handling logic to differentiate between market messages and regular chat messages, improving message management. - Enhance order update logging in nostrmarketService for better debugging and verification of order status.
This commit is contained in:
parent
db9b50240d
commit
4258ea87c4
5 changed files with 98 additions and 19 deletions
|
|
@ -28,6 +28,22 @@ export function useMarket() {
|
|||
throw new Error('AuthService not available. Make sure base module is installed.')
|
||||
}
|
||||
|
||||
// Register market DM handler with chat service (if available)
|
||||
const registerMarketMessageHandler = () => {
|
||||
try {
|
||||
// Try to get the chat service (it might not be available if chat module isn't loaded)
|
||||
const chatService = (globalThis as any).chatService
|
||||
if (chatService && chatService.setMarketMessageHandler) {
|
||||
chatService.setMarketMessageHandler(handleOrderDM)
|
||||
console.log('🛒 Registered market message handler with chat service')
|
||||
} else {
|
||||
console.log('🛒 Chat service not available, market will use its own DM subscription')
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('🛒 Could not register with chat service:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// State
|
||||
const isLoading = ref(false)
|
||||
const error = ref<Error | null>(null)
|
||||
|
|
@ -403,12 +419,14 @@ export function useMarket() {
|
|||
// Handle different types of messages
|
||||
switch (messageData.type) {
|
||||
case 1: // Payment request
|
||||
console.log('💰 Processing payment request')
|
||||
console.log('💰 Processing payment request for order:', messageData.id)
|
||||
await nostrmarketService.handlePaymentRequest(messageData)
|
||||
console.log('✅ Payment request processed successfully')
|
||||
break
|
||||
case 2: // Order status update
|
||||
console.log('📦 Processing order status update')
|
||||
console.log('📦 Processing order status update for order:', messageData.id)
|
||||
await nostrmarketService.handleOrderStatusUpdate(messageData)
|
||||
console.log('✅ Order status update processed successfully')
|
||||
break
|
||||
default:
|
||||
console.log('❓ Unknown message type:', messageData.type)
|
||||
|
|
@ -558,6 +576,9 @@ export function useMarket() {
|
|||
|
||||
console.log('🛒 Market connected successfully')
|
||||
|
||||
// Register market message handler with chat service
|
||||
registerMarketMessageHandler()
|
||||
|
||||
// Load market data
|
||||
console.log('🛒 Loading basic market data...')
|
||||
// TODO: Confirm if this should use nostrStore.account?.pubkey or authService.user.value?.pubkey
|
||||
|
|
@ -580,9 +601,8 @@ export function useMarket() {
|
|||
console.log('🛒 Subscribing to market updates...')
|
||||
subscribeToMarketUpdates()
|
||||
|
||||
// Subscribe to order-related DMs
|
||||
console.log('🛒 Subscribing to order updates...')
|
||||
subscribeToOrderUpdates()
|
||||
// Note: Order-related DMs are now handled by chat service forwarding
|
||||
// No need for separate subscription
|
||||
|
||||
} catch (err) {
|
||||
console.error('🛒 Failed to connect to market:', err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue