send_token.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --- Send token.
  2. -- Depends on tokenomics
  3. -- @module send_token
  4. local send_token = {
  5. name = "Send tokens",
  6. slug = "send_token",
  7. desc = "Send tokens to another user",
  8. hide = false;
  9. }
  10. --- (Required) Data for module
  11. -- Variables that module uses during the course of a process
  12. -- Can be blank
  13. send_token.data = {
  14. }
  15. send_token.config = {
  16. token_name = ""
  17. }
  18. --- initiate function
  19. -- @function send_token:initiate
  20. -- @param result Callback if this module is embedded in other modules
  21. function send_token:initiate(result)
  22. local token_list = {}
  23. if self.org.tokens then
  24. for k,v in pairs(self.org.tokens) do
  25. table.insert(token_list, k)
  26. end
  27. end
  28. if token_list == {} then
  29. modpol.interactions.message(
  30. self.initiator,
  31. "No tokens in org")
  32. modpol.interactions.org_dashboard(
  33. self.initiator, self.org.name)
  34. self.org:delete_process(self.id)
  35. return
  36. else
  37. modpol.interactions.dropdown_query(
  38. self.initiator,
  39. "Which token do you want to send?",
  40. token_list,
  41. function(input_token)
  42. modpol.interactions.dropdown_query(
  43. self.initiator,
  44. "Who do you want to send to?",
  45. modpol.util.copy_table(self.org.members),
  46. function(input_recipient)
  47. modpol.interactions.text_query(
  48. self.initiator,
  49. "How much do you want to give (a number)?",
  50. function(input_amount)
  51. modpol.modules.tokenomics.transfer(
  52. self.org.id,
  53. input_token,
  54. self.initiator,
  55. input_recipient,
  56. input_amount
  57. )
  58. modpol.interactions.org_dashboard(
  59. self.initiator, self.org.name)
  60. -- close process
  61. if result then result() end
  62. self.org:delete_process(self.id)
  63. end
  64. )
  65. end
  66. )
  67. end
  68. )
  69. end
  70. end
  71. modpol.modules.send_token = send_token