Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Move command-content to js files #779

Closed
alwx opened this issue Jan 31, 2017 · 3 comments
Closed

Move command-content to js files #779

alwx opened this issue Jan 31, 2017 · 3 comments
Assignees

Comments

@alwx
Copy link
Contributor

alwx commented Jan 31, 2017

There is a function called command-content, and the purpose of this function is to return a nice one-line preview for commands in chat list:

screen shot 2017-01-31 at 23 34 40

Here you can see Transaction: 0.51234 ETH, and this text comes from status.i18n namespace with the help of status-im.chats-list.views.inner-item/command-content function. But this text should be placed in the same place where we store all information about commands — in JS files like commands.js and console.js

@jumarko
Copy link

jumarko commented Feb 2, 2017

I'd like to take a look at this.
Btw. why is information about commands stored in javascript files?

@0xc1c4da
Copy link
Contributor

0xc1c4da commented Feb 2, 2017

because commands can be defined by 3rd party dapps

@0xc1c4da 0xc1c4da added this to the 0.9.5 milestone Feb 4, 2017
@jumarko
Copy link

jumarko commented Feb 8, 2017

I spend quite a while by digging into the code base and my current understanding is as follows:

  • There are few places when commands are defined and it depends on the "chat id"
    • "console" -> console.js Here are stored the commands for console, in particular commands "phone", "faucet", and "browse"
    • "wallet" -> wallet.js Here are stored the commands for wallet - just command "browse"
    • "dapp" -> dapp.js Here are stored the commands for dapps - just command "browse"
    • ELSE -> commands.js Here are stored commands for other chat ids, e.g. for the chat with a friend (added as a contact)
  • Aforementioned logic is implemented in handlers for ::fetch-commands! and ::validate-hash events
  • The short text that is shown in chat list overview (e.g. "Transaction: 0.51234 ETH") is currently stored in i18n.cljs and can be retrieved via command-content function
  • In order to extract "command content" from i18n.cljs to javascript files I need to add another Command field, let's call it label:
    • The Command definition in status.js has to be updated
    • label has to be added to commands in all javascript files (console.js, wallet.js, dapp.js, commands.js)
    • value of command's label has to be loaded and parameterized in view using the value (e.g. amount) from the last message in a chat

Issues (using the new approach):

  1. In order to get the :label for a command I need to have it available in view component chat-list-item-inner-view.
  • I think this info should be in a "chat" map: (:commands chat). However, the thing is that the commands are "added" into the chat map only when particular chat is opened (except the "console" chat, which is populated at application start). For other chats, e.g. "wallet", there's no such thing as :commands key in a chat map when I accessed the chats screen for the first time.
  • I don't know how to handle this - lazy loading of chat's commands is probably a good thing but now I don't have a label which I could show to the user.
  1. parameter values in a label have to be expanded:
  • e.g. "Transaction: {{amount}} ETH".
  • Parameters are provided when a view is rendered and this is completely decoupled from the act of loading/parsing commands via API call to status-go (parse-jail). I cannot use something like Location: {{address}} in javascript files (e.g. "commands.js") because it'd be expanded (by I18n.t) to a string like "Location: [missing ...]".
  • Thus I need to use different syntax (e.g. Location: <<address>>) and replace the parameter with actual value manually in status_im/chats_list/views/inner_item.cljs.

@alwx Could you please check if I'm going in the right direction and correct me If I am wrong.
Moreover, I'd love to know how to solve the first issue (unpopulated :commands field in a chat map).
Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants