Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for issue 103 and 132 #136

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Angor/Client/Pages/Create.razor
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<div class="mb-3">
<label class="form-label">The amount in % to allocate for stage @(project.ProjectInfo.Stages.IndexOf(stage) + 1)</label>
<div class="input-group">
<InputNumber @bind-Value="stage.AmountToRelease" class="form-control" placeholder="Enter amount to release as a percentage" min="1" max="100" step="1" />
<InputNumber @bind-Value="stage.AmountToRelease" class="form-control" placeholder="Enter amount to release as a percentage" min="0.01" max="100" step="0.01" />
dangershony marked this conversation as resolved.
Show resolved Hide resolved
<InputDate @bind-Value="stage.ReleaseDate" class="form-control" />
<button type="button" class="btn btn-danger" @onclick="() => RemoveStage(stage)">Remove</button>
</div>
Expand Down
91 changes: 46 additions & 45 deletions src/Angor/Client/Pages/Founder.razor
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,38 @@

@if (founderProjects.Count == 0)
{
<div class="row mt-4">
<div class="card card-body angor-alert-info pt-2 pb-2">
<div class="d-flex align-items-center align-items-center">
<div class="row mt-4">
dangershony marked this conversation as resolved.
Show resolved Hide resolved
<div class="card card-body angor-alert-info pt-2 pb-2">
<div class="d-flex align-items-center align-items-center">
<span class="me-3 user-select-none">
<Icon IconName="info" Width="40" Height="40" Color="var(--bs-primary-btn-icon)" />
</span>
<span class="text-white">No projects found.</span>
</div>
</div>
</div>
<div class="row">
<div class="col">

<div class="d-flex justify-content-center mt-4">
<button class="btn btn-border my-3" @onclick="LookupProjectKeysOnIndexerAsync">
<i class="@(scanningForProjects ? "rotate-icon" : "")">
<Icon IconName="refresh"></Icon>
</i>
<span class="nav-link-text ms-1">Scan for founder projects</span>
</button>
</div>

<span class="text-white">No projects found.</span>
</div>
</div>
</div>
}
else
@if (founderProjects.Count > 0)
{
<div class="row row-cols-1 row-cols-sm-1 row-cols-md-2 row-cols-lg-3 project-wrapper" data-cy="project-grid">
@foreach (var project in founderProjects)
{
<FounderProjectItem FounderProject="@project"></FounderProjectItem>
}
</div>

<div class="row row-cols-1 row-cols-sm-1 row-cols-md-2 row-cols-lg-3 project-wrapper" data-cy="project-grid">
@foreach (var project in founderProjects)
{
<FounderProjectItem FounderProject="@project"></FounderProjectItem>
}
</div>
}
<div class="row">
<div class="col">
<div class="d-flex justify-content-center mt-4">
<button class="btn btn-border my-3" @onclick="LookupProjectKeysOnIndexerAsync">
<i class="@(scanningForProjects ? "rotate-icon" : "")">
<Icon IconName="refresh"></Icon>
</i>
<span class="nav-link-text ms-1">@((founderProjects.Count == 0) ? "Scan for founder projects" : "Rescan founder projects")</span>
</button>
</div>
</div>
</div>

@code {
private string founderKey;
Expand Down Expand Up @@ -105,15 +102,16 @@ else
{
scanningForProjects = true;

// Clear the existing projects before rescan
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we clear the data we already have?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree I will remove this lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dangershony @DavidGershony I added this because of the rescan feature,
now if you rescan there are duplicates.

maybe theres a better solution instead of deleting, to just add the ones that are different (we will also need to add logic for the same project being changed on another client)

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on your answer, i'll open a PR with the according fix

founderProjects.Clear();
storage.ClearFounderProjects();

var keys = _walletStorage.GetFounderKeys();

var founderProjectsToLookup = new Dictionary<string, ProjectIndexerData>();

foreach (var key in keys.Keys)
{
if (founderProjects.Exists(_ => _.ProjectInfo.ProjectIdentifier == key.ProjectIdentifier))
continue;

var indexerProject = await _IndexerService.GetProjectByIdAsync(key.ProjectIdentifier);

if (indexerProject == null)
Expand All @@ -123,6 +121,7 @@ else
}

if (founderProjectsToLookup.Any())
{
RelayService.RequestProjectCreateEventsByPubKey(e =>
{
switch (e)
Expand All @@ -132,30 +131,32 @@ else
var founderProject = founderProjects.FirstOrDefault(_ => _.ProjectInfo.NostrPubKey == e.Pubkey);
if (founderProject != null && founderProject.Metadata is null)
founderProject.Metadata = nostrMetadata;
// else
// notificationComponent.ShowNotificationMessage($"Couldn't find the project details for the project {nostrMetadata.Name} try adding the missing relay."); //TODO
break;

case { Kind: NostrKind.ApplicationSpecificData }:
var projectInfo = serializer.Deserialize<ProjectInfo>(e.Content);
if (founderProjects.All(_ => _.ProjectInfo.NostrPubKey != e.Pubkey)) //Getting events from multiple relays
if (founderProjects.All(_ => _.ProjectInfo.NostrPubKey != e.Pubkey))
founderProjects.Add(new FounderProject
{
ProjectInfo = projectInfo,
ProjectIndex = founderProjectsToLookup.Keys.ToList().IndexOf(e.Pubkey) + 1,
CreationTransactionId = founderProjectsToLookup[e.Pubkey].TrxId
});
{
ProjectInfo = projectInfo,
ProjectIndex = founderProjectsToLookup.Keys.ToList().IndexOf(e.Pubkey) + 1,
CreationTransactionId = founderProjectsToLookup[e.Pubkey].TrxId
});
break;
}
},
() =>
{
scanningForProjects = false;
storage.AddFounderProject(founderProjects.ToArray());
StateHasChanged();
},
founderProjectsToLookup.Keys.ToArray());
() =>
{
scanningForProjects = false;
storage.AddFounderProject(founderProjects.ToArray());
StateHasChanged();
},
founderProjectsToLookup.Keys.ToArray());
}
else
{
scanningForProjects = false;
}
}

