<commit_before>(ns status-im.ui.screens.wallet.collectibles.kudos.events
  (:require [status-im.ui.screens.wallet.collectibles.events :as collectibles]
            [status-im.utils.http :as http]
            [status-im.utils.ethereum.erc721 :as erc721]
            [status-im.utils.ethereum.tokens :as tokens]
            [re-frame.core :as re-frame]
            [status-im.utils.handlers :as handlers]
            [status-im.constants :as constants]
            [status-im.utils.ethereum.core :as ethereum]))

(def kudos :KDO)

(defmethod collectibles/load-collectible-fx kudos [{db :db} symbol id]
  (let [chain-id (get-in constants/default-networks [(:network db) :config :NetworkId])]
    {:erc721-token-uri [(:web3 db) symbol id chain-id]}))

(re-frame/reg-fx
 :erc721-token-uri
 (fn [[web3 symbol tokenId chain-id]]
   (let [chain (ethereum/chain-id->chain-keyword chain-id)
         contract (:address (tokens/symbol->token chain symbol))]
     (erc721/token-uri web3 contract tokenId
                       #(re-frame/dispatch [:token-uri-success
                                            tokenId
                                            (when %2
                                              ;;TODO extra chars in rinkeby
                                              (subs %2 (.indexOf %2 "http")))])))))

(handlers/register-handler-fx
 :token-uri-success
 (fn [_ [_ tokenId token-uri]]
   {:http-get {:url                    token-uri
               :success-event-creator (fn [o]
                                        [:load-collectible-success kudos {tokenId (http/parse-payload o)}])
               :failure-event-creator (fn [o]
                                        [:load-collectible-failure kudos {tokenId (http/parse-payload o)}])}}))<commit_msg>http kudos token image<commit_after>(ns status-im.ui.screens.wallet.collectibles.kudos.events
  (:require [status-im.ui.screens.wallet.collectibles.events :as collectibles]
            [status-im.utils.http :as http]
            [status-im.utils.ethereum.erc721 :as erc721]
            [status-im.utils.ethereum.tokens :as tokens]
            [re-frame.core :as re-frame]
            [status-im.utils.handlers :as handlers]
            [status-im.constants :as constants]
            [status-im.utils.ethereum.core :as ethereum]
            [clojure.string :as string]))

(def kudos :KDO)

(defmethod collectibles/load-collectible-fx kudos [{db :db} symbol id]
  (let [chain-id (get-in constants/default-networks [(:network db) :config :NetworkId])]
    {:erc721-token-uri [(:web3 db) symbol id chain-id]}))

(re-frame/reg-fx
 :erc721-token-uri
 (fn [[web3 symbol tokenId chain-id]]
   (let [chain (ethereum/chain-id->chain-keyword chain-id)
         contract (:address (tokens/symbol->token chain symbol))]
     (erc721/token-uri web3 contract tokenId
                       #(re-frame/dispatch [:token-uri-success
                                            tokenId
                                            (when %2
                                              (subs %2 (.indexOf %2 "http")))]))))) ;; extra chars in rinkeby

(handlers/register-handler-fx
 :token-uri-success
 (fn [_ [_ tokenId token-uri]]
   {:http-get {:url
               token-uri
               :success-event-creator
               (fn [o]
                 [:load-collectible-success kudos {tokenId (update (http/parse-payload o)
                                                                   :image
                                                                   string/replace
                                                                   #"http:"
                                                                   "https:")}]) ;; http in mainnet
               :failure-event-creator
               (fn [o]
                 [:load-collectible-failure kudos {tokenId (http/parse-payload o)}])}}))
{'fraction_non_alphanumeric': 0.1239968936060057, 'fraction_numerical': 0.010872378980067305, 'mean_word_length': 1.5254901960784313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3226760', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1076, 'n_words': 232}