Skip to content

Commit

Permalink
Fix env vars (#939)
Browse files Browse the repository at this point in the history
* define env vars using definePlugin

* rm console.log
  • Loading branch information
piyalbasu authored Aug 11, 2023
1 parent a348f38 commit f6af798
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/submitProduction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: "18"
- run: yarn setup && yarn build:freighter-api && yarn build:extension:production --define 'process.env.AMPLITUDE_KEY="${{ secrets.AMPLITUDE_KEY }}"' --define 'process.env.SENTRY_KEY="${{ secrets.SENTRY_KEY }}"'
- run: yarn setup && yarn build:freighter-api && yarn build:extension:production --env AMPLITUDE_KEY="${{ secrets.AMPLITUDE_KEY }}" SENTRY_KEY="${{ secrets.SENTRY_KEY }}"
- name: Install zip
uses: montudor/action-zip@c25e01d7489d0274569440a2f0281b4569df16bc #v0.1.1
- name: Zip extension build
Expand Down
8 changes: 4 additions & 4 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"scripts": {
"setup": "yarn install && yarn allow-scripts",
"build": "webpack --config webpack.extension.js",
"build:experimental": "yarn build --env env.EXPERIMENTAL=true",
"build:production": "yarn build --env env.PRODUCTION",
"build:translations": "yarn build --env env.TRANSLATIONS=true",
"build:experimental": "yarn build --env EXPERIMENTAL=true",
"build:production": "yarn build --env PRODUCTION",
"build:translations": "yarn build --env TRANSLATIONS=true",
"start": "webpack-dev-server --config webpack.dev.js",
"start:experimental": "yarn start --env env.EXPERIMENTAL=true",
"start:experimental": "yarn start --env EXPERIMENTAL=true",
"start:unpacked-extension": "yarn build --watch"
},
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions extension/src/constants/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare const AMPLITUDE_KEY: string;
const _AMPLITUDE_KEY = AMPLITUDE_KEY;

declare const SENTRY_KEY: string;
const _SENTRY_KEY = SENTRY_KEY;
export { _AMPLITUDE_KEY as AMPLITUDE_KEY, _SENTRY_KEY as SENTRY_KEY };
5 changes: 3 additions & 2 deletions extension/src/helpers/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createAsyncThunk, createAction } from "@reduxjs/toolkit";

import { store } from "popup/App";
import { METRICS_DATA } from "constants/localStorageTypes";
import { AMPLITUDE_KEY } from "constants/env";
import { settingsDataSharingSelector } from "popup/ducks/settings";
import { AccountType } from "@shared/api/types";

Expand Down Expand Up @@ -86,7 +87,7 @@ let cache: event[] = [];
const uploadMetrics = throttle(() => {
const toUpload = cache;
cache = [];
if (!process.env.AMPLITUDE_KEY) {
if (!AMPLITUDE_KEY) {
// eslint-disable-next-line no-console
console.log("Not uploading metrics", toUpload);
return;
Expand All @@ -97,7 +98,7 @@ const uploadMetrics = throttle(() => {
"Content-Type": "application/json",
},
body: JSON.stringify({
api_key: process.env.AMPLITUDE_KEY,
api_key: AMPLITUDE_KEY,
events: toUpload,
}),
});
Expand Down
5 changes: 3 additions & 2 deletions extension/src/popup/components/ErrorTracking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { useSelector } from "react-redux";
import * as Sentry from "@sentry/browser";
import { Integrations } from "@sentry/tracing";

import { SENTRY_KEY } from "constants/env";
import { settingsDataSharingSelector } from "popup/ducks/settings";
import packageJson from "../../../../package.json";

export const ErrorTracking = () => {
const isDataSharingAllowed = useSelector(settingsDataSharingSelector);

if (process.env.SENTRY_KEY && isDataSharingAllowed) {
if (SENTRY_KEY && isDataSharingAllowed) {
Sentry.init({
dsn: process.env.SENTRY_KEY,
dsn: SENTRY_KEY,
release: `freighter@${packageJson.version}`,
integrations: [new Integrations.BrowserTracing()],
tracesSampleRate: 1.0,
Expand Down
11 changes: 10 additions & 1 deletion extension/webpack.extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ const { commonConfig } = require("./webpack.common.js");

const LOCALES = ["en", "pt"];

const prodConfig = (env = { PRODUCTION: false, TRANSLATIONS: false }) => ({
const prodConfig = (
env = {
PRODUCTION: false,
TRANSLATIONS: false,
AMPLITUDE_KEY: "",
SENTRY_KEY: "",
},
) => ({
mode: "production",
optimization: {
minimize: env.PRODUCTION,
Expand All @@ -20,6 +27,8 @@ const prodConfig = (env = { PRODUCTION: false, TRANSLATIONS: false }) => ({
plugins: [
new webpack.DefinePlugin({
DEV_SERVER: false,
AMPLITUDE_KEY: JSON.stringify(env.AMPLITUDE_KEY),
SENTRY_KEY: JSON.stringify(env.SENTRY_KEY),
}),
...(env.TRANSLATIONS
? [
Expand Down

0 comments on commit f6af798

Please sign in to comment.