Skip to content

Commit

Permalink
refactor: remove testnet_STAGING and directly retrieve NEAR_WALLET_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
esaminu committed Jan 6, 2022
1 parent 9826978 commit 8c8d6e5
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 113 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ node_js: 12
jobs:
include:
- name: yarn
env:
- NEAR_WALLET_ENV=mainnet
script:
- yarn lint
- yarn test
Expand Down
1 change: 0 additions & 1 deletion features/environments.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"DEVELOPMENT": "development",
"TESTNET": "testnet",
"TESTNET_STAGING": "testnet_STAGING",
"MAINNET": "mainnet",
"MAINNET_STAGING": "mainnet_STAGING"
}
3 changes: 1 addition & 2 deletions features/features.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { initFeatureFlags } = require('@near-wallet/feature-flags');
const { NEAR_WALLET_ENV } = require('../packages/frontend/ci/config')
const Environments = require('./environments.json');
const FeatureFlags = require('./flags.json');

const Features = initFeatureFlags({
flagState: FeatureFlags,
currentEnvironment: NEAR_WALLET_ENV,
currentEnvironment: process.env.NEAR_WALLET_ENV,
environments: Environments,
});

Expand Down
5 changes: 0 additions & 5 deletions features/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
"lastEditedBy": "Daryl Collins",
"lastEditedAt": "2021-11-09T04:34:12.847Z"
},
"testnet_STAGING": {
"enabled": false,
"lastEditedBy": "Daryl Collins",
"lastEditedAt": "2021-11-09T04:34:33.102Z"
},
"mainnet": {
"enabled": true,
"lastEditedBy": "Andy Haynes",
Expand Down
3 changes: 0 additions & 3 deletions packages/frontend/ci/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const envDefaults = {
[Environments.TESTNET]: {
CLOUDFLARE_BASE_URL: "https://content.near-wallet.workers.dev",
},
[Environments.TESTNET_STAGING]: {
CLOUDFLARE_BASE_URL: "https://content.near-wallet.workers.dev",
},
[Environments.MAINNET]: {
CLOUDFLARE_BASE_URL: "https://content.near-wallet.workers.dev",
},
Expand Down
58 changes: 12 additions & 46 deletions packages/frontend/ci/configFromEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,34 @@ const assert = require("assert");
const Environments = require("../../../features/environments.json");
const { parseBooleanFromShell } = require("../src/config/envParsers");

const Config = {
const NEAR_WALLET_ENV = process.env.NEAR_WALLET_ENV;

assert(
Object.values(Environments).some((env) => NEAR_WALLET_ENV === env),
`Invalid environment: "${NEAR_WALLET_ENV}"`
);

module.exports = {
BRANCH: process.env.BRANCH,
CLOUDFLARE_BASE_URL: process.env.CLOUDFLARE_BASE_URL,
CONTEXT: process.env.CONTEXT,
DEBUG_BUILD: process.env.DEBUG_BUILD,
DEBUG_BUILD: parseBooleanFromShell(process.env.DEBUG_BUILD) || true,
DEPLOY_PRIME_URL: process.env.DEPLOY_PRIME_URL,
IS_DEVELOPMENT: process.env.NODE_ENV === "development",
IS_NETLIFY: parseBooleanFromShell(process.env.NETLIFY),
IS_RENDER: parseBooleanFromShell(process.env.RENDER),
IS_PULL_REQUEST: parseBooleanFromShell(process.env.IS_PULL_REQUEST),
NEAR_WALLET_ENV: process.env.NEAR_WALLET_ENV,
RENDER: process.env.RENDER,
NEAR_WALLET_ENV,
RENDER: parseBooleanFromShell(process.env.RENDER),
RENDER_EXTERNAL_URL: process.env.RENDER_EXTERNAL_URL,
RENDER_GIT_COMMIT: process.env.RENDER_GIT_COMMIT,
REVIEW_ID: process.env.REVIEW_ID,
SENTRY_AUTH_TOKEN: process.env.SENTRY_AUTH_TOKEN,
SENTRY_DSN: process.env.SENTRY_DSN,
SENTRY_RELEASE:
process.env.SENTRY_RELEASE ||
(process.env.RENDER &&
(parseBooleanFromShell(process.env.RENDER) &&
`render:${process.env.RENDER_SERVICE_NAME}:${process.env.RENDER_GIT_BRANCH}:${process.env.RENDER_GIT_COMMIT}`),
SHOULD_USE_CLOUDFLARE: parseBooleanFromShell(process.env.USE_CLOUDFLARE),
TRAVIS: parseBooleanFromShell(process.env.TRAVIS),
};

const computeCiNearWalletEnv = (Config) => {
if(Config.IS_DEVELOPMENT || Config.SHOULD_USE_CLOUDFLARE) {
return Environments.DEVELOPMENT;
}

if(Config.IS_NETLIFY) {
switch (Config.CONTEXT) {
case "production":
case "deploy-preview":
return Config.DEPLOY_PRIME_URL.includes("near-wallet-staging")
? Environments.MAINNET_STAGING
: Environments.MAINNET;
case "branch-deploy":
return Environments.MAINNET_STAGING;
}
}

if(Config.IS_RENDER) {
return Config.IS_PULL_REQUEST
? Environments.TESTNET_STAGING
: Environments.TESTNET;
}

if(Config.TRAVIS) {
return Environments.MAINNET_STAGING;
}
};

const NEAR_WALLET_ENV =
Config.NEAR_WALLET_ENV || computeCiNearWalletEnv(Config);

assert(
Object.values(Environments).some((env) => NEAR_WALLET_ENV === env),
`Invalid environment: "${NEAR_WALLET_ENV}"`
);

module.exports = {
...Config,
NEAR_WALLET_ENV,
};
14 changes: 8 additions & 6 deletions packages/frontend/src/config/configFromEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import assert from "assert";

import Environments from "../../../../features/environments.json";
import { NEAR_WALLET_ENV } from "../../ci/config";
import {
parseBooleanFromShell,
parseObjectFromShell,
parseCommaSeperatedStringAsArrayFromShell,
} from "./envParsers";

const NEAR_WALLET_ENV = process.env.NEAR_WALLET_ENV;

assert(
Object.values(Environments).some((env) => NEAR_WALLET_ENV === env),
`Invalid environment: "${NEAR_WALLET_ENV}"`
Expand All @@ -31,7 +31,7 @@ module.exports = {
process.env.HIDE_SIGN_IN_WITH_LEDGER_ENTER_ACCOUNT_ID_MODAL
),
IS_MAINNET: [Environments.MAINNET, Environments.MAINNET_STAGING].some(
(env) => env === process.env.NEAR_WALLET_ENV
(env) => env === NEAR_WALLET_ENV
),
LINKDROP_GAS: process.env.LINKDROP_GAS,
LOCKUP_ACCOUNT_ID_SUFFIX: process.env.LOCKUP_ACCOUNT_ID_SUFFIX,
Expand All @@ -40,7 +40,7 @@ module.exports = {
MOONPAY_API_KEY: process.env.MOONPAY_API_KEY,
MOONPAY_API_URL: process.env.MOONPAY_API_URL,
MOONPAY_BUY_URL: process.env.MOONPAY_BUY_URL,
MULTISIG_CONTRACT_HASHES: parseObjectFromShell(
MULTISIG_CONTRACT_HASHES: parseCommaSeperatedStringAsArrayFromShell(
process.env.MULTISIG_CONTRACT_HASHES
),
MULTISIG_MIN_AMOUNT: process.env.REACT_APP_MULTISIG_MIN_AMOUNT,
Expand All @@ -57,14 +57,16 @@ module.exports = {
RECAPTCHA_ENTERPRISE_SITE_KEY: process.env.RECAPTCHA_ENTERPRISE_SITE_KEY,
SENTRY_DSN: process.env.SENTRY_DSN,
SENTRY_RELEASE: process.env.SENTRY_RELEASE
? process.env.RENDER
? parseBooleanFromShell(process.env.RENDER)
? `render:${process.env.RENDER_SERVICE_NAME}:${process.env.RENDER_GIT_BRANCH}:${process.env.RENDER_GIT_COMMIT}`
: undefined
: undefined,
SHOW_PRERELEASE_WARNING: parseBooleanFromShell(
process.env.SHOW_PRERELEASE_WARNING
),
SMS_BLACKLIST: process.env.SMS_BLACKLIST,
SMS_BLACKLIST: parseCommaSeperatedStringAsArrayFromShell(
process.env.SMS_BLACKLIST
),
STAKING_GAS_BASE: process.env.REACT_APP_STAKING_GAS_BASE,
WHITELISTED_CONTRACTS: parseCommaSeperatedStringAsArrayFromShell(
process.env.TOKEN_CONTRACTS
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/config/envParsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const parseObjectFromShell = (envVal) => {
};

const parseCommaSeperatedStringAsArrayFromShell = (envVal) =>
envValIsSet(envVal) ? envVal.split(",") : undefined;
envValIsSet(envVal) ? envVal.replace(/\s/g, "").split(",") : undefined;

module.exports = {
envValIsSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
SENTRY_DSN: "https://75d1dabd0ab646329fad8a3e7d6c761d@o398573.ingest.sentry.io/5254526",
SENTRY_RELEASE: "development",
SHOW_PRERELEASE_WARNING: false,
SMS_BLACKLIST: "",
SMS_BLACKLIST: [],
STAKING_GAS_BASE: "25000000000000", // 25 Tgas
WHITELISTED_CONTRACTS: ["meta.pool.testnet"],
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
RECAPTCHA_ENTERPRISE_SITE_KEY: "6LcpJ3EcAAAAAFgA-nixKFNGWMo9IG9FQhH4XjSY",
SENTRY_DSN: "https://15d0d1b94e8548dd9663b8c93bf4550a@o398573.ingest.sentry.io/5396205",
SHOW_PRERELEASE_WARNING: false,
SMS_BLACKLIST: "CN,VN",
SMS_BLACKLIST: ["CN", "VN"],
STAKING_GAS_BASE: "25000000000000", // 25 Tgas
WHITELISTED_CONTRACTS: [
"berryclub.ek.near",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
RECAPTCHA_ENTERPRISE_SITE_KEY: "6LcpJ3EcAAAAAFgA-nixKFNGWMo9IG9FQhH4XjSY",
SENTRY_DSN: "https://15d0d1b94e8548dd9663b8c93bf4550a@o398573.ingest.sentry.io/5396205",
SHOW_PRERELEASE_WARNING: true,
SMS_BLACKLIST: "CN,VN",
SMS_BLACKLIST: ["CN", "VN"],
STAKING_GAS_BASE: "25000000000000", // 25 Tgas
WHITELISTED_CONTRACTS: [
"berryclub.ek.near",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
REACT_APP_USE_TESTINGLOCKUP: false,
SENTRY_DSN: "https://75d1dabd0ab646329fad8a3e7d6c761d@o398573.ingest.sentry.io/5254526",
SHOW_PRERELEASE_WARNING: false,
SMS_BLACKLIST: "",
SMS_BLACKLIST: ["CN", "VN"],
STAKING_GAS_BASE:"25000000000000", // 25 Tgas
WHITELISTED_CONTRACTS: ["meta.pool.testnet"],
};

This file was deleted.

2 changes: 0 additions & 2 deletions packages/frontend/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import development from "./environmentDefaults/development";
import mainnet from "./environmentDefaults/mainnet";
import mainnet_STAGING from "./environmentDefaults/mainnet_STAGING";
import testnet from "./environmentDefaults/testnet";
import testnet_STAGING from "./environmentDefaults/testnet_STAGING";

const envDefaults = {
[Environments.DEVELOPMENT]: development,
[Environments.TESTNET]: testnet,
[Environments.TESTNET_STAGING]: testnet_STAGING,
[Environments.MAINNET]: mainnet,
[Environments.MAINNET_STAGING]: mainnet_STAGING,
};
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/src/utils/isApprovedCountryCode.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { SMS_BLACKLIST } from '../config';

const isApprovedCountryCode = (countryCode) => {
const blackList = SMS_BLACKLIST.replace(/\s/g, "").split(",");
return !blackList.includes(countryCode);
return !SMS_BLACKLIST.includes(countryCode);
};

export default isApprovedCountryCode;

0 comments on commit 8c8d6e5

Please sign in to comment.