Skip to content

Commit 2bbe2a8

Browse files
tmigoneabarmat
authored andcommitted
chore: add confirmation step to a few more commands
Signed-off-by: Tomás Migone <[email protected]>
1 parent aca18a3 commit 2bbe2a8

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

cli/commands/airdrop.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import inquirer from 'inquirer'
21
import fs from 'fs'
32
import PQueue from 'p-queue'
43
import yargs, { Argv } from 'yargs'
@@ -10,6 +9,7 @@ import { NonceManager } from '@ethersproject/experimental'
109
import { logger } from '../logging'
1110
import { sendTransaction } from '../network'
1211
import { loadEnv, CLIArgs, CLIEnvironment } from '../env'
12+
import { confirm } from '../helpers'
1313

1414
const { getAddress } = utils
1515

@@ -66,20 +66,6 @@ interface AirdropRecipient {
6666
txHash?: string
6767
}
6868

69-
const sure = async (message = 'Are you sure?'): Promise<boolean> => {
70-
// Warn about changing ownership
71-
const res = await inquirer.prompt({
72-
name: 'confirm',
73-
type: 'confirm',
74-
message,
75-
})
76-
if (!res.confirm) {
77-
logger.info('Cancelled')
78-
return false
79-
}
80-
return true
81-
}
82-
8369
const getDisperseContract = (chainID: number, provider) => {
8470
return new Contract(DISPERSE_CONTRACT_ADDRESS[chainID], DISPERSE_CONTRACT_ABI, provider)
8571
}
@@ -193,10 +179,8 @@ export const airdrop = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<vo
193179
}
194180

195181
// Confirmation
196-
logger.info('Are you sure you want to proceed with the distribution?')
197-
if (!(await sure())) {
198-
process.exit(1)
199-
}
182+
const sure = await confirm('Are you sure you want to proceed with the distribution?')
183+
if (!sure) return
200184

201185
// Approve
202186
logger.info('## Token approval')

cli/commands/migrate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
sendTransaction,
1212
} from '../network'
1313
import { loadEnv, CLIArgs, CLIEnvironment } from '../env'
14+
import { confirm } from '../helpers'
1415

1516
const { EtherSymbol } = constants
1617
const { formatEther } = utils
@@ -40,6 +41,10 @@ export const migrate = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<vo
4041
const contractName = cliArgs.contract
4142
const chainId = cli.chainId
4243

44+
// Ensure action
45+
const sure = await confirm('Are you sure you want to migrate contracts?')
46+
if (!sure) return
47+
4348
if (chainId == 1337) {
4449
await (cli.wallet.provider as providers.JsonRpcProvider).send('evm_setAutomine', [true])
4550
allContracts = ['EthereumDIDRegistry', ...allContracts]

cli/commands/proxy/admin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ export const setProxyAdmin = async (cli: CLIEnvironment, cliArgs: CLIArgs): Prom
1313

1414
// Warn about changing ownership
1515
const sure = await confirm(`Are you sure to set the admin to ${adminAddress}?`)
16-
if (!sure) {
17-
return
18-
}
16+
if (!sure) return
1917

2018
// Get address book info
2119
const addressEntry = cli.addressBook.getEntry(contractName)

cli/commands/proxy/upgrade.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import yargs, { Argv } from 'yargs'
33
import { logger } from '../../logging'
44
import { getContractAt, isContractDeployed, sendTransaction } from '../../network'
55
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
6+
import { confirm } from '../../helpers'
67

78
export const upgradeProxy = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
89
const contractName = cliArgs.contract
910
const implAddress = cliArgs.impl
1011
const initArgs = cliArgs.init
1112
const buildAcceptProxyTx = cliArgs.buildTx
1213

14+
// Warn about upgrade
15+
const sure = await confirm(`Are you sure you want to upgrade ${contractName} to ${implAddress}?`)
16+
if (!sure) return
17+
1318
logger.info(`Upgrading contract ${contractName}...`)
1419

1520
// Get address book info

0 commit comments

Comments
 (0)