flip_trader.c 4.0 KB

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