flip_trader.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include <flip_trader.h>
  2. void asset_names_free(char** names) {
  3. if(names) {
  4. for(int i = 0; i < ASSET_COUNT; i++) {
  5. free(names[i]);
  6. }
  7. free(names);
  8. }
  9. }
  10. char** asset_names_alloc() {
  11. // Allocate memory for an array of 42 string pointers
  12. char** names = malloc(ASSET_COUNT * sizeof(char*));
  13. if(!names) {
  14. FURI_LOG_E(TAG, "Failed to allocate memory for asset names");
  15. return NULL;
  16. }
  17. // Assign each asset name to the array
  18. names[0] = strdup("ETHUSD");
  19. names[1] = strdup("BTCUSD");
  20. names[2] = strdup("AAPL");
  21. names[3] = strdup("AMZN");
  22. names[4] = strdup("GOOGL");
  23. names[5] = strdup("MSFT");
  24. names[6] = strdup("TSLA");
  25. names[7] = strdup("NFLX");
  26. names[8] = strdup("META");
  27. names[9] = strdup("NVDA");
  28. names[10] = strdup("AMD");
  29. names[11] = strdup("INTC");
  30. names[12] = strdup("PLTR");
  31. names[13] = strdup("EURUSD");
  32. names[14] = strdup("GBPUSD");
  33. names[15] = strdup("AUDUSD");
  34. names[16] = strdup("NZDUSD");
  35. names[17] = strdup("XAUUSD");
  36. names[18] = strdup("USDJPY");
  37. names[19] = strdup("USDCHF");
  38. names[20] = strdup("USDCAD");
  39. names[21] = strdup("EURJPY");
  40. names[22] = strdup("EURGBP");
  41. names[23] = strdup("EURCHF");
  42. names[24] = strdup("EURCAD");
  43. names[25] = strdup("EURAUD");
  44. names[26] = strdup("EURNZD");
  45. names[27] = strdup("AUDJPY");
  46. names[28] = strdup("AUDCHF");
  47. names[29] = strdup("AUDCAD");
  48. names[30] = strdup("NZDJPY");
  49. names[31] = strdup("NZDCHF");
  50. names[32] = strdup("NZDCAD");
  51. names[33] = strdup("GBPJPY");
  52. names[34] = strdup("GBPCHF");
  53. names[35] = strdup("GBPCAD");
  54. names[36] = strdup("CHFJPY");
  55. names[37] = strdup("CADJPY");
  56. names[38] = strdup("CADCHF");
  57. names[39] = strdup("GBPAUD");
  58. names[40] = strdup("GBPNZD");
  59. names[41] = strdup("AUDNZD");
  60. return names;
  61. }
  62. char** asset_names = NULL;
  63. // index
  64. uint32_t asset_index = 0;
  65. // Function to free the resources used by FlipTraderApp
  66. void flip_trader_app_free(FlipTraderApp* app) {
  67. if(!app) {
  68. FURI_LOG_E(TAG, "FlipTraderApp is NULL");
  69. return;
  70. }
  71. // Free View(s)
  72. if(app->view_main) {
  73. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewMain);
  74. view_free(app->view_main);
  75. }
  76. // Free Submenu(s)
  77. if(app->submenu_main) {
  78. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewMainSubmenu);
  79. submenu_free(app->submenu_main);
  80. }
  81. if(app->submenu_assets) {
  82. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewAssetsSubmenu);
  83. submenu_free(app->submenu_assets);
  84. }
  85. // Free Widget(s)
  86. if(app->widget) {
  87. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewAbout);
  88. widget_free(app->widget);
  89. }
  90. // Free Variable Item List(s)
  91. if(app->variable_item_list_wifi) {
  92. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewWiFiSettings);
  93. variable_item_list_free(app->variable_item_list_wifi);
  94. }
  95. // Free Text Input(s)
  96. if(app->uart_text_input_ssid) {
  97. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewTextInputSSID);
  98. text_input_free(app->uart_text_input_ssid);
  99. }
  100. if(app->uart_text_input_password) {
  101. view_dispatcher_remove_view(app->view_dispatcher, FlipTraderViewTextInputPassword);
  102. text_input_free(app->uart_text_input_password);
  103. }
  104. asset_names_free(asset_names);
  105. // deinitalize flipper http
  106. flipper_http_deinit();
  107. // free the view dispatcher
  108. view_dispatcher_free(app->view_dispatcher);
  109. // close the gui
  110. furi_record_close(RECORD_GUI);
  111. // free the app
  112. free(app);
  113. }