private void NavigateToCreateProject()
Expand Down
20 changes: 18 additions & 2 deletions src/Angor/Client/Pages/Invest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,24 @@

<NotificationComponent @ref="notificationComponent" />
<PasswordComponent @ref="passwordComponent" />

@if(project is not InvestorProject investorProject)
@if (@project.ProjectInfo.StartDate < DateTime.UtcNow) //TODO: what should the order be here? if an investor has a signed trx that he has not invested yet, and the project has started, could he invest?
{
<div class="alert alert-warning">
<h4>Investing Period is Over</h4>
<p>The investing period for this project ended on @project.ProjectInfo.ExpiryDate.ToString("dd/MM/yyyy").</p>
<p>You can no longer invest in this project.</p>
<p>Here are some details:</p>
<ul>
<li><strong>Project ID:</strong> @project.ProjectInfo.ProjectIdentifier</li>
<li><strong>Target Amount:</strong> @project.ProjectInfo.TargetAmount BTC</li>
<li><strong>Start Date:</strong> @project.ProjectInfo.StartDate.ToString("dd/MM/yyyy")</li>
<li><strong>End Date:</strong> @project.ProjectInfo.ExpiryDate.ToString("dd/MM/yyyy")</li>
<li><strong>Total Stages:</strong> @project.ProjectInfo.Stages.Count</li>
</ul>
<p>If you are already invested, you will continue to receive updates on the project's progress.</p>
</div>
}
else if(project is not InvestorProject investorProject)
{
<div class="card">
<div class="card-body">
Expand Down
30 changes: 26 additions & 4 deletions src/Angor/Client/Pages/View.razor
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<div class="col-12 col-md-12 col-lg-4 order-1 order-md-1 d-flex justify-content-center align-items-center mt-4">
<div class="w-100">
@{
int startsInDays = (project.ProjectInfo.StartDate - DateTime.Now).Days;
int startsInDays = (project.ProjectInfo.StartDate - DateTime.UtcNow).Days;

if (startsInDays > 0)
{
Expand Down Expand Up @@ -165,7 +165,16 @@
@* <p class="card-text mb-0">Total Seeders: @projectStats.TotalSeeders</p>*@
<div class="form-control mt-1 d-flex align-items-center">
<Icon IconName="calendar"></Icon>
<p class="card-text ms-2">Time Left for Investing: @projectStats.TimeLeft days</p>
<p class="card-text ms-2">
@if (projectStats.TimeLeft > 0)
{
<span>Time Left for Investing: @projectStats.TimeLeft days</span>
}
else
{
<span>The investing period is over</span>
}
</p>
</div>
}
</div>
Expand Down Expand Up @@ -284,8 +293,21 @@
<p class="mt-4">
Seize the opportunity to invest in this project.
</p>
<button class="btn btn-secondary mb-3" data-cy="INVEST_BUTTON" @onclick="InvestInProject">Invest Now</button>
<button class="btn btn-secondary mb-3" data-cy="INVEST_BUTTON"
@onclick="InvestInProject"
disabled="@(projectStats.TimeLeft == 0 ? "disabled" : null)"
title="@(projectStats.TimeLeft == 0 ? "The investing period is over" : null)">
@if (projectStats.TimeLeft > 0)
{
<text>Invest Now</text>
}
else
{
<text>The investing period is over</text>
}
</button>
</div>

}
</div>

Expand Down Expand Up @@ -510,7 +532,7 @@
projectStats.TotalInvestors = (int)data.InvestorCount;
projectStats.TotalRaised = data.AmountInvested;

projectStats.TimeLeft = (project.ProjectInfo.ExpiryDate - DateTime.UtcNow).Days;
projectStats.TimeLeft = (project.ProjectInfo.StartDate - DateTime.UtcNow).Days;
if (projectStats.TimeLeft < 0)
projectStats.TimeLeft = 0;

Expand Down
5 changes: 5 additions & 0 deletions src/Angor/Client/Storage/ClientStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public void AddFounderProject(params FounderProject[] projects)

_storage.SetItem("founder-projects", ret.OrderBy(_ => _.ProjectIndex));
}

public void ClearFounderProjects()
dangershony marked this conversation as resolved.
Show resolved Hide resolved
{
_storage.SetItem("founder-projects", new List<FounderProject>());
}

public List<FounderProject> GetFounderProjects()
{
Expand Down
1 change: 1 addition & 0 deletions src/Angor/Client/Storage/IClientStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IClientStorage


void AddFounderProject(params FounderProject[] projects);
void ClearFounderProjects();
List<FounderProject> GetFounderProjects();
FounderProject? GetFounderProjects(string projectIdentifier);
void UpdateFounderProject(FounderProject project);
Expand Down
Loading