2023-12-19 17:41:30 +00:00
|
|
|
(ns legacy.status-im.ethereum.macros
|
2023-10-16 22:03:18 +00:00
|
|
|
(:require
|
|
|
|
[clojure.java.io :as io]
|
|
|
|
[clojure.string :as string]))
|
2017-11-22 10:37:20 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn token-icon-path
|
|
|
|
[path]
|
2022-01-17 12:52:54 +00:00
|
|
|
(fn [el]
|
2022-12-20 14:45:37 +00:00
|
|
|
(let [el (string/replace el ".png" "")
|
|
|
|
s (str path el ".png")
|
|
|
|
s-js (str "." s)]
|
2022-01-17 12:52:54 +00:00
|
|
|
(when (.exists (io/file s))
|
|
|
|
[el `(js/require ~s-js)]))))
|
2017-11-22 10:37:20 +00:00
|
|
|
|
|
|
|
(defmacro resolve-icons
|
|
|
|
"In react-native arguments to require must be static strings.
|
|
|
|
Resolve all icons at compilation time so no variable is used."
|
2022-01-17 12:52:54 +00:00
|
|
|
[network]
|
2022-12-20 14:45:37 +00:00
|
|
|
(let [path (str "./resources/images/tokens/" (name network) "/")
|
2022-01-17 12:52:54 +00:00
|
|
|
files (->> (io/file path)
|
|
|
|
file-seq
|
2022-12-13 20:04:26 +00:00
|
|
|
(filter #(string/ends-with? % "png"))
|
|
|
|
(map #(first (string/split (.getName %) #"@")))
|
2022-01-17 12:52:54 +00:00
|
|
|
distinct)]
|
|
|
|
(into {} (map (token-icon-path path) files))))
|
2018-10-10 11:07:48 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn network->icon
|
|
|
|
[network]
|
|
|
|
(let [s (str "./resources/images/tokens/" (name network) "/0-native.png")
|
|
|
|
s-js (str "." s)]
|
2018-10-10 11:07:48 +00:00
|
|
|
(if (.exists (io/file s))
|
2022-08-31 15:19:33 +00:00
|
|
|
`(js/require ~s-js)
|
|
|
|
`(js/require "../resources/images/tokens/default-token.png"))))
|
2018-10-10 11:07:48 +00:00
|
|
|
|
|
|
|
(defmacro resolve-native-currency-icons
|
|
|
|
"In react-native arguments to require must be static strings.
|
|
|
|
Resolve all icons at compilation time so no variable is used."
|
|
|
|
[all-native-currencies]
|
|
|
|
(into {}
|
|
|
|
(map (fn [[network native-currency]]
|
2022-12-20 14:45:37 +00:00
|
|
|
[network
|
|
|
|
(assoc-in native-currency
|
|
|
|
[:icon :source]
|
|
|
|
(network->icon network))])
|
|
|
|
all-native-currencies)))
|