(args: CommonArgs)
| 6 | import type { CommonArgs } from '../../types/cli'; |
| 7 | |
| 8 | export async function importWallet(args: CommonArgs) { |
| 9 | const { wallet } = args; |
| 10 | const replaceTilde = str => str.startsWith('~') ? str.replace('~', os.homedir()) : str; |
| 11 | |
| 12 | const filename = await prompt.text({ |
| 13 | message: 'Enter filename to import:', |
| 14 | initialValue: `~/${wallet.name}-export.json`, |
| 15 | validate: (value) => { |
| 16 | value = value.trim(); |
| 17 | if (!value) return 'Filename is required'; |
| 18 | value = replaceTilde(value); |
| 19 | if (!fs.existsSync(value)) { |
| 20 | return 'File does not exist: ' + value; |
| 21 | } |
| 22 | return; // valid value |
| 23 | } |
| 24 | }); |
| 25 | if (prompt.isCancel(filename)) { |
| 26 | throw new UserCancelled(); |
| 27 | } |
| 28 | |
| 29 | const importPassword = await getPassword('File decryption password:', { hidden: true }); |
| 30 | |
| 31 | await wallet.import({ |
| 32 | filename: replaceTilde(filename), |
| 33 | importPassword |
| 34 | }); |
| 35 | |
| 36 | prompt.log.success(`Wallet ${wallet.name} imported successfully!`); |
| 37 | }; |
nothing calls this directly
no test coverage detected