From d6aae3fb5e4af4c503da432e0fa97d1d2af563fa Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Tue, 22 Aug 2017 23:15:16 +0300 Subject: [PATCH] Render token balances to Github comment image --- resources/templates/bounty.html | 28 +++++++++++++++++++++--- src/clj/commiteth/bounties.clj | 9 ++++---- src/clj/commiteth/scheduler.clj | 6 +++-- src/clj/commiteth/util/png_rendering.clj | 18 +++++++++++---- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/resources/templates/bounty.html b/resources/templates/bounty.html index 9697ae0..1560911 100644 --- a/resources/templates/bounty.html +++ b/resources/templates/bounty.html @@ -11,7 +11,7 @@ margin: 0px; padding: 1em; width: 1336px; - height: 300px; + height: {{ image-height }}px; } .commiteth-logo { @@ -34,11 +34,28 @@ top: 196px; left: 32px; } - .comment-balance { + .comment-eth-balance { color: #343434; position: fixed; top: 196px; left: 135px; + } + + .token-list { + position: fixed; + top: 253px; + left: 32px; + } + .comment-token { + color: #a8aab1; + display: inline; + font-size: 48px; + } + .comment-token-balance { + color: #343434; + display:inline; + font-size: 48px; + left: 135px; } .qr-image { @@ -64,7 +81,12 @@
{{issue-url}}
-
ETH
{{balance}}
+
ETH
{{eth-balance}}
+
+ {% for token in tokens %} +
{{ token.tla }}
 {{ token.balance }}
+ {% endfor %} +
diff --git a/src/clj/commiteth/bounties.clj b/src/clj/commiteth/bounties.clj index 6e9aedb..f0770bd 100644 --- a/src/clj/commiteth/bounties.clj +++ b/src/clj/commiteth/bounties.clj @@ -59,15 +59,16 @@ (map (partial add-bounty-for-issue repo repo-id) bounty-issues)))) -(defn update-bounty-comment-image [issue-id owner repo issue-number contract-address balance balance-str] - (let [hash (github/github-comment-hash owner repo issue-number balance) +(defn update-bounty-comment-image [issue-id owner repo issue-number contract-address eth-balance eth-balance-str tokens] + (let [hash (github/github-comment-hash owner repo issue-number eth-balance) issue-url (str owner "/" repo "/issues/" (str issue-number)) png-data (png-rendering/gen-comment-image contract-address - balance-str + eth-balance-str + tokens issue-url)] (log/debug "update-bounty-comment-image" issue-id owner repo issue-number) - (log/debug contract-address balance-str) + (log/debug contract-address eth-balance-str) (log/debug "hash" hash) (if png-data diff --git a/src/clj/commiteth/scheduler.clj b/src/clj/commiteth/scheduler.clj index fbf5b0e..d2d67c3 100644 --- a/src/clj/commiteth/scheduler.clj +++ b/src/clj/commiteth/scheduler.clj @@ -37,7 +37,8 @@ issue-number contract-address balance - balance-str) + balance-str + {}) (github/update-comment owner repo comment-id @@ -227,7 +228,8 @@ issue-number contract-address balance-eth - balance-eth-str) + balance-eth-str + token-balances) (github/update-comment owner repo comment-id diff --git a/src/clj/commiteth/util/png_rendering.clj b/src/clj/commiteth/util/png_rendering.clj index 0845bb0..05a79a6 100644 --- a/src/clj/commiteth/util/png_rendering.clj +++ b/src/clj/commiteth/util/png_rendering.clj @@ -25,13 +25,23 @@ :size [255 255]))) -(defn gen-comment-image [address balance issue-url] +(defn token-map->list [tokens] + (mapv (fn [[tla balance]] {:tla (subs (str tla) 1) + :balance balance}) + tokens)) + +(defn image-height [tokens] + (+ 300 (* 32 (count (keys tokens))))) + +(defn gen-comment-image [address balance-eth tokens issue-url] (let [qr-image (String. (image->base64 (generate-qr-image address)) "ISO-8859-1") html (:body (render "bounty.html" - {:qr-image qr-image - :balance balance - :address address + {:qr-image qr-image + :eth-balance balance-eth + :tokens (token-map->list tokens) + :image-height (image-height tokens) + :address address :issue-url issue-url})) command (env :html2png-command "wkhtmltoimage") {out :out err :err exit :exit}