2017-06-26 22:27:55 +00:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2017-09-05 21:28:19 +00:00
|
|
|
// UTILS
|
|
|
|
import { formatGasLimit } from 'utils/formatters';
|
2017-06-26 22:27:55 +00:00
|
|
|
import translate from 'translations';
|
2017-09-05 21:28:19 +00:00
|
|
|
import pickBy from 'lodash/pickBy';
|
|
|
|
// SELECTORS
|
|
|
|
import { getNodeConfig } from 'selectors/config';
|
|
|
|
import {
|
|
|
|
getNodeLib,
|
|
|
|
getNetworkConfig,
|
|
|
|
getGasPriceGwei
|
|
|
|
} from 'selectors/config';
|
|
|
|
import {
|
|
|
|
getTokenBalances,
|
|
|
|
getTxFromBroadcastTransactionStatus
|
|
|
|
} from 'selectors/wallet';
|
|
|
|
import { getTokens } from 'selectors/wallet';
|
|
|
|
import type { TokenBalance } from 'selectors/wallet';
|
|
|
|
// COMPONENTS
|
2017-06-26 22:27:55 +00:00
|
|
|
import { UnlockHeader } from 'components/ui';
|
|
|
|
import {
|
2017-07-02 05:49:06 +00:00
|
|
|
Donate,
|
|
|
|
DataField,
|
|
|
|
CustomMessage,
|
|
|
|
GasField,
|
|
|
|
AmountField,
|
2017-08-23 06:57:18 +00:00
|
|
|
AddressField,
|
|
|
|
ConfirmationModal
|
2017-06-26 22:27:55 +00:00
|
|
|
} from './components';
|
2017-07-13 21:02:39 +00:00
|
|
|
import { BalanceSidebar } from 'components';
|
2017-09-05 21:28:19 +00:00
|
|
|
// CONFIG
|
|
|
|
import type { NodeConfig } from 'config/data';
|
|
|
|
import type { Token, NetworkConfig } from 'config/data';
|
|
|
|
import { donationAddressMap } from 'config/data';
|
|
|
|
// REDUX
|
2017-06-29 23:03:11 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-09-05 21:28:19 +00:00
|
|
|
import type { State as AppState } from 'reducers';
|
|
|
|
import { broadcastTx } from 'actions/wallet';
|
|
|
|
import type { BroadcastTxRequestedAction } from 'actions/wallet';
|
|
|
|
import { showNotification } from 'actions/notifications';
|
|
|
|
import type { ShowNotificationAction } from 'actions/notifications';
|
|
|
|
// LIBS
|
2017-09-12 00:26:16 +00:00
|
|
|
import type { IWallet } from 'libs/wallet/IWallet';
|
2017-08-08 03:45:08 +00:00
|
|
|
import { isValidETHAddress } from 'libs/validators';
|
2017-08-11 21:54:10 +00:00
|
|
|
import type { RPCNode } from 'libs/nodes';
|
|
|
|
import type {
|
2017-09-05 21:28:19 +00:00
|
|
|
BroadcastTransactionStatus,
|
|
|
|
TransactionInput,
|
|
|
|
CompleteTransaction
|
2017-08-11 21:54:10 +00:00
|
|
|
} from 'libs/transaction';
|
2017-09-05 21:28:19 +00:00
|
|
|
import type { TransactionWithoutGas } from 'libs/messages';
|
2017-08-11 21:54:10 +00:00
|
|
|
import type { UNIT } from 'libs/units';
|
2017-09-08 19:01:31 +00:00
|
|
|
import { Wei, Ether, GWei } from 'libs/units';
|
2017-09-05 21:28:19 +00:00
|
|
|
import {
|
|
|
|
generateCompleteTransaction,
|
|
|
|
getBalanceMinusGasCosts,
|
|
|
|
formatTxInput
|
|
|
|
} from 'libs/transaction';
|
|
|
|
// MISC
|
|
|
|
import customMessages from './messages';
|
|
|
|
import Big from 'bignumber.js';
|
2017-06-26 22:27:55 +00:00
|
|
|
|
|
|
|
type State = {
|
2017-07-02 05:49:06 +00:00
|
|
|
hasQueryString: boolean,
|
|
|
|
readOnly: boolean,
|
|
|
|
to: string,
|
2017-08-31 04:00:31 +00:00
|
|
|
// amount value
|
2017-07-02 05:49:06 +00:00
|
|
|
value: string,
|
2017-08-11 21:54:10 +00:00
|
|
|
// $FlowFixMe - Comes from getParam not validating unit
|
|
|
|
unit: UNIT,
|
2017-08-23 06:57:18 +00:00
|
|
|
token: ?Token,
|
2017-07-02 05:49:06 +00:00
|
|
|
gasLimit: string,
|
|
|
|
data: string,
|
2017-08-11 21:54:10 +00:00
|
|
|
gasChanged: boolean,
|
2017-09-05 21:28:19 +00:00
|
|
|
transaction: ?CompleteTransaction,
|
2017-08-31 04:00:31 +00:00
|
|
|
showTxConfirm: boolean,
|
|
|
|
generateDisabled: boolean
|
2017-06-26 22:27:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function getParam(query: { [string]: string }, key: string) {
|
2017-07-02 05:49:06 +00:00
|
|
|
const keys = Object.keys(query);
|
|
|
|
const index = keys.findIndex(k => k.toLowerCase() === key.toLowerCase());
|
|
|
|
if (index === -1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return query[keys[index]];
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-15 23:05:57 +00:00
|
|
|
type Props = {
|
|
|
|
location: {
|
|
|
|
query: {
|
|
|
|
[string]: string
|
|
|
|
}
|
|
|
|
},
|
2017-09-12 00:26:16 +00:00
|
|
|
wallet: IWallet,
|
2017-09-08 19:01:31 +00:00
|
|
|
balance: Ether,
|
2017-08-23 06:57:18 +00:00
|
|
|
node: NodeConfig,
|
2017-08-11 21:54:10 +00:00
|
|
|
nodeLib: RPCNode,
|
|
|
|
network: NetworkConfig,
|
2017-08-08 03:45:08 +00:00
|
|
|
tokens: Token[],
|
2017-08-11 21:54:10 +00:00
|
|
|
tokenBalances: TokenBalance[],
|
2017-09-08 19:01:31 +00:00
|
|
|
gasPrice: Wei,
|
2017-08-31 04:00:31 +00:00
|
|
|
broadcastTx: (signedTx: string) => BroadcastTxRequestedAction,
|
2017-08-11 21:54:10 +00:00
|
|
|
showNotification: (
|
|
|
|
level: string,
|
|
|
|
msg: string,
|
|
|
|
duration?: number
|
2017-08-31 04:00:31 +00:00
|
|
|
) => ShowNotificationAction,
|
2017-09-05 21:28:19 +00:00
|
|
|
transactions: Array<BroadcastTransactionStatus>
|
2017-08-31 04:00:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
hasQueryString: false,
|
|
|
|
readOnly: false,
|
|
|
|
to: '',
|
|
|
|
value: '',
|
|
|
|
unit: 'ether',
|
|
|
|
token: null,
|
|
|
|
gasLimit: '21000',
|
|
|
|
data: '',
|
|
|
|
gasChanged: false,
|
|
|
|
showTxConfirm: false,
|
|
|
|
transaction: null,
|
|
|
|
generateDisabled: true
|
2017-07-15 23:05:57 +00:00
|
|
|
};
|
|
|
|
|
2017-06-26 22:27:55 +00:00
|
|
|
export class SendTransaction extends React.Component {
|
2017-07-15 23:05:57 +00:00
|
|
|
props: Props;
|
2017-08-31 04:00:31 +00:00
|
|
|
state: State = initialState;
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
componentDidMount() {
|
|
|
|
const queryPresets = pickBy(this.parseQuery());
|
|
|
|
if (Object.keys(queryPresets).length) {
|
|
|
|
this.setState({ ...queryPresets, hasQueryString: true });
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
2017-07-02 05:49:06 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 03:45:08 +00:00
|
|
|
componentDidUpdate(_prevProps: Props, prevState: State) {
|
2017-08-31 04:00:31 +00:00
|
|
|
// TODO listen to gas price changes here
|
|
|
|
// TODO debounce the call
|
2017-08-08 03:45:08 +00:00
|
|
|
if (
|
2017-08-31 04:00:31 +00:00
|
|
|
// if gas has not changed
|
2017-08-08 03:45:08 +00:00
|
|
|
!this.state.gasChanged &&
|
2017-08-31 04:00:31 +00:00
|
|
|
// if we have valid tx
|
2017-08-08 03:45:08 +00:00
|
|
|
this.isValid() &&
|
2017-08-31 04:00:31 +00:00
|
|
|
// if any relevant fields changed
|
2017-08-08 03:45:08 +00:00
|
|
|
(this.state.to !== prevState.to ||
|
|
|
|
this.state.value !== prevState.value ||
|
|
|
|
this.state.unit !== prevState.unit ||
|
|
|
|
this.state.data !== prevState.data)
|
|
|
|
) {
|
2017-08-31 04:00:31 +00:00
|
|
|
if (!isNaN(parseInt(this.state.value))) {
|
|
|
|
this.estimateGas();
|
|
|
|
}
|
|
|
|
}
|
2017-09-05 21:28:19 +00:00
|
|
|
if (this.state.generateDisabled === this.isValid()) {
|
2017-08-31 04:00:31 +00:00
|
|
|
this.setState({ generateDisabled: !this.isValid() });
|
|
|
|
}
|
|
|
|
const componentStateTransaction = this.state.transaction;
|
|
|
|
if (componentStateTransaction) {
|
|
|
|
// lives in redux state
|
2017-09-05 21:28:19 +00:00
|
|
|
const currentTxAsSignedTransaction = getTxFromBroadcastTransactionStatus(
|
2017-08-31 04:00:31 +00:00
|
|
|
this.props.transactions,
|
|
|
|
componentStateTransaction.signedTx
|
|
|
|
);
|
|
|
|
// if there is a matching tx in redux state
|
2017-09-05 21:28:19 +00:00
|
|
|
if (currentTxAsSignedTransaction) {
|
2017-08-31 04:00:31 +00:00
|
|
|
// if the broad-casted transaction attempt is successful, clear the form
|
2017-09-05 21:28:19 +00:00
|
|
|
if (currentTxAsSignedTransaction.successfullyBroadcast) {
|
|
|
|
this.resetTx();
|
2017-08-31 04:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-08 03:45:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
render() {
|
2017-07-04 03:21:19 +00:00
|
|
|
const unlocked = !!this.props.wallet;
|
2017-07-16 21:02:13 +00:00
|
|
|
const {
|
|
|
|
to,
|
|
|
|
value,
|
|
|
|
unit,
|
|
|
|
gasLimit,
|
|
|
|
data,
|
|
|
|
readOnly,
|
2017-08-11 21:54:10 +00:00
|
|
|
hasQueryString,
|
2017-08-23 06:57:18 +00:00
|
|
|
showTxConfirm,
|
2017-08-11 21:54:10 +00:00
|
|
|
transaction
|
2017-07-16 21:02:13 +00:00
|
|
|
} = this.state;
|
2017-07-02 05:49:06 +00:00
|
|
|
const customMessage = customMessages.find(m => m.to === to);
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
return (
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
<section className="Tab-content">
|
|
|
|
<UnlockHeader title={'NAV_SendEther'} />
|
2017-06-26 22:27:55 +00:00
|
|
|
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
<div className="row">
|
|
|
|
{/* Send Form */}
|
|
|
|
{unlocked &&
|
|
|
|
<main className="col-sm-8">
|
|
|
|
<div className="Tab-content-pane">
|
|
|
|
{hasQueryString &&
|
|
|
|
<div className="alert alert-info">
|
|
|
|
<p>
|
|
|
|
{translate('WARN_Send_Link')}
|
|
|
|
</p>
|
|
|
|
</div>}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
<AddressField
|
|
|
|
placeholder={donationAddressMap.ETH}
|
|
|
|
value={this.state.to}
|
|
|
|
onChange={readOnly ? null : this.onAddressChange}
|
|
|
|
/>
|
|
|
|
<AmountField
|
|
|
|
value={value}
|
|
|
|
unit={unit}
|
|
|
|
tokens={this.props.tokenBalances
|
|
|
|
.filter(token => !token.balance.eq(0))
|
|
|
|
.map(token => token.symbol)
|
|
|
|
.sort()}
|
|
|
|
onChange={readOnly ? void 0 : this.onAmountChange}
|
|
|
|
/>
|
|
|
|
<GasField
|
|
|
|
value={gasLimit}
|
|
|
|
onChange={readOnly ? void 0 : this.onGasChange}
|
|
|
|
/>
|
|
|
|
{unit === 'ether' &&
|
|
|
|
<DataField
|
|
|
|
value={data}
|
|
|
|
onChange={readOnly ? void 0 : this.onDataChange}
|
|
|
|
/>}
|
|
|
|
<CustomMessage message={customMessage} />
|
2017-06-26 22:27:55 +00:00
|
|
|
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-xs-12 clearfix">
|
|
|
|
<button
|
|
|
|
disabled={this.state.generateDisabled}
|
|
|
|
className="btn btn-info btn-block"
|
2017-09-05 21:28:19 +00:00
|
|
|
onClick={this.generateTxFromState}
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
>
|
|
|
|
{translate('SEND_generate')}
|
|
|
|
</button>
|
2017-07-02 05:49:06 +00:00
|
|
|
</div>
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
{transaction &&
|
|
|
|
<div>
|
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-sm-6">
|
|
|
|
<label>
|
|
|
|
{translate('SEND_raw')}
|
|
|
|
</label>
|
|
|
|
<textarea
|
|
|
|
className="form-control"
|
|
|
|
value={transaction.rawTx}
|
|
|
|
rows="4"
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-sm-6">
|
|
|
|
<label>
|
|
|
|
{translate('SEND_signed')}
|
|
|
|
</label>
|
|
|
|
<textarea
|
|
|
|
className="form-control"
|
|
|
|
value={transaction.signedTx}
|
|
|
|
rows="4"
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-06-26 22:27:55 +00:00
|
|
|
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
<div className="form-group">
|
2017-08-31 04:00:31 +00:00
|
|
|
<button
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
className="btn btn-primary btn-block col-sm-11"
|
2017-09-05 21:28:19 +00:00
|
|
|
disabled={!this.state.transaction}
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
onClick={this.openTxModal}
|
2017-07-16 21:02:13 +00:00
|
|
|
>
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
{translate('SEND_trans')}
|
2017-08-31 04:00:31 +00:00
|
|
|
</button>
|
2017-07-02 05:49:06 +00:00
|
|
|
</div>
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
</div>}
|
|
|
|
</div>
|
|
|
|
</main>}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
{/* Sidebar */}
|
|
|
|
{unlocked &&
|
|
|
|
<section className="col-sm-4">
|
Sidebar refactor / style update (#173)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
<BalanceSidebar />
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
</section>}
|
2017-07-02 05:49:06 +00:00
|
|
|
</div>
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
|
2017-08-23 06:57:18 +00:00
|
|
|
{transaction &&
|
|
|
|
showTxConfirm &&
|
|
|
|
<ConfirmationModal
|
|
|
|
wallet={this.props.wallet}
|
|
|
|
node={this.props.node}
|
2017-08-31 04:00:31 +00:00
|
|
|
signedTx={transaction.signedTx}
|
|
|
|
onClose={this.hideConfirmTx}
|
2017-08-23 06:57:18 +00:00
|
|
|
onConfirm={this.confirmTx}
|
|
|
|
/>}
|
2017-07-02 05:49:06 +00:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
parseQuery() {
|
|
|
|
const query = this.props.location.query;
|
|
|
|
const to = getParam(query, 'to');
|
|
|
|
const data = getParam(query, 'data');
|
|
|
|
// FIXME validate token against presets
|
|
|
|
const unit = getParam(query, 'tokenSymbol');
|
|
|
|
const value = getParam(query, 'value');
|
|
|
|
let gasLimit = getParam(query, 'gas');
|
|
|
|
if (gasLimit === null) {
|
|
|
|
gasLimit = getParam(query, 'limit');
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
2017-08-31 04:00:31 +00:00
|
|
|
const readOnly = getParam(query, 'readOnly') != null;
|
2017-07-02 05:49:06 +00:00
|
|
|
return { to, data, value, unit, gasLimit, readOnly };
|
|
|
|
}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-08-08 03:45:08 +00:00
|
|
|
isValid() {
|
2017-08-31 04:00:31 +00:00
|
|
|
const { to, value, gasLimit } = this.state;
|
2017-08-08 03:45:08 +00:00
|
|
|
return (
|
|
|
|
isValidETHAddress(to) &&
|
|
|
|
value &&
|
|
|
|
Number(value) > 0 &&
|
|
|
|
!isNaN(Number(value)) &&
|
2017-08-31 04:00:31 +00:00
|
|
|
isFinite(Number(value)) &&
|
|
|
|
!isNaN(parseInt(gasLimit)) &&
|
|
|
|
isFinite(parseInt(gasLimit))
|
2017-08-08 03:45:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-09-05 21:28:19 +00:00
|
|
|
async getFormattedTxFromState(): Promise<TransactionWithoutGas> {
|
2017-08-11 21:54:10 +00:00
|
|
|
const { wallet } = this.props;
|
2017-09-01 00:01:34 +00:00
|
|
|
const { token, unit, value, to, data } = this.state;
|
2017-09-05 21:28:19 +00:00
|
|
|
const transactionInput: TransactionInput = {
|
|
|
|
token,
|
|
|
|
unit,
|
|
|
|
value,
|
|
|
|
to,
|
|
|
|
data
|
|
|
|
};
|
|
|
|
return await formatTxInput(wallet, transactionInput);
|
2017-08-08 03:45:08 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 21:54:10 +00:00
|
|
|
async estimateGas() {
|
2017-09-05 21:28:19 +00:00
|
|
|
if (isNaN(parseInt(this.state.value))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const cachedFormattedTx = await this.getFormattedTxFromState();
|
|
|
|
// Grab a reference to state. If it has changed by the time the estimateGas
|
|
|
|
// call comes back, we don't want to replace the gasLimit in state.
|
|
|
|
const state = this.state;
|
|
|
|
const gasLimit = await this.props.nodeLib.estimateGas(cachedFormattedTx);
|
|
|
|
if (this.state === state) {
|
|
|
|
this.setState({ gasLimit: formatGasLimit(gasLimit, state.unit) });
|
|
|
|
} else {
|
|
|
|
// state has changed, so try again from the start (with the hope that state won't change by the next time)
|
|
|
|
this.estimateGas();
|
2017-08-08 03:45:08 +00:00
|
|
|
}
|
2017-09-05 21:28:19 +00:00
|
|
|
} catch (error) {
|
2017-09-08 19:01:31 +00:00
|
|
|
this.setState({ generateDisabled: true });
|
2017-09-05 21:28:19 +00:00
|
|
|
this.props.showNotification('danger', error.message, 5000);
|
2017-08-31 04:00:31 +00:00
|
|
|
}
|
2017-08-08 03:45:08 +00:00
|
|
|
}
|
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
// FIXME use mkTx instead or something that could take care of default gas/data and whatnot,
|
|
|
|
onNewTx = (
|
|
|
|
address: string,
|
|
|
|
amount: string,
|
|
|
|
unit: string,
|
|
|
|
data: string = '',
|
|
|
|
gasLimit: string = '21000'
|
|
|
|
) => {
|
|
|
|
this.setState({
|
|
|
|
to: address,
|
|
|
|
value: amount,
|
|
|
|
unit,
|
|
|
|
data,
|
|
|
|
gasLimit,
|
|
|
|
gasChanged: false
|
|
|
|
});
|
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
onAddressChange = (value: string) => {
|
|
|
|
this.setState({
|
|
|
|
to: value
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onDataChange = (value: string) => {
|
2017-09-05 21:28:19 +00:00
|
|
|
if (this.state.unit === 'ether') {
|
|
|
|
this.setState({ data: value });
|
2017-07-02 05:49:06 +00:00
|
|
|
}
|
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
onGasChange = (value: string) => {
|
|
|
|
this.setState({ gasLimit: value, gasChanged: true });
|
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-08 19:01:31 +00:00
|
|
|
handleEverythingAmountChange = (value: string, unit: string): string => {
|
|
|
|
if (unit === 'ether') {
|
|
|
|
const { balance, gasPrice } = this.props;
|
|
|
|
const { gasLimit } = this.state;
|
|
|
|
const weiBalance = balance.toWei();
|
|
|
|
const bigGasLimit = new Big(gasLimit);
|
|
|
|
value = getBalanceMinusGasCosts(
|
|
|
|
bigGasLimit,
|
|
|
|
gasPrice,
|
|
|
|
weiBalance
|
|
|
|
).toString();
|
|
|
|
} else {
|
|
|
|
const tokenBalance = this.props.tokenBalances.find(
|
|
|
|
tokenBalance => tokenBalance.symbol === unit
|
|
|
|
);
|
|
|
|
if (!tokenBalance) {
|
|
|
|
throw new Error(`${unit}: not found in token balances;`);
|
|
|
|
}
|
|
|
|
value = tokenBalance.balance.toString();
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
onAmountChange = (value: string, unit: string) => {
|
2017-07-13 21:02:39 +00:00
|
|
|
if (value === 'everything') {
|
2017-09-08 19:01:31 +00:00
|
|
|
value = this.handleEverythingAmountChange(value, unit);
|
|
|
|
}
|
|
|
|
let transaction = this.state.transaction;
|
|
|
|
let generateDisabled = this.state.generateDisabled;
|
|
|
|
if (unit && unit !== this.state.unit) {
|
|
|
|
value = '';
|
|
|
|
transaction = null;
|
|
|
|
generateDisabled = true;
|
2017-07-13 21:02:39 +00:00
|
|
|
}
|
2017-08-23 06:57:18 +00:00
|
|
|
let token = this.props.tokens.find(x => x.symbol === unit);
|
2017-07-02 05:49:06 +00:00
|
|
|
this.setState({
|
|
|
|
value,
|
2017-08-23 06:57:18 +00:00
|
|
|
unit,
|
2017-09-08 19:01:31 +00:00
|
|
|
token,
|
|
|
|
transaction,
|
|
|
|
generateDisabled
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
resetJustTx = async (): Promise<*> => {
|
|
|
|
new Promise(resolve => {
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
transaction: null
|
|
|
|
},
|
|
|
|
resolve
|
|
|
|
);
|
2017-07-02 05:49:06 +00:00
|
|
|
});
|
|
|
|
};
|
2017-08-11 21:54:10 +00:00
|
|
|
|
2017-09-05 21:28:19 +00:00
|
|
|
generateTxFromState = async () => {
|
2017-09-08 19:01:31 +00:00
|
|
|
await this.resetJustTx();
|
2017-09-05 21:28:19 +00:00
|
|
|
const { nodeLib, wallet, gasPrice, network } = this.props;
|
|
|
|
const { token, unit, value, to, data, gasLimit } = this.state;
|
|
|
|
const chainId = network.chainId;
|
|
|
|
const transactionInput = {
|
|
|
|
token,
|
|
|
|
unit,
|
|
|
|
value,
|
|
|
|
to,
|
|
|
|
data
|
|
|
|
};
|
2017-09-08 19:01:31 +00:00
|
|
|
const bigGasLimit = new Big(gasLimit);
|
2017-08-11 21:54:10 +00:00
|
|
|
try {
|
2017-09-05 21:28:19 +00:00
|
|
|
const signedTx = await generateCompleteTransaction(
|
2017-08-23 06:57:18 +00:00
|
|
|
wallet,
|
2017-09-05 21:28:19 +00:00
|
|
|
nodeLib,
|
|
|
|
gasPrice,
|
2017-09-08 19:01:31 +00:00
|
|
|
bigGasLimit,
|
2017-09-05 21:28:19 +00:00
|
|
|
chainId,
|
|
|
|
transactionInput
|
2017-08-11 21:54:10 +00:00
|
|
|
);
|
2017-09-05 21:28:19 +00:00
|
|
|
this.setState({ transaction: signedTx });
|
2017-08-11 21:54:10 +00:00
|
|
|
} catch (err) {
|
|
|
|
this.props.showNotification('danger', err.message, 5000);
|
|
|
|
}
|
|
|
|
};
|
2017-08-23 06:57:18 +00:00
|
|
|
|
|
|
|
openTxModal = () => {
|
2017-09-05 21:28:19 +00:00
|
|
|
this.setState({ showTxConfirm: true });
|
2017-08-23 06:57:18 +00:00
|
|
|
};
|
|
|
|
|
2017-08-31 04:00:31 +00:00
|
|
|
hideConfirmTx = () => {
|
2017-08-23 06:57:18 +00:00
|
|
|
this.setState({ showTxConfirm: false });
|
|
|
|
};
|
|
|
|
|
2017-09-05 21:28:19 +00:00
|
|
|
resetTx = () => {
|
2017-08-31 04:00:31 +00:00
|
|
|
this.setState({
|
|
|
|
to: '',
|
|
|
|
value: '',
|
|
|
|
transaction: null
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
confirmTx = (signedTx: string) => {
|
|
|
|
this.props.broadcastTx(signedTx);
|
2017-08-23 06:57:18 +00:00
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
2017-06-29 23:03:11 +00:00
|
|
|
|
|
|
|
function mapStateToProps(state: AppState) {
|
2017-07-04 03:21:19 +00:00
|
|
|
return {
|
2017-07-13 21:02:39 +00:00
|
|
|
wallet: state.wallet.inst,
|
Sidebar refactor / style update (#173)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
balance: state.wallet.balance,
|
2017-08-11 21:54:10 +00:00
|
|
|
tokenBalances: getTokenBalances(state),
|
2017-08-23 06:57:18 +00:00
|
|
|
node: getNodeConfig(state),
|
2017-08-11 21:54:10 +00:00
|
|
|
nodeLib: getNodeLib(state),
|
|
|
|
network: getNetworkConfig(state),
|
2017-08-08 03:45:08 +00:00
|
|
|
tokens: getTokens(state),
|
2017-09-08 19:01:31 +00:00
|
|
|
gasPrice: new GWei(getGasPriceGwei(state)).toWei(),
|
2017-08-31 04:00:31 +00:00
|
|
|
transactions: state.wallet.transactions
|
2017-07-04 03:21:19 +00:00
|
|
|
};
|
2017-06-29 23:03:11 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 04:00:31 +00:00
|
|
|
export default connect(mapStateToProps, { showNotification, broadcastTx })(
|
|
|
|
SendTransaction
|
|
|
|
);
|