status-mobile/resources/commands.js

133 lines
3.2 KiB
JavaScript
Raw Normal View History

status.command({
name: "location",
description: "Send location",
2016-06-29 11:28:43 +00:00
color: "#9a5dcf",
preview: function (params) {
2016-07-07 16:09:16 +00:00
var text = status.components.text(
2016-06-29 11:28:43 +00:00
{
style: {
marginTop: 5,
marginHorizontal: 0,
fontSize: 14,
fontFamily: "font",
color: "black"
}
}, params.value);
var uri = "https://maps.googleapis.com/maps/api/staticmap?center="
+ params.value
+ "&size=100x100&maptype=roadmap&key=AIzaSyBNsj1qoQEYPb3IllmWMAscuXW0eeuYqAA&language=en"
+ "&markers=size:mid%7Ccolor:0xff0000%7Clabel:%7C"
+ params.value;
var image = status.components.image(
{
source: {uri: uri},
style: {
width: 100,
height: 100
}
}
);
return status.components.view({}, [text, image]);
}
}).param({
name: "address",
2016-06-27 15:38:44 +00:00
type: status.types.TEXT,
placeholder: "Address"
});
2016-09-21 09:42:59 +00:00
function browseSuggestions(params) {
2016-07-18 07:38:24 +00:00
if (params.value != "") {
var url = params.value;
if (!/^[a-zA-Z-_]+:/.test(url)) {
url = 'http://' + url;
}
return {webViewUrl: url};
}
}
status.command({
name: "browse",
description: "browser",
color: "#ffa500",
fullscreen: true,
suggestionsTrigger: 'on-send',
params: [{
name: "webpage",
2016-09-21 09:42:59 +00:00
suggestions: browseSuggestions,
2016-07-18 07:38:24 +00:00
type: status.types.TEXT
}]
});
2016-06-30 16:00:44 +00:00
function validateBalance(params) {
2016-09-20 14:15:29 +00:00
if(!params.value){
return {
errors: [
status.components.validationMessage(
"Amount",
"Amount must be specified"
)
]
};
}
2016-06-30 16:00:44 +00:00
try {
var val = web3.toWei(params.value, "ether");
} catch (err) {
return {
errors: [
status.components.validationMessage(
"Amount",
"Amount is not valid number"//err.message
)
]
};
}
2016-08-03 13:15:04 +00:00
2016-06-30 16:00:44 +00:00
var balance = web3.eth.getBalance(params.command.address);
if (bn(val).greaterThan(bn(balance))) {
return {
errors: [
status.components.validationMessage(
"Amount",
"Not enough ETH on balance ("
+ web3.fromWei(balance, "ether")
+ " ETH)"
)
]
};
}
}
function sendTransaction(params) {
var data = {
from: params.command.from,
to: params.command.to,
value: web3.toWei(params.value, "ether")
};
var hash = web3.eth.sendTransaction(data);
return {"transaction-hash": hash};
}
status.command({
name: "send",
color: "#5fc48d",
description: "Send transaction",
params: [{
name: "amount",
type: status.types.NUMBER
}],
preview: function (params) {
return status.components.text(
{},
params.value + " ETH"
);
},
handler: sendTransaction,
validator: validateBalance
});