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
|
2018-04-18 12:17:10 +00:00
|
|
|
[network symbol]
|
|
|
|
(let [s (str "./resources/images/tokens/" (name network) "/" (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"))))
|
|
|
|
|
2018-04-18 12:17:10 +00:00
|
|
|
(defn- token->icon [network {:keys [icon symbol]}]
|
2017-11-22 10:37:20 +00:00
|
|
|
;; 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.
|
2018-04-18 12:17:10 +00:00
|
|
|
(or icon (icon-path network symbol)))
|
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."
|
2018-04-18 12:17:10 +00:00
|
|
|
[network tokens]
|
|
|
|
(mapv #(assoc-in % [:icon :source] (token->icon network %)) tokens))
|