aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/eth_weth_conversion_button.tsx
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-01-25 23:42:58 +0800
committerFabio Berger <me@fabioberger.com>2018-01-25 23:42:58 +0800
commit71d68f975cd7bc089f0cbef4e5888a73eab4ee42 (patch)
tree9482602fc23d2baec3fff1fb97750ad45adc6eca /packages/website/ts/components/eth_weth_conversion_button.tsx
parentec3d8a034fe763d8255935985b1fb97aff6c177b (diff)
parentf58f0ddb67555c3f0c7252ea3e003824984c48ad (diff)
downloaddexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.gz
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.bz2
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.lz
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.xz
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.tar.zst
dexon-sol-tools-71d68f975cd7bc089f0cbef4e5888a73eab4ee42.zip
Merge branch 'development' into feature/portal-ledger-support
* development: (437 commits) Publish Update yarn.lock Update the CHANGELOG Fix the bug making it impossible to specify the custom ZRX address Fix fill/cancel order by looking for NoError instead of empty blockchainErr given the BlockchainErrs type refactor Add a comment about a yarn bug Add our mainnet and kovan nodes as backups for Portal requests Fix bug hiding the user info from topBar Add dev-utils package to top level README Prettier newline Prettier Allow Token symbols to be alphanumeric Update CHANGELOG, rebase on development Should not -> cannot Reject negative amounts in isValidBaseUnitAmount Re-add changelog for 0x.js Fix prettier Update yarn.lock Move tests to a separate folder Change file layout ... # Conflicts: # packages/website/README.md
Diffstat (limited to 'packages/website/ts/components/eth_weth_conversion_button.tsx')
-rw-r--r--packages/website/ts/components/eth_weth_conversion_button.tsx90
1 files changed, 58 insertions, 32 deletions
diff --git a/packages/website/ts/components/eth_weth_conversion_button.tsx b/packages/website/ts/components/eth_weth_conversion_button.tsx
index a83b1543f..300e71f1f 100644
--- a/packages/website/ts/components/eth_weth_conversion_button.tsx
+++ b/packages/website/ts/components/eth_weth_conversion_button.tsx
@@ -1,23 +1,26 @@
-import {ZeroEx} from '0x.js';
-import BigNumber from 'bignumber.js';
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import RaisedButton from 'material-ui/RaisedButton';
import * as React from 'react';
-import {Blockchain} from 'ts/blockchain';
-import {EthWethConversionDialog} from 'ts/components/dialogs/eth_weth_conversion_dialog';
-import {Dispatcher} from 'ts/redux/dispatcher';
-import {BlockchainCallErrs, Side, Token, TokenState} from 'ts/types';
-import {constants} from 'ts/utils/constants';
-import {errorReporter} from 'ts/utils/error_reporter';
-import {utils} from 'ts/utils/utils';
+import { Blockchain } from 'ts/blockchain';
+import { EthWethConversionDialog } from 'ts/components/dialogs/eth_weth_conversion_dialog';
+import { Dispatcher } from 'ts/redux/dispatcher';
+import { BlockchainCallErrs, Side, Token, TokenState } from 'ts/types';
+import { constants } from 'ts/utils/constants';
+import { errorReporter } from 'ts/utils/error_reporter';
+import { utils } from 'ts/utils/utils';
interface EthWethConversionButtonProps {
+ direction: Side;
ethToken: Token;
ethTokenState: TokenState;
dispatcher: Dispatcher;
blockchain: Blockchain;
userEtherBalance: BigNumber;
- onError: () => void;
+ isOutdatedWrappedEther: boolean;
+ onConversionSuccessful?: () => void;
+ isDisabled?: boolean;
}
interface EthWethConversionButtonState {
@@ -25,8 +28,14 @@ interface EthWethConversionButtonState {
isEthConversionHappening: boolean;
}
-export class EthWethConversionButton extends
- React.Component<EthWethConversionButtonProps, EthWethConversionButtonState> {
+export class EthWethConversionButton extends React.Component<
+ EthWethConversionButtonProps,
+ EthWethConversionButtonState
+> {
+ public static defaultProps: Partial<EthWethConversionButtonProps> = {
+ isDisabled: false,
+ onConversionSuccessful: _.noop,
+ };
public constructor(props: EthWethConversionButtonProps) {
super(props);
this.state = {
@@ -35,20 +44,30 @@ export class EthWethConversionButton extends
};
}
public render() {
- const labelStyle = this.state.isEthConversionHappening ? {fontSize: 10} : {};
+ const labelStyle = this.state.isEthConversionHappening ? { fontSize: 10 } : {};
+ let callToActionLabel;
+ let inProgressLabel;
+ if (this.props.direction === Side.Deposit) {
+ callToActionLabel = 'Wrap';
+ inProgressLabel = 'Wrapping...';
+ } else {
+ callToActionLabel = 'Unwrap';
+ inProgressLabel = 'Unwrapping...';
+ }
return (
<div>
<RaisedButton
- style={{width: '100%'}}
+ style={{ width: '100%' }}
labelStyle={labelStyle}
- disabled={this.state.isEthConversionHappening}
- label={this.state.isEthConversionHappening ? 'Converting...' : 'Convert'}
- onClick={this.toggleConversionDialog.bind(this)}
+ disabled={this.props.isDisabled || this.state.isEthConversionHappening}
+ label={this.state.isEthConversionHappening ? inProgressLabel : callToActionLabel}
+ onClick={this._toggleConversionDialog.bind(this)}
/>
<EthWethConversionDialog
+ direction={this.props.direction}
isOpen={this.state.isEthConversionDialogVisible}
- onComplete={this.onConversionAmountSelectedAsync.bind(this)}
- onCancelled={this.toggleConversionDialog.bind(this)}
+ onComplete={this._onConversionAmountSelectedAsync.bind(this)}
+ onCancelled={this._toggleConversionDialog.bind(this)}
etherBalance={this.props.userEtherBalance}
token={this.props.ethToken}
tokenState={this.props.ethTokenState}
@@ -56,41 +75,48 @@ export class EthWethConversionButton extends
</div>
);
}
- private toggleConversionDialog() {
+ private _toggleConversionDialog() {
this.setState({
isEthConversionDialogVisible: !this.state.isEthConversionDialogVisible,
});
}
- private async onConversionAmountSelectedAsync(direction: Side, value: BigNumber) {
+ private async _onConversionAmountSelectedAsync(direction: Side, value: BigNumber) {
this.setState({
isEthConversionHappening: true,
});
- this.toggleConversionDialog();
+ this._toggleConversionDialog();
const token = this.props.ethToken;
const tokenState = this.props.ethTokenState;
let balance = tokenState.balance;
try {
- if (direction === Side.deposit) {
- await this.props.blockchain.convertEthToWrappedEthTokensAsync(value);
- const ethAmount = ZeroEx.toUnitAmount(value, constants.ETH_DECIMAL_PLACES);
- this.props.dispatcher.showFlashMessage(`Successfully converted ${ethAmount.toString()} ETH to WETH`);
+ if (direction === Side.Deposit) {
+ await this.props.blockchain.convertEthToWrappedEthTokensAsync(token.address, value);
+ const ethAmount = ZeroEx.toUnitAmount(value, constants.DECIMAL_PLACES_ETH);
+ this.props.dispatcher.showFlashMessage(`Successfully wrapped ${ethAmount.toString()} ETH to WETH`);
balance = balance.plus(value);
} else {
- await this.props.blockchain.convertWrappedEthTokensToEthAsync(value);
+ await this.props.blockchain.convertWrappedEthTokensToEthAsync(token.address, value);
const tokenAmount = ZeroEx.toUnitAmount(value, token.decimals);
- this.props.dispatcher.showFlashMessage(`Successfully converted ${tokenAmount.toString()} WETH to ETH`);
+ this.props.dispatcher.showFlashMessage(`Successfully unwrapped ${tokenAmount.toString()} WETH to ETH`);
balance = balance.minus(value);
}
- this.props.dispatcher.replaceTokenBalanceByAddress(token.address, balance);
+ if (!this.props.isOutdatedWrappedEther) {
+ this.props.dispatcher.replaceTokenBalanceByAddress(token.address, balance);
+ }
+ this.props.onConversionSuccessful();
} catch (err) {
- const errMsg = '' + err;
- if (_.includes(errMsg, BlockchainCallErrs.USER_HAS_NO_ASSOCIATED_ADDRESSES)) {
+ const errMsg = `${err}`;
+ if (_.includes(errMsg, BlockchainCallErrs.UserHasNoAssociatedAddresses)) {
this.props.dispatcher.updateShouldBlockchainErrDialogBeOpen(true);
} else if (!_.includes(errMsg, 'User denied transaction')) {
utils.consoleLog(`Unexpected error encountered: ${err}`);
utils.consoleLog(err.stack);
+ const errorMsg =
+ direction === Side.Deposit
+ ? 'Failed to wrap your ETH. Please try again.'
+ : 'Failed to unwrap your WETH. Please try again.';
+ this.props.dispatcher.showFlashMessage(errorMsg);
await errorReporter.reportAsync(err);
- this.props.onError();
}
}
this.setState({