Skip to content

Commit

Permalink
Changed the scanning to fix bug in project index and added validation…
Browse files Browse the repository at this point in the history
… of noster event id
  • Loading branch information
DavidGershony committed Dec 12, 2024
1 parent b795a04 commit 10dd648
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions src/Angor/Client/Pages/Founder.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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<ProjectInfo>(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;
}
Expand Down Expand Up @@ -207,6 +200,23 @@
founderProjectsToLookup.Keys.ToArray());
}

private FounderProject CreateFounderProject(Dictionary<string, ProjectIndexerData> 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)
Expand Down

0 comments on commit 10dd648

Please sign in to comment.