Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts Tab UI #277

Merged
merged 86 commits into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
259fe34
Refactor BaseNode to be an interface INode
Sep 5, 2017
bcebd74
Initial contract commit
Sep 7, 2017
718c54e
Merge develop
Sep 7, 2017
753aa00
Remove redundant fallback ABI function
Sep 7, 2017
f6b85c1
First working iteration of Contract generator to be used in ENS branch
Sep 7, 2017
3e0d0a1
Hide abi to clean up logging output
Sep 7, 2017
1b16b13
Strip 0x prefix from output decode
Sep 7, 2017
40579f8
Handle unnamed output params
Sep 7, 2017
f577768
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Sep 8, 2017
35d3d29
Implement ability to supply output mappings to ABI functions
Sep 8, 2017
aa079bf
Fix null case in outputMapping
Sep 8, 2017
d37c41a
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Sep 8, 2017
760a166
Add flow typing
Sep 8, 2017
1831172
Add .call method to functions
Sep 12, 2017
aa5c5a9
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Sep 17, 2017
baae972
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Sep 18, 2017
9c117c5
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Sep 25, 2017
e0e8590
Partial commit for type refactor
Sep 25, 2017
cad65d2
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Sep 26, 2017
4cf4951
Temp contract type fix -- waiting for NPM modularization
Sep 26, 2017
70cba3a
Misc. Optimizations to tsconfig + webpack
Sep 26, 2017
12321b1
Convert Contracts to TS
Sep 26, 2017
ec94c90
Remove nested prop passing from contracts, get rid of contract reduce…
Sep 26, 2017
7e6ffb3
Merge branch 'contract-refactor' of https://github.com/MyEtherWallet/…
Sep 26, 2017
9ea3884
Add disclaimer modal to footer
Sep 29, 2017
6f2bd19
Merge branch 'develop' into update-disclaimer
james-prado Sep 29, 2017
e2d9bf4
Merge router upgrade
Oct 2, 2017
60db6b4
Remove duplicate code & unnecessary styles
Oct 2, 2017
d52ce10
Add contracts to nav
Oct 2, 2017
d00a761
Wrap Contracts in App
Oct 2, 2017
05fc28f
Add ether/hex validation override for contract creation calls
Oct 2, 2017
d320c5e
First iteration of working deploy contract
Oct 2, 2017
4cf0b44
Delete routing file that shouldnt exist
Oct 2, 2017
93ce173
Revert "Misc. Optimizations to tsconfig + webpack"
Oct 3, 2017
4d95eb2
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 3, 2017
4d9efbe
Cleanup HOC code
Oct 3, 2017
2aa4942
Fix formatting noise
Oct 3, 2017
88f6bd1
Merge branch 'update-disclaimer' of https://github.com/james-prado/My…
Oct 3, 2017
b9f5244
remove un-used css style
Oct 3, 2017
4e4691e
Remove deterministic contract address computation
Oct 3, 2017
5f4c3ba
Remove empty files
Oct 3, 2017
8f014a5
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 3, 2017
ec08893
Cleanup contract
Oct 3, 2017
8fd9a77
Add call request to node interface
Oct 3, 2017
f8ea4ca
Fix output mapping types
Oct 3, 2017
f8c097a
Revert destructuring overboard
Oct 3, 2017
3f0cc16
Add sendCallRequest to rpcNode class and add typing
Oct 3, 2017
e7700ae
Use enum for selecting ABI methods
Oct 3, 2017
c2409fd
Merge branch 'contract-refactor' of https://github.com/MyEtherWallet/…
Oct 3, 2017
099cd0e
Fix tslint error & add media query for modals
Oct 5, 2017
46af5cf
Nest Media Query
Oct 5, 2017
244b4c0
Merge branch 'develop' into update-disclaimer
james-prado Oct 5, 2017
141ebec
Merge pull request #243 from james-prado/update-disclaimer
james-prado Oct 5, 2017
7ccc6c6
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 5, 2017
d991711
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 5, 2017
c2c6e6b
Fix contracts to include new router fixes
Oct 6, 2017
24cf4f4
Add transaction capability to contracts
Oct 6, 2017
6556b21
Get ABI parsing + contract calls almost fully integrated using dynami…
Oct 6, 2017
9cfe43c
Refactor contract deploy to have a reusable HOC for contract interact
Oct 6, 2017
8a9b93c
Move modal and tx comparasion up file tree
Oct 8, 2017
544a2d2
Include ABI outputs in display
Oct 8, 2017
8c55017
Cleanup privaite/public members
Oct 8, 2017
9b9d5b1
Remove broadcasting step from a contract transaction
Oct 10, 2017
786a945
Update TX contract components to inter-op with interact and deploy
Oct 10, 2017
00dda7a
Finish contracts-interact functionality
Oct 10, 2017
0cda5c5
Add transaction capability to contracts
Oct 6, 2017
9131df1
Cleanup privaite/public members
Oct 8, 2017
7b115d3
Remove broadcasting step from a contract transaction
Oct 10, 2017
1d5f163
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 10, 2017
15fee4f
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 10, 2017
7594fad
Apply James's CSS fix
Oct 10, 2017
cf47730
Cleanup uneeded types
Oct 10, 2017
b53cffe
Merge contracts-refactor
Oct 10, 2017
038415d
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 10, 2017
5e23a3c
Merge branch 'contracts-tab-interact' of https://github.com/MyEtherWa…
Oct 10, 2017
533cfcc
Remove unecessary class
Oct 10, 2017
d134e04
Add UI side validation and helper utils, addresess PR comments
Oct 11, 2017
2b1e9a3
Merge branch 'contracts-tab-interact' of https://github.com/MyEtherWa…
Oct 11, 2017
bfa6eb6
Fix spacing + remove unused imports / types
Oct 16, 2017
c5f29df
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 16, 2017
9ba1fd2
Fix spacing + remove unused imports / types
Oct 16, 2017
6c767e6
Address PR comments
Oct 16, 2017
6819dc8
Actually address PR comments
Oct 16, 2017
254b0f1
Actually address PR comments
Oct 16, 2017
afa87ac
Merge conflicts
Oct 17, 2017
8b0f03a
Merge branch 'develop' of https://github.com/MyEtherWallet/MyEtherWal…
Oct 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions common/actions/contracts/actionCreators.ts

