Total Complexity | 4 |
Complexity/F | 0 |
Lines of Code | 68 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | // eslint-disable-next-line @typescript-eslint/no-var-requires |
||
2 | import getWallets from './handlers/getWallets' |
||
3 | |||
4 | const level: any = require('level') |
||
5 | const print: any = require('print-message') |
||
6 | |||
7 | import env from 'dotenv' |
||
8 | import { |
||
9 | isEnvFile, |
||
10 | } from './utils' |
||
11 | import { getCount, getWallet } from './handlers' |
||
12 | import { Wallet } from './models' |
||
13 | |||
14 | const loaded = env.config() |
||
15 | |||
16 | const app = async (query: { command?: string, arg?: string }): Promise<void> => { |
||
17 | let db = null |
||
18 | |||
19 | try { |
||
20 | if (!isEnvFile(loaded)) { |
||
21 | return |
||
22 | } |
||
23 | db = level(process.env.DB_LOCATION) |
||
24 | |||
25 | switch (query.command) { |
||
26 | case 'f': |
||
27 | const wallet: Wallet| {result: string} = await getWallet(db, query.arg!) |
||
28 | |||
29 | if ('member_wallet' in wallet) { |
||
30 | print([ |
||
31 | `Wallet Address: ${ wallet.member_wallet.wallet_address }`, |
||
32 | `Wallet Coin Balance: ${ wallet.member_wallet.coin_balance }`, |
||
33 | ]) |
||
34 | } |
||
35 | print([ |
||
36 | 'Result Row:', |
||
37 | JSON.stringify(wallet) |
||
38 | ], { |
||
39 | border: false, |
||
40 | marginTop: 1, |
||
41 | marginBottom: 3, |
||
42 | color: 'green', |
||
43 | }) |
||
44 | break |
||
45 | case 'c': |
||
46 | const count: number = await getCount(db) |
||
47 | print([ |
||
48 | `Found Number of Wallets`, |
||
49 | `Wallets: ${count} pcs.` |
||
50 | ]) |
||
51 | break |
||
52 | case 'l': |
||
53 | const file = await getWallets(db) |
||
54 | print([ |
||
55 | `Please open file ${file}` |
||
56 | ]) |
||
57 | break |
||
58 | default: |
||
59 | break |
||
60 | } |
||
61 | |||
62 | } catch (e) { |
||
63 | console.error(e.message) |
||
64 | } |
||
65 | } |
||
66 | |||
67 | export default app |
||
68 |