-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
130 lines (122 loc) · 3.95 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'dotenv/config'
import inquirer from 'inquirer'
// @ts-ignore
import inquirerSearchList from 'inquirer-search-list'
import { getTokenCreator, getTokenList } from './tokens.js'
import {
getUser,
createPlatformUser,
loginPlatformUser,
getPlatformUserDepositAddress,
loginMultiplePlatformUsers,
} from './users.js'
import {
getPlatformUserTokenBalance,
getPlatformUserTokenBalances,
getUserBalances,
getUserTokenBalance,
hasBalance,
} from './balances.js'
import {
getMultiSendById,
getMultiSendSummary,
getMultisendTransactions,
multiSendFromPlatformUser,
sendFromPlatformUser,
} from './transaction.js'
import {
generateClientSecret,
getClient,
getClients,
} from './client-credentials.js'
import {
generateClientCredentialsToken,
refreshClientCredentialsToken,
} from './client-credentials-token.js'
import logger from './logger.js'
inquirer.registerPrompt('search-list', inquirerSearchList)
enum Choice {
GetTokenList = 'Get token list',
GetTokenCreator = 'Get token creator',
GetUser = 'Get user',
GetUserBalances = 'Get user balances',
GetUserTokenBalance = 'Get user token balance',
CheckIfUserHasTokenBalance = 'Check if user has token balance',
CreatePlatformUser = 'Create platform user',
LoginPlatformUser = 'Login platform user',
LoginMultiplePlatformUser = 'Login multiple platform users',
GetClient = 'Get client',
SendFromPlatformUser = 'Send From Platform User',
MultiSendFromPlatformUser = 'Multi send From Platform User',
GetMultiSend = 'Get multiSend',
GetMultisendSummary = 'Get multiSend summary',
GetMultisendTransactions = 'Get multiSend Transactions',
GetPlatformUserDepositAddress = 'Get platform user deposit address',
GetPlatformUserBalance = 'Get platform user balance',
GetPlatformUserBalances = 'Get platform user balances',
GetClients = 'Get clients',
GenerateClientSecret = 'Generate client secret',
GenerateClientCredentialsToken = 'Generate client credentials token',
RefreshClientCredentialsToken = 'Refresh client credentials token',
}
const actionByChoice: Record<Choice, Function> = {
[Choice.GetTokenList]: getTokenList,
[Choice.GetTokenCreator]: getTokenCreator,
[Choice.GetUser]: getUser,
[Choice.GetUserBalances]: getUserBalances,
[Choice.GetUserTokenBalance]: getUserTokenBalance,
[Choice.CheckIfUserHasTokenBalance]: hasBalance,
[Choice.CreatePlatformUser]: createPlatformUser,
[Choice.LoginPlatformUser]: loginPlatformUser,
[Choice.LoginMultiplePlatformUser]: loginMultiplePlatformUsers,
[Choice.GetClient]: getClient,
[Choice.SendFromPlatformUser]: sendFromPlatformUser,
[Choice.MultiSendFromPlatformUser]: multiSendFromPlatformUser,
[Choice.GetMultisendSummary]: getMultiSendSummary,
[Choice.GetMultisendTransactions]: getMultisendTransactions,
[Choice.GetMultiSend]: getMultiSendById,
[Choice.GetPlatformUserDepositAddress]: getPlatformUserDepositAddress,
[Choice.GetPlatformUserBalances]: getPlatformUserTokenBalances,
[Choice.GetPlatformUserBalance]: getPlatformUserTokenBalance,
[Choice.GetClients]: getClients,
[Choice.GenerateClientSecret]: generateClientSecret,
[Choice.GenerateClientCredentialsToken]: generateClientCredentialsToken,
[Choice.RefreshClientCredentialsToken]: refreshClientCredentialsToken,
}
async function main() {
inquirer
.prompt([
{
type: 'search-list',
name: 'option',
message: 'What do you want to do?',
choices: Object.values(Choice),
},
])
.then(async (answers) => {
try {
await actionByChoice[answers.option as Choice]()
} catch (error) {
logger.fatal(JSON.stringify(error as Error))
}
promptOptionsAgain()
})
}
function promptOptionsAgain() {
inquirer
.prompt([
{
type: 'confirm',
name: 'again',
message: 'Do you want to do something else?',
},
])
.then((answers) => {
if (answers.again) {
main()
} else {
process.exit(0)
}
})
}
main()