Skip to content

Commit

Permalink
- Support separate devnet network #242
Browse files Browse the repository at this point in the history
- fix wallet's dist build
  - fully switch to parcel
  • Loading branch information
TobiaszCudnik committed Jul 11, 2019
1 parent dae8e93 commit 9d129ea
Show file tree
Hide file tree
Showing 16 changed files with 13,855 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -44,3 +44,6 @@ yarn-error.log*
/sync
/.cache
/now.json

.browserslistrc

6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -7,7 +7,7 @@ cache:
- node_modules
- desktop/node_modules
- "~/.cache/Cypress"
- build
- dist
before_install:
- openssl aes-256-cbc -K $encrypted_63d69a2d54d1_key -iv $encrypted_63d69a2d54d1_iv
-in cypress/fixtures/accounts.json.enc -out cypress/fixtures/accounts.json -d
Expand Down Expand Up @@ -55,9 +55,9 @@ deploy:
condition: $TRAVIS_JOB_NAME = Release
- provider: pages
verbose: true
local-dir: build
local-dir: dist/build
skip-cleanup: true
github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable
on:
branch: master
condition: $TRAVIS_JOB_NAME = Release
condition: $TRAVIS_JOB_NAME = Release
26 changes: 12 additions & 14 deletions package.json
Expand Up @@ -20,7 +20,7 @@
"delay": "^4.1.0",
"downshift": "^3.1.7",
"dpos-ledger-api": "^3.0.1",
"dpos-offline": "^3.0.2",
"dpos-offline": "^3.0.4",
"inobounce": "^0.1.6",
"is-mobile": "^2.0.0",
"jdenticon": "^2.1.0",
Expand All @@ -37,7 +37,7 @@
"react-dom": "^16.6.3",
"react-helmet": "^5.2.0",
"react-intl": "^2.7.2",
"react-scripts-ts": "3.1.0",
"react-scripts": "^3.0.1",
"regenerator-runtime": "^0.13.2",
"risejs": "^1.4.1",
"sinon": "^7.2.2",
Expand All @@ -49,17 +49,16 @@
"unique-random": "^2.0.0",
"utils": "^0.3.1"
},
"browserslist": [
"last 1 Chrome version"
],
"scripts": {
"clean-es6-module": "rm -R dist/build-es6",
"start": "yarn clean-es6-module; parcel --out-dir dist/build-es6 src/dev.html --https",
"start-http": "yarn clean-es6-module; parcel --out-dir dist/build-es6 src/dev.html",
"build": "react-scripts-ts build",
"build-es6-module": "yarn clean-es6-module; parcel build --out-dir dist/build-es6 src/dev.html",
"set-build:dev": "rm .browserslistrc; cp scripts/browserslistrc-dev .browserslistrc",
"set-build:compat": "rm .browserslistrc; cp scripts/browserslistrc-compat .browserslistrc",
"clean-dev-build": "rm -R dist/build-dev",
"start": "yarn set-build:dev; yarn clean-dev-build; parcel --out-dir dist/build-dev src/dev.html --https",
"start-http": "yarn set-build:dev; yarn clean-dev-build; parcel --out-dir dist/build-dev src/dev.html",
"build": "yarn set-build:compat; rm -R dist/build; parcel build --out-dir dist/build src/dev.html",
"build-dev": "yarn set-build:dev; yarn clean-dev-build; mkdirp build/dev; parcel build --out-dir dist/build-dev src/dev.html",
"bundle": "cd desktop; yarn bundle",
"deploy-now": "yarn build; cd build && now && now alias rise-wallet",
"deploy-now": "yarn build; cd dist/build && now && now alias rise-wallet",
"cypress": "cypress open",
"test": "run-p --race serve test-cypress",
"test-ci": "run-p --race serve test-cypress",
Expand All @@ -68,7 +67,6 @@
"test-unit": "jest",
"test-unit:prepare": "rm -rf tmp/unit-test/; tsc --project tsconfig.test.json",
"test-unit:prepare-watch": "rm -rf tmp/unit-test/; tsc --watch --project tsconfig.test.json",
"eject": "react-scripts-ts eject",
"release": "./scripts/release.sh",
"intl:prepare": "babel -o tmp/transpiled-bundle.js --config-file './babelrc.intl.js' $(./scripts/intl-files.sh)",
"intl:export": "bash scripts/intl-export.sh",
Expand All @@ -85,15 +83,15 @@
"precommit"
],
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.4.5",
"@babel/preset-es2015": "^7.0.0-beta.53",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@bahmutov/add-typescript-to-cypress": "^2.0.0",
"@types/bip39": "^2.4.1",
"@types/bytebuffer": "^5.0.37",
Expand Down
3 changes: 3 additions & 0 deletions scripts/browserslistrc-compat
@@ -0,0 +1,3 @@
# file changes depending on the build command
since 2015
> 1%
2 changes: 2 additions & 0 deletions scripts/browserslistrc-dev
@@ -0,0 +1,2 @@
# file changes depending on the build command
last 1 Chrome version
4 changes: 2 additions & 2 deletions scripts/release.sh
Expand Up @@ -7,8 +7,8 @@ rm -f release.zip
rm -rf releases
mkdir releases
# place the web release archive in /releases with a proper version number
pushd build
pushd dist/build
zip -r ../releases/rise-wallet-web-$VERSION.zip *
popd
# create a CNAME file for a custom domain in gh-pages
printf "gh-wallet.rise.vision\n" > build/CNAME
printf "gh-wallet.rise.vision\n" > dist/build/CNAME
8 changes: 4 additions & 4 deletions src/components/content/RegisterDelegateDialogContent.tsx
Expand Up @@ -51,7 +51,7 @@ type BaseProps = WithStyles<typeof styles> & DialogContentProps;
interface Props extends BaseProps, ICloseInterruptFormProps {
delegateFee: RawAmount;
registeredUsername?: string;
forgingPK: string;
forgingPK: string | null;
error?: null | 'insufficient-funds';
onSubmit: (data: StateForm) => void;
onClose: ReactEventHandler<{}>;
Expand Down Expand Up @@ -120,8 +120,8 @@ class RegisterDelegateDialogContent extends React.Component<
state: State = {
username: '',
usernameInvalid: false,
mnemonic: null,
mnemonicInvalid: null,
mnemonic: '',
mnemonicInvalid: false,
forgingPK: ''
};

Expand Down Expand Up @@ -338,7 +338,7 @@ class RegisterDelegateDialogContent extends React.Component<
const { mnemonic, mnemonicInvalid } = this.state;
const { registeredUsername, classes } = this.props;

const forgingPK = this.state.forgingPK || this.props.forgingPK;
const forgingPK = this.state.forgingPK || this.props.forgingPK || '';
const alreadyRegistered = Boolean(registeredUsername);

return (
Expand Down
9 changes: 9 additions & 0 deletions src/containers/onboarding/AddAccountPage.tsx
Expand Up @@ -95,6 +95,15 @@ class AddAccountPage extends React.Component<Props> {
/>
);
break;
case 'devnet':
network = (
<FormattedMessage
id="onboarding-add-account.official-dev-network"
description="Label for a dev network"
defaultMessage="official devnet"
/>
);
break;
case 'custom':
network = (
<FormattedMessage
Expand Down
45 changes: 32 additions & 13 deletions src/containers/onboarding/ChooseNetworkPage.tsx
@@ -1,20 +1,22 @@
import Button from '@material-ui/core/es/Button';
import Radio from '@material-ui/core/es/Radio';
import TextField from '@material-ui/core/es/TextField';
import List from '@material-ui/core/es/List';
import ListItem from '@material-ui/core/es/ListItem';
import ListItemText from '@material-ui/core/es/ListItemText';
import { createStyles, withStyles, WithStyles } from '@material-ui/core/es/styles';
import Radio from '@material-ui/core/es/Radio';
import {
createStyles,
withStyles,
WithStyles
} from '@material-ui/core/es/styles';
import { inject, observer } from 'mobx-react';
import { RouterStore } from 'mobx-router-rise';
import { FormEvent } from 'react';
import React from 'react';
import React, { FormEvent } from 'react';
import { FormattedMessage } from 'react-intl';
import lstore from '../../utils/store';
import ModalPaper from '../../components/ModalPaper';
import ModalPaperHeader from '../../components/ModalPaperHeader';
import { onboardingAddAccountRoute } from '../../routes';
import WalletStore, { NetworkType } from '../../stores/wallet';
import lstore from '../../utils/store';
import { isMainnet } from '../../utils/utils';

const styles = createStyles({
Expand Down Expand Up @@ -76,18 +78,18 @@ class ChooseNetworkPage extends React.Component<Props, State> {

handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ network: event.target.value as NetworkType });
}
};

handleSetNetwork = (network: NetworkType) => () => {
this.setState({ network });
}
};

handleCustomURL = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
url: event.target.value,
urlError: false
});
}
};

handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
Expand Down Expand Up @@ -116,11 +118,12 @@ class ChooseNetworkPage extends React.Component<Props, State> {
walletStore.setNetwork(network, url);
routerStore.goTo(onboardingAddAccountRoute);
}
}
};

render() {
const { classes } = this.injected;
const { network, url, urlError } = this.state;
const { network } = this.state;
// const { network, url, urlError } = this.state;

return (
<ModalPaper open={true}>
Expand Down Expand Up @@ -165,7 +168,23 @@ class ChooseNetworkPage extends React.Component<Props, State> {
/>
</ListItemText>
</ListItem>
<ListItem button={true}>
<ListItem button={true} onClick={this.handleSetNetwork('devnet')}>
<ListItemText>
<Radio
className={classes.radio}
name="network"
value="devnet"
onChange={this.handleChange}
checked={network === 'devnet'}
/>
<FormattedMessage
id="onboarding-choose-network.official-dev-network"
description="Label for official dev network"
defaultMessage="Official devnet"
/>
</ListItemText>
</ListItem>
{/*<ListItem button={true}>
<ListItemText onClick={this.handleSetNetwork('custom')}>
<Radio
name="network"
Expand Down Expand Up @@ -195,7 +214,7 @@ class ChooseNetworkPage extends React.Component<Props, State> {
value={url}
/>
</ListItemText>
</ListItem>
</ListItem>*/}
<ListItem>
<Button type="submit" fullWidth={true}>
<FormattedMessage
Expand Down
2 changes: 1 addition & 1 deletion src/containers/wallet/RegisterDelegateDialog.tsx
Expand Up @@ -156,7 +156,7 @@ class RegisterDelegateDialog extends React.Component<Props, State>
? {
kind: 'delegate',
forgingPK: transaction.forgingPK,
username: registeredDelegate ? null : transaction.username
username: registeredDelegate ? '' : transaction.username
}
: null
}
Expand Down
1 change: 1 addition & 0 deletions src/stores/fixtures.ts
Expand Up @@ -466,6 +466,7 @@ export const serverTransactionDelegates = {
export const config: TConfig = {
api_url: '',
api_url_testnet: '',
api_url_devnet: '',
domain: '',
date_format: '',
explorer_url: '',
Expand Down
1 change: 1 addition & 0 deletions src/stores/index.ts
Expand Up @@ -10,6 +10,7 @@ import LedgerStore from './ledger';
export type TConfig = {
api_url: string;
api_url_testnet: string;
api_url_devnet: string;
domain: string;
explorer_url: string;
date_format: string;
Expand Down
28 changes: 15 additions & 13 deletions src/stores/wallet.ts
Expand Up @@ -3,7 +3,7 @@ import {
RiseV2Transaction as GenericRiseTransaction,
PostableRiseV2Transaction as GenericPostableRiseTransaction,
RecipientId,
RiseV2 as Rise
RiseV2 as Rise, ISendRiseV2Tx
} from 'dpos-offline';
import { isMobile } from 'is-mobile';
import { get, pick } from 'lodash';
Expand Down Expand Up @@ -51,7 +51,7 @@ import { Transaction } from './transactions';

// TODO merge with NetworkTxType
// TODO move to utils.ts
export type NetworkType = 'mainnet' | 'testnet' | 'custom';
export type NetworkType = 'mainnet' | 'testnet' | 'devnet' | 'custom';

// TODO move to /utils/utils.ts
// TODO proper type instead of any
Expand Down Expand Up @@ -112,6 +112,8 @@ export default class WalletStore {
return this.config.api_url;
case 'testnet':
return this.config.api_url_testnet;
case 'devnet':
return this.config.api_url_devnet;
case 'custom':
return url;
default:
Expand Down Expand Up @@ -281,9 +283,14 @@ export default class WalletStore {
* TODO merge with NetworkType
*/
getTxNetwork(): NetworkTXType {
return this.getNetwork() === 'mainnet'
? NetworkTXType.MAINNET
: NetworkTXType.TESTNET;
switch (this.getNetwork()) {
case 'testnet':
return NetworkTXType.TESTNET;
case 'devnet':
return NetworkTXType.DEVNET;
default:
return NetworkTXType.MAINNET;
}
}

@action
Expand Down Expand Up @@ -475,9 +482,9 @@ export default class WalletStore {
: this.selectedAccount;
assert(account, 'Account required');

return Rise.txs.transform(
return Rise.txs.transform<ISendRiseV2Tx>(
{
kind: 'send',
kind: 'send-v2',
amount: amount.toString(),
recipient: recipientId as RecipientId,
sender: account.toSenderObject()
Expand Down Expand Up @@ -509,7 +516,7 @@ export default class WalletStore {
// and votes for the new delegate.
return Rise.txs.transform(
{
kind: 'vote',
kind: 'vote-v2',
sender: account.toSenderObject(),
preferences: [
...(account.votedDelegate
Expand Down Expand Up @@ -548,12 +555,7 @@ export default class WalletStore {
if (account.registeredDelegateState !== LoadingState.LOADED) {
await this.loadRegisteredDelegate(account.id);
}
// delegate registrations arent mutable
if (account.registeredDelegate) {
throw new Error('Already registered as a delegate');
}

// TODO fix types in dpos-offline
return Rise.txs.transform(
{
kind: 'register-delegate-v2',
Expand Down
3 changes: 2 additions & 1 deletion src/utils/utils.ts
Expand Up @@ -174,7 +174,8 @@ export enum AccountIDVersion {

export enum NetworkTXType {
MAINNET = 'main',
TESTNET = 'test'
TESTNET = 'test',
DEVNET = 'dev',
}

/**
Expand Down

0 comments on commit 9d129ea

Please sign in to comment.