feat(market): fix publish-duplicates, add offer detail page + filters

The vecino/market view had three gaps:

- Publishing inventory duplicated the listing. discover() appended every
  offer the relay streamed, but relays legitimately resend an addressable
  NIP-99 event (stored copy + live echo on publish). Merge by
  (authorPubkeyHex, id) so each offer appears once; two authors reusing a
  lot id stay distinct.
- No product detail. Tapping a card jumped straight to chat. Add a
  read-only "product page" (MarketOfferDetailScreen) with title, mode,
  category, eco badge, coarse location, price, a "Shared by" seller
  section (profile fetched by pubkey) and the message button. Reached via
  a new /market/offer route; cards are now fully tappable. Shows only what
  the network already carries — no photos/description added to the wire.
- No filters. Add a filter bar (type, category, eco) mirroring inventory,
  each chip group shown only when a discovered offer can match it. To make
  the eco filter real, publish the organic flag on the wire: Offer.isOrganic
  -> NIP-99 'organic' tag -> OfferMapper -> ShareableLot.

Tests: commons_core organic round-trip; app-side dedup, two-author
separation, filter logic, mapper passthrough; detail-screen widget tests.
i18n keys added to en/es/pt/ast and slang regenerated.
This commit is contained in:
vjrj 2026-07-10 19:10:40 +02:00
parent e852b569ce
commit 54d7c2d3b5
21 changed files with 982 additions and 107 deletions

View file

@ -0,0 +1,73 @@
import 'package:commons_core/commons_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/i18n/strings.g.dart';
import 'package:tane/services/social_service.dart';
import 'package:tane/services/social_settings.dart';
import 'package:tane/ui/market_offer_detail_screen.dart';
import '../support/test_support.dart';
Widget _wrap(MarketOfferDetailScreen screen) {
LocaleSettings.setLocaleSync(AppLocale.en);
return TranslationProvider(
child: MaterialApp(
locale: AppLocale.en.flutterLocale,
supportedLocales: AppLocaleUtils.supportedLocales,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: screen,
),
);
}
Offer _offer({bool organic = false}) => Offer(
id: 'lot-1',
authorPubkeyHex: 'ab' * 32,
summary: 'Tomate rosa de Barbastro',
type: OfferType.gift,
category: 'Solanaceae',
approxGeohash: 'sp3e9',
isOrganic: organic,
);
void main() {
testWidgets('renders the offer and a message button for a stranger',
(tester) async {
final social = await SocialService.fromRootSeedHex('00' * 32);
final settings = SocialSettings(InMemorySecretStore());
await settings.setRelayUrls(const []); // offline: no network in the test
await tester.pumpWidget(_wrap(MarketOfferDetailScreen(
offer: _offer(organic: true),
social: social,
settings: settings,
)));
await tester.pumpAndSettle();
expect(find.text('Tomate rosa de Barbastro'), findsWidgets);
expect(find.text('Solanaceae'), findsOneWidget);
expect(find.text('Organic'), findsOneWidget); // eco badge
expect(find.byKey(const Key('offerDetail.contact')), findsOneWidget);
});
testWidgets('hides the message button on my own listing', (tester) async {
final social = await SocialService.fromRootSeedHex('00' * 32);
final settings = SocialSettings(InMemorySecretStore());
await settings.setRelayUrls(const []);
await tester.pumpWidget(_wrap(MarketOfferDetailScreen(
offer: _offer(),
social: social,
settings: settings,
mine: true,
)));
await tester.pumpAndSettle();
expect(find.byKey(const Key('offerDetail.contact')), findsNothing);
});
}