Skip to content
Open
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
1 change: 1 addition & 0 deletions src/Angor/Avalonia/AngorApp/AngorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ItemGroup>
<PackageReference Include="AsyncImageLoader.Avalonia"/>
<PackageReference Include="Avalonia"/>
<PackageReference Include="Branta" />
<PackageReference Include="ReactiveUI.Avalonia"/>
<PackageReference Include="Avalonia.Themes.Fluent"/>
<PackageReference Include="Avalonia.Fonts.Inter"/>
Expand Down
10 changes: 9 additions & 1 deletion src/Angor/Avalonia/AngorApp/Composition/CompositionRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using AngorApp.UI.Shell;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Zafiro.UI.Navigation;
using Branta.V2.Extensions;

namespace AngorApp.Composition;

Expand Down Expand Up @@ -51,8 +53,14 @@ public static IShellViewModel CreateMainViewModel(Control topLevelView, string p
.AddModelServices()
.AddViewModels()
.AddUIServices(topLevelView, profileContext, applicationStorage);

services.ConfigureBrantaServices(new Branta.Classes.BrantaClientOptions() {
BaseUrl = System.Diagnostics.Debugger.IsAttached
? Branta.Enums.BrantaServerBaseUrl.Staging
: Branta.Enums.BrantaServerBaseUrl.Production
});

services.AddAnnotatedSections(logger);
services.AddNavigator(logger);
services.AddSecurityContext();
RegisterWalletServices(services, logger, network);
FundingContextServices.Register(services, logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
d:DesignWidth="300"
x:Class="AngorApp.UI.Flows.SendWalletMoney.AddressAndAmount.AddressAndAmountView"
x:DataType="ad:IAddressAndAmountViewModel">

<Design.DataContext>
<UserControl.Resources>
<controls:UrlToBitmapConverter x:Key="UrlToBitmapConverter" />
</UserControl.Resources>

<Design.DataContext>
<ad:AddressAndAmountViewModelSample />
</Design.DataContext>

Expand All @@ -25,7 +28,36 @@
</TextBox.InnerLeftContent>
</TextBox>
</Card>
<Card Header="Enter amount to send:" Subheader="{Binding WalletBalance.BtcString, StringFormat='Available balance: {0}'}">

<Panel IsVisible="{Binding ShowBrantaVerification}">
<Panel IsVisible="{Binding Address, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
<StackPanel>
<StackPanel IsVisible="{Binding BrantaPaymentsFound}">
<TextBlock Text="Address Verified by Branta!" Classes="Success" Margin="0 5" />
<ItemsControl ItemsSource="{Binding BrantaPayments}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Spacing="10" Margin="0 0 0 5">
<Image Source="{Binding PlatformLogoUrl, Converter={StaticResource UrlToBitmapConverter}}"
Height="50" Width="50" />
<TextBlock Text="{Binding Platform}" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>

<TextBlock Text="Branta verified payment not found."
IsVisible="{Binding !BrantaPaymentsFound}" />
</StackPanel>
</Panel>
</Panel>

<Panel IsVisible="{Binding BrantaLoading}">
<TextBlock Text="Branta Verifcation Loading..." />
</Panel>

<Card Header="Enter amount to send:" Subheader="{Binding WalletBalance.BtcString, StringFormat='Available balance: {0}'}">

<controls:AmountControl Padding="0" Satoshis="{Binding Amount}">
<Interaction.Behaviors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Branta.V2.Classes;
using Branta.V2.Models;
using ReactiveUI.Validation.Extensions;
using ReactiveUI.Validation.Helpers;

Expand All @@ -7,22 +9,55 @@ public partial class AddressAndAmountViewModel : ReactiveValidationObject, IAddr
{
[Reactive] private string? address;
[Reactive] private long? amount;
[Reactive] private bool brantaLoading = false;
[Reactive] public bool showBrantaVerification = false;
[Reactive] public bool brantaPaymentsFound = false;
[Reactive] public List<Payment>? brantaPayments = [];
[ObservableAsProperty] private IAmountUI? walletBalance;

private readonly BrantaClient _brantaClient;

public AddressAndAmountViewModel(IWallet wallet)

public AddressAndAmountViewModel(IWallet wallet, BrantaClient brantaClient)
{
_brantaClient = brantaClient;

walletBalanceHelper = wallet.WhenAnyValue(w => w.Balance)
.ToProperty(this, model => model.WalletBalance);

this.ValidationRule(x => x.Amount, x => x is null or > 0, _ => "Amount must be greater than zero");
this.ValidationRule(x => x.Amount, x => x is not null, _ => "Please, specify an amount");
var isValidAmount = this.WhenAnyValue(x => x.Amount, x => x.WalletBalance, (amount, balance) => amount is null || amount <= balance.Sats);
this.ValidationRule(x => x.Amount, isValidAmount, "Amount exceeds balance");

this.ValidationRule(x => x.Address, x => !string.IsNullOrWhiteSpace(x), _ => "Please, specify an address");
this.ValidationRule(x => x.Address, x => string.IsNullOrWhiteSpace(x) || wallet.IsAddressValid(x).IsSuccess, message => wallet.IsAddressValid(message).Error);

this.WhenAnyValue(x => x.Address)
.Subscribe(async newAddress => {
await OnAddressChangedAsync(newAddress);
});
}

public IObservable<bool> IsValid => this.IsValid();

private async Task OnAddressChangedAsync(string? newAddress)
{
BrantaLoading = true;

if (string.IsNullOrEmpty(newAddress)) {
BrantaPayments = null;
ShowBrantaVerification = false;
BrantaLoading = false;
return;
}

var payments = await _brantaClient.GetPaymentsAsync(newAddress);

BrantaPayments = payments;
BrantaPaymentsFound = payments.Count != 0;
ShowBrantaVerification = true;

BrantaLoading = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Branta.V2.Models;

namespace AngorApp.UI.Flows.SendWalletMoney.AddressAndAmount;

public class AddressAndAmountViewModelSample : IAddressAndAmountViewModel
Expand All @@ -8,4 +10,8 @@ public class AddressAndAmountViewModelSample : IAddressAndAmountViewModel
public long? Amount { get; set; } = 100;
public string? Address { get; set; } = "testaddress";
public IAmountUI WalletBalance { get; } = new AmountUI(113000);
public bool ShowBrantaVerification { get; set; } = false;
public bool BrantaLoading { get; set; } = false;
public bool BrantaPaymentsFound { get; set; } = false;
public List<Payment>? BrantaPayments { get; set; } = [];
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using Branta.V2.Models;

namespace AngorApp.UI.Flows.SendWalletMoney.AddressAndAmount;

public interface IAddressAndAmountViewModel
{
public long? Amount { get; set; }
public string? Address { get; set; }
public IAmountUI WalletBalance { get; }
public bool ShowBrantaVerification { get; set; }
public bool BrantaLoading { get; set; }
public bool BrantaPaymentsFound { get; set; }
public List<Payment>? BrantaPayments { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using Angor.Sdk.Wallet.Application;
using AngorApp.Model.Contracts.Flows;
using AngorApp.UI.Shared.Controls.Common.Success;
using Branta.V2.Classes;
using Zafiro.Avalonia.Dialogs.Wizards.Slim;
using Zafiro.UI.Wizards.Slim.Builder;
using AddressAndAmountViewModel = AngorApp.UI.Flows.SendWalletMoney.AddressAndAmount.AddressAndAmountViewModel;
using TransactionDraftViewModel = AngorApp.UI.Flows.SendWalletMoney.TransactionDraft.TransactionDraftViewModel;

namespace AngorApp.UI.Flows.SendWalletMoney;

public class SendMoneyFlow(IWalletAppService walletAppService, UIServices uiServices) : ISendMoneyFlow
public class SendMoneyFlow(IWalletAppService walletAppService, UIServices uiServices, BrantaClient brantaClient) : ISendMoneyFlow
{
public async Task SendMoney(IWallet sourceWallet)
{
var wizard = WizardBuilder
.StartWith(() => new AddressAndAmountViewModel(sourceWallet), "Amount and address").Next(model => (model.Amount, model.Address)).WhenValid<AddressAndAmountViewModel>()
.StartWith(() => new AddressAndAmountViewModel(sourceWallet, brantaClient), "Amount and address").Next(model => (model.Amount, model.Address)).WhenValid<AddressAndAmountViewModel>()
.Then(sendData => new TransactionDraftViewModel(sourceWallet.Id, walletAppService, new SendAmount("Test", sendData.Amount.Value, sendData.Address), uiServices), "Summary").NextCommand(model => model.Confirm.Enhance("Confirm"))
.Then(_ => new SuccessViewModel("Transaction sent!"), "Transaction sent").NextUnit("Close").Always()
.WithCompletionFinalStep();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Avalonia.Data.Converters;
using Avalonia.Media.Imaging;
using System.Globalization;
using System.Net.Http;

namespace AngorApp.UI.Shared.Controls;

public class UrlToBitmapConverter : IValueConverter
{
private static readonly HttpClient httpClient = new HttpClient();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string url && !string.IsNullOrEmpty(url)) {
try {
// For web URLs
if (url.StartsWith("http://") || url.StartsWith("https://")) {
var data = httpClient.GetByteArrayAsync(url).Result;
using var stream = new System.IO.MemoryStream(data);
return new Bitmap(stream);
}

// For local resources
return new Bitmap(url);
}
catch {
return null;
}
}
return null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
1 change: 1 addition & 0 deletions src/Angor/Avalonia/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageVersion Include="Avalonia.iOS" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Browser" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia.Android" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Branta" Version="0.0.4" />
<PackageVersion Include="ReactiveUI.Avalonia" Version="11.3.8" />
<PackageVersion Include="Svg.Controls.Skia.Avalonia" Version="11.3.6.2" />
<PackageVersion Include="AsyncImageLoader.Avalonia" Version="3.3.0" />
Expand Down