From 5e6a558571b36c64dd40d983275fcec7681e9652 Mon Sep 17 00:00:00 2001 From: Alejandro Date: Sun, 3 Mar 2024 09:39:36 -0300 Subject: [PATCH] Simplify prompts --- packages/ethernaut-interact-ui/src/index.js | 7 ++++- .../src/prompts/{params => }/abi.js | 0 .../src/prompts/{params => }/address.js | 0 .../src/prompts/{params => }/fn.js | 0 .../src/prompts/{params => }/params.js | 0 .../src/prompts/tasks/contract.js | 9 ------ .../src/prompts/{params => }/value.js | 0 packages/ethernaut-network-ui/src/index.js | 31 +++++++++++++++---- .../src/prompts/{params => }/alias.js | 0 .../src/prompts/{params => }/fork.js | 0 .../src/prompts/tasks/activate.js | 6 ---- .../src/prompts/tasks/add.js | 5 --- .../src/prompts/tasks/edit.js | 6 ---- .../src/prompts/tasks/info.js | 6 ---- .../src/prompts/tasks/node.js | 5 --- .../src/prompts/tasks/remove.js | 6 ---- .../src/prompts/{params => }/url.js | 0 packages/ethernaut-util-ui/src/index.js | 5 ++- .../src/prompts/{tasks => }/unit.js | 15 +++++---- packages/ethernaut-wallet-ui/src/index.js | 15 +++++++-- .../src/prompts/{params => }/alias.js | 0 .../src/prompts/tasks/activate.js | 6 ---- .../src/prompts/tasks/info.js | 6 ---- .../src/prompts/tasks/remove.js | 6 ---- 24 files changed, 54 insertions(+), 80 deletions(-) rename packages/ethernaut-interact-ui/src/prompts/{params => }/abi.js (100%) rename packages/ethernaut-interact-ui/src/prompts/{params => }/address.js (100%) rename packages/ethernaut-interact-ui/src/prompts/{params => }/fn.js (100%) rename packages/ethernaut-interact-ui/src/prompts/{params => }/params.js (100%) delete mode 100644 packages/ethernaut-interact-ui/src/prompts/tasks/contract.js rename packages/ethernaut-interact-ui/src/prompts/{params => }/value.js (100%) rename packages/ethernaut-network-ui/src/prompts/{params => }/alias.js (100%) rename packages/ethernaut-network-ui/src/prompts/{params => }/fork.js (100%) delete mode 100644 packages/ethernaut-network-ui/src/prompts/tasks/activate.js delete mode 100644 packages/ethernaut-network-ui/src/prompts/tasks/add.js delete mode 100644 packages/ethernaut-network-ui/src/prompts/tasks/edit.js delete mode 100644 packages/ethernaut-network-ui/src/prompts/tasks/info.js delete mode 100644 packages/ethernaut-network-ui/src/prompts/tasks/node.js delete mode 100644 packages/ethernaut-network-ui/src/prompts/tasks/remove.js rename packages/ethernaut-network-ui/src/prompts/{params => }/url.js (100%) rename packages/ethernaut-util-ui/src/prompts/{tasks => }/unit.js (74%) rename packages/ethernaut-wallet-ui/src/prompts/{params => }/alias.js (100%) delete mode 100644 packages/ethernaut-wallet-ui/src/prompts/tasks/activate.js delete mode 100644 packages/ethernaut-wallet-ui/src/prompts/tasks/info.js delete mode 100644 packages/ethernaut-wallet-ui/src/prompts/tasks/remove.js diff --git a/packages/ethernaut-interact-ui/src/index.js b/packages/ethernaut-interact-ui/src/index.js index a18fdfc1..d7dc0a0a 100644 --- a/packages/ethernaut-interact-ui/src/index.js +++ b/packages/ethernaut-interact-ui/src/index.js @@ -4,5 +4,10 @@ require('ethernaut-ui/src/index') require('ethernaut-interact/src/index') extendEnvironment((hre) => { - require('./prompts/tasks/contract')(hre) + const contract = hre.scopes.interact.tasks.contract + contract.paramDefinitions.abi.prompt = require('./prompts/abi') + contract.paramDefinitions.address.prompt = require('./prompts/address') + contract.paramDefinitions.fn.prompt = require('./prompts/fn') + contract.paramDefinitions.params.prompt = require('./prompts/params') + contract.paramDefinitions.value.prompt = require('./prompts/value') }) diff --git a/packages/ethernaut-interact-ui/src/prompts/params/abi.js b/packages/ethernaut-interact-ui/src/prompts/abi.js similarity index 100% rename from packages/ethernaut-interact-ui/src/prompts/params/abi.js rename to packages/ethernaut-interact-ui/src/prompts/abi.js diff --git a/packages/ethernaut-interact-ui/src/prompts/params/address.js b/packages/ethernaut-interact-ui/src/prompts/address.js similarity index 100% rename from packages/ethernaut-interact-ui/src/prompts/params/address.js rename to packages/ethernaut-interact-ui/src/prompts/address.js diff --git a/packages/ethernaut-interact-ui/src/prompts/params/fn.js b/packages/ethernaut-interact-ui/src/prompts/fn.js similarity index 100% rename from packages/ethernaut-interact-ui/src/prompts/params/fn.js rename to packages/ethernaut-interact-ui/src/prompts/fn.js diff --git a/packages/ethernaut-interact-ui/src/prompts/params/params.js b/packages/ethernaut-interact-ui/src/prompts/params.js similarity index 100% rename from packages/ethernaut-interact-ui/src/prompts/params/params.js rename to packages/ethernaut-interact-ui/src/prompts/params.js diff --git a/packages/ethernaut-interact-ui/src/prompts/tasks/contract.js b/packages/ethernaut-interact-ui/src/prompts/tasks/contract.js deleted file mode 100644 index 2cb4dfbe..00000000 --- a/packages/ethernaut-interact-ui/src/prompts/tasks/contract.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = function setup(hre) { - const contract = hre.scopes.interact.tasks.contract - - contract.paramDefinitions.abi.prompt = require('../params/abi') - contract.paramDefinitions.address.prompt = require('../params/address') - contract.paramDefinitions.fn.prompt = require('../params/fn') - contract.paramDefinitions.params.prompt = require('../params/params') - contract.paramDefinitions.value.prompt = require('../params/value') -} diff --git a/packages/ethernaut-interact-ui/src/prompts/params/value.js b/packages/ethernaut-interact-ui/src/prompts/value.js similarity index 100% rename from packages/ethernaut-interact-ui/src/prompts/params/value.js rename to packages/ethernaut-interact-ui/src/prompts/value.js diff --git a/packages/ethernaut-network-ui/src/index.js b/packages/ethernaut-network-ui/src/index.js index 5572a21e..9fcdea74 100644 --- a/packages/ethernaut-network-ui/src/index.js +++ b/packages/ethernaut-network-ui/src/index.js @@ -1,13 +1,32 @@ const { extendEnvironment } = require('hardhat/config') +const promptUrl = require('./prompts/url') +const promptAlias = require('./prompts/alias') +const promptFork = require('./prompts/fork') + require('ethernaut-ui/src/index') require('ethernaut-network/src/index') extendEnvironment((hre) => { - require('./prompts/tasks/activate')(hre) - require('./prompts/tasks/add')(hre) - require('./prompts/tasks/edit')(hre) - require('./prompts/tasks/info')(hre) - require('./prompts/tasks/node')(hre) - require('./prompts/tasks/remove')(hre) + const add = hre.scopes.network.tasks.add + add.paramDefinitions.url.prompt = promptUrl + + const activate = hre.scopes.network.tasks.activate + activate.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = + promptAlias('Select a network to activate') + + const edit = hre.scopes.network.tasks.edit + edit.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = + promptAlias('Select a network to edit') + + const remove = hre.scopes.network.tasks.remove + remove.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = + promptAlias('Select a network') + + const node = hre.scopes.network.tasks.node + node.paramDefinitions.fork.prompt = promptFork + + const info = hre.scopes.network.tasks.info + info.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = + promptAlias('Select a network') }) diff --git a/packages/ethernaut-network-ui/src/prompts/params/alias.js b/packages/ethernaut-network-ui/src/prompts/alias.js similarity index 100% rename from packages/ethernaut-network-ui/src/prompts/params/alias.js rename to packages/ethernaut-network-ui/src/prompts/alias.js diff --git a/packages/ethernaut-network-ui/src/prompts/params/fork.js b/packages/ethernaut-network-ui/src/prompts/fork.js similarity index 100% rename from packages/ethernaut-network-ui/src/prompts/params/fork.js rename to packages/ethernaut-network-ui/src/prompts/fork.js diff --git a/packages/ethernaut-network-ui/src/prompts/tasks/activate.js b/packages/ethernaut-network-ui/src/prompts/tasks/activate.js deleted file mode 100644 index 9957c4d2..00000000 --- a/packages/ethernaut-network-ui/src/prompts/tasks/activate.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function setup(hre) { - const activate = hre.scopes.network.tasks.activate - - activate.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = - require('../params/alias')('Select a network to activate') -} diff --git a/packages/ethernaut-network-ui/src/prompts/tasks/add.js b/packages/ethernaut-network-ui/src/prompts/tasks/add.js deleted file mode 100644 index 0814999e..00000000 --- a/packages/ethernaut-network-ui/src/prompts/tasks/add.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = function setup(hre) { - const add = hre.scopes.network.tasks.add - - add.paramDefinitions.url.prompt = require('../params/url') -} diff --git a/packages/ethernaut-network-ui/src/prompts/tasks/edit.js b/packages/ethernaut-network-ui/src/prompts/tasks/edit.js deleted file mode 100644 index 54778a5b..00000000 --- a/packages/ethernaut-network-ui/src/prompts/tasks/edit.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function setup(hre) { - const edit = hre.scopes.network.tasks.edit - - edit.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = - require('../params/alias')('Select a network to edit') -} diff --git a/packages/ethernaut-network-ui/src/prompts/tasks/info.js b/packages/ethernaut-network-ui/src/prompts/tasks/info.js deleted file mode 100644 index ffa0cae8..00000000 --- a/packages/ethernaut-network-ui/src/prompts/tasks/info.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function setup(hre) { - const info = hre.scopes.network.tasks.info - - info.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = - require('../params/alias')('Select a network') -} diff --git a/packages/ethernaut-network-ui/src/prompts/tasks/node.js b/packages/ethernaut-network-ui/src/prompts/tasks/node.js deleted file mode 100644 index e6e1914d..00000000 --- a/packages/ethernaut-network-ui/src/prompts/tasks/node.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = function setup(hre) { - const node = hre.scopes.network.tasks.node - - node.paramDefinitions.fork.prompt = require('../params/fork') -} diff --git a/packages/ethernaut-network-ui/src/prompts/tasks/remove.js b/packages/ethernaut-network-ui/src/prompts/tasks/remove.js deleted file mode 100644 index 3e03fcdb..00000000 --- a/packages/ethernaut-network-ui/src/prompts/tasks/remove.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function setup(hre) { - const remove = hre.scopes.network.tasks.remove - - remove.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = - require('../params/alias')('Select a network') -} diff --git a/packages/ethernaut-network-ui/src/prompts/params/url.js b/packages/ethernaut-network-ui/src/prompts/url.js similarity index 100% rename from packages/ethernaut-network-ui/src/prompts/params/url.js rename to packages/ethernaut-network-ui/src/prompts/url.js diff --git a/packages/ethernaut-util-ui/src/index.js b/packages/ethernaut-util-ui/src/index.js index 1a285dc7..2e058ad9 100644 --- a/packages/ethernaut-util-ui/src/index.js +++ b/packages/ethernaut-util-ui/src/index.js @@ -1,8 +1,11 @@ const { extendEnvironment } = require('hardhat/config') +const promptUnit = require('./prompts/unit') require('ethernaut-ui/src/index') require('ethernaut-util/src/index') extendEnvironment((hre) => { - require('./prompts/tasks/unit')(hre) + const unit = hre.scopes.util.tasks.unit + unit.paramDefinitions['from'].prompt = promptUnit + unit.paramDefinitions['to'].prompt = promptUnit }) diff --git a/packages/ethernaut-util-ui/src/prompts/tasks/unit.js b/packages/ethernaut-util-ui/src/prompts/unit.js similarity index 74% rename from packages/ethernaut-util-ui/src/prompts/tasks/unit.js rename to packages/ethernaut-util-ui/src/prompts/unit.js index b2727110..c691ee27 100644 --- a/packages/ethernaut-util-ui/src/prompts/tasks/unit.js +++ b/packages/ethernaut-util-ui/src/prompts/unit.js @@ -1,14 +1,13 @@ const { units } = require('ethernaut-util/src/tasks/unit') const prompt = require('common/src/prompt') -module.exports = function setup(hre) { - const unit = hre.scopes.util.tasks.unit - - unit.paramDefinitions['from'].prompt = promptUnit - unit.paramDefinitions['to'].prompt = promptUnit -} - -async function promptUnit({ paramName, paramDefault, description, from, to }) { +module.exports = async function promptUnit({ + paramName, + paramDefault, + description, + from, + to, +}) { const valueProvided = paramName === 'from' ? from !== undefined : to !== undefined const isDefault = diff --git a/packages/ethernaut-wallet-ui/src/index.js b/packages/ethernaut-wallet-ui/src/index.js index 4e1d16fb..87b86ff9 100644 --- a/packages/ethernaut-wallet-ui/src/index.js +++ b/packages/ethernaut-wallet-ui/src/index.js @@ -1,10 +1,19 @@ const { extendEnvironment } = require('hardhat/config') +const promptAlias = require('./prompts/alias') require('ethernaut-ui/src/index') require('ethernaut-wallet/src/index') extendEnvironment((hre) => { - require('./prompts/tasks/activate')(hre) - require('./prompts/tasks/info')(hre) - require('./prompts/tasks/remove')(hre) + const activate = hre.scopes.wallet.tasks.activate + activate.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = + promptAlias('Select a wallet to activate') + + const info = hre.scopes.wallet.tasks.info + info.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = + promptAlias('Select a wallet') + + const remove = hre.scopes.wallet.tasks.remove + remove.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = + promptAlias('Select a wallet to remove') }) diff --git a/packages/ethernaut-wallet-ui/src/prompts/params/alias.js b/packages/ethernaut-wallet-ui/src/prompts/alias.js similarity index 100% rename from packages/ethernaut-wallet-ui/src/prompts/params/alias.js rename to packages/ethernaut-wallet-ui/src/prompts/alias.js diff --git a/packages/ethernaut-wallet-ui/src/prompts/tasks/activate.js b/packages/ethernaut-wallet-ui/src/prompts/tasks/activate.js deleted file mode 100644 index d9a49726..00000000 --- a/packages/ethernaut-wallet-ui/src/prompts/tasks/activate.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function setup(hre) { - const activate = hre.scopes.wallet.tasks.activate - - activate.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = - require('../params/alias')('Select a wallet to activate') -} diff --git a/packages/ethernaut-wallet-ui/src/prompts/tasks/info.js b/packages/ethernaut-wallet-ui/src/prompts/tasks/info.js deleted file mode 100644 index 7127cfff..00000000 --- a/packages/ethernaut-wallet-ui/src/prompts/tasks/info.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function setup(hre) { - const info = hre.scopes.wallet.tasks.info - - info.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = - require('../params/alias')('Select a wallet') -} diff --git a/packages/ethernaut-wallet-ui/src/prompts/tasks/remove.js b/packages/ethernaut-wallet-ui/src/prompts/tasks/remove.js deleted file mode 100644 index ea6da27c..00000000 --- a/packages/ethernaut-wallet-ui/src/prompts/tasks/remove.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = function setup(hre) { - const remove = hre.scopes.wallet.tasks.remove - - remove.positionalParamDefinitions.find((p) => p.name === 'alias').prompt = - require('../params/alias')('Select a wallet to remove') -}