send_token.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --- send_token
  2. -- @module send_token
  3. -- depends on tokenomics
  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. --- (Required): initiate function
  19. -- @param result (optional) Callback if this module is embedded in other modules
  20. -- @function initiate
  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. --- (Required) Add to module table
  72. modpol.modules.send_token = send_token