forked from Nikeweke/kuna-api-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkunacode.js
More file actions
41 lines (38 loc) · 1.11 KB
/
kunacode.js
File metadata and controls
41 lines (38 loc) · 1.11 KB
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
const keys = require('./keys');
const kuna = require('./v3')(keys);
const prompt = require('prompt-sync')();
function checkCode(inkunacode, autoaccept) {
try {
if (autoaccept === true) {
kuna.private.activateKunaCode(inkunacode).then((data)=> console.log(data));
} else {
kuna.public.validateKunaCode(inkunacode);
var kunacodepattern1=inkunacode.slice(0, 5);
kuna.public.checkKunaCode(kunacodepattern1)
.then((data) => step2(data, inkunacode))
.catch(err => console.log('Error: ', err));
}
} catch (error) {
return error.message;
}
}
function step2(data,inkunacode) {
console.log(data);
if (data.status === 'active') {
const isactivate = prompt('Activate code? (y/N)');
if (isactivate === 'y') {
try {
kuna.private.activateKunaCode(inkunacode).then((data)=> console.log(data));
} catch (error) {
return error.message;
}
}
}
}
if (process.argv.length < 3)
{
const kunacode = prompt('Get me kuna code:');
console.log(checkCode(kunacode));
} else {
console.log(checkCode(process.argv.slice(2)[0], true));
}