diff --git a/deps.edn b/deps.edn index 938ae75..456b7cc 100644 --- a/deps.edn +++ b/deps.edn @@ -25,7 +25,8 @@ district0x/district-ui-window-size {:mvn/version "1.0.1"} is.d0x/cljs-web3-next {:mvn/version "23.3.1"} is.d0x/district-server-config {:mvn/version "23.4.7"} - is.d0x/district-server-db {:mvn/version "24.6.19"} + ;is.d0x/district-server-db {:mvn/version "24.6.19"} + is.d0x/district-server-db {:local/root "../d0x-libs/server/district-server-db"} 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"} diff --git a/package.json b/package.json index 10f1445..30e5f22 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "expo-modules-core": "^1.12.15", "expo-web-browser": "^13.0.3", "express": "4.18.2", - "graphql": "16.6.0", + "graphql": "16.8.2", "graphql-fields": "2.0.3", "graphql-tools": "8.3.14", "highlight.js": "11.5.1", @@ -55,8 +55,8 @@ "xregexp": "5.1.1" }, "resolutions": { - "graphql": "^16.6.0", - "**/graphql": "^16.6.0" + "graphql": "16.8.2", + "**/graphql": "16.8.2" }, "devDependencies": { "@openzeppelin/contracts": "4.8.2", diff --git a/src/streamtide/ui/components/connect_wallet.cljs b/src/streamtide/ui/components/connect_wallet.cljs index 818e352..9ace1d3 100644 --- a/src/streamtide/ui/components/connect_wallet.cljs +++ b/src/streamtide/ui/components/connect_wallet.cljs @@ -1,8 +1,8 @@ (ns streamtide.ui.components.connect-wallet (:require - ["thirdweb/react" :refer [ConnectButton ThirdwebProvider useActiveWallet useActiveAccount useConnect useActiveWalletChain]] - ["thirdweb/wallets" :refer [createWallet inAppWallet]] - ["thirdweb" :refer [createThirdwebClient defineChain]] + ["thirdweb/react" :refer [ConnectButton ThirdwebProvider useActiveWallet useActiveAccount useConnect useActiveWalletChain useConnectModal]] + ["thirdweb/wallets" :refer [createWallet]] + ["thirdweb" :refer [createThirdwebClient]] ["react" :as react] [camel-snake-kebab.core :as csk] [camel-snake-kebab.extras :refer [transform-keys]] @@ -29,26 +29,28 @@ :chain-name :name :native-currency :nativeCurrency})))) -(defn create-provider [^js wallet] +(defn create-provider [^js wallet ^js connectModal connect-config] #js {:request (fn [^js args] - (case (.-method args) - "eth_chainId" (js/Promise. (fn [] (-> wallet .getChain .-id))) - "eth_sendTransaction" (let [chainId (-> wallet .getChain .-id) - params (js->clj (aget (.-params args) 0) :keywordize-keys true) - params (merge params {:chainId chainId}) - params (dissoc params :gasPrice :gas) - params (clj->js params)] - (-> wallet .getAccount (.sendTransaction params ))) - "personal_sign" (let [account (aget (.-params args) 1) - data-raw (aget (.-params args) 0) - data (web3-next/to-ascii data-raw) - params (clj->js {:account account - :message {:raw data}}) - response (-> wallet .getAccount (.signMessage params))] - response) - ;"eth_requestAccounts" "" - "wallet_switchEthereumChain" (.switchChain wallet (build-chain-info)) - (js/Error. (str "Method not implemented: " (.-method args)))))}) + (if (nil? wallet) + ((.-connect connectModal) connect-config) + (case (.-method args) + "eth_chainId" (js/Promise. (fn [] (-> wallet .getChain .-id))) + "eth_sendTransaction" (let [chainId (-> wallet .getChain .-id) + params (js->clj (aget (.-params args) 0) :keywordize-keys true) + params (merge params {:chainId chainId}) + params (dissoc params :gasPrice :gas) + params (clj->js params)] + (-> wallet .getAccount (.sendTransaction params ))) + "personal_sign" (let [account (aget (.-params args) 1) + data-raw (aget (.-params args) 0) + data (web3-next/to-ascii data-raw) + params (clj->js {:account account + :message {:raw data}}) + response (-> wallet .getAccount (.signMessage params))] + response) + ;"eth_requestAccounts" "" + "wallet_switchEthereumChain" (.switchChain wallet (build-chain-info)) + (js/Promise.reject (str "Method not implemented: " (.-method args))))))}) (re-frame/reg-event-fx :logged-in? @@ -58,26 +60,76 @@ :result (= address (:user/address active-session))}}))) (defn connect-wallet [{:keys [:class]}] - (let [ - day-night (subscribe [::st-subs/day-night-switch]) + (let [day-night (subscribe [::st-subs/day-night-switch]) active-account (subscribe [::accounts-subs/active-account]) active-chain (subscribe [::chain-subs/chain]) active-wallet (useActiveWallet) loaded? (not (.-isConnecting (useConnect))) account (useActiveAccount) chain (useActiveWalletChain) - client (createThirdwebClient #js {:clientId "f478f4123340f16303e57df57b6e26ef"})] + client (createThirdwebClient #js {:clientId "f478f4123340f16303e57df57b6e26ef"}) + connect-config (clj->js {:auth {:doLogin (fn [^js signedPayload] + (js/Promise. (fn [resolve reject] + (dispatch [:user/-authenticate + {:payload (transform-keys csk/->kebab-case (js->clj (.-payload signedPayload) :keywordize-keys true)) + :signature (.-signature signedPayload) + :callback (fn [err res] + (if err + (reject err) + (resolve res)))}])))) + :getLoginPayload (fn [^js account] + (js/Promise. + (fn [resolve reject] + (dispatch [:user/request-login-payload + {:address (eip55/address->checksum (.-address account)) + :chain-id (.-chainId account) + :callback + (fn [err res] + (if err + (reject err) + (resolve (clj->js + (into {} + (filter (fn [[_ v]] + (some? v)) + (transform-keys csk/->snake_case res)))))))}])))) + :isLoggedIn (fn [address] + (js/Promise. (fn [resolve reject] + (dispatch [:logged-in? {:user/address (eip55/address->checksum address) + :callback (fn [err res] + (if err + (reject err) + (resolve res)))}])))) + :doLogout (fn [] + (js/Promise. (fn [resolve] + (dispatch [:user/sign-out {:callback (fn [] + (resolve))}]))))} + :connectButton {:className class} + :detailsButton {:className class} + :switchButton {:className class} + :signInButton {:className class} + :client client + :theme (if (= @day-night "day") "light" "dark") + :wallets [ + (createWallet "io.metamask") + (createWallet "com.coinbase.wallet") + (createWallet "io.rabby") + (createWallet "walletConnect")] + :showAllWallets false + :chain (build-chain-info) + :switchToActiveChain true}) + connectModal (useConnectModal) + provider (create-provider active-wallet connectModal connect-config)] + ;; some libraries assume the provider is in window.ethereum, so we set our wrapper in there to intercept any call + (set! (.-ethereum js/window) provider) + (dispatch [::web3-events/create-web3-with-user-permitted-provider {} provider]) (react/useEffect (fn [] - (when (and loaded? active-wallet) - (let [provider (create-provider active-wallet)] - (set! (.-ethereum js/window) provider) - (dispatch [::web3-events/create-web3-with-user-permitted-provider {} provider]) + (when (and loaded? active-wallet) (dispatch [::chain-events/set-chain (-> active-wallet .getChain .-id)]) - (dispatch [::accounts-events/set-accounts [(-> active-wallet .getAccount .-address)]]))) - js/undefined) + (dispatch [::accounts-events/set-accounts [(-> active-wallet .getAccount .-address)]])) + js/undefined) (array active-wallet)) (react/useEffect (fn [] - (when (and loaded?) + (when loaded? (let [account-address (if account (.-address account) nil)] (if account-address (when (not= account-address @active-account) @@ -94,57 +146,7 @@ js/undefined) (array chain)) (r/create-element ConnectButton - (clj->js { - :auth { - :doLogin (fn [^js signedPayload] - (js/Promise. (fn [resolve reject] - (dispatch [:user/-authenticate - {:payload (transform-keys csk/->kebab-case (js->clj (.-payload signedPayload) :keywordize-keys true)) - :signature (.-signature signedPayload) - :callback (fn [err res] - (if err - (reject err) - (resolve res)))}])))) - :getLoginPayload (fn [^js account] - (js/Promise. - (fn [resolve reject] - (dispatch [:user/request-login-payload - {:address (eip55/address->checksum (.-address account)) - :chain-id (.-chainId account) - :callback - (fn [err res] - (if err - (reject err) - (resolve (clj->js - (into {} - (filter (fn [[_ v]] - (some? v)) - (transform-keys csk/->snake_case res)))))))}])))) - :isLoggedIn (fn [address] - (js/Promise. (fn [resolve reject] - (dispatch [:logged-in? {:user/address (eip55/address->checksum address) - :callback (fn [err res] - (if err - (reject err) - (resolve res)))}])))) - :doLogout (fn [] - (js/Promise. (fn [resolve] - (dispatch [:user/sign-out {:callback (fn [] - (resolve))}]))))} - :connectButton {:className class} - :detailsButton {:className class} - :switchButton {:className class} - :signInButton {:className class} - :client client - :theme (if (= @day-night "day") "light" "dark") - :wallets [ - (createWallet "io.metamask") - (createWallet "com.coinbase.wallet") - (createWallet "io.rabby") - (createWallet "walletConnect")] - :showAllWallets false - :chain (build-chain-info) - :switchToActiveChain true})))) + connect-config))) (defn connect-wallet-btn [{:keys [:class] :as opts}] diff --git a/src/streamtide/ui/core.cljs b/src/streamtide/ui/core.cljs index 8c29776..30e2930 100644 --- a/src/streamtide/ui/core.cljs +++ b/src/streamtide/ui/core.cljs @@ -117,9 +117,9 @@ {:register :on-navigate :events #{::router-events/navigate} :dispatch-to [::close-mobile-menu]} - {:register :web3-created - :events #{::web3-events/web3-created} - :dispatch-to [::st-events/web3-created]} + ;{:register :web3-created + ; :events #{::web3-events/web3-created} + ; :dispatch-to [::st-events/web3-created]} {:register :web3-creation-failed :events #{::web3-events/web3-creation-failed} :dispatch-to [::st-events/web3-creation-failed]} @@ -142,6 +142,7 @@ :web3-accounts {:eip55? true :disable-loading-at-start? true :disable-polling? true} + :web3-chain {:disable-loading-at-start? true} :smart-contracts {:format :truffle-json :contracts-path "/contracts/build/"} :web3-tx {:disable-loading-recommended-gas-prices? true} diff --git a/webpack.config.js b/webpack.config.js index 5933443..6fb147d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -28,6 +28,7 @@ module.exports = { "crypto": false, "buffer": require.resolve("buffer"), "process/browser": require.resolve('process/browser'), + "vm": false } }, module: { diff --git a/yarn.lock b/yarn.lock index 6c306d0..18ed367 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4499,9 +4499,9 @@ "@types/range-parser" "*" "@types/express-serve-static-core@^4.17.18", "@types/express-serve-static-core@^4.17.30", "@types/express-serve-static-core@^4.17.33": - version "4.19.3" - resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.19.3.tgz#e469a13e4186c9e1c0418fb17be8bc8ff1b19a7a" - integrity sha512-KOzM7MhcBFlmnlr/fzISFF5vGWVSvN6fTd4T+ExOt08bA/dA5kpSzY52nMsI1KDFmUREpJelPYyuslLRSjjgCg== + version "4.19.5" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.19.5.tgz#218064e321126fcf9048d1ca25dd2465da55d9c6" + integrity sha512-y6W03tvrACO72aijJ5uF02FRq5cgDR9lUxddQ8vyF+GvmjJQqbzDcJngEjURc+ZsG31VI3hODNZJ2URj86pzmg== dependencies: "@types/node" "*" "@types/qs" "*" @@ -4574,9 +4574,9 @@ form-data "^4.0.0" "@types/node@*", "@types/node@>=10.0.0": - version "20.14.5" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.5.tgz#fe35e3022ebe58b8f201580eb24e1fcfc0f2487d" - integrity sha512-aoRR+fJkZT2l0aGOJhuA8frnCSoNX6W7U2mpNq63+BxBIj5BQFt8rHy627kijCmm63ijdSdwvGgpUsU6MBsZZA== + version "20.14.6" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.6.tgz#f3c19ffc98c2220e18de259bb172dd4d892a6075" + integrity sha512-JbA0XIJPL1IiNnU7PFxDXyfAwcwVVrOoqyzzyQTyMeVhBzkJVMSkC1LlVsRQ2lpqiY4n6Bb9oCS6lzDKVQxbZw== dependencies: undici-types "~5.26.4" @@ -7178,9 +7178,9 @@ ee-first@1.1.1: integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== electron-to-chromium@^1.4.796: - version "1.4.806" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.806.tgz#2cb046631cbabceb26fc72be68d273fa183e36bc" - integrity sha512-nkoEX2QIB8kwCOtvtgwhXWy2IHVcOLQZu9Qo36uaGB835mdX/h8uLRlosL6QIhLVUnAiicXRW00PwaPZC74Nrg== + version "1.4.807" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.807.tgz#4d6c5ea1516f0164ac5bfd487ccd4ee9507c8f01" + integrity sha512-kSmJl2ZwhNf/bcIuCH/imtNOKlpkLDn2jqT5FJ+/0CXjhnFaOa9cOe9gHKKy71eM49izwuQjZhKk+lWQ1JxB7A== element-resize-detector@^1.1.9: version "1.2.4" @@ -8716,16 +8716,11 @@ graphql-tools@8.3.14: optionalDependencies: "@apollo/client" "~3.2.5 || ~3.3.0 || ~3.4.0 || ~3.5.0 || ~3.6.0 || ~3.7.0" -graphql@15.8.0, graphql@^15.3.0, graphql@^16.6.0: +graphql@15.8.0, graphql@16.8.2, graphql@^15.3.0: version "16.8.2" resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.2.tgz#54771c7ff195da913f5e70af8044a026d32eca2a" integrity sha512-cvVIBILwuoSyD54U4cF/UXDh5yAobhNV/tPygI4lZhgOIJQE/WLWC4waBRb4I6bDVYb3OVx3lfHbaQOEoUD5sg== -graphql@16.6.0: - version "16.6.0" - resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.6.0.tgz#c2dcffa4649db149f6282af726c8c83f1c7c5fdb" - integrity sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw== - h3@^1.10.2, h3@^1.11.1: version "1.11.1" resolved "https://registry.yarnpkg.com/h3/-/h3-1.11.1.tgz#e9414ae6f2a076a345ea07256b320edb29bab9f7"