<commit_before>(ns status-im.ui.screens.accounts.recover.events
  (:require
    status-im.ui.screens.accounts.recover.navigation
    [re-frame.core :as re-frame]
    [status-im.native-module.core :as status]
    [status-im.ui.screens.accounts.events :as accounts-events]
    [status-im.utils.types :as types]
    [status-im.utils.identicon :as identicon]
    [clojure.string :as string]
    [status-im.utils.handlers :as handlers]
    [status-im.utils.gfycat.core :as gfycat]
    [status-im.utils.signing-phrase.core :as signing-phrase]
    [status-im.utils.hex :as utils.hex]
    [status-im.constants :as constants]))

;;;; FX

(re-frame/reg-fx
  ::recover-account-fx
  (fn [[passphrase password]]
    (status/recover-account
     (string/trim passphrase)
     password
     #(re-frame/dispatch [:account-recovered % password]))))

;;;; Handlers

(handlers/register-handler-fx
  :account-recovered
  [(re-frame/inject-cofx :get-new-keypair!)]
  (fn [{:keys [db keypair]} [_ result password]]
    (let [data       (types/json->clj result)
          public-key (:pubkey data)
          address    (-> data :address utils.hex/normalize-hex)
          phrase     (signing-phrase/generate)
          {:keys [public private]} keypair
          account {:public-key          public-key
                   :address             address
                   :name                (gfycat/generate-gfy public-key)
                   :photo-path          (identicon/identicon public-key)
                   :updates-public-key  public
                   :updates-private-key private
                   :mnemonic            ""
                   :signed-up?          true
                   :signing-phrase      phrase
                   :settings            constants/default-account-settings}]
      (when-not (string/blank? public-key)
        (-> db 
            (accounts-events/add-account account)
            (assoc :dispatch [:login-account address password]))))))

(handlers/register-handler-fx
  :recover-account
  (fn [_ [_ passphrase password]]
    {::recover-account-fx [passphrase password]}))<commit_msg>show 'opt-in' screen to recovery<commit_after>(ns status-im.ui.screens.accounts.recover.events
  (:require
    status-im.ui.screens.accounts.recover.navigation
    [re-frame.core :as re-frame]
    [status-im.native-module.core :as status]
    [status-im.ui.screens.accounts.events :as accounts-events]
    [status-im.utils.types :as types]
    [status-im.utils.identicon :as identicon]
    [clojure.string :as string]
    [status-im.utils.handlers :as handlers]
    [status-im.utils.gfycat.core :as gfycat]
    [status-im.utils.signing-phrase.core :as signing-phrase]
    [status-im.utils.hex :as utils.hex]
    [status-im.constants :as constants]))

;;;; FX

(re-frame/reg-fx
  ::recover-account-fx
  (fn [[passphrase password]]
    (status/recover-account
     (string/trim passphrase)
     password
     #(re-frame/dispatch [:account-recovered % password]))))

;;;; Handlers

(handlers/register-handler-fx
  :account-recovered
  [(re-frame/inject-cofx :get-new-keypair!)]
  (fn [{:keys [db keypair]} [_ result password]]
    (let [data       (types/json->clj result)
          public-key (:pubkey data)
          address    (-> data :address utils.hex/normalize-hex)
          phrase     (signing-phrase/generate)
          {:keys [public private]} keypair
          account {:public-key          public-key
                   :address             address
                   :name                (gfycat/generate-gfy public-key)
                   :photo-path          (identicon/identicon public-key)
                   :updates-public-key  public
                   :updates-private-key private
                   :mnemonic            ""
                   :signed-up?          true
                   :signing-phrase      phrase
                   :settings            constants/default-account-settings}]
      (when-not (string/blank? public-key)
        (-> db 
            (accounts-events/add-account account)
            (assoc :dispatch [:login-account address password])
            (assoc :dispatch-later [{:ms 2000 :dispatch [:navigate-to :usage-data]}]))))))

(handlers/register-handler-fx
  :recover-account
  (fn [_ [_ passphrase password]]
    {::recover-account-fx [passphrase password]}))
{'fraction_non_alphanumeric': 0.13047508690614137, 'fraction_numerical': 0.0009269988412514484, 'mean_word_length': 2.069701280227596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2491276', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1303, 'n_words': 248}