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

[UI] Send - move recipient entry to the first dialog #12657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions WalletWasabi.Fluent/Controls/DualCurrencyEntryBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@
</Setter>
</Style>

<Style Selector="^/template/ Border#PART_BorderElement">
<Setter Property="CornerRadius" Value="4" />
</Style>

<Style Selector="^:noexchangerate /template/ Button#PART_SwapButton">
<Setter Property="IsVisible" Value="False" />
</Style>
Expand Down
1 change: 1 addition & 0 deletions WalletWasabi.Fluent/Controls/TagsBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<Setter Property="Padding" Value="{DynamicResource TagsBoxBorderPadding}" />
<Setter Property="Cursor" Value="IBeam" />
<Setter Property="Focusable" Value="True" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<ControlTemplate>
<DataValidationErrors>
Expand Down
8 changes: 8 additions & 0 deletions WalletWasabi.Fluent/Controls/TagsBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@
CheckIsCurrentTextValid();
})
.DisposeWith(_compositeDisposable);

this.WhenAnyValue(x => x.Items)
.Subscribe(_ =>
{
InvalidateWatermark();
CheckIsCurrentTextValid();
})
.DisposeWith(_compositeDisposable);

Check warning on line 303 in WalletWasabi.Fluent/Controls/TagsBox.axaml.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (master)

❌ Getting worse: Large Method

Initialize increases from 74 to 81 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
}

private void CheckIsCurrentTextValid()
Expand Down
32 changes: 20 additions & 12 deletions WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;

Check notice on line 1 in WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (master)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 4.80 to 4.90, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
Expand All @@ -23,6 +24,7 @@
using WalletWasabi.WebClients.PayJoin;
using WalletWasabi.Fluent.Models.UI;
using WalletWasabi.Fluent.Models.Wallets;
using WalletWasabi.Fluent.ViewModels.Wallets.Labels;
using WalletWasabi.Userfacing.Bip21;
using Constants = WalletWasabi.Helpers.Constants;

Expand All @@ -46,7 +48,6 @@
private readonly ClipboardObserver _clipboardObserver;

private bool _parsingTo;
private LabelsArray _parsedLabel = LabelsArray.Empty;

[AutoNotify] private string _to;
[AutoNotify] private decimal? _amountBtc;
Expand All @@ -55,6 +56,7 @@
[AutoNotify] private bool _isPayJoin;
[AutoNotify] private string? _payJoinEndPoint;
[AutoNotify] private bool _conversionReversed;
[AutoNotify(SetterModifier = AccessModifier.Private)] private SuggestionLabelsViewModel _suggestionLabels;

public SendViewModel(UiContext uiContext, WalletViewModel walletVm)
{
Expand All @@ -71,53 +73,54 @@

Balance = walletVm.WalletModel.Balances;

_suggestionLabels = new SuggestionLabelsViewModel(WalletVm.WalletModel, Intent.Send, 3);

SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true);

EnableBack = false;

this.ValidateProperty(x => x.To, ValidateToField);
this.ValidateProperty(x => x.AmountBtc, ValidateAmount);

this.WhenAnyValue(x => x.To)
.Skip(1)
.Subscribe(ParseToField);

this.WhenAnyValue(x => x.PayJoinEndPoint)
.Subscribe(endPoint => IsPayJoin = endPoint is { });

PasteCommand = ReactiveCommand.CreateFromTask(async () => await OnPasteAsync());
AutoPasteCommand = ReactiveCommand.CreateFromTask(async () => await OnAutoPasteAsync());
InsertMaxCommand = ReactiveCommand.Create(() => AmountBtc = _wallet.Coins.TotalAmount().ToDecimal(MoneyUnit.BTC));
QrCommand = ReactiveCommand.Create(async () =>
{
ShowQrCameraDialogViewModel dialog = new(UiContext, _wallet.Network);
var result = await NavigateDialogAsync(dialog, NavigationTarget.CompactDialogScreen);
if (!string.IsNullOrWhiteSpace(result.Result))
{
To = result.Result;
}
});

