nfc_scene_emv_read_success.c 4.0 KB

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