You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Convert AssetsContractController from BaseControllerV1 to BaseControllerV2 #4072
Considering that converting TokenDetectionController to BaseController v2 took longer than expected due to unforeseen changes, we want to be more conscientious about converting AssetsContractController.
Figure out all of the changes we would want to make in upgrading this controller, outline those changes here and create new tickets if appropriate.
changed the title [-](`assets-controllers`) AssetsContractController[/-][+]Convert AssetsContractController from BaseControllerV1 to BaseControllerV2[/+]on Mar 18, 2024
Move properties of this type to private class fields of the AssetsContractController class.
Set default values from this.defaultConfig object.
Replace this.configure calls with assignments to corresponding class fields.
constructor
Replace super call so that it conforms to V2 requirements.
Remove this.initialize()
Remove override name class field.
Replace all private keywords for class fields and methods with # prefix.
Refactor tests. Use withController pattern.
Consider replacing type annotation for SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID with satisfies keyword.
Note: This controller has an empty state object
May not need to be a controller class at all (i.e. should not extend from BaseControllerV2).
Could be modeled as collection of utility functions or as a service class instead.
Public class methods could be static methods instead of messenger actions.
Devise new API for downstream invocation of methods (currently using constructor option callbacks), or define messenger actions even if they don't interact with state?
All of the steps above are correct. Rename to not be called Controller and remove it from using the BaseController class. Whoever picks this up should decide how to make this class have the best api.
Acceptance criteria is basically we are not using BaseControllerV1 here.
Some functions seems to be just helper function used within the controller only for example getERC20Standard and getChainId which can be private instead
Activity
[-](`assets-controllers`) AssetsContractController[/-][+]Convert AssetsContractController from BaseControllerV1 to BaseControllerV2[/+]MajorLift commentedon May 23, 2024
Define internal messenger actions/events types.
AssetsContractControllerclass.AssetsContractControllerActions,AssetsContractControllerEvents,AssetsContractControllerGetStateAction(usingControllerGetStateActiontype),AssetsContractControllerStateChangeEvent(usingControllerStateChangeEventtype)Replace constructor option callbacks with messenger actions/events
onPreferencesStateChangePreferencesController:stateChangePreferencesControllerStateChangeEventonNetworkDidChangeNetworkController:networkDidChangeNetworkControllerNetworkDidChangeEventgetNetworkClientByIdNetworkController:getNetworkClientByIdNetworkControllerGetNetworkClientByIdActionAllowedActionsunion type and add the above as its members.subscribe()calls, using the existing listener logic.Define
AssetsContractControllerMessengerusing the types defined in the above bullet points.AssetsContractController extends BaseControllerV2.AssetsContractConfigAssetsContractControllerclass.this.defaultConfigobject.this.configurecalls with assignments to corresponding class fields.constructor
supercall so that it conforms to V2 requirements.this.initialize()Remove
override nameclass field.Replace all
privatekeywords for class fields and methods with#prefix.Refactor tests. Use
withControllerpattern.Consider replacing type annotation for
SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINIDwithsatisfieskeyword.Note: This controller has an empty state object
BaseControllerV2).desi commentedon May 23, 2024
All of the steps above are correct. Rename to not be called Controller and remove it from using the BaseController class. Whoever picks this up should decide how to make this class have the best api.
Acceptance criteria is basically we are not using BaseControllerV1 here.
cryptodev-2s commentedon May 23, 2024
Some functions seems to be just helper function used within the controller only for example
getERC20StandardandgetChainIdwhich can be private instead[assets-contract-controller] Apply messenger pattern and remove inher…
Add public `name` property to `AssetsContractController` class (#4564)
Add public `name` property to `AssetsContractController` class (#4564)