Skip to content

Commit

Permalink
Simplify prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Mar 3, 2024
1 parent 1f11cb7 commit 5e6a558
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 80 deletions.
7 changes: 6 additions & 1 deletion packages/ethernaut-interact-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
9 changes: 0 additions & 9 deletions packages/ethernaut-interact-ui/src/prompts/tasks/contract.js

This file was deleted.

31 changes: 25 additions & 6 deletions packages/ethernaut-network-ui/src/index.js
Original file line number Diff line number Diff line change
@@ -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')
})
6 changes: 0 additions & 6 deletions packages/ethernaut-network-ui/src/prompts/tasks/activate.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/ethernaut-network-ui/src/prompts/tasks/add.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/ethernaut-network-ui/src/prompts/tasks/edit.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/ethernaut-network-ui/src/prompts/tasks/info.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/ethernaut-network-ui/src/prompts/tasks/node.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/ethernaut-network-ui/src/prompts/tasks/remove.js

This file was deleted.

5 changes: 4 additions & 1 deletion packages/ethernaut-util-ui/src/index.js
Original file line number Diff line number Diff line change
@@ -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
})
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
15 changes: 12 additions & 3 deletions packages/ethernaut-wallet-ui/src/index.js
Original file line number Diff line number Diff line change
@@ -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')
})
6 changes: 0 additions & 6 deletions packages/ethernaut-wallet-ui/src/prompts/tasks/activate.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/ethernaut-wallet-ui/src/prompts/tasks/info.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/ethernaut-wallet-ui/src/prompts/tasks/remove.js

This file was deleted.

0 comments on commit 5e6a558

Please sign in to comment.