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

Withdrawalrequestspsbt can be stored more than once per signer #362

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
6 changes: 3 additions & 3 deletions src/Data/Repositories/ChannelOperationRequestRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public async Task<List<ChannelOperationRequest>> GetUnsignedPendingRequestsByUse
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();

return await applicationDbContext.ChannelOperationRequests
.Where(request => request.Wallet.Keys.Any(key => key.User != null && key.User.Id == userId) &&
(request.Status == ChannelOperationRequestStatus.Pending || request.Status == ChannelOperationRequestStatus.PSBTSignaturesPending) &&
request.ChannelOperationRequestPsbts.All(signature => signature.UserSignerId != userId))
.Include(request => request.SourceNode)
.Include(request => request.Wallet).ThenInclude(x => x.InternalWallet)
.Include(x => x.Wallet).ThenInclude(x => x.Keys)
.Include(request => request.DestNode)
.Include(request => request.ChannelOperationRequestPsbts)
.Include(x => x.Utxos)
.Where(request => request.Wallet != null
&& request.Wallet.Keys.Count(key => userId == key.UserId) > request.ChannelOperationRequestPsbts.Count(req => req.UserSignerId == userId)
&& (request.Status == ChannelOperationRequestStatus.Pending || request.Status == ChannelOperationRequestStatus.PSBTSignaturesPending))
.AsSplitQuery()
.ToListAsync();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Data/Repositories/WalletWithdrawalRequestRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public async Task<List<WalletWithdrawalRequest>> GetUnsignedPendingRequestsByUse
.Include(x => x.Wallet).ThenInclude(x => x.Keys)
.Include(x => x.UserRequestor)
.Include(x => x.WalletWithdrawalRequestPSBTs)
.Where(request => request.Wallet.Keys.Any(key => key.User != null && key.User.Id == userId) &&
(request.Status == WalletWithdrawalRequestStatus.Pending || request.Status == WalletWithdrawalRequestStatus.PSBTSignaturesPending) &&
request.WalletWithdrawalRequestPSBTs.All(signature => signature.SignerId != userId))
.Where(request => request.Wallet != null
&& request.Wallet.Keys.Count(key => userId == key.UserId) > request.WalletWithdrawalRequestPSBTs.Count(req => req.SignerId == userId)
&& (request.Status == WalletWithdrawalRequestStatus.Pending || request.Status == WalletWithdrawalRequestStatus.PSBTSignaturesPending))
.AsSplitQuery()
.ToListAsync();
}
Expand Down
11 changes: 10 additions & 1 deletion src/Pages/ChannelRequests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
TemplatePsbtString="@_templatePSBTString"
SignedPSBT="@_psbt"/>

<CancelOrRejectPopup

Check warning on line 401 in src/Pages/ChannelRequests.razor

View workflow job for this annotation

GitHub Actions / build-and-test

Component 'CancelOrRejectPopup' expects a value for the parameter 'Reason', but a value may not have been provided.
@ref=@_rejectCancelModalRef
Title='@(_selectedStatusActionString + " operation: " + _selectedRequest?.Id)'
Validator="@RejectReasonValidator"
Expand Down Expand Up @@ -793,9 +793,18 @@
{
_psbtSignRef?.HideModal();

if (_selectedRequest != null)
{
_selectedRequest = await ChannelOperationRequestRepository.GetById(_selectedRequest.Id);
}

if (_selectedRequest == null || string.IsNullOrEmpty(_psbtSignRef?.SignedPSBT) || LoggedUser == null)
{
ToastService.ShowError("Error: Not all fields were set");
ToastService.ShowError("Not all fields were set");
}
else if (_selectedRequest.ChannelOperationRequestPsbts.Any(x => _psbtSignRef.SignedPSBT.Equals(x.PSBT)))
{
ToastService.ShowError("You already signed this PSBT");
}
else
{
Expand Down
20 changes: 11 additions & 9 deletions src/Pages/Withdrawals.razor
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@
<DataGridColumn TItem="WalletWithdrawalRequest" Filterable="false" Field="@nameof(WalletWithdrawalRequest.Id)" Caption="#" Sortable="false" Displayable="true"/>
<DataGridColumn TItem="WalletWithdrawalRequest" Filterable="false" Caption="Actions" Sortable="false" Displayable="true">
<DisplayTemplate>
@if (context.Wallet != null && context.Wallet.Keys != null && context.Wallet.Keys.Any(x => x.UserId == LoggedUser?.Id)
&& !context.AreAllRequiredHumanSignaturesCollected
&& context.WalletWithdrawalRequestPSBTs.All(x => x.SignerId != LoggedUser?.Id))
{
<Button Color="Color.Success" Clicked="() => ShowApprovalModal(context)">Approve</Button>
}
<Button Color="Color.Success" hidden="@(!_isFinanceManager)" Clicked="() => ShowApprovalModal(context)">Approve</Button>
</DisplayTemplate>
</DataGridColumn>
<DataGridColumn TItem="WalletWithdrawalRequest" Filterable="false" Caption="" Sortable="false" Displayable="true">
Expand Down Expand Up @@ -413,7 +408,7 @@
TemplatePsbtString="@_templatePsbtString"
ApproveRequestDelegate="async () => await ApproveRequestDelegate()"/>

<CancelOrRejectPopup

Check warning on line 411 in src/Pages/Withdrawals.razor

View workflow job for this annotation

GitHub Actions / build-and-test

Component 'CancelOrRejectPopup' expects a value for the parameter 'Reason', but a value may not have been provided.
@ref="@_rejectCancelModalRef"
Title='@("Wallet withdrawal:" + _selectedRequest?.Id)'
Validator="@RejectReasonValidator"
Expand Down Expand Up @@ -552,7 +547,7 @@
{
if (LoggedUser?.Id != null && _isFinanceManager)
{
_userPendingRequests = await WalletWithdrawalRequestRepository.GetAllUnsignedPendingRequests();
_userPendingRequests = await WalletWithdrawalRequestRepository.GetUnsignedPendingRequestsByUser(LoggedUser.Id);
}

_withdrawalRequests = (await WalletWithdrawalRequestRepository.GetAll()).Except(_userPendingRequests).ToList();
Expand Down Expand Up @@ -761,13 +756,17 @@
}
}

private async Task Approve(WalletWithdrawalRequest request)
private async Task Approve()
{
if (_selectedRequest == null || string.IsNullOrEmpty(_psbtSignRef?.SignedPSBT) || LoggedUser == null)
{
_utxoSelectorModalRef.ClearModal();
ToastService.ShowError("Invalid request");
}
else if (_selectedRequest.WalletWithdrawalRequestPSBTs.Any(x => _psbtSignRef.SignedPSBT.Equals(x.PSBT)))
{
ToastService.ShowError("You already signed this request with this key");
}
else
{
WalletWithdrawalRequestPSBT walletWithdrawalRequestPsbt = new()
Expand Down Expand Up @@ -831,7 +830,10 @@
private async Task ApproveRequestDelegate()
{
if (_selectedRequest != null)
await Approve(_selectedRequest);
{
_selectedRequest = await WalletWithdrawalRequestRepository.GetById(_selectedRequest.Id);
await Approve();
}
}

private async Task RejectOrCancel()
Expand Down
Loading