From 8ec2f23203dd1643205a8ff022ff4e4530b7e905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 4 Aug 2022 10:20:44 +0200 Subject: [PATCH] nix: pass OPENSEA_API_KEY via saveAccountAndLogin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here the injection of OpenSea API key was done at compile time: https://github.com/status-im/status-mobile/commit/aa72ac57 But this makes `status-go` builds impure, and also prevents them from being extracted from `status-mobile` into `status-go` repo. Instead we pass the `OPENSEA_API_KEY` env variable to JS bundle at build time, which is then passed to `status-go` via the `Statusgo.saveAccountAndLogin` call in `saveAccountAndLogin`: https://github.com/status-im/status-mobile/blob/51174f84/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java#L323-L327 Which sends `NodeConfig` that also contains `WalletConfig` which can include `OpenseaAPIKey`: ```go type WalletConfig struct { Enabled bool OpenseaAPIKey string `json:"OpenseaAPIKey"` } ``` https://github.com/status-im/status-go/blob/0135cc15/params/config.go#L510-L514 Signed-off-by: Jakub SokoĊ‚owski --- nix/mobile/android/default.nix | 2 +- nix/mobile/android/release.nix | 2 +- nix/mobile/ios/status-go-shell.nix | 2 +- nix/status-go/mobile/build.nix | 13 +------------ shadow-cljs.edn | 13 ++++++++++--- src/status_im/keycard/simulated_keycard.cljs | 5 +++-- src/status_im/multiaccounts/login/core.cljs | 5 +++-- src/status_im/node/core.cljs | 14 ++++++++++++-- src/status_im/utils/config.cljs | 2 ++ 9 files changed, 34 insertions(+), 24 deletions(-) diff --git a/nix/mobile/android/default.nix b/nix/mobile/android/default.nix index 65a885d90a..015aa65df0 100644 --- a/nix/mobile/android/default.nix +++ b/nix/mobile/android/default.nix @@ -37,7 +37,7 @@ in { export STATUS_NIX_MAVEN_REPO="${deps.gradle}" # required by some makefile targets - export STATUS_GO_ANDROID_LIBDIR=${status-go {}} + export STATUS_GO_ANDROID_LIBDIR=${status-go} # check if node modules changed and if so install them $STATUS_MOBILE_HOME/nix/scripts/node_modules.sh ${deps.nodejs-patched} diff --git a/nix/mobile/android/release.nix b/nix/mobile/android/release.nix index 19f139055e..2b74f057d6 100644 --- a/nix/mobile/android/release.nix +++ b/nix/mobile/android/release.nix @@ -77,7 +77,7 @@ in stdenv.mkDerivation rec { ANDROID_NDK_ROOT = "${androidPkgs.ndk}"; # Used by the Android Gradle build script in android/build.gradle - STATUS_GO_ANDROID_LIBDIR = status-go { inherit secretsFile; }; + STATUS_GO_ANDROID_LIBDIR = status-go; phases = [ "unpackPhase" "secretsPhase" "buildPhase" "checkPhase" "installPhase" diff --git a/nix/mobile/ios/status-go-shell.nix b/nix/mobile/ios/status-go-shell.nix index 777b1540a9..4b9ecd1b8b 100644 --- a/nix/mobile/ios/status-go-shell.nix +++ b/nix/mobile/ios/status-go-shell.nix @@ -7,7 +7,7 @@ mkShell { shellHook = '' - export STATUS_GO_IOS_LIBDIR=${status-go {}}/Statusgo.xcframework + export STATUS_GO_IOS_LIBDIR=${status-go}/Statusgo.xcframework RCTSTATUS_DIR="$STATUS_MOBILE_HOME/modules/react-native-status/ios/RCTStatus" targetBasename='Statusgo.xcframework' diff --git a/nix/status-go/mobile/build.nix b/nix/status-go/mobile/build.nix index 6426d232d2..decbe53d71 100644 --- a/nix/status-go/mobile/build.nix +++ b/nix/status-go/mobile/build.nix @@ -9,9 +9,6 @@ , goBuildLdFlags ? [ ] , outputFileName ? "status-go-${source.shortRev}-${platform}.aar" }: -# Path to the file containing secret environment variables -{ secretsFile ? "" }: - let inherit (lib) concatStringsSep optionalString optional; in buildGoPackage { @@ -26,21 +23,13 @@ in buildGoPackage { ++ optional (platform == "android") openjdk ++ optional (platform == "ios") xcodeWrapper; - ldflags = concatStringsSep " " (goBuildLdFlags - ++ lib.optionals (secretsFile != "") ["-X node.OpenseaKeyFromEnv=$OPENSEA_API_KEY"]); + ldflags = concatStringsSep " " goBuildLdFlags; ANDROID_HOME = optionalString (platform == "android") androidPkgs.sdk; # Ensure XCode is present for iOS, instead of failing at the end of the build. preConfigure = optionalString (platform == "ios") utils.enforceXCodeAvailable; - # If secretsFile is not set we use generate keystore. - preBuild = if (secretsFile != "") then '' - source "${secretsFile}" - '' else '' - echo "No secrets provided!" - ''; - buildPhase = '' runHook preBuild echo -e "\nBuilding $pname for: ${concatStringsSep "," targets}" diff --git a/shadow-cljs.edn b/shadow-cljs.edn index def3554ec6..dbee5cc24b 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -43,7 +43,9 @@ :dev {:devtools {:after-load status-im.reloader/reload :build-notify status-im.reloader/build-notify :preloads [re-frisk-remote.preload]} - :closure-defines {status-im.utils.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"} + :closure-defines + {status-im.utils.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN" + status-im.utils.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"} :compiler-options {:output-feature-set :es5 :closure-defines {re-frame.trace/trace-enabled? true} @@ -55,7 +57,10 @@ :local-ip #shadow/env "SHADOW_HOST"} :chunks {:fleets status-im.fleet.default-fleet/default-fleets :chats status-im.chat.default-chats/default-chats} - :release {:closure-defines {status-im.utils.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"} + :release + {:closure-defines + {status-im.utils.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN" + status-im.utils.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"} :compiler-options {:output-feature-set :es6 ;;disable for android build as there ;;is an intermittent warning with deftype @@ -77,7 +82,9 @@ :main status-im.test-runner/main ;; set :ui-driven to true to let shadow-cljs inject node-repl :ui-driven true - :closure-defines {status-im.utils.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"} + :closure-defines + {status-im.utils.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN" + status-im.utils.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"} :compiler-options {;; needed because we override require and it ;; messes with source-map which reports callstack ;; exceeded exceptions instead of real issues diff --git a/src/status_im/keycard/simulated_keycard.cljs b/src/status_im/keycard/simulated_keycard.cljs index f6951175c5..63942c041a 100644 --- a/src/status_im/keycard/simulated_keycard.cljs +++ b/src/status_im/keycard/simulated_keycard.cljs @@ -10,7 +10,8 @@ [status-im.i18n.i18n :as i18n] [clojure.string :as string] [taoensso.timbre :as log] - [status-im.multiaccounts.create.core :as multiaccounts.create])) + [status-im.multiaccounts.create.core :as multiaccounts.create] + [status-im.node.core :as node])) (def kk1-password "000000") (def default-pin "111111") @@ -432,7 +433,7 @@ (types/clj->json accounts-data))) (defn login [{:keys [key-uid multiaccount-data password]}] - (status/login-with-config key-uid multiaccount-data password nil)) + (status/login-with-config key-uid multiaccount-data password node/login-node-config)) (defn send-transaction-with-signature [{:keys [transaction on-completed]}] diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index b9052f2572..7f8d26de00 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -40,7 +40,8 @@ [status-im.utils.platform :as platform] [status-im.ethereum.tokens :as tokens] [clojure.string :as string] - [status-im.utils.wallet-connect :as wallet-connect])) + [status-im.utils.wallet-connect :as wallet-connect] + [status-im.node.core :as node])) (re-frame/reg-fx ::initialize-communities-enabled @@ -63,7 +64,7 @@ (re-frame/reg-fx ::login (fn [[key-uid account-data hashed-password]] - (status/login-with-config key-uid account-data hashed-password nil))) + (status/login-with-config key-uid account-data hashed-password node/login-node-config))) (re-frame/reg-fx ::export-db diff --git a/src/status_im/node/core.cljs b/src/status_im/node/core.cljs index 5e3699a6a9..c05350c754 100644 --- a/src/status_im/node/core.cljs +++ b/src/status_im/node/core.cljs @@ -60,6 +60,14 @@ (assoc :ListenAddr ":30304" :DataDir (str (:DataDir config) "_dev")))) +(def login-node-config + {:WalletConfig (cond-> {:Enabled true} + (not= config/opensea-api-key "") + (assoc :OpenseaAPIKey config/opensea-api-key))}) + +(defn- get-login-node-config [config] + (merge config login-node-config)) + (defn- pick-nodes "Picks `limit` different nodes randomly from the list of nodes if there is more than `limit` nodes in the list, otherwise return the list @@ -99,6 +107,9 @@ :always (get-base-node-config) + :always + (get-login-node-config) + current-fleet (assoc :NoDiscovery wakuv2-enabled :Rendezvous (if wakuv2-enabled false (boolean (seq rendezvous-nodes))) @@ -118,8 +129,7 @@ :RendezvousNodes (if wakuv2-enabled [] rendezvous-nodes)}) :always - (assoc :WalletConfig {:Enabled true} - :LocalNotificationsConfig {:Enabled true} + (assoc :LocalNotificationsConfig {:Enabled true} :BrowsersConfig {:Enabled true} :PermissionsConfig {:Enabled true} :MailserversConfig {:Enabled true} diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index eaba05fd5a..c64f8e01ad 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -20,10 +20,12 @@ ;; flags stay up to date and are removed once behavior introduced is stable. (goog-define INFURA_TOKEN "800c641949d64d768a5070a1b0511938") +(goog-define OPENSEA_API_KEY "") (def mainnet-rpc-url (str "https://mainnet.infura.io/v3/" INFURA_TOKEN)) (def testnet-rpc-url (str "https://ropsten.infura.io/v3/" INFURA_TOKEN)) (def goerli-rpc-url (str "https://goerli.infura.io/v3/" INFURA_TOKEN)) +(def opensea-api-key OPENSEA_API_KEY) (def bootnodes-settings-enabled? (enabled? (get-config :BOOTNODES_SETTINGS_ENABLED "1"))) (def rpc-networks-only? (enabled? (get-config :RPC_NETWORKS_ONLY "1"))) (def mailserver-confirmations-enabled? (enabled? (get-config :MAILSERVER_CONFIRMATIONS_ENABLED)))