Skip to content

Commit 3f1f9c5

Browse files
refactor: removed the fee credit system (#1769)
1 parent 2d046cd commit 3f1f9c5

File tree

8 files changed

+1
-366
lines changed

8 files changed

+1
-366
lines changed

alby/alby_oauth_service.go

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -479,141 +479,6 @@ func (svc *albyOAuthService) GetMe(ctx context.Context) (*AlbyMe, error) {
479479
return me, nil
480480
}
481481

482-
func (svc *albyOAuthService) GetBalance(ctx context.Context) (*AlbyBalance, error) {
483-
484-
token, err := svc.fetchUserToken(ctx)
485-
if err != nil {
486-
logger.Logger.WithError(err).Error("Failed to fetch user token")
487-
return nil, err
488-
}
489-
490-
client := svc.oauthConf.Client(ctx, token)
491-
client.Timeout = 10 * time.Second
492-
493-
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/internal/lndhub/balance", albyOAuthAPIURL), nil)
494-
if err != nil {
495-
logger.Logger.WithError(err).Error("Error creating request to balance endpoint")
496-
return nil, err
497-
}
498-
499-
setDefaultRequestHeaders(req)
500-
501-
res, err := client.Do(req)
502-
if err != nil {
503-
logger.Logger.WithError(err).Error("Failed to fetch balance endpoint")
504-
return nil, err
505-
}
506-
507-
body, err := io.ReadAll(res.Body)
508-
if err != nil {
509-
logger.Logger.WithError(err).Error("Failed to read response body")
510-
return nil, errors.New("failed to read response body")
511-
}
512-
513-
if res.StatusCode >= 300 {
514-
logger.Logger.WithFields(logrus.Fields{
515-
"body": string(body),
516-
"status_code": res.StatusCode,
517-
}).Error("balance endpoint returned non-success code")
518-
return nil, fmt.Errorf("balance endpoint returned non-success code: %s", string(body))
519-
}
520-
521-
balance := &AlbyBalance{}
522-
err = json.Unmarshal(body, balance)
523-
if err != nil {
524-
logger.Logger.WithError(err).Error("Failed to decode API response")
525-
return nil, err
526-
}
527-
528-
logger.Logger.WithFields(logrus.Fields{"balance": balance}).Debug("Alby balance response")
529-
return balance, nil
530-
}
531-
532-
func (svc *albyOAuthService) SendPayment(ctx context.Context, invoice string) error {
533-
token, err := svc.fetchUserToken(ctx)
534-
if err != nil {
535-
logger.Logger.WithError(err).Error("Failed to fetch user token")
536-
return err
537-
}
538-
539-
client := svc.oauthConf.Client(ctx, token)
540-
client.Timeout = 10 * time.Second
541-
542-
type payRequest struct {
543-
Invoice string `json:"invoice"`
544-
}
545-
546-
body := bytes.NewBuffer([]byte{})
547-
payload := payRequest{
548-
Invoice: invoice,
549-
}
550-
err = json.NewEncoder(body).Encode(&payload)
551-
552-
if err != nil {
553-
logger.Logger.WithError(err).Error("Failed to encode request payload")
554-
return err
555-
}
556-
557-
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/internal/lndhub/bolt11", albyOAuthAPIURL), body)
558-
if err != nil {
559-
logger.Logger.WithError(err).Error("Error creating request bolt11 endpoint")
560-
return err
561-
}
562-
563-
setDefaultRequestHeaders(req)
564-
565-
resp, err := client.Do(req)
566-
if err != nil {
567-
logger.Logger.WithFields(logrus.Fields{
568-
"invoice": invoice,
569-
}).WithError(err).Error("Failed to pay invoice")
570-
return err
571-
}
572-
573-
type PayResponse struct {
574-
Preimage string `json:"payment_preimage"`
575-
PaymentHash string `json:"payment_hash"`
576-
}
577-
578-
if resp.StatusCode >= 300 {
579-
580-
type ErrorResponse struct {
581-
Error bool `json:"error"`
582-
Code int `json:"code"`
583-
Message string `json:"message"`
584-
}
585-
586-
errorPayload := &ErrorResponse{}
587-
err = json.NewDecoder(resp.Body).Decode(errorPayload)
588-
if err != nil {
589-
logger.Logger.WithFields(logrus.Fields{
590-
"status": resp.StatusCode,
591-
}).WithError(err).Error("Failed to decode payment error response payload")
592-
return err
593-
}
594-
595-
logger.Logger.WithFields(logrus.Fields{
596-
"invoice": invoice,
597-
"status": resp.StatusCode,
598-
"message": errorPayload.Message,
599-
}).Error("Payment failed")
600-
return errors.New(errorPayload.Message)
601-
}
602-
603-
responsePayload := &PayResponse{}
604-
err = json.NewDecoder(resp.Body).Decode(responsePayload)
605-
if err != nil {
606-
logger.Logger.WithError(err).Error("Failed to decode response payload")
607-
return err
608-
}
609-
logger.Logger.WithFields(logrus.Fields{
610-
"invoice": invoice,
611-
"paymentHash": responsePayload.PaymentHash,
612-
"preimage": responsePayload.Preimage,
613-
}).Info("Alby Payment successful")
614-
return nil
615-
}
616-
617482
func (svc *albyOAuthService) GetAuthUrl() string {
618483
return svc.oauthConf.AuthCodeURL("unused")
619484
}

alby/models.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ type AlbyOAuthService interface {
2424
IsConnected(ctx context.Context) bool
2525
LinkAccount(ctx context.Context, lnClient lnclient.LNClient, budget uint64, renewal string) error
2626
CallbackHandler(ctx context.Context, code string, lnClient lnclient.LNClient) error
27-
GetBalance(ctx context.Context) (*AlbyBalance, error)
2827
GetMe(ctx context.Context) (*AlbyMe, error)
29-
SendPayment(ctx context.Context, invoice string) error
3028
UnlinkAccount(ctx context.Context) error
3129
RequestAutoChannel(ctx context.Context, lnClient lnclient.LNClient, isPublic bool) (*AutoChannelResponse, error)
3230
GetVssAuthToken(ctx context.Context, nodeIdentifier string) (string, error)
@@ -40,14 +38,6 @@ type CreateLightningAddressResponse struct {
4038
FullAddress string `json:"full_address"`
4139
}
4240

43-
type AlbyBalanceResponse struct {
44-
Sats int64 `json:"sats"`
45-
}
46-
47-
type AlbyPayRequest struct {
48-
Invoice string `json:"invoice"`
49-
}
50-
5141
type AlbyLinkAccountRequest struct {
5242
Budget uint64 `json:"budget"`
5343
Renewal string `json:"renewal"`
@@ -106,12 +96,6 @@ type AlbyMe struct {
10696
Subscription AlbyMeSubscription `json:"subscription"`
10797
}
10898

109-
type AlbyBalance struct {
110-
Balance int64 `json:"balance"`
111-
Unit string `json:"unit"`
112-
Currency string `json:"currency"`
113-
}
114-
11599
type ChannelPeerSuggestion struct {
116100
Network string `json:"network"`
117101
PaymentMethod string `json:"paymentMethod"`

frontend/src/hooks/useAlbyBalance.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

frontend/src/screens/channels/first/FirstChannel.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { Checkbox } from "src/components/ui/checkbox";
1515
import { LoadingButton } from "src/components/ui/custom/loading-button";
1616
import { Label } from "src/components/ui/label";
1717
import { Separator } from "src/components/ui/separator";
18-
import { useAlbyBalance } from "src/hooks/useAlbyBalance";
1918
import { useChannels } from "src/hooks/useChannels";
2019

2120
import { useInfo } from "src/hooks/useInfo";
@@ -51,7 +50,6 @@ export function FirstChannel() {
5150
const navigate = useNavigate();
5251
const [invoice, setInvoice] = React.useState<string>();
5352
const [channelSize, setChannelSize] = React.useState<number>();
54-
const { data: albyBalance } = useAlbyBalance();
5553

5654
React.useEffect(() => {
5755
if (channels?.length) {
@@ -338,28 +336,7 @@ export function FirstChannel() {
338336
</Button>
339337
</div>
340338
)}
341-
{lspChannelOffer.currentPaymentMethod === "fee_credits" && (
342-
<>
343-
<p className="text-sm">
344-
You currently have{" "}
345-
<span className="font-medium text-foreground sensitive slashed-zero">
346-
{new Intl.NumberFormat().format(
347-
albyBalance?.sats || 0
348-
)}{" "}
349-
</span>{" "}
350-
Alby fee credits which will be used to open your first
351-
Lightning channel.{" "}
352-
<ExternalLink
353-
to="https://guides.getalby.com/user-guide/alby-account/faq/what-are-fee-credits-in-my-alby-account"
354-
className="underline"
355-
>
356-
Learn more
357-
</ExternalLink>
358-
</p>
359-
</>
360-
)}
361339
{lspChannelOffer.currentPaymentMethod !== "prepaid" &&
362-
lspChannelOffer.currentPaymentMethod !== "fee_credits" &&
363340
lspChannelOffer.currentPaymentMethod !== "included" && (
364341
<p className="text-xs text-muted-foreground flex items-center justify-center -mb-4">
365342
The payment for the channel will be due immediately.

frontend/src/types.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,7 @@ export type LSPChannelOffer = {
449449
lspBalanceSat: number;
450450
feeTotalSat: number;
451451
feeTotalUsd: number;
452-
currentPaymentMethod:
453-
| "card"
454-
| "wallet"
455-
| "prepaid"
456-
| "fee_credits"
457-
| "included";
452+
currentPaymentMethod: "card" | "wallet" | "prepaid" | "included";
458453
terms: string;
459454
};
460455

@@ -522,10 +517,6 @@ export type AlbyMe = {
522517
};
523518
};
524519

525-
export type AlbyBalance = {
526-
sats: number;
527-
};
528-
529520
export type LSPOrderRequest = {
530521
amount: number;
531522
lspType: LSPType;

http/alby_http_service.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ func (albyHttpSvc *AlbyHttpService) RegisterSharedRoutes(readOnlyApiGroup *echo.
3333
e.GET("/api/alby/info", albyHttpSvc.albyInfoHandler)
3434
e.GET("/api/alby/rates", albyHttpSvc.albyBitcoinRateHandler)
3535
readOnlyApiGroup.GET("/alby/me", albyHttpSvc.albyMeHandler)
36-
readOnlyApiGroup.GET("/alby/balance", albyHttpSvc.albyBalanceHandler)
37-
fullAccessApiGroup.POST("/alby/pay", albyHttpSvc.albyPayHandler)
3836
fullAccessApiGroup.POST("/alby/link-account", albyHttpSvc.albyLinkAccountHandler)
3937
fullAccessApiGroup.POST("/alby/auto-channel", albyHttpSvc.autoChannelHandler)
4038
fullAccessApiGroup.POST("/alby/unlink-account", albyHttpSvc.unlinkHandler)
@@ -137,39 +135,6 @@ func (albyHttpSvc *AlbyHttpService) albyMeHandler(c echo.Context) error {
137135
return c.JSON(http.StatusOK, me)
138136
}
139137

140-
func (albyHttpSvc *AlbyHttpService) albyBalanceHandler(c echo.Context) error {
141-
balance, err := albyHttpSvc.albyOAuthSvc.GetBalance(c.Request().Context())
142-
if err != nil {
143-
logger.Logger.WithError(err).Error("Failed to request alby balance endpoint")
144-
return c.JSON(http.StatusInternalServerError, ErrorResponse{
145-
Message: fmt.Sprintf("Failed to request alby balance endpoint: %s", err.Error()),
146-
})
147-
}
148-
149-
return c.JSON(http.StatusOK, &alby.AlbyBalanceResponse{
150-
Sats: balance.Balance,
151-
})
152-
}
153-
154-
func (albyHttpSvc *AlbyHttpService) albyPayHandler(c echo.Context) error {
155-
var payRequest alby.AlbyPayRequest
156-
if err := c.Bind(&payRequest); err != nil {
157-
return c.JSON(http.StatusBadRequest, ErrorResponse{
158-
Message: fmt.Sprintf("Bad request: %s", err.Error()),
159-
})
160-
}
161-
162-
err := albyHttpSvc.albyOAuthSvc.SendPayment(c.Request().Context(), payRequest.Invoice)
163-
if err != nil {
164-
logger.Logger.WithError(err).Error("Failed to request alby pay endpoint")
165-
return c.JSON(http.StatusInternalServerError, ErrorResponse{
166-
Message: fmt.Sprintf("Failed to request alby pay endpoint: %s", err.Error()),
167-
})
168-
}
169-
170-
return c.NoContent(http.StatusNoContent)
171-
}
172-
173138
func (albyHttpSvc *AlbyHttpService) albyLinkAccountHandler(c echo.Context) error {
174139
var linkAccountRequest alby.AlbyLinkAccountRequest
175140
if err := c.Bind(&linkAccountRequest); err != nil {

0 commit comments

Comments
 (0)