-
Notifications
You must be signed in to change notification settings - Fork 45
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
Refactor state management with custom hooks for loading and error states #222
base: main
Are you sure you want to change the base?
Refactor state management with custom hooks for loading and error states #222
Conversation
- Use useMemo to ensure the client is only created when the config changes.
…ient" This reverts commit 0fe6c5c.
WalkthroughThe changes introduce custom React hooks, Changes
Poem
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- packages/react-sdk/src/hooks/useError.ts (1 hunks)
- packages/react-sdk/src/hooks/useLoading.ts (1 hunks)
- packages/react-sdk/src/resources/useDispute.ts (4 hunks)
- packages/react-sdk/src/resources/useIpAccount.ts (4 hunks)
- packages/react-sdk/src/resources/useIpAsset.ts (7 hunks)
- packages/react-sdk/src/resources/useLicense.ts (7 hunks)
- packages/react-sdk/src/resources/useNftClient.ts (2 hunks)
- packages/react-sdk/src/resources/usePermission.ts (6 hunks)
- packages/react-sdk/src/resources/useRoyalty.ts (7 hunks)
Additional comments not posted (51)
packages/react-sdk/src/hooks/useError.ts (3)
3-3
: Type definition looks good!The
ErrorState
type definition is correct and provides the necessary structure for error states.
5-13
: Hook implementation looks good!The
useErrors
hook correctly initializes the error state and provides a method to update it. UsinguseCallback
forsetError
is a good practice.
18-18
: Export statement looks good!The export statement correctly exports the
ErrorState
type and theuseErrors
hook.packages/react-sdk/src/hooks/useLoading.ts (3)
3-3
: Type definition looks good!The
LoadingState
type definition is correct and provides the necessary structure for loading states.
5-13
: Hook implementation looks good!The
useLoading
hook correctly initializes the loading state and provides a method to update it. UsinguseCallback
forsetLoading
is a good practice.
18-18
: Export statement looks good!The export statement correctly exports the
LoadingState
type and theuseLoading
hook.packages/react-sdk/src/resources/useNftClient.ts (4)
8-9
: Import statements look good!The import statements for
useLoading
anduseErrors
are correct and necessary for using the new hooks.
13-16
: Initialization of loading states looks good!The initialization of loading states using the
useLoading
hook is correct and follows the new approach.
16-16
: Initialization of error states looks good!The initialization of error states using the
useErrors
hook is correct and follows the new approach.
37-45
: Usage of the new hooks looks good!The usage of the new hooks
useLoading
anduseErrors
in thecreateNFTCollection
function is correct and simplifies the state management.packages/react-sdk/src/resources/useIpAccount.ts (6)
11-12
: Import statements look good!The import statements for
useLoading
anduseErrors
are correct and necessary for using the new hooks.
16-21
: Initialization of loading states looks good!The initialization of loading states using the
useLoading
hook is correct and follows the new approach.
21-21
: Initialization of error states looks good!The initialization of error states using the
useErrors
hook is correct and follows the new approach.
40-48
: Usage of the new hooks inexecute
function looks good!The usage of the new hooks
useLoading
anduseErrors
in theexecute
function is correct and simplifies the state management.
68-76
: Usage of the new hooks inexecuteWithSig
function looks good!The usage of the new hooks
useLoading
anduseErrors
in theexecuteWithSig
function is correct and simplifies the state management.
89-97
: Usage of the new hooks ingetIpAccountNonce
function looks good!The usage of the new hooks
useLoading
anduseErrors
in thegetIpAccountNonce
function is correct and simplifies the state management.packages/react-sdk/src/resources/useDispute.ts (5)
17-22
: Initialization of loading states looks good.The use of
useLoading
hook to manage loading states for specific dispute actions is a good approach.
22-24
: Initialization of error states looks good.The use of
useErrors
hook to manage error states for specific dispute actions is a good approach.
48-56
: Handling loading and error states looks good.The
raiseDispute
function correctly sets loading and error states using the custom hooks.
77-85
: Handling loading and error states looks good.The
cancelDispute
function correctly sets loading and error states using the custom hooks.
104-112
: Handling loading and error states looks good.The
resolveDispute
function correctly sets loading and error states using the custom hooks.packages/react-sdk/src/resources/useRoyalty.ts (8)
22-30
: Initialization of loading states looks good.The use of
useLoading
hook to manage loading states for specific royalty-related actions is a good approach.
30-32
: Initialization of error states looks good.The use of
useErrors
hook to manage error states for specific royalty-related actions is a good approach.
52-60
: Handling loading and error states looks good.The
collectRoyaltyTokens
function correctly sets loading and error states using the custom hooks.
79-87
: Handling loading and error states looks good.The
payRoyaltyOnBehalf
function correctly sets loading and error states using the custom hooks.
106-114
: Handling loading and error states looks good.The
claimableRevenue
function correctly sets loading and error states using the custom hooks.
134-142
: Handling loading and error states looks good.The
claimRevenue
function correctly sets loading and error states using the custom hooks.
159-167
: Handling loading and error states looks good.The
snapshot
function correctly sets loading and error states using the custom hooks.
181-191
: Handling loading and error states looks good.The
getRoyaltyVaultAddress
function correctly sets loading and error states using the custom hooks.packages/react-sdk/src/resources/useLicense.ts (8)
21-29
: Initialization of loading states looks good.The use of
useLoading
hook to manage loading states for specific license-related actions is a good approach.
29-31
: Initialization of error states looks good.The use of
useErrors
hook to manage error states for specific license-related actions is a good approach.
49-59
: Handling loading and error states looks good.The
registerNonComSocialRemixingPIL
function correctly sets loading and error states using the custom hooks.
77-85
: Handling loading and error states looks good.The
registerCommercialUsePIL
function correctly sets loading and error states using the custom hooks.
104-112
: Handling loading and error states looks good.The
registerCommercialRemixPIL
function correctly sets loading and error states using the custom hooks.
130-138
: Handling loading and error states looks good.The
attachLicenseTerms
function correctly sets loading and error states using the custom hooks.
169-177
: Handling loading and error states looks good.The
mintLicenseTokens
function correctly sets loading and error states using the custom hooks.
191-201
: Handling loading and error states looks good.The
getLicenseTerms
function correctly sets loading and error states using the custom hooks.packages/react-sdk/src/resources/usePermission.ts (7)
17-24
: Initialization of loading states looks good.The use of
useLoading
hook to manage loading states for specific permission-related actions is a good approach.
24-26
: Initialization of error states looks good.The use of
useErrors
hook to manage error states for specific permission-related actions is a good approach.
56-64
: Handling loading and error states looks good.The
setPermission
function correctly sets loading and error states using the custom hooks.
86-96
: Handling loading and error states looks good.The
createSetPermissionSignature
function correctly sets loading and error states using the custom hooks.
115-123
: Handling loading and error states looks good.The
setAllPermissions
function correctly sets loading and error states using the custom hooks.
146-154
: Handling loading and error states looks good.The
setBatchPermissions
function correctly sets loading and error states using the custom hooks.
177-187
: Handling loading and error states looks good.The
createBatchPermissionSignature
function correctly sets loading and error states using the custom hooks.packages/react-sdk/src/resources/useIpAsset.ts (7)
18-19
: Imports look good.The new hooks
useLoading
anduseErrors
are correctly imported.
58-66
: Changes inregister
function look good.The loading and error states are managed correctly using the new hooks.
88-96
: Changes inregisterDerivative
function look good.The loading and error states are managed correctly using the new hooks.
116-126
: Changes inregisterDerivativeWithLicenseTokens
function look good.The loading and error states are managed correctly using the new hooks.
153-163
: Changes inmintAndRegisterIpAssetWithPilTerms
function look good.The loading and error states are managed correctly using the new hooks.
190-200
: Changes inregisterIpAndAttachPilTerms
function look good.The loading and error states are managed correctly using the new hooks.
227-235
: Changes inregisterDerivativeIp
function look good.The loading and error states are managed correctly using the new hooks.
Overview
This PR refactors the state management for loading and error states by introducing custom hooks. The new approach uses generic types to dynamically handle different state keys, improving code maintainability and reducing repetition.
Changes
useLoading
hook to manage loading states.useErrors
hook to manage error states.Benefits
How to Test
Additional Notes
Summary by CodeRabbit
Refactor
useLoading
anduseErrors
to manage loading states and errors across various functions, replacing the previoususeState
approach.Bug Fixes
useDispute
,useIpAccount
,useIpAsset
,useLicense
,useNftClient
,usePermission
, anduseRoyalty
functions.These updates streamline state handling and enhance the user experience by providing more reliable and maintainable state management for various operations.