Skip to content
Merged
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
9 changes: 5 additions & 4 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type API interface {
CreateApp(createAppRequest *CreateAppRequest) (*CreateAppResponse, error)
UpdateApp(app *db.App, updateAppRequest *UpdateAppRequest) error
Transfer(ctx context.Context, fromAppId *uint, toAppId *uint, amountMsat uint64) error
Transfer(ctx context.Context, fromAppId *uint, toAppId *uint, amountMsat uint64, description string) error
DeleteApp(app *db.App) error
GetApp(app *db.App) (*App, error)
ListApps(limit uint64, offset uint64, filters ListAppsFilters, orderBy string) (*ListAppsResponse, error)
Expand Down Expand Up @@ -131,9 +131,10 @@ type UpdateAppRequest struct {
}

type TransferRequest struct {
AmountSat uint64 `json:"amountSat"`
FromAppId *uint `json:"fromAppId"`
ToAppId *uint `json:"toAppId"`
AmountSat uint64 `json:"amountSat"`
FromAppId *uint `json:"fromAppId"`
ToAppId *uint `json:"toAppId"`
Description string `json:"description"`
}

type CreateAppRequest struct {
Expand Down
9 changes: 7 additions & 2 deletions api/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func toApiTransaction(transaction *transactions.Transaction) *Transaction {
}
}

func (api *api) Transfer(ctx context.Context, fromAppId *uint, toAppId *uint, amountMsat uint64) error {
func (api *api) Transfer(ctx context.Context, fromAppId *uint, toAppId *uint, amountMsat uint64, description string) error {
lnClient := api.svc.GetLNClient()
if lnClient == nil {
return errors.New("LNClient not started")
Expand All @@ -150,7 +150,12 @@ func (api *api) Transfer(ctx context.Context, fromAppId *uint, toAppId *uint, am
}
}

transaction, err := api.svc.GetTransactionsService().MakeInvoice(ctx, amountMsat, "transfer", "", 0, nil, lnClient, toAppId, nil, nil)
// default to "transfer"
if description == "" {
description = "transfer"
}

transaction, err := api.svc.GetTransactionsService().MakeInvoice(ctx, amountMsat, description, "", 0, nil, lnClient, toAppId, nil, nil)

if err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/components/IsolatedAppDrawDownDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function IsolatedAppDrawDownDialog({
}: React.PropsWithChildren<IsolatedAppTopupProps>) {
const { mutate: reloadApp } = useApp(appId);
const [amountSat, setAmountSat] = React.useState("");
const [description, setDescription] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [open, setOpen] = React.useState(false);
async function onSubmit(e: React.FormEvent) {
Expand All @@ -40,6 +41,7 @@ export function IsolatedAppDrawDownDialog({
body: JSON.stringify({
fromAppId: appId,
amountSat: +amountSat,
description,
}),
});
await reloadApp();
Expand All @@ -54,6 +56,7 @@ export function IsolatedAppDrawDownDialog({
function reset() {
setOpen(false);
setAmountSat("");
setDescription("");
}

return (
Expand All @@ -80,6 +83,18 @@ export function IsolatedAppDrawDownDialog({
}}
/>
</div>
<div className="grid gap-2 mt-3">
<Label htmlFor="description">Description (optional)</Label>
<Input
id="description"
type="text"
placeholder="transfer"
value={description}
onChange={(e) => {
setDescription(e.target.value);
}}
/>
</div>
<DialogFooter className="mt-5">
<LoadingButton loading={loading}>Decrease</LoadingButton>
</DialogFooter>
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/components/IsolatedAppTopupDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function IsolatedAppTopupDialog({
}: React.PropsWithChildren<IsolatedAppTopupProps>) {
const { mutate: reloadApp } = useApp(appId);
const [amountSat, setAmountSat] = React.useState("");
const [description, setDescription] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [open, setOpen] = React.useState(false);
async function onSubmit(e: React.FormEvent) {
Expand All @@ -40,6 +41,7 @@ export function IsolatedAppTopupDialog({
body: JSON.stringify({
toAppId: appId,
amountSat: +amountSat,
description,
}),
});
await reloadApp();
Expand All @@ -54,6 +56,7 @@ export function IsolatedAppTopupDialog({
function reset() {
setOpen(false);
setAmountSat("");
setDescription("");
}

return (
Expand Down Expand Up @@ -82,6 +85,18 @@ export function IsolatedAppTopupDialog({
}}
/>
</div>
<div className="grid gap-2 mt-3">
<Label htmlFor="description">Description (optional)</Label>
<Input
id="description"
type="text"
placeholder="transfer"
value={description}
onChange={(e) => {
setDescription(e.target.value);
}}
/>
</div>
<DialogFooter className="mt-5">
<LoadingButton loading={loading}>Increase</LoadingButton>
</DialogFooter>
Expand Down
2 changes: 1 addition & 1 deletion http/http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ func (httpSvc *HttpService) transfersHandler(c echo.Context) error {
})
}

err := httpSvc.api.Transfer(c.Request().Context(), requestData.FromAppId, requestData.ToAppId, requestData.AmountSat*1000)
err := httpSvc.api.Transfer(c.Request().Context(), requestData.FromAppId, requestData.ToAppId, requestData.AmountSat*1000, requestData.Description)

if err != nil {
logger.Logger.WithError(err).Error("Failed to transfer funds")
Expand Down
3 changes: 2 additions & 1 deletion wails/wails_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ 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()}
}
err = app.api.Transfer(ctx, transferRequest.FromAppId, transferRequest.ToAppId, transferRequest.AmountSat*1000)

err = app.api.Transfer(ctx, transferRequest.FromAppId, transferRequest.ToAppId, transferRequest.AmountSat*1000, transferRequest.Description)
if err != nil {
return WailsRequestRouterResponse{Body: nil, Error: err.Error()}
}
Expand Down
Loading