nfc_scene_emv_read_success.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "../nfc_i.h"
  2. #include "../helpers/nfc_emv_parser.h"
  3. #include <dolphin/dolphin.h>
  4. void nfc_scene_emv_read_success_widget_callback(
  5. GuiButtonType result,
  6. InputType type,
  7. void* context) {
  8. Nfc* nfc = context;
  9. if(type == InputTypeShort) {
  10. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  11. }
  12. }
  13. void nfc_scene_emv_read_success_on_enter(void* context) {
  14. Nfc* nfc = context;
  15. EmvData* emv_data = &nfc->dev->dev_data.emv_data;
  16. DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
  17. // Setup Custom Widget view
  18. widget_add_button_element(
  19. nfc->widget, GuiButtonTypeLeft, "Retry", nfc_scene_emv_read_success_widget_callback, nfc);
  20. widget_add_button_element(
  21. nfc->widget, GuiButtonTypeRight, "More", nfc_scene_emv_read_success_widget_callback, nfc);
  22. FuriString* temp_str;
  23. temp_str = furi_string_alloc_printf("\e#%s\n", emv_data->name);
  24. for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
  25. furi_string_cat_printf(
  26. temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
  27. }
  28. furi_string_trim(temp_str);
  29. // Add expiration date
  30. if(emv_data->exp_mon) {
  31. furi_string_cat_printf(
  32. temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
  33. }
  34. // Parse currency code
  35. if((emv_data->currency_code)) {
  36. FuriString* currency_name;
  37. currency_name = furi_string_alloc();
  38. if(nfc_emv_parser_get_currency_name(
  39. nfc->dev->storage, emv_data->currency_code, currency_name)) {
  40. furi_string_cat_printf(temp_str, "\nCur: %s ", furi_string_get_cstr(currency_name));
  41. }
  42. furi_string_free(currency_name);
  43. }
  44. // Parse country code
  45. if((emv_data->country_code)) {
  46. FuriString* country_name;
  47. country_name = furi_string_alloc();
  48. if(nfc_emv_parser_get_country_name(
  49. nfc->dev->storage, emv_data->country_code, country_name)) {
  50. furi_string_cat_printf(temp_str, "Reg: %s", furi_string_get_cstr(country_name));
  51. }
  52. furi_string_free(country_name);
  53. }
  54. notification_message_block(nfc->notifications, &sequence_set_green_255);
  55. widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
  56. furi_string_free(temp_str);
  57. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  58. }
  59. bool nfc_scene_emv_read_success_on_event(void* context, SceneManagerEvent event) {
  60. Nfc* nfc = context;
  61. bool consumed = false;
  62. if(event.type == SceneManagerEventTypeCustom) {
  63. if(event.event == GuiButtonTypeLeft) {
  64. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  65. consumed = true;
  66. } else if(event.event == GuiButtonTypeRight) {
  67. scene_manager_next_scene(nfc->scene_manager, NfcSceneEmvMenu);
  68. consumed = true;
  69. }
  70. } else if(event.type == SceneManagerEventTypeBack) {
  71. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  72. consumed = true;
  73. }
  74. return consumed;
  75. }
  76. void nfc_scene_emv_read_success_on_exit(void* context) {
  77. Nfc* nfc = context;
  78. notification_message_block(nfc->notifications, &sequence_reset_green);
  79. // Clear view
  80. widget_reset(nfc->widget);
  81. }