From b59419a9b72bdf02b910695f58273f5dde577b9a Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 21 Sep 2016 12:42:59 +0300 Subject: [PATCH] closes #245 Former-commit-id: 263e48de04b1c39911e64625d4921eb4b93fb070 --- resources/commands.js | 203 +------------------ src/status_im/commands/handlers/loading.cljs | 2 +- 2 files changed, 3 insertions(+), 202 deletions(-) diff --git a/resources/commands.js b/resources/commands.js index 21038b2c9f..0b8e0284f1 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -37,207 +37,8 @@ status.command({ placeholder: "Address" }); -var phones = [ - { - number: "89171111111", - description: "Number format 1" - }, - { - number: "89371111111", - description: "Number format 1" - }, - { - number: "+79171111111", - description: "Number format 2" - }, - { - number: "9171111111", - description: "Number format 3" - } -]; -function suggestionsContainerStyle(suggestionsCount) { - return { - marginVertical: 1, - marginHorizontal: 0, - height: Math.min(150, (56 * suggestionsCount)), - backgroundColor: "white", - borderRadius: 5 - }; -} - -var suggestionContainerStyle = { - paddingLeft: 16, - backgroundColor: "white" -}; - -var suggestionSubContainerStyle = { - height: 56, - borderBottomWidth: 1, - borderBottomColor: "#0000001f" -}; - -var valueStyle = { - marginTop: 9, - fontSize: 14, - fontFamily: "font", - color: "#000000de" -}; - -var descriptionStyle = { - marginTop: 1.5, - fontSize: 14, - fontFamily: "font", - color: "#838c93de" -}; - -function startsWith(str1, str2) { - // String.startsWith(...) doesn't work in otto - return str1.lastIndexOf(str2, 0) == 0 && str1 != str2; -} - -function phoneSuggestions(params) { - var ph, suggestions; - if (!params.value || params.value == "") { - ph = phones; - } else { - ph = phones.filter(function (phone) { - return startsWith(phone.number, params.value); - }); - } - - if (ph.length == 0) { - return; - } - - suggestions = ph.map(function (phone) { - return status.components.touchable( - {onPress: [status.events.SET_VALUE, phone.number]}, - status.components.view(suggestionContainerStyle, - [status.components.view(suggestionSubContainerStyle, - [ - status.components.text( - {style: valueStyle}, - phone.number - ), - status.components.text( - {style: descriptionStyle}, - phone.description - ) - ])]) - ); - }); - - var view = status.components.scrollView( - suggestionsContainerStyle(ph.length), - suggestions - ); - - return {markup: view}; -} - -var phoneConfig = { - name: "phone", - description: "Send phone number", - color: "#5fc48d", - validator: function (params) { - return { - validationHandler: "phone", - parameters: [params.value] - }; - }, - params: [{ - name: "phone", - type: status.types.PHONE, - suggestions: phoneSuggestions, - placeholder: "Phone number" - }], - handler: function (params) { - return { - event: "sign-up", - params: [params.value] - }; - } -}; -status.response(phoneConfig); -status.command(phoneConfig); - -status.command({ - name: "help", - description: "Help", - color: "#7099e6", - /* Validator example - validator: function (params) { - if (params.value != "3") { - var error = status.components.view( - {backgroundColor: "red"}, - [status.components.text({}, "ooops :(")] - ); - return {errors: [error]} - } - },*/ - params: [{ - name: "query", - type: status.types.TEXT - }] -}); - -status.response({ - name: "confirmation-code", - color: "#7099e6", - description: "Confirmation code", - params: [{ - name: "code", - type: status.types.NUMBER - }], - handler: function (params) { - return { - event: "confirm-sign-up", - params: [params.value] - }; - }, - validator: function(params){ - if(!/^[\d]{4}$/.test(params.value)){ - var error = status.components.validationMessage( - "Confirmation code", - "Wrong format" - ); - - return {errors: [error]} - } - } -}); - -status.response({ - name: "keypair", - color: "#7099e6", - description: "Keypair password", - icon: "icon_lock_white", - params: [{ - name: "password", - type: status.types.PASSWORD - }], - handler: function (params) { - return { - event: "save-password", - params: [params.value] - }; - }, - preview: function (params) { - return status.components.text( - { - style: { - marginTop: 5, - marginHorizontal: 0, - fontSize: 14, - fontFamily: "font", - color: "black" - } - }, "*****"); - } -}); - -function walletView(params) { +function browseSuggestions(params) { if (params.value != "") { var url = params.value; if (!/^[a-zA-Z-_]+:/.test(url)) { @@ -256,7 +57,7 @@ status.command({ suggestionsTrigger: 'on-send', params: [{ name: "webpage", - suggestions: walletView, + suggestions: browseSuggestions, type: status.types.TEXT }] }); diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index e81057d51d..76cd8250c4 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -26,7 +26,7 @@ ;-let [url (get-in db [:chats identity :dapp-url])] (cond (= "console" identity) - (dispatch [::validate-hash identity (slurp "resources/commands.js")]) + (dispatch [::validate-hash identity (slurp "resources/console.js")]) (= "wallet" identity) (dispatch [::validate-hash identity (slurp "resources/wallet.js")])