diff --git a/example/pubspec.lock b/example/pubspec.lock index 9c46e8f..979e942 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -683,7 +683,7 @@ packages: path: ".." relative: true source: path - version: "0.1.5" + version: "0.1.6" vector_math: dependency: transitive description: diff --git a/lib/src/4337/wallet.dart b/lib/src/4337/wallet.dart index 41336dc..70aa268 100644 --- a/lib/src/4337/wallet.dart +++ b/lib/src/4337/wallet.dart @@ -148,25 +148,33 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { @override Future sendUserOperation(UserOperation op) => - prepareUserOperation(op) - .then(applyCustomGasSettings) - .then(signUserOperation) - .then(sendSignedUserOperation); + _prepareAndSignOperation(op).then(sendSignedUserOperation); + + Future _prepareAndSignOperation(UserOperation op) async { + final prepared = await prepareUserOperation(op); + return signUserOperation(prepared); + } @override Future prepareUserOperation(UserOperation op, {bool update = true}) async { - // Update the user operation with the latest nonce and gas prices if needed - if (update) op = await _updateUserOperation(op); - // If the 'paymaster' plugin is enabled, intercept the user operation - if (hasPlugin('paymaster')) { - op = await plugin('paymaster').intercept(op); - } - // Validate the user operation + op = await _updateIfNeeded(op, update); + op = await _applyPlugins(op); op.validate(op.nonce > BigInt.zero, initCode); return op; } + Future _updateIfNeeded(UserOperation op, bool update) async { + if (!update) return op; + op = await _updateUserOperation(op); + return applyCustomGasSettings(op); + } + + Future _applyPlugins(UserOperation op) async { + if (!hasPlugin('paymaster')) return op; + return plugin('paymaster').intercept(op); + } + @override Future signUserOperation(UserOperation op, {int? index}) async {