Skip to content

Commit

Permalink
Load UI app config from server
Browse files Browse the repository at this point in the history
  • Loading branch information
madis committed Feb 15, 2024
1 parent c110d84 commit 8441dc5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ designs/deploy
tags
temp
release
config
26 changes: 14 additions & 12 deletions server/src/ethlance/server/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -982,20 +982,22 @@


(defn load-processed-events-checkpoint [callback]
(db/with-async-resolver-conn
conn
(let [result-chan (db/get conn {:select [:*]
:from [:ContractEventCheckpoint]
:order-by [[:created-at :desc]]})]
(take! result-chan (fn [result] (callback nil (clojure.walk/keywordize-keys (get result :checkpoint))))))))
(.then
(district.server.async-db/get-connection)
(fn [conn]
(let [result-chan (db/get conn {:select [:*]
:from [:ContractEventCheckpoint]
:order-by [[:created-at :desc]]})]
(take! result-chan (fn [result] (callback nil (clojure.walk/keywordize-keys (get result :checkpoint)))))))))

(defn save-processed-events-checkpoint [checkpoint & [callback]]
(db/with-async-resolver-conn
conn
(let [result-chan (db/run! conn {:insert-into :ContractEventCheckpoint
:values [{:checkpoint (.stringify js/JSON (clj->js checkpoint))
:created-at (new js/Date)}]} )]
(when (fn? callback) (take! result-chan callback)))))
(.then
(district.server.async-db/get-connection)
(fn [conn]
(let [result-chan (db/run! conn {:insert-into :ContractEventCheckpoint
:values [{:checkpoint (.stringify js/JSON (clj->js checkpoint))
:created-at (new js/Date)}]} )]
(when (fn? callback) (take! result-chan callback))))))

(defn ready-state?
[]
Expand Down
23 changes: 17 additions & 6 deletions ui/src/ethlance/ui/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,28 @@

(def environment (shared-utils/get-environment))

(defn fetch-config-from-server [url callback]
(let []
(-> (js/fetch url)
(.then ,,, (fn [response]
(.json response)))
(.then ,,, (fn [config]
(callback (js->clj config {:keywordize-keys true})))))))

(defn ^:export init []
(let [main-config (ui.config/get-config environment)]
(util.injection/inject-data-scroll! {:injection-selector "#app"})

;; Initialize our district re-mount components
(-> (mount/with-args main-config)
(mount/start))
(fetch-config-from-server
(get-in main-config [:server-config :url])
(fn [config]
;; Initialize our district re-mount components
(-> (mount/with-args (shared-utils/deep-merge main-config config))
(mount/start))

(reg-co-fx! :ethlance {:fx :store :cofx :store})
(reg-co-fx! :ethlance {:fx :store :cofx :store})

;; Initialize our re-frame app state
(re/dispatch-sync [:ethlance/initialize main-config])
;; Initialize our re-frame app state
(re/dispatch-sync [:ethlance/initialize (shared-utils/deep-merge main-config config)])))

::started))
21 changes: 12 additions & 9 deletions ui/src/ethlance/ui/util/urls.cljs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
(ns ethlance.ui.util.urls
(:require
[re-frame.core :as re]
[ethlance.ui.config :as ui-config]))

(defn ipfs-hash->gateway-url
[ipfs-hash]
;TODO: This URL should come from configuration
(cond
(= nil ipfs-hash)
ipfs-hash
(let [config @(re/subscribe [:ethlance.ui.subscriptions/config])
ipfs-gateway (get-in config [:ipfs :gateway])]
(cond
(nil? ipfs-hash)
ipfs-hash

(or
(clojure.string/starts-with? ipfs-hash "http")
(clojure.string/starts-with? ipfs-hash "/"))
ipfs-hash
(or
(clojure.string/starts-with? ipfs-hash "http")
(clojure.string/starts-with? ipfs-hash "/"))
ipfs-hash

:else
(str (get-in (ui-config/get-config) [:ipfs :gateway]) "/" ipfs-hash)))
:else
(str ipfs-gateway "/" ipfs-hash))))

0 comments on commit 8441dc5

Please sign in to comment.