Adds Contract Utils (Caveats, Delegation)#45
Conversation
jeffsmale90
left a comment
There was a problem hiding this comment.
Looking nice! Couple pedantic comments about function signatures!
| export const caveatEnforcerActions = ({ | ||
| client, | ||
| config, | ||
| }: { | ||
| client: PublicClient; | ||
| config: CaveatEnforcerClientConfig; | ||
| }) => ({ |
There was a problem hiding this comment.
it makes for a somewhat awkward function signature, but I think caveatEnforcerActions should return a function that takes the client as the argument. ie.
const caveatEnforcerActions = (config) => (client) => {
return {...};
}
Then you can do this, instead of nesting the call to caveatEnforcerActions inside of an anonymous function:
const client = createPublicClient({...})
.extend(caveatEnforcerActions({ environment }));
There was a problem hiding this comment.
Sure, do you like the function createCaveatEnforcerClient or you prefer to call the function extend directly where it is needed client.extend(caveatEnforcerActions({ environment }));
There was a problem hiding this comment.
I definitely like the createCaveatEnforcerClient function, as that's the easiest way to access the functionality, but supporting the second is also nice - maybe the user already has a client that they want to add those actions to.
jeffsmale90
left a comment
There was a problem hiding this comment.
Looks great! A couple comments about any types in the tests, but nbd
| const randomBytes32 = (): Hex => randomBytes(32); | ||
|
|
||
| describe('Caveat Contract Methods', () => { | ||
| let publicClient: ReturnType<typeof createPublicClient>; |
There was a problem hiding this comment.
if you do this
| let publicClient: ReturnType<typeof createPublicClient>; | |
| let publicClient: PublicClient; |
you can remove the publicClient as any assertion when creating the CaveatClient
| const environmentWithoutDelegationManager = { | ||
| ...mockEnvironment, | ||
| DelegationManager: undefined, | ||
| } as any; |
There was a problem hiding this comment.
this could be as unknown as DeleGatorEnvironment to avoid unnecessary any types
📝 Description
Some caveats enforcers that distribute amounts require the user to call a function to know how many tokens the user has available. This PR adds new utilities for that function.
The delegations can be disabled and enabled at any time; this PR adds a function to validate the current state of a delegation.
🔄 What Changed?
List the specific changes made:
🚀 Why?
Explain the motivation behind these changes:
🧪 How to Test?
Describe how to test these changes:
List any breaking changes:
📋 Checklist
Check off completed items:
🔗 Related Issues
Link to related issues:
Related to # https://app.zenhub.com/workspaces/readable-permissions-67982ce51eb4360029b2c1a1/issues/gh/metamask/delegator-readable-permissions/268
Previous PR: #35