Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: correctly handle query parameters in new UI (WIP) #155

Merged
merged 6 commits into from
Nov 6, 2023
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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ As data storage SQLite or PostgreSQL (recommended) can be used.

## Development

`go run .`
`go run .` or `gow -e=go,mod,html,css run .` using [gow](https://github.com/mitranim/gow)

To build the CSS run:

Expand Down Expand Up @@ -83,7 +83,6 @@ If the client creates the secret the client only needs to share the public key o
- `expires_at` (optional) connection cannot be used after this date. Unix timestamp in seconds.
- `max_amount` (optional) maximum amount in sats that can be sent per renewal period
- `budget_renewal` (optional) reset the budget at the end of the given budget renewal. Can be `never` (default), `daily`, `weekly`, `monthly`, `yearly`
- `editable` (optional) set to `false` to disable form editing by the user
- `request_methods` (optional) url encoded, space separated list of request types that you need permission for: `pay_invoice` (default), `get_balance` (see NIP47). For example: `..&request_methods=pay_invoice%20get_balance`

Example:
Expand Down
41 changes: 28 additions & 13 deletions echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func (svc *Service) AppsShowHandler(c echo.Context) error {
requestMethods = append(requestMethods, nip47MethodDescriptions[appPerm.RequestMethod])
}

expiresAtFormatted := expiresAt.Format("January 2, 2006 03:04 PM")

renewsIn := ""
budgetUsage := int64(0)
maxAmount := paySpecificPermission.MaxAmount
Expand All @@ -201,6 +203,7 @@ func (svc *Service) AppsShowHandler(c echo.Context) error {
"PaySpecificPermission": paySpecificPermission,
"RequestMethods": requestMethods,
"ExpiresAt": expiresAt,
"ExpiresAtFormatted": expiresAtFormatted,
"User": user,
"LastEvent": lastEvent,
"EventsCount": eventsCount,
Expand Down Expand Up @@ -250,8 +253,11 @@ func (svc *Service) AppsNewHandler(c echo.Context) error {
if expiresAtTimestamp, err := strconv.Atoi(expiresAt); err == nil {
expiresAt = time.Unix(int64(expiresAtTimestamp), 0).Format(time.RFC3339)
}
disabled := c.QueryParam("editable") == "false"
expiresAtISO, _ := time.Parse(time.RFC3339, expiresAt)
expiresAtFormatted := expiresAtISO.Format("January 2, 2006 03:04 PM")

requestMethods := c.QueryParam("request_methods")
customRequestMethods := requestMethods
if requestMethods == "" {
// if no request methods are given, enable them all by default
keys := []string{}
Expand Down Expand Up @@ -302,17 +308,18 @@ func (svc *Service) AppsNewHandler(c echo.Context) error {
}

return c.Render(http.StatusOK, "apps/new.html", map[string]interface{}{
"User": user,
"Name": appName,
"Pubkey": pubkey,
"ReturnTo": returnTo,
"MaxAmount": maxAmount,
"BudgetRenewal": budgetRenewal,
"ExpiresAt": expiresAt,
"RequestMethods": requestMethods,
"RequestMethodHelper": requestMethodHelper,
"Disabled": disabled,
"Csrf": csrf,
"User": user,
"Name": appName,
"Pubkey": pubkey,
"ReturnTo": returnTo,
"MaxAmount": maxAmount,
"BudgetRenewal": budgetRenewal,
"ExpiresAt": expiresAt,
"ExpiresAtFormatted": expiresAtFormatted,
"RequestMethods": requestMethods,
"CustomRequestMethods": customRequestMethods,
"RequestMethodHelper": requestMethodHelper,
"Csrf": csrf,
})
}

Expand Down Expand Up @@ -343,7 +350,15 @@ func (svc *Service) AppsCreateHandler(c echo.Context) error {
app := App{Name: name, NostrPubkey: pairingPublicKey}
maxAmount, _ := strconv.Atoi(c.FormValue("MaxAmount"))
budgetRenewal := c.FormValue("BudgetRenewal")
expiresAt, _ := time.Parse("2006-01-02", c.FormValue("ExpiresAt"))

expiresAt := time.Time{}
if c.FormValue("ExpiresAt") != "" {
expiresAt, err = time.Parse(time.RFC3339, c.FormValue("ExpiresAt"))
if (err != nil) {
return fmt.Errorf("Invalid ExpiresAt: %v", err)
}
}

if !expiresAt.IsZero() {
expiresAt = time.Date(expiresAt.Year(), expiresAt.Month(), expiresAt.Day(), 23, 59, 59, 0, expiresAt.Location())
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"css": "npx tailwindcss -i ./views/application.css -o ./public/css/application.css --watch"
"css": "tailwindcss -i ./views/application.css -o ./public/css/application.css --watch"
},
"devDependencies": {
"@tailwindcss/aspect-ratio": "^0.4.2",
Expand Down
Loading
Loading