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

feat: revamp permissions component #14

Closed
wants to merge 21 commits into from
Closed

Conversation

im-adithya
Copy link
Member

@im-adithya im-adithya commented Jul 5, 2024

Screenshots

No Params

Screenshot 2024-07-12 at 7 58 20 PM

max_amount=172166

Screenshot 2024-07-12 at 7 59 17 PM

expires_at=1721673000

Screenshot 2024-07-12 at 7 58 45 PM

request_methods=make_invoice pay_invoice&max_amount=172166

Screenshot 2024-07-12 at 7 59 49 PM

request_methods=make_invoice pay_invoice&expires_at=1721673000

Screenshot 2024-07-12 at 8 00 37 PM

request_methods=make_invoice pay_invoice&expires_at=1721673000

Screenshot 2024-07-12 at 8 00 37 PM

request_methods=make_invoice pay_invoice&expires_at=1721673000&max_amount=212121

Screenshot 2024-07-12 at 8 04 43 PM

@im-adithya im-adithya marked this pull request as draft July 5, 2024 08:47
@im-adithya im-adithya marked this pull request as ready for review July 9, 2024 07:11
frontend/src/types.ts Outdated Show resolved Hide resolved
frontend/src/types.ts Outdated Show resolved Hide resolved
@rolznz
Copy link
Contributor

rolznz commented Jul 10, 2024

@im-adithya we had a meeting with @stackingsaunter and @reneaaron to review this, and the implementation is not the same as I thought we agreed upon. If an app passes anything in, then that should not be able to be edited.

And the scope group of "Send and Receive" makes no sense to me as a default if it discards ALL the scopes except for those two scopes. Why do we do that? why do we want to restrict apps to only these two scopes by default?

@im-adithya im-adithya marked this pull request as draft July 11, 2024 14:08
};

export const scopeGroupDescriptions: Record<ScopeGroupType, string> = {
[SCOPE_GROUP_FULL_ACCESS]: "Complete wallet control",
Copy link
Member Author

Choose a reason for hiding this comment

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

Review scope group descriptions

NIP_47_GET_INFO_METHOD,
NIP_47_LOOKUP_INVOICE_METHOD,
NIP_47_LIST_TRANSACTIONS_METHOD,
NIP_47_NOTIFICATIONS_PERMISSION,
Copy link
Member Author

Choose a reason for hiding this comment

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

Are these good for Read Only Scopes?

Copy link
Contributor

Choose a reason for hiding this comment

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

note: the variables you used are not even scopes (as you see _METHOD etc)

)}
{capabilities.scopes.includes(NIP_47_PAY_INVOICE_METHOD) &&
permissions.scopes.has(NIP_47_PAY_INVOICE_METHOD) &&
(!isBudgetAmountEditable ? (
Copy link
Member Author

Choose a reason for hiding this comment

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

If budget amount is set and budget renewal isn't (in the params) then it assumes renewal as "Monthly" and the user can't change it. Avoiding option to edit budget renewal in these cases as that adds unnecessary complexity.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if the default should be never in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I believe default should be never. Budgets from a deeplink-created app are different than the default user flow, and monthly in this case does not make sense

);
const [isExpiryEditable, setExpiryEditable] = React.useState(
isNewConnection ? !initialPermissions.expiresAt : canEditPermissions
);
Copy link
Member Author

Choose a reason for hiding this comment

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

Current flow (given nothing is passed in parameters)
permissions are set in NewApp as

scopes: []
maxAmount:NaN (as AppPermissions type expects a number)
expiresAt: undefined (thankfully it expects Date | undefined)

And hence we use these checks to identify if the params had any permission data

Copy link
Contributor

Choose a reason for hiding this comment

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

Using NaN seems a bit strange, I'll take a look and see if there's another way

const handlePermissionsChange = React.useCallback(
(changedPermissions: Partial<AppPermissions>) => {
const updatedPermissions = { ...permissions, ...changedPermissions };
setPermissions(updatedPermissions);
Copy link
Member Author

Choose a reason for hiding this comment

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

Setting local permissions separately as depending on initialPermissions might cause issues due to param data being changed. (Param data is only set from permissions and not initialPermissions so it doesn't change when it is updated, and the isEditable states are not disturbed post that in NewApp screen)

try {
const createAppRequest: CreateAppRequest = {
name: appName,
pubkey,
budgetRenewal: permissions.budgetRenewal,
maxAmount: permissions.maxAmount,
maxAmount: permissions.maxAmount || 0,
Copy link
Member Author

Choose a reason for hiding this comment

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

^if user doesn't change and it stays in NaN
This whole NaN thing feels hacky, but changing maxAmount to number | undefined would need a lot of changes

@im-adithya im-adithya marked this pull request as ready for review July 12, 2024 14:36
}, [capabilities.scopes]);

const [scopeGroup, setScopeGroup] = React.useState<ScopeGroup>(() => {
if (!scopes.size || isSetEqual(scopes, fullAccessScopes)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to do this, if an app passes in any request methods it can just be the custom option

return SCOPE_GROUP_CUSTOM;
});

// we need scopes to be empty till this point for isScopesEditable
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment sounds like a hack

same with // stop setting scopes on re-renders

export const NIP_47_MULTI_PAY_KEYSEND_METHOD = "multi_pay_keysend";
export const NIP_47_MULTI_PAY_INVOICE_METHOD = "multi_pay_invoice";

export const SCOPE_GROUP_FULL_ACCESS = "full_access";
Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to only put types here which are used in multiple files.

Also, there is a mix of these constant variables, and string unions. We should be consistent here

) {
scopes.add("pay_invoice");
scopes.add(NIP_47_PAY_INVOICE_METHOD);
Copy link
Contributor

Choose a reason for hiding this comment

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

Scopes are not the same as methods.

@rolznz
Copy link
Contributor

rolznz commented Jul 14, 2024

@im-adithya there are a lot of issues here still and some things that are fundamentally wrong, and this will take too long to fix if I keep adding review comments like this. We also need to ensure this works with the new isolated app type, so I have started a new branch off of this one, started cleaning things up, and have also merged the dynamic budgets PR into it. I will be continuing there: #273

Please read through my commits to get an idea of what I have changed and let me know if you have any questions.

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.

2 participants