diff --git a/src/Angor/Client/Pages/Founder.razor b/src/Angor/Client/Pages/Founder.razor index 1ccbc398..fb2b9fde 100644 --- a/src/Angor/Client/Pages/Founder.razor +++ b/src/Angor/Client/Pages/Founder.razor @@ -121,10 +121,8 @@ var indexerProject = await _IndexerService.GetProjectByIdAsync(key.ProjectIdentifier); - if (indexerProject != null) - { + if (indexerProject != null) //TODO we need to talk about supporting projects that are created with gaps founderProjectsToLookup.Add(key.NostrPubKey, indexerProject); - } } if (!founderProjectsToLookup.Any()) @@ -144,42 +142,37 @@ if (existingProject != null) { - if (existingProject.Metadata is null) - existingProject.Metadata = nostrMetadata; + existingProject.Metadata ??= nostrMetadata; } else { - founderProjects.Add(new FounderProject - { - Metadata = nostrMetadata, - ProjectInfo = new ProjectInfo { NostrPubKey = e.Pubkey } - }); + var founderProject = CreateFounderProject(founderProjectsToLookup, e); + founderProject.Metadata = nostrMetadata; + founderProjects.Add(founderProject); } break; case { Kind: NostrKind.ApplicationSpecificData }: + + if (e.Id != founderProjectsToLookup[e.Pubkey].NostrEventId) + return; + var projectInfo = serializer.Deserialize(e.Content); var project = founderProjects.FirstOrDefault(_ => _.ProjectInfo.NostrPubKey == e.Pubkey); if (project != null) { + if (!string.IsNullOrEmpty(project.ProjectInfo.ProjectIdentifier)) + return; + project.ProjectInfo = projectInfo; } else { - var projectIndex = founderProjectsToLookup.Keys.ToList().IndexOf(e.Pubkey) + 1; - var trxId = founderProjectsToLookup[e.Pubkey].TrxId; - - founderProjects.Add(new FounderProject - { - ProjectInfo = projectInfo, - ProjectIndex = projectIndex, - CreationTransactionId = trxId, - NostrProfileCreated = true, - ProjectInfoEventId = e.Id // todo: david to verify this is correct - }); - } + project ??= CreateFounderProject(founderProjectsToLookup, e, projectInfo); + founderProjects.Add(project); + } break; } @@ -207,6 +200,23 @@ founderProjectsToLookup.Keys.ToArray()); } + private FounderProject CreateFounderProject(Dictionary founderProjectsToLookup, + NostrEvent e, ProjectInfo? projectInfo = null) + { + var keys = _walletStorage.GetFounderKeys(); + var projectIndex = keys.Keys.First(x => x.NostrPubKey == e.Pubkey).Index; //we throw if not found + var trxId = founderProjectsToLookup[e.Pubkey].TrxId; + + return new FounderProject + { + ProjectInfo = projectInfo ?? new ProjectInfo { NostrPubKey = e.Pubkey }, + ProjectIndex = projectIndex, + CreationTransactionId = trxId, + NostrProfileCreated = true, + ProjectInfoEventId = founderProjectsToLookup[e.Pubkey].NostrEventId + }; + } + private async Task NavigateToCreateProject() { // perform a rescan before creating a project (to update the keys)