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

feat: show pending payments in transactions list #576

Closed
wants to merge 1 commit into from
Closed
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 api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ type Transaction struct {
AppId *uint `json:"appId"`
Metadata Metadata `json:"metadata,omitempty"`
Boostagram *Boostagram `json:"boostagram,omitempty"`
IsPending bool `json:"isPending,omitempty"`
}

type Metadata = map[string]interface{}
Expand Down
4 changes: 3 additions & 1 deletion api/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"time"

"github.com/getAlby/hub/constants"
"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/transactions"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -38,7 +39,7 @@ func (api *api) ListTransactions(ctx context.Context, limit uint64, offset uint6
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
transactions, err := api.svc.GetTransactionsService().ListTransactions(ctx, 0, 0, limit, offset, false, nil, api.svc.GetLNClient(), nil)
transactions, err := api.svc.GetTransactionsService().ListTransactions(ctx, 0, 0, limit, offset, true, false, nil, api.svc.GetLNClient(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -111,6 +112,7 @@ func toApiTransaction(transaction *transactions.Transaction) *Transaction {
SettledAt: settledAt,
Metadata: metadata,
Boostagram: boostagram,
IsPending: transaction.State == constants.TRANSACTION_STATE_PENDING,
}
}

Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/TransactionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ function TransactionItem({ tx }: Props) {
<div className="overflow-hidden mr-3">
<div className="flex items-center gap-2 truncate">
<p className="text-lg md:text-xl font-semibold">
{app ? app.name : type == "incoming" ? "Received" : "Sent"}
{tx.isPending
? type == "incoming"
? "Receiving"
: "Sending"
: app
? app.name
: type == "incoming"
? "Received"
: "Sent"}
</p>
<p className="text-sm md:text-base truncate text-muted-foreground">
{dayjs(tx.settledAt).fromNow()}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export type Transaction = {
settledAt: string | undefined;
metadata?: Record<string, unknown>;
boostagram?: Boostagram;
isPending?: boolean;
};

export type Boostagram = {
Expand Down
2 changes: 1 addition & 1 deletion nip47/controllers/list_transactions_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (controller *nip47Controller) HandleListTransactionsEvent(ctx context.Conte
transactionType = &listParams.Type
}

dbTransactions, err := controller.transactionsService.ListTransactions(ctx, listParams.From, listParams.Until, limit, listParams.Offset, listParams.Unpaid, transactionType, controller.lnClient, &appId)
dbTransactions, err := controller.transactionsService.ListTransactions(ctx, listParams.From, listParams.Until, limit, listParams.Offset, false, listParams.Unpaid, transactionType, controller.lnClient, &appId)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"params": listParams,
Expand Down
13 changes: 10 additions & 3 deletions transactions/transactions_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type TransactionsService interface {
events.EventSubscriber
MakeInvoice(ctx context.Context, amount int64, description string, descriptionHash string, expiry int64, metadata map[string]interface{}, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
LookupTransaction(ctx context.Context, paymentHash string, transactionType *string, lnClient lnclient.LNClient, appId *uint) (*Transaction, error)
ListTransactions(ctx context.Context, from, until, limit, offset uint64, unpaid bool, transactionType *string, lnClient lnclient.LNClient, appId *uint) (transactions []Transaction, err error)
ListTransactions(ctx context.Context, from, until, limit, offset uint64, pending, unpaid bool, transactionType *string, lnClient lnclient.LNClient, appId *uint) (transactions []Transaction, err error)
SendPaymentSync(ctx context.Context, payReq string, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
SendKeysend(ctx context.Context, amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
}
Expand Down Expand Up @@ -474,7 +474,7 @@ func (svc *transactionsService) LookupTransaction(ctx context.Context, paymentHa
return &transaction, nil
}

func (svc *transactionsService) ListTransactions(ctx context.Context, from, until, limit, offset uint64, unpaid bool, transactionType *string, lnClient lnclient.LNClient, appId *uint) (transactions []Transaction, err error) {
func (svc *transactionsService) ListTransactions(ctx context.Context, from, until, limit, offset uint64, pending, unpaid bool, transactionType *string, lnClient lnclient.LNClient, appId *uint) (transactions []Transaction, err error) {
Copy link
Contributor

@rolznz rolznz Aug 31, 2024

Choose a reason for hiding this comment

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

this introduces another bool and now there is the complexity you see below.

What about we have a stateTypes which and use that. the default would be []string{"TRANSACTION_STATE_SETTLED"}

Copy link
Contributor

@rolznz rolznz Aug 31, 2024

Choose a reason for hiding this comment

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

But this is problematic because we only want to see pending outgoing payments. This needs more thought. Maybe a function that can alter the query could be passed in 🤔 This will also be a problem for NWC though.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is more complicated than I thought, let's move it to the next milestone

svc.checkUnsettledTransactions(ctx, lnClient)

// TODO: add other filtering and pagination
Expand All @@ -483,7 +483,14 @@ func (svc *transactionsService) ListTransactions(ctx context.Context, from, unti
tx = tx.Order("settled_at desc, created_at desc")

if !unpaid {
tx = tx.Where("state == ?", constants.TRANSACTION_STATE_SETTLED)
if pending {
tx = tx.Where("state IN (?)", []string{
constants.TRANSACTION_STATE_SETTLED,
constants.TRANSACTION_STATE_PENDING,
})
} else {
tx = tx.Where("state == ?", constants.TRANSACTION_STATE_SETTLED)
}
}

if transactionType != nil {
Expand Down
Loading