var nextCommandCanExecute =
this.WhenAnyValue(x => x.AmountBtc, x => x.To)
this.WhenAnyValue(
x => x.AmountBtc,
x => x.To,
x => x.SuggestionLabels.Labels.Count,
x => x.SuggestionLabels.IsCurrentTextValid)
.Select(tup =>
{
var (amountBtc, to) = tup;
var (amountBtc, to, labelsCount, isCurrentTextValid) = tup;
var allFilled = !string.IsNullOrEmpty(to) && amountBtc > 0;
var hasError = Validations.Any;

return allFilled && !hasError;
return allFilled && !hasError && (labelsCount > 0 || isCurrentTextValid);
});

NextCommand = ReactiveCommand.CreateFromTask(
async () =>
{
var labelDialog = new LabelEntryDialogViewModel(WalletVm.WalletModel, _parsedLabel);
var result = await NavigateDialogAsync(labelDialog, NavigationTarget.CompactDialogScreen);
if (result.Result is not { } label)
{
return;
}
var label = new LabelsArray(SuggestionLabels.Labels.ToArray());

Check notice on line 123 in WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (master)

ℹ Getting worse: Complex Method

SendViewModel increases in cyclomatic complexity from 9 to 10, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

if (AmountBtc is not { } amountBtc)
{
Expand Down Expand Up @@ -285,7 +288,7 @@
{
result = true;

_parsedLabel = parserResult.Label is { } label ? new LabelsArray(label) : LabelsArray.Empty;
var parsedLabel = parserResult.Label is { } label ? new LabelsArray(label) : LabelsArray.Empty;

PayJoinEndPoint = parserResult.UnknownParameters.TryGetValue("pj", out var endPoint) ? endPoint : null;

Expand All @@ -303,12 +306,17 @@
{
IsFixedAmount = false;
}

SuggestionLabels = new SuggestionLabelsViewModel(
WalletVm.WalletModel,
Intent.Send,
3,
parsedLabel.AsEnumerable());
}
else
{
IsFixedAmount = false;
PayJoinEndPoint = null;
_parsedLabel = LabelsArray.Empty;
}

Dispatcher.UIThread.Post(() => _parsingTo = false);
Expand Down
20 changes: 19 additions & 1 deletion WalletWasabi.Fluent/Views/Wallets/Send/SendView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
</TextBox>
</DockPanel>
<!-- Amount -->
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,10">
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,15">
<Label DockPanel.Dock="Left" Content="_Amount:" Target="amountTb" />
<DockPanel>
<Image Width="120" Source="avares://WalletWasabi.Fluent/Assets/TechnologyLogos/payjoin.png"
Expand Down Expand Up @@ -149,6 +149,24 @@
</DualCurrencyEntryBox>
</DockPanel>
</DockPanel>
<!-- Recipient -->
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,10">
<Label DockPanel.Dock="Left" Content="_Recipient:" Target="LabelTagBox"
Margin="0,10,0,10"/>
<TagsBox x:Name="LabelTagBox"
VerticalAlignment="Top"
Watermark="{StaticResource LabelsWatermarkText}"
TagSeparator=","
SuggestionsAreCaseSensitive="True"
RestrictInputToSuggestions="False"
Items="{Binding SuggestionLabels.Labels}"
TopItems="{Binding SuggestionLabels.TopSuggestions}"
Suggestions="{Binding SuggestionLabels.Suggestions}"
MaxTextLength="{StaticResource MaxLabelLength}"
IsCurrentTextValid="{Binding SuggestionLabels.IsCurrentTextValid, Mode=OneWayToSource}"
ForceAdd="{Binding SuggestionLabels.ForceAdd, Mode=TwoWay}">
</TagsBox>
</DockPanel>
</DockPanel>
</ContentArea>
</UserControl>