Skip to content
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
4 changes: 4 additions & 0 deletions src/Angor/Avalonia/AngorApp.Model/Amounts/AmountUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ public class AmountUI(long sats, string symbol = "BTC") : IAmountUI
{
public long Sats { get; } = sats;
public string Symbol { get; } = symbol;

public static AmountUI FromBtc(int btc) => new(btc * 100_000_000);
public static AmountUI FromBtc(decimal btc) => new((long)(btc * 100_000_000));
Copy link
Member

Choose a reason for hiding this comment

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

are you sure this is correct? decimal normally means it is in sats format

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's correct! The FromBtc factory methods take BTC as input and convert to sats (internal representation). I went with decimal to avoid floating-point precision issues when dealing with fractional BTC values.

Copy link
Member

Choose a reason for hiding this comment

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

We probably won't have such a use case, if we do maybe we should not allow it.
Basically eiher sats or btc is what I suggest.

public static AmountUI FromBtc(double btc) => new((long)(btc * 100_000_000));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IAmountUI

public string BtcString => $"{Btc:0.00 000 000} " + Symbol;

private decimal Btc => Sats / (decimal)1_0000_0000;
public decimal Btc => Sats / (decimal)1_0000_0000;

public string DecimalString => $"{Btc:G} {Symbol}";
public string RoundedDecimalString => $"{Btc:N2} {Symbol}";
Expand Down
2 changes: 1 addition & 1 deletion src/Angor/Avalonia/AngorApp/AngorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AvaloniaResource Include="Assets/**"/>
<!-- Link theme-specific app icons located at the solution root to our Assets folder -->
<AvaloniaResource Include="../angor-app-icon-light.png">
<Link>Assets/angor-app-icon-light.png</Link>
<Link>Assets/angor-app-icon-light84c17bc6d299ec806d065d7d23c9b42aa21f330e.png</Link>
</AvaloniaResource>
<AvaloniaResource Include="../angor-app-icon-dark.png">
<Link>Assets/angor-app-icon-dark.png</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static IServiceCollection AddModelServices(this IServiceCollection servic
return services
.AddSingleton<IAmountFactory, AmountFactory>()
.AddSingleton<IWalletProvider, SimpleWalletProvider>()
.AddScoped<ICreateProjectFlow, CreateProjectFlow>()
.AddScoped<ICreateProjectFlow, CreateProjectFlowV2>()
.AddScoped<ISendMoneyFlow, SendMoneyFlow>()
.AddSingleton<InvestFlow>()
.AddSingleton<WalletCreationWizard>()
Expand Down
6 changes: 6 additions & 0 deletions src/Angor/Avalonia/AngorApp/IProjectTypeViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AngorApp
{
public interface IProjectTypeViewModel : IHaveTitle
{
}
}
19 changes: 19 additions & 0 deletions src/Angor/Avalonia/AngorApp/ProjectTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using AngorApp.UI.Flows.CreateProject.Wizard;
using Avalonia.Data.Converters;
using Avalonia.Media;

namespace AngorApp
{
public static class ProjectTypeConverter
{
public static FuncValueConverter<ProjectType, IBrush> ToBrush { get; } =
new FuncValueConverter<ProjectType, IBrush>(type =>
{
return type.Name switch
{
"Investment" => Brushes.Green,
_ => Brushes.Orange,
};
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Angor.Sdk.Common;
using Angor.Sdk.Funding.Founder;
using Angor.Sdk.Funding.Founder.Dtos;
using Angor.Sdk.Funding.Founder.Operations;
using AngorApp.UI.Flows.CreateProject.Wizard;
using AngorApp.UI.Flows.CreateProject.Wizard.InvestmentProject;
using AngorApp.UI.Flows.CreateProject.Wizard.InvestmentProject.Model;
using Zafiro.Avalonia.Controls.Wizards.Slim;
using Zafiro.UI.Navigation;
using Zafiro.UI.Wizards.Slim;
using Zafiro.UI.Wizards.Slim.Builder;

namespace AngorApp.UI.Flows.CreateProject
{
public class CreateProjectFlowV2(
INavigator navigator,
IFounderAppService founderAppService,
IWalletContext walletContext
)
: ICreateProjectFlow
{
public Task<Result<Maybe<string>>> CreateProject()
{
var createWizardResult = from wallet in walletContext.GetDefaultWallet()
from seed in GetProjectSeed(wallet.Id)
select CreateInvestmentProjectWizard();

NewProject newProject = null!;

var rootWizard = WizardBuilder
.StartWith(() => new WelcomeViewModel()).NextCommand(model => model.Start)
.Then(_ => new ProjectTypeViewModel())
.NextCommand<Unit, ProjectTypeViewModel, String>(_ => StartSubwizard())
.WithCompletionFinalStep();

return createWizardResult.Map(wizard => rootWizard.Navigate(navigator));
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this code exactly but it is ok lol (ui magic)

}

private IEnhancedCommand<Result<string>> StartSubwizard()
{
return ReactiveCommand
.CreateFromTask(() => CreateInvestmentProjectWizard().Navigate(navigator).ToResult("Salute"))
.Enhance();
}

private SlimWizard<string> CreateInvestmentProjectWizard()
{
var newProject = new NewProject();
var wizard = WizardBuilder
.StartWith(() => new ProjectProfileViewModel(newProject)).NextUnit().Always()
.Then(_ => new ProjectImagesViewModel(newProject)).NextUnit().Always()
.Then(_ => new FundingConfigurationViewModel(newProject)).NextUnit().Always()
.Then(_ => new StagesViewModel(newProject)).NextUnit().Always()
.Then(_ => new ReviewAndDeployViewModel(newProject)).NextResult(_ => Result.Success(""))
.Always()
.WithCommitFinalStep();

return wizard;
}

private async Task<Result<ProjectSeedDto>> GetProjectSeed(WalletId walletId)
{
var result = await founderAppService.CreateNewProjectKeysAsync(new CreateProjectNewKeys.CreateProjectNewKeysRequest(walletId));
return result.Map(response => response.ProjectSeedDto);
}
}
}
Loading
Loading