forked from WalletWasabi/WalletWasabi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coordinator Connection String (WalletWasabi#13190)
* Introduce CoordinatorConfigString * implement basic UI for the feature * Rename + Wipe clipboard on DialogCreation * Write todo NewCoordinatorConfirmationDialog refresh * Fix stupid mistakes * Add sanity checks * Add Name * Don't display dialog if new string doesn't change anything * refactoring * Polishing * make link clickable * simplification * Small refactoring * Move `CoordinatorConnectionString` to Discoverability directory * Refactor `ToString` * Rename `CoordinatorFeePercentage` to `CoordinationFeeRate` * Minor improvements * Minor fixes * Get navigation target from the dialog * Add constants * Rename Endpoint to CoordinatorUri --------- Co-authored-by: Turbolay <[email protected]> Co-authored-by: Roland Soós <[email protected]> Co-authored-by: Lucas Ontivero <[email protected]>
- Loading branch information
1 parent
0d837c4
commit 40ab4a1
Showing
14 changed files
with
440 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
WalletWasabi.Fluent/Behaviors/CoordinatorConnectionStringBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Reactive.Disposables; | ||
using System.Reactive.Linq; | ||
using Avalonia.Controls; | ||
using Avalonia.Xaml.Interactions.Custom; | ||
using ReactiveUI; | ||
using WalletWasabi.Discoverability; | ||
using WalletWasabi.Fluent.Extensions; | ||
using WalletWasabi.Fluent.Helpers; | ||
using WalletWasabi.Fluent.Models.UI; | ||
using WalletWasabi.Fluent.ViewModels.Dialogs; | ||
using WalletWasabi.Helpers; | ||
using WalletWasabi.Models; | ||
|
||
namespace WalletWasabi.Fluent.Behaviors; | ||
|
||
public class CoordinatorConnectionStringBehavior : DisposingBehavior<Window> | ||
{ | ||
|
||
protected override void OnAttached(CompositeDisposable disposables) | ||
{ | ||
if (AssociatedObject is null) | ||
{ | ||
return; | ||
} | ||
|
||
var uiContext = UiContext.Default; | ||
|
||
Observable | ||
.FromEventPattern(AssociatedObject, nameof(AssociatedObject.Activated)) | ||
.Where(_ => !uiContext.ApplicationSettings.Oobe) | ||
.SelectMany(async _ => | ||
{ | ||
var clipboardValue = await uiContext.Clipboard.GetTextAsync(); | ||
if (!CoordinatorConnectionString.TryParse(clipboardValue, out var coordinatorConnectionString)) | ||
{ | ||
return null; | ||
} | ||
await uiContext.Clipboard.ClearAsync(); | ||
var navigationTarget = NewCoordinatorConfirmationDialogViewModel.MetaData.NavigationTarget; | ||
if (uiContext.Navigate(navigationTarget).CurrentPage is NewCoordinatorConfirmationDialogViewModel currentDialog) | ||
{ | ||
if (currentDialog.CoordinatorConnection.ToString() == coordinatorConnectionString.ToString()) | ||
{ | ||
return null; | ||
} | ||
currentDialog.CancelCommand.ExecuteIfCan(); | ||
} | ||
return coordinatorConnectionString; | ||
}) | ||
.WhereNotNull() | ||
.DoAsync(async coordinatorConnectionString => | ||
{ | ||
var accepted = await uiContext.Navigate().To().NewCoordinatorConfirmationDialog(coordinatorConnectionString).GetResultAsync(); | ||
if (!accepted) | ||
{ | ||
return; | ||
} | ||
if (!uiContext.ApplicationSettings.TryProcessCoordinatorConnectionString(coordinatorConnectionString)) | ||
{ | ||
uiContext.Navigate().To().ShowErrorDialog( | ||
message: "Some of the values were incorrect. See logs for more details.", | ||
title: "Coordinator detected", | ||
caption: ""); | ||
} | ||
}) | ||
.Subscribe() | ||
.DisposeWith(disposables); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.