mirror of
https://github.com/zapstore/zapstore.git
synced 2026-10-05 20:48:24 +00:00
Fix zappers list
This commit is contained in:
@@ -226,8 +226,6 @@ class _UserZapsList extends HookConsumerWidget {
|
||||
query<Zap>(
|
||||
tags: allAppTags,
|
||||
source: const LocalAndRemoteSource(relays: 'social'),
|
||||
and: (zap) => {zap.zapRequest},
|
||||
andSource: const LocalAndRemoteSource(relays: 'social', stream: false),
|
||||
subscriptionPrefix: 'user-app-zaps',
|
||||
),
|
||||
);
|
||||
@@ -237,8 +235,6 @@ class _UserZapsList extends HookConsumerWidget {
|
||||
query<Zap>(
|
||||
tags: {'#e': metadataIds},
|
||||
source: const LocalAndRemoteSource(relays: 'social'),
|
||||
and: (zap) => {zap.zapRequest},
|
||||
andSource: const LocalAndRemoteSource(relays: 'social', stream: false),
|
||||
subscriptionPrefix: 'user-metadata-zaps',
|
||||
),
|
||||
);
|
||||
@@ -250,13 +246,13 @@ class _UserZapsList extends HookConsumerWidget {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
// Collect pubkeys from zaps and zapRequests for profile query
|
||||
// Collect zapper pubkeys from metadata (already extracted from description tag)
|
||||
final zapperPubkeys = <String>{};
|
||||
for (final zap in allZaps) {
|
||||
zapperPubkeys.add(zap.event.pubkey);
|
||||
final zapRequest = zap.zapRequest.value;
|
||||
if (zapRequest != null) {
|
||||
zapperPubkeys.add(zapRequest.event.pubkey);
|
||||
// The zapper's pubkey is in event.metadata['author'], extracted from description
|
||||
final zapperPubkey = zap.event.metadata['author'] as String?;
|
||||
if (zapperPubkey != null) {
|
||||
zapperPubkeys.add(zapperPubkey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -296,34 +296,61 @@ class _ZappersListSectionWithMetadata extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// Query zaps on app (via #a tag)
|
||||
final zapsState = ref.watch(
|
||||
query<Zap>(
|
||||
tags: app.event.addressableIdTagMap,
|
||||
source: LocalAndRemoteSource(relays: 'social'),
|
||||
and: (zap) => {zap.author},
|
||||
andSource: LocalAndRemoteSource(relays: 'social', stream: false),
|
||||
source: const LocalAndRemoteSource(relays: 'social'),
|
||||
subscriptionPrefix: 'app-zaps',
|
||||
),
|
||||
);
|
||||
|
||||
// Query zaps on metadata (via #e tag)
|
||||
final zapsOnMetadataState = ref.watch(
|
||||
query<Zap>(
|
||||
tags: {
|
||||
'#e': {metadataId},
|
||||
},
|
||||
and: (zap) => {zap.author},
|
||||
source: LocalAndRemoteSource(relays: 'social'),
|
||||
andSource: LocalAndRemoteSource(relays: 'social', stream: false),
|
||||
source: const LocalAndRemoteSource(relays: 'social'),
|
||||
subscriptionPrefix: 'metadata-zaps',
|
||||
),
|
||||
);
|
||||
|
||||
final zaps = {...zapsState.models, ...zapsOnMetadataState.models};
|
||||
if (zaps.isEmpty) return const SizedBox.shrink();
|
||||
// Combine zaps from both queries
|
||||
final allZaps = {...zapsState.models, ...zapsOnMetadataState.models};
|
||||
|
||||
if (allZaps.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
// Collect zapper pubkeys from metadata (already extracted from description tag)
|
||||
final zapperPubkeys = <String>{};
|
||||
for (final zap in allZaps) {
|
||||
// The zapper's pubkey is in event.metadata['author'], extracted from description
|
||||
final zapperPubkey = zap.event.metadata['author'] as String?;
|
||||
if (zapperPubkey != null) {
|
||||
zapperPubkeys.add(zapperPubkey);
|
||||
}
|
||||
}
|
||||
|
||||
// Query profiles separately with cachedFor
|
||||
final profilesState = ref.watch(
|
||||
query<Profile>(
|
||||
authors: zapperPubkeys,
|
||||
source: const LocalAndRemoteSource(
|
||||
relays: {'social', 'vertex'},
|
||||
cachedFor: Duration(hours: 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
final profilesMap = {
|
||||
for (final p in profilesState.models) p.pubkey: p,
|
||||
};
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: ZappersHorizontalList(zaps: zaps.toList()),
|
||||
child: ZappersHorizontalList(
|
||||
zaps: allZaps.toList(),
|
||||
profilesMap: profilesMap,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,22 +229,12 @@ class _SkeletonStackCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: List.generate(
|
||||
3,
|
||||
(index) => Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.darkSkeletonBase,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
AspectRatio(
|
||||
aspectRatio: 4,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.darkSkeletonBase,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -90,31 +90,28 @@ class ZappersHorizontalList extends StatelessWidget {
|
||||
final theme = Theme.of(context);
|
||||
final color = theme.textTheme.bodySmall?.color?.withValues(alpha: 0.8);
|
||||
|
||||
// Group sats per zapper (prefer zapRequest author over wallet author)
|
||||
// Group sats per zapper using metadata['author'] (extracted from description tag)
|
||||
final Map<String, int> satsPerPubkey = <String, int>{};
|
||||
final Map<String, Profile> profileByPubkey = <String, Profile>{};
|
||||
|
||||
for (final zap in zaps) {
|
||||
// Get pubkeys - prefer zapRequest author over wallet author
|
||||
final requestPubkey = zap.zapRequest.value?.event.pubkey;
|
||||
final walletPubkey = zap.event.pubkey;
|
||||
final chosenPubkey = requestPubkey ?? walletPubkey;
|
||||
// The zapper's pubkey is in event.metadata['author'], extracted from description
|
||||
final zapperPubkey = zap.event.metadata['author'] as String?;
|
||||
if (zapperPubkey == null) continue;
|
||||
|
||||
// Get profile from provided map or fall back to relationship
|
||||
// Get profile from provided map or fall back to author relationship
|
||||
Profile? chosenProfile;
|
||||
if (profilesMap != null) {
|
||||
chosenProfile = profilesMap![chosenPubkey];
|
||||
chosenProfile = profilesMap![zapperPubkey];
|
||||
} else {
|
||||
// Legacy: try to get from relationship
|
||||
final requestAuthor = zap.zapRequest.value?.author.value;
|
||||
final walletAuthor = zap.author.value;
|
||||
chosenProfile = requestAuthor ?? walletAuthor;
|
||||
// Legacy: try to get from author relationship (which now points to zapper)
|
||||
chosenProfile = zap.author.value;
|
||||
}
|
||||
|
||||
satsPerPubkey[chosenPubkey] =
|
||||
(satsPerPubkey[chosenPubkey] ?? 0) + zap.amount;
|
||||
satsPerPubkey[zapperPubkey] =
|
||||
(satsPerPubkey[zapperPubkey] ?? 0) + zap.amount;
|
||||
if (chosenProfile != null) {
|
||||
profileByPubkey[chosenPubkey] = chosenProfile;
|
||||
profileByPubkey[zapperPubkey] = chosenProfile;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user