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

Fix/cleanup create app screen #118

Merged
merged 11 commits into from
Aug 7, 2023
Merged

Fix/cleanup create app screen #118

merged 11 commits into from
Aug 7, 2023

Conversation

kiwiidb
Copy link
Contributor

@kiwiidb kiwiidb commented Aug 3, 2023

There is currently an issue because there are several places where the pay_invoice permission is handled in a special way. In this PR this is mostly removed. This causes a bug in the current master where an app that has both get_balance and pay_invoice permissions is not in fact able to pay invoices.

  • We now create app_permissions based on what the client requests, no more special treatment of the pay_invoice permission.
  • From now on we never create an app without permissions.
  • budgets have no meaning for non-pay-invoice-requests.
  • Removes hard-coded front-end code for the permissions' description, this is now set from the backend.

@kiwiidb kiwiidb marked this pull request as ready for review August 3, 2023 11:26
@kiwiidb kiwiidb requested review from rolznz, bumi and im-adithya August 3, 2023 11:26
@rolznz
Copy link
Contributor

rolznz commented Aug 3, 2023

image

This looks a bit wrong now. I wonder if we should remove the top section? if now you can create an app without permission to do payments in some cases (for creating invoices in the future)

@bumi
Copy link
Contributor

bumi commented Aug 3, 2023

@stackingsaunter we probably need some hirachy in the permissions here now?

  • send payment
    • expiry
    • budget
  • create invoices
  • read the balance
    ...

for _, appPerm := range appPermissions {
if appPerm.RequestMethod == NIP_47_PAY_INVOICE_METHOD {
//find the pay_invoice-specific permissions
Copy link
Contributor

@rolznz rolznz Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is no pay permission for this app? won't this break? (Edit: for example the expiry will not show on the show screen currently)

Copy link
Contributor

@rolznz rolznz Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be renamed to appPayInvoicePermission?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name it paySpecificPermission or something like that then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the AppPermission is the wrong place for the expiry, since it should be the same across all permissions for an app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any problems with it. Yes it will be the same across all permissions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get the first permission of the app if it exists then to display the expiry in show.html? right now it will not show the expiry for apps that don't have a pay permission

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really don't wish to give payInvoice special treatment then ig we shouldn't also send the paySpecificPermission to the frontend separately. Let's send ExpiresAt, MaxAmount and BudgetRenewal just like we send BudgetUsage

renewsIn := ""
budgetRenewal := ""
budgetUsage := int64(0)
maxAmount := 0
expiresAt := time.Time{}

for _, appPerm := range appPermissions {
	if expiresAt.isZero() && !appPerm.ExpiresAt.isZero() {
		expiresAt = appPerm.ExpiresAt
	}
	if appPerm.RequestMethod == NIP_47_PAY_INVOICE_METHOD {
		//find the pay_invoice-specific permissions
		if appPerm.MaxAmount > 0 {
			budgetUsage = svc.GetBudgetUsage(&appPerm)
			budgetRenewal = appPerm.BudgetRenewal
			endOfBudget := GetEndOfBudget(budgetRenewal, app.CreatedAt)
			renewsIn = getEndOfBudgetString(endOfBudget)
		}
	}
	requestMethods = append(requestMethods, nip47MethodDescriptions[appPerm.RequestMethod])
}

// and then send all of them to frontend

@kiwiidb
Copy link
Contributor Author

kiwiidb commented Aug 3, 2023

This looks a bit wrong now. I wonder if we should remove the top section? if now you can create an app without permission to do payments in some cases (for creating invoices in the future)

We can probably put the bottom section on top and drop the top section, yes.

@kiwiidb
Copy link
Contributor Author

kiwiidb commented Aug 3, 2023

All permissions can have an expiry. And I would just leave the budget like it is and have it be meaningless when set for non-paying requests.

@kiwiidb
Copy link
Contributor Author

kiwiidb commented Aug 4, 2023

  • Return ExpiresAt seperately if is present in one of the permissions.
  • Move the permission choice up and remove the redundant permissions summary.

@kiwiidb kiwiidb requested a review from rolznz August 4, 2023 16:07
echo_handlers.go Outdated
renewsIn = getEndOfBudgetString(endOfBudget)
}

return c.Render(http.StatusOK, "apps/show.html", map[string]interface{}{
"App": app,
"AppPermission": appPermission,
"AppPermission": paySpecificPermission,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could "AppPermission" also be renamed?

{{end}}
{{end}}
{{ if not .AppPermission.ExpiresAt.IsZero}}
{{ if not .ExpiresAt.IsZero}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few lines down it uses the wrong value {{.AppPermission.ExpiresAt}} should be {{.ExpiresAt}}

@kiwiidb kiwiidb merged commit 7fa1aa3 into main Aug 7, 2023
@kiwiidb kiwiidb deleted the fix/cleanup-create-app-screen branch August 7, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants