nfc_scene_emv_read_success.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. string_t temp_str;
  23. string_init_printf(temp_str, "\e#%s\n", emv_data->name);
  24. for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
  25. string_cat_printf(temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
  26. }
  27. string_strim(temp_str);
  28. // Add expiration date
  29. if(emv_data->exp_mon) {
  30. string_cat_printf(temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
  31. }
  32. // Parse currency code
  33. if((emv_data->currency_code)) {
  34. string_t currency_name;
  35. string_init(currency_name);
  36. if(nfc_emv_parser_get_currency_name(
  37. nfc->dev->storage, emv_data->currency_code, currency_name)) {
  38. string_cat_printf(temp_str, "\nCur: %s ", string_get_cstr(currency_name));
  39. }
  40. string_clear(currency_name);
  41. }
  42. // Parse country code
  43. if((emv_data->country_code)) {
  44. string_t country_name;
  45. string_init(country_name);
  46. if(nfc_emv_parser_get_country_name(
  47. nfc->dev->storage, emv_data->country_code, country_name)) {
  48. string_cat_printf(temp_str, "Reg: %s", string_get_cstr(country_name));
  49. }
  50. string_clear(country_name);
  51. }
  52. widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, string_get_cstr(temp_str));
  53. string_clear(temp_str);
  54. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
  55. }
  56. bool nfc_scene_emv_read_success_on_event(void* context, SceneManagerEvent event) {
  57. Nfc* nfc = context;
  58. bool consumed = false;
  59. if(event.type == SceneManagerEventTypeCustom) {
  60. if(event.event == GuiButtonTypeLeft) {
  61. scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
  62. consumed = true;
  63. } else if(event.event == GuiButtonTypeRight) {
  64. scene_manager_next_scene(nfc->scene_manager, NfcSceneEmvMenu);
  65. consumed = true;
  66. }
  67. } else if(event.type == SceneManagerEventTypeBack) {
  68. scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
  69. consumed = true;
  70. }
  71. return consumed;
  72. }
  73. void nfc_scene_emv_read_success_on_exit(void* context) {
  74. Nfc* nfc = context;
  75. // Clear view
  76. widget_reset(nfc->widget);
  77. }