Commit 3228669f authored by Jared Pereira's avatar Jared Pereira

call functions from contracts with /commands

parent 89e96cc4
......@@ -209,11 +209,13 @@ function parseMessage(msg) {
}
function parseCommand(cmd) {
switch(cmd[0]) {
case '/help':
var command = cmd[0].slice(1, cmd[0].length)
switch(true){
case command == 'help':
const message = "Use /send to send ether. Ex. \"/send 0.1 0x...\""
COMMANDS.notification({text:message})
case '/send':
case command == '/send':
const amount = cmd[1]
const address = cmd[2] || '0x0'
......@@ -243,8 +245,33 @@ function parseCommand(cmd) {
return
}
return
case '/online':
case command == 'online':
return send({cmd: 'getOnline'})
case command == 'contracts':
return COMMANDS.notification({text: Object.keys(contracts).join(', ')})
case command in contracts :
const commandContract= contracts[command]
if(cmd[1] in commandContract){
try {
commandContract[cmd[1]].apply(this, cmd.slice(2, cmd.length)).then(function(result){
var text = command + "." + cmd[1] + "(" + cmd.slice(2, cmd.length).join(', ') + "): "
if(result[0].constructor.name == 'BN'){
COMMANDS.notification({text: text+ result[0].toString()})
}
else {
COMMANDS.notification({text: text+ result[0]})
}
})
}
catch(err){
console.log(err)
}
}
return
default:
return COMMANDS.alert({text:cmd[0]+" is not a valid command. Try /help"})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment