Skip to content

Commit f3fe1ef

Browse files
committed
fix: console
1 parent c269edd commit f3fe1ef

3 files changed

Lines changed: 9 additions & 38 deletions

File tree

src/commands/wallet/create.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Wallet } from 'ethers';
22
import signale from 'signale';
3-
import fs from 'fs';
43
import {
54
isDirectoryValid,
65
progress,
76
writeFile,
87
promptOutputDirectory,
98
promptWalletPassword,
109
checkAndPromptOverwrite,
10+
isDir,
1111
} from '../../utils';
1212

1313
export const command = 'create';
@@ -37,22 +37,15 @@ export const promptQuestions = async () => {
3737
!walletPath || walletPath.trim() === '' || walletPath === '.' ? '.' : walletPath;
3838

3939
// Validate: must be either an existing directory or a path ending with .json
40-
let isDirectory = false;
41-
try {
42-
isDirectory = fs.lstatSync(normalizedPath).isDirectory();
43-
} catch (_e) {
44-
// Path doesn't exist, check if it's a .json file path
45-
}
46-
4740
const isJsonFilePath = normalizedPath.toLowerCase().endsWith('.json');
4841

49-
if (!isDirectory && !isJsonFilePath) {
42+
if (!isDir(normalizedPath) && !isJsonFilePath) {
5043
throw new Error(
5144
`Invalid path: ${normalizedPath}. Please provide either a directory path or a file path ending with .json`,
5245
);
5346
}
5447

55-
if (isDirectory && !isDirectoryValid(normalizedPath)) {
48+
if (isDir(normalizedPath) && !isDirectoryValid(normalizedPath)) {
5649
throw new Error(`Invalid directory path provided: ${normalizedPath}`);
5750
}
5851

@@ -65,14 +58,7 @@ export const generateAndSaveWallet = async (walletPassword: string, walletPath:
6558
const normalizedPath = !walletPath || walletPath.trim() === '' ? '.' : walletPath;
6659

6760
// Check if path is a directory
68-
let isDirectory = false;
69-
try {
70-
isDirectory = fs.lstatSync(normalizedPath).isDirectory();
71-
} catch (_e) {
72-
// Path doesn't exist yet, that's okay
73-
}
74-
75-
if (isDirectory) {
61+
if (isDir(normalizedPath)) {
7662
// If it's a directory (including current directory), create wallet.json inside it
7763
walletFilePath = normalizedPath === '.' ? 'wallet.json' : `${normalizedPath}/wallet.json`;
7864
} else if (normalizedPath.toLowerCase().endsWith('.json')) {

src/commands/wallet/encrypt.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { input } from '@inquirer/prompts';
22
import { Wallet } from 'ethers';
33
import signale from 'signale';
4-
import fs from 'fs';
54
import {
65
highlight,
76
isDirectoryValid,
@@ -10,6 +9,7 @@ import {
109
promptOutputDirectory,
1110
promptWalletPassword,
1211
checkAndPromptOverwrite,
12+
isDir,
1313
} from '../../utils';
1414

1515
export const command = 'encrypt';
@@ -56,13 +56,7 @@ export const promptQuestions = async () => {
5656
!walletPath || walletPath.trim() === '' || walletPath === '.' ? '.' : walletPath;
5757

5858
// Validate: must be either an existing directory or a path ending with .json
59-
let isDirectory = false;
60-
try {
61-
isDirectory = fs.lstatSync(normalizedPath).isDirectory();
62-
} catch (_e) {
63-
// Path doesn't exist, check if it's a .json file path
64-
}
65-
59+
const isDirectory = isDir(normalizedPath);
6660
const isJsonFilePath = normalizedPath.toLowerCase().endsWith('.json');
6761

6862
if (!isDirectory && !isJsonFilePath) {
@@ -88,14 +82,7 @@ export const encryptAndSaveWallet = async (
8882
const normalizedPath = !walletPath || walletPath.trim() === '' ? '.' : walletPath;
8983

9084
// Check if path is a directory
91-
let isDirectory = false;
92-
try {
93-
isDirectory = fs.lstatSync(normalizedPath).isDirectory();
94-
} catch (_e) {
95-
// Path doesn't exist yet, that's okay
96-
}
97-
98-
if (isDirectory) {
85+
if (isDir(normalizedPath)) {
9986
// If it's a directory (including current directory), create wallet.json inside it
10087
walletFilePath = normalizedPath === '.' ? 'wallet.json' : `${normalizedPath}/wallet.json`;
10188
} else if (normalizedPath.toLowerCase().endsWith('.json')) {

src/utils/file-io.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export const isFile = (path: fs.PathLike): boolean => {
1010
try {
1111
const stat = fs.lstatSync(path);
1212
return stat.isFile();
13-
} catch (e) {
14-
console.error(e);
13+
} catch (_e) {
1514
return false;
1615
}
1716
};
@@ -20,8 +19,7 @@ export const isDir = (path: fs.PathLike): boolean => {
2019
try {
2120
const stat = fs.lstatSync(path);
2221
return stat.isDirectory();
23-
} catch (e) {
24-
console.error(e);
22+
} catch (_e) {
2523
return false;
2624
}
2725
};

0 commit comments

Comments
 (0)