This file was deleted.

31 changes: 0 additions & 31 deletions common/actions/contracts/actionTypes.ts

This file was deleted.

4 changes: 0 additions & 4 deletions common/actions/contracts/constants.ts

This file was deleted.

3 changes: 0 additions & 3 deletions common/actions/contracts/index.ts

This file was deleted.

4 changes: 4 additions & 0 deletions common/components/Header/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const tabs = [
name: 'NAV_ViewWallet'
// to: 'view-wallet'
},
{
name: 'NAV_Contracts',
to: 'contracts'
},
{
name: 'NAV_ENS',
to: 'ens'
Expand Down
2 changes: 2 additions & 0 deletions common/components/Root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { Router, Route } from 'react-router-dom';
// Components
import Contracts from 'containers/Tabs/Contracts';
import ENS from 'containers/Tabs/ENS';
import GenerateWallet from 'containers/Tabs/GenerateWallet';
import Help from 'containers/Tabs/Help';
Expand All @@ -28,6 +29,7 @@ export default class Root extends Component<Props, {}> {
<Route path="/help" component={Help} />
<Route path="/swap" component={Swap} />
<Route path="/send-transaction" component={SendTransaction} />
<Route path="/contracts" component={Contracts} />
<Route path="/ens" component={ENS} />
</div>
</Router>
Expand Down
14 changes: 14 additions & 0 deletions common/components/ui/Code.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pre {
color: #333;
background-color: #fafafa;
border: 1px solid #ececec;
border-radius: 0px;
padding: 8px;
code {
font-size: 14px;
line-height: 20px;
word-break: break-all;
word-wrap: break-word;
white-space: pre;
}
}
10 changes: 10 additions & 0 deletions common/components/ui/Code.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { Component } from 'react';
import './Code.scss';

const Code = ({ children }) => (
<pre>
<code>{children}</code>
</pre>
);

export default Code;
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import Big from 'bignumber.js';
import React, { Component } from 'react';
import {
generateCompleteTransaction as makeAndSignTx,
TransactionInput
} from 'libs/transaction';
import { Props, State, initialState } from './types';
import { TxModal, Props as DMProps } from '../../../TxModal';
import { TxCompare, Props as TCProps } from '../../../TxCompare';
import { withTx } from '../../../withTx';

export const deployHOC = PassedComponent => {
class WrappedComponent extends Component<Props, State> {
public state: State = initialState;

public asyncSetState = value =>
new Promise(resolve => this.setState(value, resolve));

public resetState = () => this.setState(initialState);

public handleSignTx = async () => {
const { props, state } = this;

if (state.data === '') {
return;
}

try {
await this.getAddressAndNonce();
await this.makeSignedTxFromState();
} catch (e) {
props.showNotification(
'danger',
e.message || 'Error during contract tx generation',
5000
);

return this.resetState();
}
};

public handleInput = inputName => ev =>
this.setState({
[inputName]: ev.target.value
});

public handleDeploy = () => this.setState({ displayModal: true });

public render() {
const { data: byteCode, gasLimit, signedTx, displayModal } = this.state;

const props = {
handleInput: this.handleInput,
handleSignTx: this.handleSignTx,
handleDeploy: this.handleDeploy,
byteCode,
gasLimit,
displayModal,
walletExists: !!this.props.wallet,
TxCompare: signedTx ? this.displayCompareTx() : null,
DeployModal: signedTx ? this.displayDeployModal() : null
};

return <PassedComponent {...props} />;
}

private displayCompareTx = () => {
const { nonce, gasLimit, data, value, signedTx, to } = this.state;
const { gasPrice, chainId } = this.props;

if (!nonce || !signedTx) {
throw Error('Can not display raw tx, nonce empty or no signed tx');
}

const props: TCProps = {
nonce,
gasPrice,
chainId,
data,
gasLimit,
to,
value,
signedTx
};

return <TxCompare {...props} />;
};

private displayDeployModal = () => {
const { networkName, node: { network, service } } = this.props;
const { signedTx } = this.state;

if (!signedTx) {
throw Error('Can not deploy contract, no signed tx');
}

const props: DMProps = {
action: 'deploy a contract',
networkName,
network,
service,
handleBroadcastTx: this.handleBroadcastTx,
onClose: this.resetState
};

return <TxModal {...props} />;
};

private handleBroadcastTx = () => {
if (!this.state.signedTx) {
throw Error('Can not broadcast tx, signed tx does not exist');
}
this.props.broadcastTx(this.state.signedTx);
this.resetState();
};

private makeSignedTxFromState = () => {
const { props, state: { data, gasLimit, value, to } } = this;
const transactionInput: TransactionInput = {
unit: 'ether',
to,
data,
value
};

return makeAndSignTx(
props.wallet,
props.nodeLib,
props.gasPrice,
new Big(gasLimit),
props.chainId,
transactionInput,
true
).then(({ signedTx }) => this.asyncSetState({ signedTx }));
};

private getAddressAndNonce = async () => {
const address = await this.props.wallet.getAddress();
const nonce = await this.props.nodeLib
.getTransactionCount(address)
.then(n => new Big(n).toString());
return this.asyncSetState({ nonce, address });
};
}
return withTx(WrappedComponent);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Wei, Ether } from 'libs/units';
import { IWallet } from 'libs/wallet/IWallet';
import { RPCNode } from 'libs/nodes';
import { NodeConfig, NetworkConfig } from 'config/data';
import { TBroadcastTx } from 'actions/wallet';
import { TShowNotification } from 'actions/notifications';

export interface Props {
wallet: IWallet;
balance: Ether;
node: NodeConfig;
nodeLib: RPCNode;
chainId: NetworkConfig['chainId'];
networkName: NetworkConfig['name'];
gasPrice: Wei;
broadcastTx: TBroadcastTx;
showNotification: TShowNotification;
}

export interface State {
data: string;
gasLimit: string;
determinedContractAddress: string;
signedTx: null | string;
nonce: null | string;
address: null | string;
value: string;
to: string;
displayModal: boolean;
}

export const initialState: State = {
data: '',
gasLimit: '300000',
determinedContractAddress: '',
signedTx: null,
nonce: null,
address: null,
to: '0x',
value: '0x0',
displayModal: false
};
86 changes: 86 additions & 0 deletions common/containers/Tabs/Contracts/components/Deploy/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import translate from 'translations';
import WalletDecrypt from 'components/WalletDecrypt';
import { deployHOC } from './components/DeployHoc';
import { TTxCompare } from '../TxCompare';
import { TTxModal } from '../TxModal';
interface Props {
byteCode: string;
gasLimit: string;
walletExists: boolean;
TxCompare: TTxCompare | null;
displayModal: boolean;
DeployModal: TTxModal | null;
handleInput(input: string): () => null;
handleSignTx(): null;
handleDeploy(): null;
}

const Deploy = (props: Props) => {
const {
handleSignTx,
handleInput,
handleDeploy,
byteCode,
gasLimit,
walletExists,
DeployModal,
displayModal,
TxCompare
} = props;
return (
<div className="Deploy">
<section>
<label className="Deploy-field form-group">
<h4 className="Deploy-field-label">
{translate('CONTRACT_ByteCode')}
</h4>
<textarea
name="byteCode"
placeholder="0x8f87a973e..."
rows={6}
onChange={handleInput('data')}
className="Deploy-field-input form-control"
value={byteCode}
/>
</label>

<label className="Deploy-field form-group">
<h4 className="Deploy-field-label">Gas Limit</h4>
<input
name="gasLimit"
value={gasLimit}
onChange={handleInput('gasLimit')}
placeholder="30000"
className="Deploy-field-input form-control"
/>
</label>

{(walletExists && (
<button
className="Sign-submit btn btn-primary"
onClick={handleSignTx}
>
{translate('DEP_signtx')}
</button>
)) || <WalletDecrypt />}

{TxCompare ? (
<section>
{TxCompare}
<button
className="Deploy-submit btn btn-primary"
onClick={handleDeploy}
>
{translate('NAV_DeployContract')}
</button>
</section>
) : null}

{displayModal && DeployModal}
</section>
</div>
);
};

export default deployHOC(Deploy);
Loading