Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
chore: renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jun 28, 2024
1 parent f0c70c8 commit 95a1b89
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 31 deletions.
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (api *api) GetBalances(ctx context.Context) (*BalancesResponse, error) {
}

// TODO: accept offset, limit params for pagination
func (api *api) GetTransactions(ctx context.Context) (*TransactionsResponse, error) {
func (api *api) GetTransactions(ctx context.Context) (*ListTransactionsResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
Expand All @@ -516,7 +516,7 @@ func (api *api) SendPayment(ctx context.Context, invoice string) (*SendPaymentRe
return resp, nil
}

func (api *api) CreateInvoice(ctx context.Context, amount int64, description string) (*CreateInvoiceResponse, error) {
func (api *api) CreateInvoice(ctx context.Context, amount int64, description string) (*MakeInvoiceResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
Expand Down
12 changes: 6 additions & 6 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type API interface {
SignMessage(ctx context.Context, message string) (*SignMessageResponse, error)
RedeemOnchainFunds(ctx context.Context, toAddress string) (*RedeemOnchainFundsResponse, error)
GetBalances(ctx context.Context) (*BalancesResponse, error)
GetTransactions(ctx context.Context) (*TransactionsResponse, error)
GetTransactions(ctx context.Context) (*ListTransactionsResponse, error)
SendPayment(ctx context.Context, invoice string) (*SendPaymentResponse, error)
CreateInvoice(ctx context.Context, amount int64, description string) (*CreateInvoiceResponse, error)
CreateInvoice(ctx context.Context, amount int64, description string) (*MakeInvoiceResponse, error)
LookupInvoice(ctx context.Context, paymentHash string) (*LookupInvoiceResponse, error)
RequestMempoolApi(endpoint string) (interface{}, error)
GetInfo(ctx context.Context) (*InfoResponse, error)
Expand Down Expand Up @@ -184,9 +184,9 @@ type OnchainBalanceResponse = lnclient.OnchainBalanceResponse
type BalancesResponse = lnclient.BalancesResponse

type SendPaymentResponse = lnclient.PayInvoiceResponse
type CreateInvoiceResponse = lnclient.Transaction
type MakeInvoiceResponse = lnclient.Transaction
type LookupInvoiceResponse = lnclient.Transaction
type TransactionsResponse = []lnclient.Transaction
type ListTransactionsResponse = []lnclient.Transaction

// debug api
type SendPaymentProbesRequest struct {
Expand Down Expand Up @@ -228,11 +228,11 @@ type SignMessageResponse struct {
Signature string `json:"signature"`
}

type WalletSendRequest struct {
type SendPaymentRequest struct {
Invoice string `json:"invoice"`
}

type WalletReceiveRequest struct {
type MakeInvoiceRequest struct {
Amount int64 `json:"amount"`
Description string `json:"description"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const pollConfiguration: SWRConfiguration = {
refreshInterval: 3000,
};

export function useInvoice(invoice: string, poll = false) {
export function useTransaction(paymentHash: string, poll = false) {
return useSWR<Transaction>(
invoice && `/api/invoice/${invoice}`,
paymentHash && `/api/invoice/${paymentHash}`,
swrFetcher,
poll ? pollConfiguration : undefined
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/screens/wallet/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Label } from "src/components/ui/label";
import { LoadingButton } from "src/components/ui/loading-button";
import { useToast } from "src/components/ui/use-toast";
import { useCSRF } from "src/hooks/useCSRF";
import { useInvoice } from "src/hooks/useInvoice";
import { useTransaction } from "src/hooks/useTransaction";
import { copyToClipboard } from "src/lib/clipboard";
import { CreateInvoiceRequest, Transaction } from "src/types";
import { request } from "src/utils/request";
Expand All @@ -29,7 +29,7 @@ export default function Receive() {
const [description, setDescription] = React.useState<string>("");
const [invoice, setInvoice] = React.useState<Transaction | null>(null);
const [paymentDone, setPaymentDone] = React.useState(false);
const { data: invoiceData } = useInvoice(
const { data: invoiceData } = useTransaction(
invoice ? invoice.payment_hash : "",
true
);
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/screens/wallet/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,10 @@ export default function Send() {
}}
/>
<Button
type="button"
variant="outline"
className="px-2"
onClick={(e) => {
paste();
}}
onClick={paste}
>
<ClipboardPaste className="w-4 h-4" />
</Button>
Expand Down
20 changes: 10 additions & 10 deletions http/http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func (httpSvc *HttpService) RegisterSharedRoutes(e *echo.Echo) {
e.POST("/api/wallet/redeem-onchain-funds", httpSvc.redeemOnchainFundsHandler, authMiddleware)
e.POST("/api/wallet/sign-message", httpSvc.signMessageHandler, authMiddleware)
e.POST("/api/wallet/sync", httpSvc.walletSyncHandler, authMiddleware)
e.POST("/api/wallet/send", httpSvc.sendHandler, authMiddleware)
e.POST("/api/wallet/send", httpSvc.sendPaymentHandler, authMiddleware)
e.POST("/api/wallet/receive", httpSvc.receiveHandler, authMiddleware)
e.GET("/api/transactions", httpSvc.transactionsHandler, authMiddleware)
e.GET("/api/transactions", httpSvc.listTransactionsHandler, authMiddleware)
e.GET("/api/invoice/:paymentHash", httpSvc.lookupInvoiceHandler, authMiddleware)
e.GET("/api/balances", httpSvc.balancesHandler, authMiddleware)
e.POST("/api/reset-router", httpSvc.resetRouterHandler, authMiddleware)
Expand Down Expand Up @@ -396,15 +396,15 @@ func (httpSvc *HttpService) balancesHandler(c echo.Context) error {
return c.JSON(http.StatusOK, balances)
}

func (httpSvc *HttpService) sendHandler(c echo.Context) error {
var walletSendRequest api.WalletSendRequest
if err := c.Bind(&walletSendRequest); err != nil {
func (httpSvc *HttpService) sendPaymentHandler(c echo.Context) error {
var sendPaymentRequest api.SendPaymentRequest
if err := c.Bind(&sendPaymentRequest); err != nil {
return c.JSON(http.StatusBadRequest, ErrorResponse{
Message: fmt.Sprintf("Bad request: %s", err.Error()),
})
}

paymentResponse, err := httpSvc.api.SendPayment(c.Request().Context(), walletSendRequest.Invoice)
paymentResponse, err := httpSvc.api.SendPayment(c.Request().Context(), sendPaymentRequest.Invoice)

if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Expand All @@ -416,14 +416,14 @@ func (httpSvc *HttpService) sendHandler(c echo.Context) error {
}

func (httpSvc *HttpService) receiveHandler(c echo.Context) error {
var walletReceiveRequest api.WalletReceiveRequest
if err := c.Bind(&walletReceiveRequest); err != nil {
var makeInvoiceRequest api.MakeInvoiceRequest
if err := c.Bind(&makeInvoiceRequest); err != nil {
return c.JSON(http.StatusBadRequest, ErrorResponse{
Message: fmt.Sprintf("Bad request: %s", err.Error()),
})
}

invoice, err := httpSvc.api.CreateInvoice(c.Request().Context(), walletReceiveRequest.Amount, walletReceiveRequest.Description)
invoice, err := httpSvc.api.CreateInvoice(c.Request().Context(), makeInvoiceRequest.Amount, makeInvoiceRequest.Description)

if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Expand All @@ -448,7 +448,7 @@ func (httpSvc *HttpService) lookupInvoiceHandler(c echo.Context) error {
return c.JSON(http.StatusOK, paymentInfo)
}

func (httpSvc *HttpService) transactionsHandler(c echo.Context) error {
func (httpSvc *HttpService) listTransactionsHandler(c echo.Context) error {
ctx := c.Request().Context()

transactions, err := httpSvc.api.GetTransactions(ctx)
Expand Down
12 changes: 6 additions & 6 deletions wails/wails_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ func (app *WailsApp) WailsRequestRouter(route string, method string, body string
res := WailsRequestRouterResponse{Body: *balancesResponse, Error: ""}
return res
case "/api/wallet/send":
walletSendRequest := &api.WalletSendRequest{}
err := json.Unmarshal([]byte(body), walletSendRequest)
sendPaymentRequest := &api.SendPaymentRequest{}
err := json.Unmarshal([]byte(body), sendPaymentRequest)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"route": route,
Expand All @@ -349,15 +349,15 @@ func (app *WailsApp) WailsRequestRouter(route string, method string, body string
}).WithError(err).Error("Failed to decode request to wails router")
return WailsRequestRouterResponse{Body: nil, Error: err.Error()}
}
paymentResponse, err := app.api.SendPayment(ctx, walletSendRequest.Invoice)
paymentResponse, err := app.api.SendPayment(ctx, sendPaymentRequest.Invoice)
if err != nil {
return WailsRequestRouterResponse{Body: nil, Error: err.Error()}
}
res := WailsRequestRouterResponse{Body: paymentResponse, Error: ""}
return res
case "/api/wallet/receive":
walletReceiveRequest := &api.WalletReceiveRequest{}
err := json.Unmarshal([]byte(body), walletReceiveRequest)
makeInvoiceRequest := &api.MakeInvoiceRequest{}
err := json.Unmarshal([]byte(body), makeInvoiceRequest)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"route": route,
Expand All @@ -366,7 +366,7 @@ func (app *WailsApp) WailsRequestRouter(route string, method string, body string
}).WithError(err).Error("Failed to decode request to wails router")
return WailsRequestRouterResponse{Body: nil, Error: err.Error()}
}
invoice, err := app.api.CreateInvoice(ctx, walletReceiveRequest.Amount, walletReceiveRequest.Description)
invoice, err := app.api.CreateInvoice(ctx, makeInvoiceRequest.Amount, makeInvoiceRequest.Description)
if err != nil {
return WailsRequestRouterResponse{Body: nil, Error: err.Error()}
}
Expand Down

0 comments on commit 95a1b89

Please sign in to comment.