disablePlugin method
Disables a plugin for the smart wallet.
This function checks if the smart wallet is initialized, then verifies if the plugin is already disabled. If the plugin is not disabled, it sends a transaction to disable the plugin and returns the transaction hash.
Parameters:
pluginAddress: The address of the plugin to be disabled.
Returns:
- A Future
Throws:
- Exception if the smart wallet is not initialized or if the plugin is already disabled.
Implementation
Future<String> disablePlugin(String pluginAddress) async {
await checkIfInitialized();
if (!isInitialized!) throw Exception("Smart wallet not initialized");
try {
bool isEnabled = await isPluginEnabled(pluginAddress);
if (!isEnabled) throw Exception("Plugin already disabled");
String previousPluginAddress =
await _getPreviousPluginAddress(pluginAddress: pluginAddress);
TransactionResponse txResponse = await contract
.send("disableModule", [previousPluginAddress, pluginAddress]);
return txResponse.hash;
} catch (e) {
// Print any error that occurs during the process and throw a new exception with an error message.
print(e);
throw Exception("Could not disable plugin");
}
}