Skip to content

Commit

Permalink
Merge pull request #32 from district0x/thirdweb
Browse files Browse the repository at this point in the history
Connect Wallet button
  • Loading branch information
ginesdt committed Dec 1, 2023
2 parents dcb9a98 + 0f4cc4b commit 0406f62
Show file tree
Hide file tree
Showing 16 changed files with 3,744 additions and 117 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/.cpcache/
/.shadow-cljs/
/server/
/target/
19 changes: 13 additions & 6 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@
:task (do
(println "Compiling smart contracts")
(shell "npx truffle compile"))}
pack-ui-dependencies {:doc "Generate a single js file from all npm dependencies"
:task (do
(println "Packing ui dependencies")
(shell "npx webpack"))}
watch-ui {:doc "Watch and compile ui code changes CLJS -> JS in src/ui/**"
:requires ([babashka.cli :as cli])
:task (let [aliases (or *command-line-args* [])
command-args (format "-M:dev:shadow-cljs%s watch ui" (clojure.string.join "" aliases))]
(println "Starting watch-ui. args:" command-args)
(clojure command-args))}
release-ui {:doc "Compile ui CLJS -> JS in src/ui/** for release"
:requires ([babashka.cli :as cli])
:task (let [aliases (or *command-line-args* [])
command-args (format "-M:shadow-cljs%s release ui" (clojure.string.join "" aliases))]
(println "Preparing UI for release. args:" command-args)
(clojure command-args))}
compile-ui {:doc "Compile ui CLJS -> JS in src/ui/** for release"
:requires ([babashka.cli :as cli])
:task (let [aliases (or *command-line-args* [])
command-args (format "-M:shadow-cljs%s release ui" (clojure.string.join "" aliases))]
(println "Preparing UI for release. args:" command-args)
(clojure command-args))}
release-ui {:doc "compile project and pack all dependencies for release"
:requires ([babashka.cli :as cli])
:depends [compile-ui pack-ui-dependencies]}
watch-server {:doc "Watch and compile server code changes CLJS -> JS in src/server/**"
:requires ([babashka.cli :as cli])
:task (let [aliases (or *command-line-args* [])
Expand Down
8 changes: 4 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
is.d0x/district-server-web3-events {:mvn/version "23.5.22"}
is.d0x/re-frame-web3-fx {:mvn/version "23.5.3"}
is.d0x/district-sendgrid {:mvn/version "23.9.25"}
is.d0x/district-ui-reagent-render {:mvn/version "23.1.26"}
is.d0x/district-ui-reagent-render {:mvn/version "23.10.11"}
is.d0x/district-ui-router {:mvn/version "23.2.9"}
is.d0x/district-ui-smart-contracts {:mvn/version "23.8.7"}
is.d0x/district-ui-web3 {:mvn/version "23.8.7"}
is.d0x/district-ui-web3 {:mvn/version "23.10.11"}
is.d0x/district-ui-web3-accounts {:mvn/version "23.8.7"}
is.d0x/district-ui-web3-chain {:mvn/version "23.8.7"}
is.d0x/district-ui-web3-chain {:mvn/version "23.10.2"}
is.d0x/district-ui-web3-tx-id {:mvn/version "23.10.6"}
mount/mount {:mvn/version "0.1.16"}
org.clojure/clojure {:mvn/version "1.11.1"}
Expand All @@ -51,7 +51,7 @@
{binaryage/devtools {:mvn/version "1.0.7"}
cider/cider-nrepl {:mvn/version "0.27.2"}
cider/piggieback {:mvn/version "0.4.0"}
day8.re-frame/re-frame-10x {:mvn/version "1.5.0"}
day8.re-frame/re-frame-10x {:mvn/version "1.8.1"}
day8.re-frame/test {:mvn/version "0.1.5"}
day8.re-frame/tracing {:mvn/version "0.6.2"}
jamesmacaulay/cljs-promises {:mvn/version "0.1.0"}
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@apollo/server": "4.3.0",
"@metamask/eth-sig-util": "5.0.2",
"@sentry/node": "4.6.6",
"@thirdweb-dev/react": "3.16.2",
"apollo-fetch": "0.7.0",
"axios": "0.27.2",
"better-sqlite3": "7.6.2",
Expand All @@ -27,8 +28,8 @@
"jquery": "3.6.1",
"jsonwebtoken": "9.0.0",
"jwt-decode": "3.1.2",
"react": "16.14.0",
"react-dom": "16.14.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-infinite": "0.13.0",
"react-infinite-scroller": "1.2.6",
"react-masonry-component": "6.3.0",
Expand Down Expand Up @@ -58,7 +59,9 @@
"normalize.css": "8.0.1",
"sass": "1.63.6",
"shadow-cljs": "2.19.8",
"truffle": "5.8.1"
"truffle": "5.8.1",
"webpack": "5.88.2",
"webpack-cli": "5.1.4"
},
"engines": {
"node": "^18.0.0"
Expand Down
1 change: 1 addition & 0 deletions resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
</div>
</div>
</div>
<script src="/js/libs.js"></script>
<script src="/js/main.js"></script>
<script>streamtide.ui.core.init();</script>
</body>
Expand Down
35 changes: 33 additions & 2 deletions resources/scss/layouts/headerSite.scss
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,31 @@
}
}
.btLogin {
width: 297.39px;
margin: 0 auto 39px;
width: 217.39px;
margin: 0 auto 5px;
}
.connectWallet {
background-color: $lilac;
border: 0;
border-radius: 6px;
height: 52px;
color: $white;
justify-content: center;
&.btLogin {
margin-left: 2px;
}
&:hover {
background-color: $yellow;
}
div {
span {
color: $white
}
span:nth-child(2) {
opacity: 0.6;

}
}
}
.policyTerms {
display: flex;
Expand Down Expand Up @@ -340,11 +363,19 @@
}
}
}
.btLoginContainer {

order: 3;
}
.btLogin {
order: 3;
width: 139.71px;
margin: 0;
}
.connectWalletContainer {
order: 4;
min-width: 182px;
}
}
@include media-breakpoint-up(llg) {
.logoSite {
Expand Down
2 changes: 2 additions & 0 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
:main streamtide.ui.core
:infer-externs true
:output-dir "resources/public/js/"
:js-options {:js-provider :external
:external-index "target/index.js"}
:dev {
:source-map true
:source-map-timestamp true
Expand Down
2 changes: 1 addition & 1 deletion src-cljsjs/cljsjs/jwt_decode.cljs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cljsjs.jwt-decode
(:require ["jwt-decode" :as jd]))
(:require ["jwt-decode" :default jd]))

(js/goog.exportSymbol "jwt_decode" jd)
2 changes: 1 addition & 1 deletion src/streamtide/ui/admin/round/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
divisor (if (bn/= sum (new-bn 0)) sum (bn// matching-pool sum))]
(recur (next multipliers) multiplier
(bn/+ acc (bn/* amount (bn/* (- multiplier prev_mult) divisor)))))
(bn/fixed (.integerValue acc js/BigNumber.ROUND_FLOOR)))))))
(bn/fixed (.integerValue ^js/BigNumber acc js/BigNumber.ROUND_FLOOR)))))))
{} amounts)]
receivers-matchings))

Expand Down
69 changes: 69 additions & 0 deletions src/streamtide/ui/components/connect_wallet.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(ns streamtide.ui.components.connect-wallet
(:require ["@thirdweb-dev/react" :refer [ConnectWallet ThirdwebProvider NetworkSelector metamaskWallet coinbaseWallet walletConnect
;rainbowWallet trustWallet
]]
["@thirdweb-dev/chains" :refer [Ethereum, Polygon, Localhost]]
["@thirdweb-dev/react-core" :refer [useWallet useAddress useConnectionStatus]]
["react" :as react]
[district.ui.web3-accounts.subs :as accounts-subs]
[district.ui.web3-accounts.events :as accounts-events]
[district.ui.web3.events :as web3-events]
[district.ui.web3.subs :as web3-subs]
[cljs-web3-next.core :as web3-next]
[re-frame.core :refer [subscribe dispatch]]
[reagent.core :as r]
[streamtide.ui.subs :as st-subs]
[streamtide.ui.config :refer [config-map]]))


(defn connect-wallet [{:keys [:class]}]
(let [day-night (subscribe [::st-subs/day-night-switch])
active-account (subscribe [::accounts-subs/active-account])
active-web3-provider (subscribe [::web3-subs/web3])
active-wallet (useWallet)
loaded? (not= "unknown" (useConnectionStatus))
account (useAddress)]
(react/useEffect (fn []
(when (and loaded? active-wallet)
(-> active-wallet .-connector .getProvider
(.then (fn [provider]
(when (or (not @active-web3-provider) (not= provider (web3-next/current-provider @active-web3-provider)))
(dispatch [::web3-events/create-web3-with-user-permitted-provider {} provider]))))))
js/undefined)
(array active-wallet))
(react/useEffect (fn []
(when loaded?
(if account
(when (not= account @active-account)
(dispatch [::accounts-events/set-accounts [account]]))
(when @active-account
(dispatch [::accounts-events/set-accounts []]))))
js/undefined)
(array account))
(r/create-element ConnectWallet
#js {:className class
:theme (if (= @day-night "day") "light" "dark")
;:switchToActiveChain true
:modalSize "wide"})))


(defn connect-wallet-btn [{:keys [:class] :as opts}]
(r/create-element ThirdwebProvider
(clj->js {:activeChain (-> config-map
:web3-chain
(merge {:slug ""})
(update :chain-id int)
(clojure.set/rename-keys {:chain-id :chainId
:rpc-urls :rpc
:chain-name :name
:native-currency :nativeCurrency})
clj->js)
:clientId "f478f4123340f16303e57df57b6e26ef"
:supportedWallets [(metamaskWallet #js {:recommended true})
(coinbaseWallet)
(walletConnect)
;(rainbowWallet)
;(trustWallet)
]
:supportedChains []})
(r/as-element [:f> connect-wallet opts])))
32 changes: 20 additions & 12 deletions src/streamtide/ui/components/general.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
(:require
[clojure.string :as str]
[district.ui.router.events :as router-events]
[district.ui.web3-accounts.subs :as accounts-subs]
[re-frame.core :refer [dispatch subscribe]]
[streamtide.ui.subs :as streamtide-subs]))
[streamtide.ui.subs :as streamtide-subs]
[streamtide.ui.components.connect-wallet :refer [connect-wallet-btn]]))


(def discord-invite-link "https://discord.com/invite/sS2AWYm")
Expand Down Expand Up @@ -31,15 +33,21 @@

(defn sign-in-button [{:keys [:class]}]
"Button to trigger the user's login or logout"
(let []
(let [active-session? (subscribe [::streamtide-subs/active-account-has-session?])
current-account (subscribe [::accounts-subs/active-account])]
(fn []
(let [active-session? (subscribe [::streamtide-subs/active-account-has-session?])]
(if @active-session?
[:button.btLogin.btBasic.btBasic-light
{:class class
:on-click #(dispatch [:user/sign-out])}
(str "Log out")]
[:button.btLogin.btBasic.btBasic-light
{:class class
:on-click #(dispatch [:user/sign-in])}
(str "WEB3 LOGIN")])))))
[:<>
[:div.btLoginContainer
(when @current-account
(if @active-session?
[:button.btLogin.btBasic.btBasic-light
{:class class
:on-click #(dispatch [:user/sign-out])}
(str "Log out")]
[:button.btLogin.btBasic.btBasic-light
{:class class
:on-click #(dispatch [:user/sign-in])}
(str "WEB3 LOGIN")]))]
[:div.connectWalletContainer
{:class class}
[connect-wallet-btn {:class "btLogin connectWallet"}]]])))
6 changes: 5 additions & 1 deletion src/streamtide/ui/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
:smart-contracts {:contracts smart-contracts-dev/smart-contracts}
:verifiers {:discord {:client-id "1135876901093781544"}}
:web3-chain {:chain-id "1337"
:chain-name "Ganache"}
:rpc-urls ["http://localhost:8545"]
:chain-name "Ganache"
:native-currency {:name "ETH"
:symbol "ETH"
:decimals 18}}
:notifiers {:web-push {:public-key "BGtkUrXx0vlsFpfmf8rDNqswKAlrSUQUE8xN4Jf6F3rtQCpbdR-vakwnUnhnVWYl1kdfUXzjfNini19ZyGVtaMM"}}
;:domain "localhost"
})
Expand Down
10 changes: 7 additions & 3 deletions src/streamtide/ui/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"Main entry point of the Frontend.
Loads the config and load all required modules.
It also load the content of the persistent storage into the re-frame db"
(:require [akiroz.re-frame.storage :as storage]
(:require ["@thirdweb-dev/react-core" :refer [useWallet useAddress]]
[akiroz.re-frame.storage :as storage]
[cljsjs.jquery]
[cljsjs.jwt-decode]
[district.cljs-utils :as cljs-utils]
Expand Down Expand Up @@ -136,8 +137,11 @@
(dev-setup)
(let [full-config (cljs-utils/merge-in
config-map
{:web3 {:authorize-on-init? false}
:web3-accounts {:eip55? true}
{:web3 {:authorize-on-init? false
:connect-on-init? false}
:web3-accounts {:eip55? true
:disable-loading-at-start? true
:disable-polling? true}
:smart-contracts {:format :truffle-json
:contracts-path "/contracts/build/"}
:web3-tx {:disable-loading-recommended-gas-prices? true}
Expand Down
7 changes: 6 additions & 1 deletion src/streamtide/ui/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@
; request a change of network
(re-frame/dispatch [::chain-events/request-switch-chain
chain-id
{:chain-info (:web3-chain config-map)}])
{:on-error [::chain-events/request-add-chain
(:web3-chain config-map)
{:on-error
[::dispatch-n
[[::error-notification/show-error "Cannot switch network"]
[::logging/error "Cannot switch network"]]]}]}])
; interrupt the event processing
(assoc context :queue #queue [])))))))

Expand Down
36 changes: 36 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const path = require('path');
const webpack = require("webpack");
const current_mode = process.env.STREAMTIDE_ENV in ['prod', 'qa'] ? 'production' : 'development';

module.exports = {
entry: './target/index.js',
output: {
filename: 'libs.js',
path: path.resolve(__dirname, 'resources', 'public', 'js'),
},
resolve: {
fallback: {
"fs": false,
"tls": false,
"net": false,
"path": false,
"zlib": false,
"http": false,
"https": false,
"stream": require.resolve("stream-browserify"),
"os": false,
"crypto": false,
"buffer": require.resolve("buffer"),
"process/browser": require.resolve('process/browser'),
}
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser'
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
],
mode: current_mode
};

0 comments on commit 0406f62

Please sign in to comment.