8000 Handle project data loading exceptions by SuperJMN · Pull Request #400 · block-core/angor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Handle project data loading exceptions #400

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

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public async Task Get_latest_projects()
{
var sut = CreateSut();
var result = await sut.Latest();
Assert.NotEmpty(result);

Assert.True(result.IsSuccess);
Assert.NotEmpty(result.Value);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Angor.Contexts.Funding.Projects.Domain;
public interface IProjectRepository
{
Task<Result<Project>> Get(ProjectId id);
Task<IList<Project>> Latest();
Task<Result<IList<Project>>> Latest();

Task<Result<Maybe<Project>>> TryGet(ProjectId projectId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public class ProjectAppService(
: IProjectAppService
{
[MemoizeTimed]
public async Task<IList<ProjectDto>> Latest()
public async Task<Result<IEnumerable<ProjectDto>>> Latest()
{
var projects = await projectRepository.Latest();
var projectDtos = projects.Select(project => project.ToDto());
return projectDtos.ToList();
return await projectRepository.Latest().Map(t => t.AsEnumerable()).MapEach(project => project.ToDto());
}

public Task<Maybe<ProjectDto>> FindById(ProjectId projectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public Task<Result<Project>> Get(ProjectId id)
return TryGet(id).Bind(maybe => maybe.ToResult("Project not found"));
}

public Task<IList<Project>> Latest()
public Task<Result<IList<Project>>> Latest()
{
return ProjectsFrom(indexerService.GetLatest()).ToList().ToTask();
return Result.Try(() => ProjectsFrom(indexerService.GetLatest()).ToList().ToTask());
}

public Task<Result<Maybe<Project>>> TryGet(ProjectId projectId)
Expand Down
8000
Original file line numberDiff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Angor.Contexts.Funding.Projects.Infrastructure.Interfaces;

public interface IProjectAppService
{
Task<IList<ProjectDto>> Latest();
Task<Result<IEnumerable<ProjectDto>>> Latest();
Task<Maybe<ProjectDto>> FindById(ProjectId projectId);
Task<Result<IEnumerable<ProjectDto>>> GetFounderProjects(Guid walletId);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System.Linq;
using Angor.Contexts.Funding.Projects.Infrastructure.Interfaces;
using Angor.Contexts.Wallet.Application;
using AngorApp.Features.Invest;
using AngorApp.Sections.Browse.ProjectLookup;
using AngorApp.UI.Services;
using ReactiveUI.SourceGenerators;
using Zafiro.CSharpFunctionalExtensions;
using Zafiro.Mixins;
using Zafiro.Reactive;
using Zafiro.UI;
using Zafiro.UI.Navigation;

namespace AngorApp.Sections.Browse;
Expand All @@ -13,7 +17,7 @@ public partial class BrowseSectionViewModel : ReactiveObject, IBrowseSectionView
{
[Reactive] private string? projectId;

[ObservableAsProperty] private IList<IProjectViewModel>? projects;
[ObservableAsProperty] private IEnumerable<IProjectViewModel>? projects;

public BrowseSectionViewModel(IWalletAppService walletAppService,
IProjectAppService projectService, INavigator navigator,
Expand All @@ -23,14 +27,14 @@ public BrowseSectionViewModel(IWalletAppService walletAppService,
ProjectLookupViewModel = new ProjectLookupViewModel(projectService, walletAppService, navigator, investWizard, uiServices);

LoadLatestProjects = ReactiveCommand.CreateFromObservable(() => Observable.FromAsync(projectService.Latest)
.Flatten()
.Select(dto => dto.ToProject())
.Select(IProjectViewModel (project) => new ProjectViewModel(walletAppService, project, navigator, uiServices, investWizard))
.ToList());
.Map(list => list.Select(dto => dto.ToProject()))
.Map(list => list.Select(project => new ProjectViewModel(walletAppService, project, navigator, uiServices, investWizard))));

LoadLatestProjects.HandleErrorsWith(uiServices.NotificationService, "Could not load projects");

OpenHub = ReactiveCommand.CreateFromTask(() =>
uiServices.LauncherService.LaunchUri(new Uri("https://www.angor.io")));
projectsHelper = LoadLatestProjects.ToProperty(this, x => x.Projects);
projectsHelper = LoadLatestProjects.Successes().ToProperty(this, x => x.Projects);
IsLoading = LoadLatestProjects.IsExecuting;
LoadLatestProjects.Execute().Subscribe();
}
Expand All @@ -39,7 +43,7 @@ public BrowseSectionViewModel(IWalletAppService walletAppService,

public IProjectLookupViewModel ProjectLookupViewModel { get; }

public ReactiveCommand<Unit, IList<IProjectViewModel>> LoadLatestProjects { get; }
public ReactiveCommand<Unit, Result<IEnumerable<ProjectViewModel>>> LoadLatestProjects { get; }

public ReactiveCommand<Unit, Unit> OpenHub { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public BrowseSectionViewModelDesign()
Projects = SampleData.GetProjects().Select(IProjectViewModel (project) => new ProjectViewModelDesign(project)).ToList();
}

public IList<IProjectViewModel> Projects { get; }
public IEnumerable<IProjectViewModel> Projects { get; }
public ReactiveCommand<Unit, Unit> OpenHub { get; set; }
public string? ProjectId { get; set; }
public IObservable<bool> IsBusy { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace AngorApp.Sections.Browse;

public interface IBrowseSectionViewModel
{
public IList<IProjectViewModel> Projects { get; }
public IEnumerable<IProjectViewModel> Projects { get; }
ReactiveCommand<Unit, Unit> OpenHub { get; set; }
public IProjectLookupViewModel ProjectLookupViewModel { get; }
IObservable<bool> IsLoading { get; }
Expand Down
0