diff --git a/api/models.go b/api/models.go index f7583030..b6668f43 100644 --- a/api/models.go +++ b/api/models.go @@ -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{} diff --git a/api/transactions.go b/api/transactions.go index 49900f1f..8c255940 100644 --- a/api/transactions.go +++ b/api/transactions.go @@ -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" @@ -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 } @@ -111,6 +112,7 @@ func toApiTransaction(transaction *transactions.Transaction) *Transaction { SettledAt: settledAt, Metadata: metadata, Boostagram: boostagram, + IsPending: transaction.State == constants.TRANSACTION_STATE_PENDING, } } diff --git a/frontend/src/components/TransactionItem.tsx b/frontend/src/components/TransactionItem.tsx index c8a32367..4298b958 100644 --- a/frontend/src/components/TransactionItem.tsx +++ b/frontend/src/components/TransactionItem.tsx @@ -86,7 +86,15 @@ function TransactionItem({ tx }: Props) {

- {app ? app.name : type == "incoming" ? "Received" : "Sent"} + {tx.isPending + ? type == "incoming" + ? "Receiving" + : "Sending" + : app + ? app.name + : type == "incoming" + ? "Received" + : "Sent"}

{dayjs(tx.settledAt).fromNow()} diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 3cb04a58..b6471b1f 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -385,6 +385,7 @@ export type Transaction = { settledAt: string | undefined; metadata?: Record; boostagram?: Boostagram; + isPending?: boolean; }; export type Boostagram = { diff --git a/nip47/controllers/list_transactions_controller.go b/nip47/controllers/list_transactions_controller.go index 0ed8ab85..eec2d47a 100644 --- a/nip47/controllers/list_transactions_controller.go +++ b/nip47/controllers/list_transactions_controller.go @@ -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, diff --git a/transactions/transactions_service.go b/transactions/transactions_service.go index 40f4ca4f..b9d58fc4 100644 --- a/transactions/transactions_service.go +++ b/transactions/transactions_service.go @@ -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) } @@ -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) { svc.checkUnsettledTransactions(ctx, lnClient) // TODO: add other filtering and pagination @@ -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 {