-
Notifications
You must be signed in to change notification settings - Fork 132
Add useFlowAuthz hook #2652
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
base: master
Are you sure you want to change the base?
Add useFlowAuthz hook #2652
Conversation
🦋 Changeset detectedLatest commit: b43788e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
||
interface UseFlowAuthzArgs { | ||
/** Custom authorization configuration, if not provided, uses current user's wallet authorization. */ | ||
customAuthz?: CustomAuthzConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customAuthz?: CustomAuthzConfig | |
authz?: CustomAuthzConfig |
for consistency with how we expose flowClient
in useFlowClient
hook. Unless you have strong opinions here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep it make sense
const fcl = useFlowClient({flowClient}) | ||
|
||
const authorization: AuthorizationFunction = useMemo(() => { | ||
if (customAuthz) { | ||
return ( | ||
account: Partial<InteractionAccount> | ||
): Partial<InteractionAccount> => { | ||
return { | ||
...account, | ||
addr: customAuthz.address, | ||
keyId: customAuthz.keyId ?? 0, | ||
signingFunction: customAuthz.signingFunction, | ||
} | ||
} | ||
} | ||
|
||
// Current user authorization as default | ||
return fcl.currentUser.authorization as any | ||
}, [fcl, customAuthz]) | ||
|
||
return authorization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const fcl = useFlowClient({flowClient}) | |
const authorization: AuthorizationFunction = useMemo(() => { | |
if (customAuthz) { | |
return ( | |
account: Partial<InteractionAccount> | |
): Partial<InteractionAccount> => { | |
return { | |
...account, | |
addr: customAuthz.address, | |
keyId: customAuthz.keyId ?? 0, | |
signingFunction: customAuthz.signingFunction, | |
} | |
} | |
} | |
// Current user authorization as default | |
return fcl.currentUser.authorization as any | |
}, [fcl, customAuthz]) | |
return authorization | |
const fcl = useFlowClient({flowClient}) | |
return authz || fcl.authz |
.changeset/light-mice-glow.md
Outdated
"@onflow/react-sdk": minor | ||
--- | ||
|
||
Added useFlowAuthz hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be more descriptive? It bubbles up tot release notes right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented 👍
Add a hook to easily retrieve or build an authorization function to be used for signing transactions.
Close #2645