diff --git a/alby.go b/alby.go index 87fee178..d1c105ab 100644 --- a/alby.go +++ b/alby.go @@ -97,14 +97,14 @@ func (svc *AlbyOAuthService) MakeInvoice(ctx context.Context, senderPubkey strin // amount provided in msat, but Alby API currently only supports sats. Will get truncated to a whole sat value var amountSat int64 = amount / 1000 // make sure amount is not converted to 0 - if (amount > 0 && amountSat == 0) { + if amount > 0 && amountSat == 0 { svc.Logger.WithFields(logrus.Fields{ "senderPubkey": senderPubkey, "amount": amount, "description": description, "descriptionHash": descriptionHash, "expiry": expiry, - }).Errorf("Value must be 1 sat or greater"); + }).Errorf("Value must be 1 sat or greater") return "", "", errors.New("Value must be 1 sat or greater") } @@ -125,8 +125,8 @@ func (svc *AlbyOAuthService) MakeInvoice(ctx context.Context, senderPubkey strin body := bytes.NewBuffer([]byte{}) payload := &MakeInvoiceRequest{ - Amount: amountSat, - Description: description, + Amount: amountSat, + Description: description, DescriptionHash: descriptionHash, // TODO: support expiry } @@ -171,7 +171,7 @@ func (svc *AlbyOAuthService) MakeInvoice(ctx context.Context, senderPubkey strin "appId": app.ID, "userId": app.User.ID, "paymentRequest": responsePayload.PaymentRequest, - "paymentHash": responsePayload.PaymentHash, + "paymentHash": responsePayload.PaymentHash, }).Info("Make invoice successful") return responsePayload.PaymentRequest, responsePayload.PaymentHash, nil } else { @@ -185,7 +185,7 @@ func (svc *AlbyOAuthService) MakeInvoice(ctx context.Context, senderPubkey strin "expiry": expiry, "appId": app.ID, "userId": app.User.ID, - "APIHttpStatus": resp.StatusCode, + "APIHttpStatus": resp.StatusCode, }).Errorf("Make invoice failed %s", string(errorPayload.Message)) return "", "", errors.New(errorPayload.Message) } diff --git a/handle_balance_request.go b/handle_balance_request.go index 586daf2a..cb63239e 100644 --- a/handle_balance_request.go +++ b/handle_balance_request.go @@ -8,6 +8,10 @@ import ( "github.com/sirupsen/logrus" ) +const ( + MSAT_PER_SAT = 1000 +) + func (svc *Service) HandleGetBalanceEvent(ctx context.Context, request *Nip47Request, event *nostr.Event, app App, ss []byte) (result *nostr.Event, err error) { nostrEvent := NostrEvent{App: app, NostrId: event.ID, Content: event.Content, State: "received"} @@ -60,7 +64,7 @@ func (svc *Service) HandleGetBalanceEvent(ctx context.Context, request *Nip47Req } responsePayload := &Nip47BalanceResponse{ - Balance: balance, + Balance: balance * MSAT_PER_SAT, } appPermission := AppPermission{} @@ -68,7 +72,7 @@ func (svc *Service) HandleGetBalanceEvent(ctx context.Context, request *Nip47Req maxAmount := appPermission.MaxAmount if maxAmount > 0 { - responsePayload.MaxAmount = maxAmount + responsePayload.MaxAmount = maxAmount * MSAT_PER_SAT responsePayload.BudgetRenewal = appPermission.BudgetRenewal } @@ -76,7 +80,7 @@ func (svc *Service) HandleGetBalanceEvent(ctx context.Context, request *Nip47Req svc.db.Save(&nostrEvent) return svc.createResponse(event, Nip47Response{ ResultType: NIP_47_GET_BALANCE_METHOD, - Result: responsePayload, + Result: responsePayload, }, - ss) + ss) }