Skip to content

feat(merchants): add merchant discovery and location management#102

Open
ryzen-xp wants to merge 1 commit into
ericmt-98:mainfrom
ryzen-xp:P2P-merchant-discovery
Open

feat(merchants): add merchant discovery and location management#102
ryzen-xp wants to merge 1 commit into
ericmt-98:mainfrom
ryzen-xp:P2P-merchant-discovery

Conversation

@ryzen-xp
Copy link
Copy Markdown

What was implemented

Backend (micopay/backend)

src/routes/merchants.ts — added 3 new endpoints:

  • GET /merchants/available?lat&lng&radius_km&amount_mxn&flowpublic, returns merchants sorted by haversine distance, filtered by amount range and availability
  • PATCH /merchants/me/locationauthenticated, lets a merchant set their lat/lng/address
  • GET /merchants/me/tradesauthenticated, returns the merchant's trade history (was already called from frontend but missing from backend)

src/services/merchant.service.ts — added:

  • getAvailableMerchants() — haversine SQL query with LEAST(1.0, ...) guard to prevent acos domain errors, filters by merchant_available, location not null, amount within min/max, distance within radius
  • Updated getOrCreateMerchantConfig and updateMerchantConfig to include latitude, longitude, address_text fields

sql/migrations/002_merchant_discovery.sql — creates merchant_configs table (idempotent) and adds location columns with ALTER TABLE … ADD COLUMN IF NOT EXISTS

Frontend (micopay/frontend)

src/services/api.ts — added:

  • getMerchantsAvailable(query) — calls GET /merchants/available
  • updateMerchantLocation(token, lat, lng, address) — calls PATCH /merchants/me/location
  • AvailableMerchant and MerchantsAvailableQuery types

src/hooks/useMerchantsAvailable.ts — new hook that:

  • Requests geolocation (Capacitor-native + browser fallback)
  • Handles permission denied → location_denied state
  • Fetches from the real API
  • Returns typed MerchantsState union: idle | loading | location_denied | error | empty | success
  • Exposes refetch() for retry

src/pages/ExploreMap.tsx — fully rewritten:

  • Calls useMerchantsAvailable with flow: 'cashout'
  • DEFAULT_OFFERS array removed entirely
  • Loading skeleton, location-denied state, network error state, empty state, and success state all handled
  • onSelectOffer(offer.id) now passes the real seller_id UUID

src/pages/DepositMap.tsx — fully rewritten:

  • Calls useMerchantsAvailable with flow: 'deposit'
  • "Tienda Don Pepe" and "Usuario @ana_m" hardcoded cards removed
  • Same state machine as ExploreMap
  • onSelectOffer passes real seller_id

- Add public `/merchants/available` endpoint to find merchants near caller within radius and amount constraints
- Add authenticated `PATCH /merchants/me/location` endpoint for merchants to set/update their location and address
- Add authenticated `GET /merchants/me/trades` endpoint for merchants to view their trades with optional state filtering
- Add `useMerchantsAvailable` React hook for frontend merchant discovery queries
- Add `getAvailableMerchants` service function with Haversine distance calculation in SQL
- Extend `MerchantConfig` interface with latitude, longitude, and address_text fields
- Add `AvailableMerchant` and `AvailableMerchantsQuery` interfaces for type safety
- Create `002_merchant_discovery.sql` migration to add location columns to merchant_configs table
- Update DepositMap and ExploreMap pages to use merchant discovery API
- Update API service with merchant discovery endpoints
- Enables location-based merchant matching for cashout and deposit flows
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@ryzen-xp Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Real P2P merchant discovery — replace hardcoded offers

1 participant