status-react/src/status_im/utils/ethereum/macros.clj

21 lines
773 B
Clojure
Raw Normal View History

2017-11-22 10:37:20 +00:00
(ns status-im.utils.ethereum.macros
(:require [clojure.string :as string]
[clojure.java.io :as io]))
(defn icon-path
[symbol]
(let [s (str "./resources/images/tokens/" (name symbol) ".png")]
2017-11-22 10:37:20 +00:00
(if (.exists (io/file s))
`(js/require ~s)
`(js/require "./resources/images/tokens/default.png"))))
(defn- token->icon [{:keys [icon symbol]}]
;; Tokens can define their own icons.
;; If not try to make one using a local image as resource, if it does not exist fallback to default.
(or icon (icon-path symbol)))
(defmacro resolve-icons
"In react-native arguments to require must be static strings.
Resolve all icons at compilation time so no variable is used."
[tokens]
(mapv #(assoc-in % [:icon :source] (token->icon %)) tokens))