Skip to content

Instantly share code, notes, and snippets.

@andytudhope andytudhope/gretzke
Created Nov 3, 2017

What would you like to do?
var price = 50000000000000000;
name: 'hours',
description: 'How many hours do you want to book the ...?',
color: '#CCCCCC',
sequentialParams: true,
params: [{
name: 'hours',
type: status.types.NUMBER,
placeholder: 'e.g. 12 hours',
suggestions: hoursSuggestions
handler: function(params) {
return {'text-message': 'OK'};
function hoursLabel(params) {
var value = params.value;
return "Book the ... for " + value + " hours";
function priceLabel(params) {
var value = parseInt(params.value)*parseInt(price);
return "Price: " + web3.fromWei(value, "ether") + " ETH";
function validationTextLabel(params) {
var value = parseInt(params.value)*parseInt(price);
var balance = parseInt(web3.toWei(params.balance));
if (value>balance) {
return "Insufficient Balance!";
} else {
return "";
// the name of subscription and the name of the value in bot-db
// associated with this subscription
// the map of values on which subscription depends: keys are arbitrary names
// and values are db paths to another value
{value: ["sliderValue"]},
// the function which will be called as reaction on changes of values above,
// should be pure. Returned result will be associated with subscription in bot-db
{value: ["sliderValue"]},
{value: ["sliderValue"], balance: ["balance"]},
function hoursSuggestions(params, context) {
var balance = parseFloat(web3.fromWei(web3.eth.getBalance(context.from), "ether"));
var defaultSliderValue = 1;
var view = ["view", {style: {margin:10}},
["text", {}, "Set the maximum time you will be using the ... here. Don't worry, you will be refunded any time you don't use!"],
["text", {}, "Your Balance " + balance + " ETH"],
["text", {}, ["subscribe", ["setPrice"]]],
["text", {}, ["subscribe", ["setHours"]]],
["slider", {
maximumValue: 24,
value: defaultSliderValue,
minimumValue: 1,
onSlidingComplete: ["dispatch", ["set", "sliderValue"]],
step: 1
['dispatch', [, [0 /arg idx/, value, false /move-to-next? true or false/]]]
{onPress: ['dispatch', [, [0, "12", false]]]},
["view", {}, ["text", {}, "Press here to set Value!"]]
["text", {style: {color: "red"}}, ["subscribe", ["setValidationText"]]]
sliderValue: defaultSliderValue,
balance: balance,
setHours: hoursLabel({value: defaultSliderValue}),
setPrice: priceLabel({value: defaultSliderValue}),
setValidationText: validationTextLabel({value: defaultSliderValue, balance: balance})
balance: balance,
return {markup: view};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.