diff --git a/src/Angor/Client/Pages/Create.razor b/src/Angor/Client/Pages/Create.razor
index 4a8f9450..07d9399d 100644
--- a/src/Angor/Client/Pages/Create.razor
+++ b/src/Angor/Client/Pages/Create.razor
@@ -30,6 +30,13 @@
return;
}
+@if (!isValid)
+{
+
@@ -570,6 +577,8 @@
private int totalDuration;
private int numberOfStages;
+ private bool isValid = true;
+ private string errorMessage;
bool createProfileSpinner;
bool createApplicationDataSpinner;
@@ -586,16 +595,21 @@
return;
}
- var projects = storage.GetFounderProjects() ?? new List();
+ var projects = storage.GetFounderProjects();
+
var keys = _walletStorage.GetFounderKeys();
- if (projects.Count(p => !string.IsNullOrEmpty(p.CreationTransactionId)) >= keys.Keys.Count)
+ // if CreationTransactionId is not null this means the project was published to the blockchain
+ var startedProjects = projects.Where(p => !string.IsNullOrEmpty(p.CreationTransactionId)).ToList();
+
+ if (startedProjects.Count >= keys.Keys.Count)
{
- notificationComponent.ShowErrorMessage("All founder keys have been used for this wallet!");
+ errorMessage = "All founder keys have been used for this wallet!";
+ isValid = false;
return;
}
- var latestProject = projects.Where(_ => !string.IsNullOrEmpty(_.CreationTransactionId)).MaxBy(p => p.ProjectIndex);
+ var latestProject = startedProjects.MaxBy(p => p.ProjectIndex);
var projectsKeys = _derivationOperations.GetProjectKey(keys, latestProject?.ProjectIndex + 1 ?? 1);
project = projects.FirstOrDefault(p => p.ProjectInfo.ProjectIdentifier == projectsKeys.ProjectIdentifier)
@@ -1226,8 +1240,4 @@
project.Metadata.Picture = spacePhotos[random.Next(spacePhotos.Length)];
}
}
-
-
-
-
-}
+}
\ No newline at end of file
diff --git a/src/Angor/Client/Pages/Invest.razor b/src/Angor/Client/Pages/Invest.razor
index 7ec81778..71e8973f 100644
--- a/src/Angor/Client/Pages/Invest.razor
+++ b/src/Angor/Client/Pages/Invest.razor
@@ -21,15 +21,15 @@
@inject IJSRuntime JS
@inject ILogger _Logger;
-@inject IDerivationOperations _derivationOperations
+@inject IDerivationOperations _derivationOperations;
@inject IClientStorage storage;
@inject ICacheStorage SessionStorage;
-@inject IWalletOperations _WalletOperations
+@inject IWalletOperations _WalletOperations;
+@inject IApplicationLogicService applicationLogicService;
+@inject ISignService _SignService;
+@inject IRelayService _RelayService;
-@inject ISignService _SignService
-@inject IRelayService _RelayService
-
-@inject IInvestorTransactionActions _InvestorTransactionActions
+@inject IInvestorTransactionActions _InvestorTransactionActions;
@inject ISerializer serializer
@inject IEncryptionService encryption
@@ -386,7 +386,7 @@ else
}
Project? findProject = storage.GetInvestmentProjects().FirstOrDefault(p => p.ProjectInfo.ProjectIdentifier == ProjectId);
-
+
if (findProject != null)
{
var investmentProject = findProject as InvestorProject;
@@ -413,6 +413,14 @@ else
}
}
}
+
+ if (!applicationLogicService.IsInvestmentWindowOpen(project?.ProjectInfo))
+ {
+ notificationComponent.ShowNotificationMessage("You cannot invest in this project.", 5);
+ NavigationManager.NavigateTo($"/view/{ProjectId}");
+ return;
+ }
+
await CheckIfSeederTimeHasPassed();
UpdateStagesBreakdown(new ChangeEventArgs { Value = Investment.InvestmentAmount });
diff --git a/src/Angor/Client/Pages/View.razor b/src/Angor/Client/Pages/View.razor
index edbf0098..6b090623 100644
--- a/src/Angor/Client/Pages/View.razor
+++ b/src/Angor/Client/Pages/View.razor
@@ -23,7 +23,7 @@
@inject IJSRuntime Js;
@inject ILogger Logger;
@inject IHtmlStripperService HtmlStripperService;
-
+@inject IApplicationLogicService applicationLogicService;
@inject NostrConversionHelper NostrHelper
@@ -305,25 +305,19 @@ else
Seize the opportunity to invest in this project.
@{
- var timeLeft = (project.ProjectInfo.StartDate - DateTime.UtcNow).Days;
-
- if (timeLeft <= 0 && network.NetworkType == NetworkType.Testnet)
- {
- // on testnet we will not disable the ability to invest at all
- timeLeft = 1;
- }
+ var canInvest = applicationLogicService.IsInvestmentWindowOpen(project?.ProjectInfo);
}
@@ -442,6 +436,7 @@ else
private bool isGeneratingNsec;
private string errorMessage = string.Empty;
+
private string error;
private List<(string Hash, int Amount)> SelectedSeeders = new List<(string hash, int amount)>
@@ -759,5 +754,5 @@ else
string sanitizedInput = HtmlStripperService.StripHtmlTags(input);
return new MarkupString(sanitizedInput);
}
+}
-}
\ No newline at end of file
diff --git a/src/Angor/Client/Program.cs b/src/Angor/Client/Program.cs
index b6d3fdb4..38ff06ce 100644
--- a/src/Angor/Client/Program.cs
+++ b/src/Angor/Client/Program.cs
@@ -53,6 +53,8 @@
builder.Services.AddTransient
();
builder.Services.AddTransient();
+builder.Services.AddScoped();
+
builder.Services.AddSingleton();
builder.Services.AddScoped();
builder.Services.AddSingleton();
diff --git a/src/Angor/Shared/Services/ApplicationLogicService.cs b/src/Angor/Shared/Services/ApplicationLogicService.cs
new file mode 100644
index 00000000..2ad12915
--- /dev/null
+++ b/src/Angor/Shared/Services/ApplicationLogicService.cs
@@ -0,0 +1,30 @@
+using System;
+using Angor.Shared.Models;
+using Blockcore.Networks;
+
+namespace Angor.Shared.Services
+{
+ public class ApplicationLogicService : IApplicationLogicService
+ {
+ private readonly INetworkConfiguration _networkConfiguration;
+
+ public ApplicationLogicService(INetworkConfiguration networkConfiguration)
+ {
+ _networkConfiguration = networkConfiguration;
+ }
+
+ public bool IsInvestmentWindowOpen(ProjectInfo? project)
+ {
+ if (project == null) return false;
+
+ // on testnet we always allow to invest for testing purposes.
+ if (_networkConfiguration.GetNetwork().NetworkType == NetworkType.Testnet) return true;
+
+ var now = DateTime.UtcNow;
+
+ if (now <= project.StartDate) return true;
+
+ return false;
+ }
+ }
+}
diff --git a/src/Angor/Shared/Services/IApplicationLogicService.cs b/src/Angor/Shared/Services/IApplicationLogicService.cs
new file mode 100644
index 00000000..f77c90f8
--- /dev/null
+++ b/src/Angor/Shared/Services/IApplicationLogicService.cs
@@ -0,0 +1,11 @@
+using Angor.Shared.Models;
+using Blockcore.Networks;
+
+namespace Angor.Shared.Services
+{
+ public interface IApplicationLogicService
+ {
+ bool IsInvestmentWindowOpen(ProjectInfo? project);
+ }
+}
+