on master help sign in
Merge pull request #594 from urbit/m/cli-ropsten-env

dx: add Ropsten mode for local development

commit2cb91b8ac33ee92a0cb0ed85498dbc62bd1c3fa6 authortomholford <16504501+tomholford@users.noreply.github.com> dateFri 23 Jul 2021, 16:08 (5 years ago) parent55a966432400b9
7 files changed+24−9
package.json+4−1 src/Bridge.js+4−2 src/components/GlobalErrorBoundary.js+2−2 src/lib/flags.js+5 src/lib/inviteMail.js+4−1 src/lib/tank.js+3−1 src/views/Login.tsx+2−2
package.json+4−1
@@ -96,17 +96,20 @@
9696 "scripts": {
9797 "start": "react-scripts start",
9898 "build": "react-scripts build",
99+ "build:ropsten": "REACT_APP_ROPSTEN=true react-scripts build",
99100 "test": "react-scripts test --env=jsdom",
100101 "eject": "react-scripts eject",
101102 "checksum": "cd build && find . -exec shasum -a256 {} ';' > ../checksums.txt && cd ..",
102− "zip": "zip -ur bridge-$npm_package_version.zip README.md bridge-https.py checksums.txt && cd build && zip -ur ../bridge-$npm_package_version.zip ./* && cd ..",
103+ "zip": "BRIDGE_VERSION=${REACT_APP_BRIDGE_VERSION:-$npm_package_version}; zip -ur bridge-$BRIDGE_VERSION.zip README.md bridge-https.py checksums.txt && cd build && zip -ur ../bridge-$BRIDGE_VERSION.zip ./* && cd ..",
103104 "release": "npm install && npm run build && npm run checksum && npm run zip",
105+ "release:ropsten": "export REACT_APP_BRIDGE_VERSION=$npm_package_version\"r\"; npm install && npm run build:ropsten && npm run checksum && npm run zip",
104106 "pilot:ganache": "ganache-cli --blockTime 1 --networkId 5 --host '0.0.0.0' -m 'benefit crew supreme gesture quantum web media hazard theory mercy wing kitten' > /dev/null &",
105107 "pilot:setup": "npm run pilot:ganache && truffle deploy",
106108 "pilot": "HTTPS=true npm-run-all pilot:setup start pilot:cleanup --continue-on-error",
107109 "pilot-invites": "WITH_TEST_STATE=INVITES npm run pilot",
108110 "pilot-release": "WITH_TEST_STATE=STAR_RELEASE npm run pilot",
109111 "pilot-residents": "WITH_TEST_STATE=RESIDENTS npm run pilot",
112+ "pilot-ropsten": "REACT_APP_ROPSTEN=true HTTPS=true npm-run-all start --continue-on-error",
110113 "pilot:cleanup": "pkill -f ganache-cli",
111114 "lint:check": "eslint 'src/**/*.js'",
112115 "lint:fix": "eslint --fix 'src/**/*.js'",
src/Bridge.js+4−2
@@ -11,7 +11,7 @@ import { ROUTE_NAMES } from 'lib/routeNames';
1111import { ROUTES } from 'lib/router';
1212import { NETWORK_TYPES } from 'lib/network';
1313import { walletFromMnemonic } from 'lib/wallet';
14−import { isDevelopment } from 'lib/flags';
14+import { isDevelopment, isRopsten } from 'lib/flags';
1515import useImpliedTicket from 'lib/useImpliedTicket';
1616import useHasDisclaimed from 'lib/useHasDisclaimed';
1717
@@ -19,7 +19,9 @@ import 'style/index.scss';
1919import WithErrorBoundary from 'components/WithErrorBoundary';
2020import GlobalErrorBoundary from 'components/GlobalErrorBoundary';
2121
22−const INITIAL_NETWORK_TYPE = isDevelopment
22+const INITIAL_NETWORK_TYPE = isRopsten
23+ ? NETWORK_TYPES.ROPSTEN
24+ : isDevelopment
2325 ? NETWORK_TYPES.LOCAL
2426 : NETWORK_TYPES.MAINNET;
2527
src/components/GlobalErrorBoundary.js+2−2
@@ -1,7 +1,7 @@
11import React, { useMemo } from 'react';
22import newGithubIssueUrl from 'new-github-issue-url';
33import { OutButton, RestartButton } from './Buttons';
4−import { version } from '../../package.json';
4+import { versionLabel } from 'lib/flags';
55
66const buildTitle = error => `Error Report: ${error.message}`;
77
@@ -19,7 +19,7 @@ const buildBody = error => `\n
1919${error.stack}
2020\`\`\`
2121\n
22−In Bridge version ${version}.\n
22+In Bridge version ${versionLabel}.\n
2323`;
2424
2525/**
src/lib/flags.js+5
@@ -1,2 +1,7 @@
1+import { version } from '../../package.json';
2+
13// are we running bridge in a development build
24export const isDevelopment = process.env.NODE_ENV === 'development';
5+export const isRopsten = process.env.REACT_APP_ROPSTEN === 'true';
6+export const versionLabel =
7+ process.env.REACT_APP_BRIDGE_VERSION || `${version}${isRopsten ? 'r' : ''}`;
src/lib/inviteMail.js+4−1
@@ -2,7 +2,10 @@
22// did not succeed", you might need to visit localhost:3001 or whatever
33// explicitly and tell your browser that's safe to access.
44// https://stackoverflow.com/a/53011185/1334324
5−const baseUrl = 'https://onboarding-emails.urbit.org:3002';
5+import { isRopsten } from './flags';
6+
7+const port = isRopsten ? '3012' : '3002';
8+const baseUrl = `https://onboarding-emails.urbit.org:${port}`;
69
710function sendRequest(where, what) {
811 return new Promise((resolve, reject) => {
src/lib/tank.js+3−1
@@ -4,6 +4,7 @@ import retry from 'async-retry';
44import { toBN } from 'web3-utils';
55import { RETRY_OPTIONS, waitForTransactionConfirm } from './txn';
66import { WALLET_TYPES } from 'lib/constants';
7+import { isRopsten } from './flags';
78
89const TANK_ADDRESS = '0x40f0A6db85f8D7A54fF3eA915b040dE8Cd4A0Eb5';
910
@@ -11,7 +12,8 @@ const TANK_ADDRESS = '0x40f0A6db85f8D7A54fF3eA915b040dE8Cd4A0Eb5';
1112// did not succeed", you might need to visit localhost:3001 or whatever
1213// explicitly and tell your browser that's safe to access.
1314// https://stackoverflow.com/a/53011185/1334324
14−const baseUrl = 'https://gas-tank.urbit.org:3001';
15+const port = isRopsten ? '3011' : '3001';
16+const baseUrl = `https://gas-tank.urbit.org:${port}`;
1517
1618function sendRequest(where, what) {
1719 return new Promise((resolve, reject) => {
src/views/Login.tsx+2−2
@@ -1,7 +1,7 @@
11import React, { useCallback, useState } from 'react';
22import { Grid, Text, Button, Flex, LinkButton } from 'indigo-react';
33
4−import { version } from '../../package.json';
4+import { versionLabel } from 'lib/flags';
55
66import { useHistory } from 'store/history';
77
@@ -124,7 +124,7 @@ export default function Login() {
124124 className="us-none pointer">
125125 <span className="underline">Offline</span> ↗
126126 </Flex.Item>
127− <Flex.Item className="gray4">v{version}</Flex.Item>
127+ <Flex.Item className="gray4">v{versionLabel}</Flex.Item>
128128 </Flex>
129129 </Footer>
130130 </View>