nfc_scene_emv_read_success.c 4.1 KB

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