WIP for sending ether from portal (works)
This commit is contained in:
@@ -276,6 +276,32 @@ export class Blockchain {
|
|||||||
);
|
);
|
||||||
await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash);
|
await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash);
|
||||||
}
|
}
|
||||||
|
public async sendAsync(toAddress: string, amountInBaseUnits: BigNumber): Promise<void> {
|
||||||
|
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
|
||||||
|
const transaction = {
|
||||||
|
from: this._userAddressIfExists,
|
||||||
|
to: toAddress,
|
||||||
|
value: amountInBaseUnits,
|
||||||
|
gasPrice: this._defaultGasPrice,
|
||||||
|
};
|
||||||
|
this._showFlashMessageIfLedger();
|
||||||
|
const txHash = await this._web3Wrapper.sendTransactionAsync(transaction);
|
||||||
|
await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash);
|
||||||
|
const etherScanLinkIfExists = sharedUtils.getEtherScanLinkIfExists(
|
||||||
|
txHash,
|
||||||
|
this.networkId,
|
||||||
|
EtherscanLinkSuffixes.Tx,
|
||||||
|
);
|
||||||
|
// TODO
|
||||||
|
// this._dispatcher.showFlashMessage(
|
||||||
|
// React.createElement(TokenSendCompleted, {
|
||||||
|
// etherScanLinkIfExists,
|
||||||
|
// token,
|
||||||
|
// toAddress,
|
||||||
|
// amountInBaseUnits,
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
}
|
||||||
public async transferAsync(token: Token, toAddress: string, amountInBaseUnits: BigNumber): Promise<void> {
|
public async transferAsync(token: Token, toAddress: string, amountInBaseUnits: BigNumber): Promise<void> {
|
||||||
utils.assert(!_.isUndefined(this._contractWrappers), 'ContractWrappers must be instantiated.');
|
utils.assert(!_.isUndefined(this._contractWrappers), 'ContractWrappers must be instantiated.');
|
||||||
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
|
utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses);
|
||||||
|
@@ -1,15 +1,13 @@
|
|||||||
import { colors } from '@0xproject/react-shared';
|
import { colors } from '@0xproject/react-shared';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import Dialog from 'material-ui/Dialog';
|
import Dialog from 'material-ui/Dialog';
|
||||||
import FlatButton from 'material-ui/FlatButton';
|
import FlatButton from 'material-ui/FlatButton';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Blockchain } from 'ts/blockchain';
|
import { Blockchain } from 'ts/blockchain';
|
||||||
import { EthAmountInput } from 'ts/components/inputs/eth_amount_input';
|
|
||||||
import { TokenAmountInput } from 'ts/components/inputs/token_amount_input';
|
import { TokenAmountInput } from 'ts/components/inputs/token_amount_input';
|
||||||
|
import { EthAmountInput } from 'ts/containers/inputs/eth_amount_input';
|
||||||
import { Side, Token } from 'ts/types';
|
import { Side, Token } from 'ts/types';
|
||||||
import { constants } from 'ts/utils/constants';
|
|
||||||
|
|
||||||
interface EthWethConversionDialogProps {
|
interface EthWethConversionDialogProps {
|
||||||
blockchain: Blockchain;
|
blockchain: Blockchain;
|
||||||
@@ -78,7 +76,6 @@ export class EthWethConversionDialog extends React.Component<
|
|||||||
? 'Convert your Ether into a tokenized, tradable form.'
|
? 'Convert your Ether into a tokenized, tradable form.'
|
||||||
: "Convert your Wrapped Ether back into it's native form.";
|
: "Convert your Wrapped Ether back into it's native form.";
|
||||||
const isWrappedVersion = this.props.direction === Side.Receive;
|
const isWrappedVersion = this.props.direction === Side.Receive;
|
||||||
const etherBalanceInEth = Web3Wrapper.toUnitAmount(this.props.etherBalanceInWei, constants.DECIMAL_PLACES_ETH);
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="pb2">{explanation}</div>
|
<div className="pb2">{explanation}</div>
|
||||||
@@ -106,7 +103,6 @@ export class EthWethConversionDialog extends React.Component<
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<EthAmountInput
|
<EthAmountInput
|
||||||
balance={etherBalanceInEth}
|
|
||||||
amount={this.state.value}
|
amount={this.state.value}
|
||||||
onChange={this._onValueChange.bind(this)}
|
onChange={this._onValueChange.bind(this)}
|
||||||
shouldCheckBalance={true}
|
shouldCheckBalance={true}
|
||||||
|
@@ -6,6 +6,7 @@ import * as React from 'react';
|
|||||||
import { Blockchain } from 'ts/blockchain';
|
import { Blockchain } from 'ts/blockchain';
|
||||||
import { AddressInput } from 'ts/components/inputs/address_input';
|
import { AddressInput } from 'ts/components/inputs/address_input';
|
||||||
import { TokenAmountInput } from 'ts/components/inputs/token_amount_input';
|
import { TokenAmountInput } from 'ts/components/inputs/token_amount_input';
|
||||||
|
import { EthAmountInput } from 'ts/containers/inputs/eth_amount_input';
|
||||||
import { Token } from 'ts/types';
|
import { Token } from 'ts/types';
|
||||||
|
|
||||||
interface SendDialogProps {
|
interface SendDialogProps {
|
||||||
@@ -15,7 +16,7 @@ interface SendDialogProps {
|
|||||||
onComplete: (recipient: string, value: BigNumber) => void;
|
onComplete: (recipient: string, value: BigNumber) => void;
|
||||||
onCancelled: () => void;
|
onCancelled: () => void;
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
token: Token;
|
asset: Token | 'ETH';
|
||||||
lastForceTokenStateRefetch: number;
|
lastForceTokenStateRefetch: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,23 +59,23 @@ export class SendDialog extends React.Component<SendDialogProps, SendDialogState
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
private _renderSendDialogBody(): React.ReactNode {
|
private _renderSendDialogBody(): React.ReactNode {
|
||||||
return (
|
const input =
|
||||||
<div className="mx-auto" style={{ maxWidth: 300 }}>
|
this.props.asset === 'ETH' ? (
|
||||||
<div style={{ height: 80 }}>
|
<EthAmountInput
|
||||||
<AddressInput
|
label="Amount to send"
|
||||||
initialAddress={this.state.recipient}
|
shouldShowIncompleteErrs={this.state.shouldShowIncompleteErrs}
|
||||||
updateAddress={this._onRecipientChange.bind(this)}
|
shouldCheckBalance={true}
|
||||||
isRequired={true}
|
shouldShowErrs={true}
|
||||||
label={'Recipient address'}
|
onChange={this._onValueChange.bind(this)}
|
||||||
hintText={'Address'}
|
amount={this.state.value}
|
||||||
/>
|
/>
|
||||||
</div>
|
) : (
|
||||||
<TokenAmountInput
|
<TokenAmountInput
|
||||||
blockchain={this.props.blockchain}
|
blockchain={this.props.blockchain}
|
||||||
userAddress={this.props.userAddress}
|
userAddress={this.props.userAddress}
|
||||||
networkId={this.props.networkId}
|
networkId={this.props.networkId}
|
||||||
label="Amount to send"
|
label="Amount to send"
|
||||||
token={this.props.token}
|
token={this.props.asset}
|
||||||
shouldShowIncompleteErrs={this.state.shouldShowIncompleteErrs}
|
shouldShowIncompleteErrs={this.state.shouldShowIncompleteErrs}
|
||||||
shouldCheckBalance={true}
|
shouldCheckBalance={true}
|
||||||
shouldCheckAllowance={false}
|
shouldCheckAllowance={false}
|
||||||
@@ -82,6 +83,19 @@ export class SendDialog extends React.Component<SendDialogProps, SendDialogState
|
|||||||
amount={this.state.value}
|
amount={this.state.value}
|
||||||
lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch}
|
lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch}
|
||||||
/>
|
/>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div className="mx-auto" style={{ maxWidth: 300 }}>
|
||||||
|
<div style={{ height: 80 }}>
|
||||||
|
<AddressInput
|
||||||
|
initialAddress={this.state.recipient}
|
||||||
|
updateAddress={this._onRecipientChange.bind(this)}
|
||||||
|
isRequired={true}
|
||||||
|
label="Recipient address'"
|
||||||
|
hintText="Address"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{input}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -28,14 +28,13 @@ export class EthAmountInput extends React.Component<EthAmountInputProps, EthAmou
|
|||||||
public static defaultProps: Partial<EthAmountInputProps> = {
|
public static defaultProps: Partial<EthAmountInputProps> = {
|
||||||
shouldShowErrs: true,
|
shouldShowErrs: true,
|
||||||
shouldShowUnderline: true,
|
shouldShowUnderline: true,
|
||||||
style: { height: 63 },
|
|
||||||
};
|
};
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
const amount = this.props.amount
|
const amount = this.props.amount
|
||||||
? Web3Wrapper.toUnitAmount(this.props.amount, constants.DECIMAL_PLACES_ETH)
|
? Web3Wrapper.toUnitAmount(this.props.amount, constants.DECIMAL_PLACES_ETH)
|
||||||
: undefined;
|
: undefined;
|
||||||
return (
|
return (
|
||||||
<div className="flex overflow-hidden" style={this.props.style}>
|
<div className="flex" style={this.props.style}>
|
||||||
<BalanceBoundedInput
|
<BalanceBoundedInput
|
||||||
label={this.props.label}
|
label={this.props.label}
|
||||||
balance={this.props.balance}
|
balance={this.props.balance}
|
||||||
|
@@ -12,7 +12,7 @@ import { utils } from 'ts/utils/utils';
|
|||||||
interface SendButtonProps {
|
interface SendButtonProps {
|
||||||
userAddress: string;
|
userAddress: string;
|
||||||
networkId: number;
|
networkId: number;
|
||||||
token: Token;
|
asset: Token | 'ETH';
|
||||||
dispatcher: Dispatcher;
|
dispatcher: Dispatcher;
|
||||||
blockchain: Blockchain;
|
blockchain: Blockchain;
|
||||||
onError: () => void;
|
onError: () => void;
|
||||||
@@ -51,7 +51,7 @@ export class SendButton extends React.Component<SendButtonProps, SendButtonState
|
|||||||
isOpen={this.state.isSendDialogVisible}
|
isOpen={this.state.isSendDialogVisible}
|
||||||
onComplete={this._onSendAmountSelectedAsync.bind(this)}
|
onComplete={this._onSendAmountSelectedAsync.bind(this)}
|
||||||
onCancelled={this._toggleSendDialog.bind(this)}
|
onCancelled={this._toggleSendDialog.bind(this)}
|
||||||
token={this.props.token}
|
asset={this.props.asset}
|
||||||
lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch}
|
lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -67,10 +67,14 @@ export class SendButton extends React.Component<SendButtonProps, SendButtonState
|
|||||||
isSending: true,
|
isSending: true,
|
||||||
});
|
});
|
||||||
this._toggleSendDialog();
|
this._toggleSendDialog();
|
||||||
const token = this.props.token;
|
|
||||||
try {
|
try {
|
||||||
await this.props.blockchain.transferAsync(token, recipient, value);
|
if (this.props.asset === 'ETH') {
|
||||||
await this.props.refetchTokenStateAsync(token.address);
|
await this.props.blockchain.sendAsync(recipient, value);
|
||||||
|
} else {
|
||||||
|
const token = this.props.asset;
|
||||||
|
await this.props.blockchain.transferAsync(token, recipient, value);
|
||||||
|
await this.props.refetchTokenStateAsync(token.address);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errMsg = `${err}`;
|
const errMsg = `${err}`;
|
||||||
if (_.includes(errMsg, BlockchainCallErrs.UserHasNoAssociatedAddresses)) {
|
if (_.includes(errMsg, BlockchainCallErrs.UserHasNoAssociatedAddresses)) {
|
||||||
|
@@ -204,11 +204,8 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
|
|||||||
<TableHeaderColumn>Currency</TableHeaderColumn>
|
<TableHeaderColumn>Currency</TableHeaderColumn>
|
||||||
<TableHeaderColumn>Balance</TableHeaderColumn>
|
<TableHeaderColumn>Balance</TableHeaderColumn>
|
||||||
<TableRowColumn className="sm-hide xs-hide" style={stubColumnStyle} />
|
<TableRowColumn className="sm-hide xs-hide" style={stubColumnStyle} />
|
||||||
{isTestNetwork && (
|
{isTestNetwork && <TableHeaderColumn style={{ paddingLeft: 3 }}>Action</TableHeaderColumn>}
|
||||||
<TableHeaderColumn style={{ paddingLeft: 3 }}>
|
<TableHeaderColumn>Send</TableHeaderColumn>
|
||||||
{isSmallScreen ? 'Faucet' : 'Request from faucet'}
|
|
||||||
</TableHeaderColumn>
|
|
||||||
)}
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody displayRowCheckbox={false}>
|
<TableBody displayRowCheckbox={false}>
|
||||||
@@ -235,6 +232,20 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
|
|||||||
/>
|
/>
|
||||||
</TableRowColumn>
|
</TableRowColumn>
|
||||||
)}
|
)}
|
||||||
|
<TableRowColumn>
|
||||||
|
<SendButton
|
||||||
|
userAddress={this.props.userAddress}
|
||||||
|
networkId={this.props.networkId}
|
||||||
|
blockchain={this.props.blockchain}
|
||||||
|
dispatcher={this.props.dispatcher}
|
||||||
|
asset="ETH"
|
||||||
|
onError={this._onSendFailed.bind(this)}
|
||||||
|
lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch}
|
||||||
|
// This is not necessary for ETH.
|
||||||
|
// tslint:disable:jsx-no-lambda
|
||||||
|
refetchTokenStateAsync={() => undefined}
|
||||||
|
/>
|
||||||
|
</TableRowColumn>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
@@ -402,7 +413,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
|
|||||||
networkId={this.props.networkId}
|
networkId={this.props.networkId}
|
||||||
blockchain={this.props.blockchain}
|
blockchain={this.props.blockchain}
|
||||||
dispatcher={this.props.dispatcher}
|
dispatcher={this.props.dispatcher}
|
||||||
token={token}
|
asset={token}
|
||||||
onError={this._onSendFailed.bind(this)}
|
onError={this._onSendFailed.bind(this)}
|
||||||
lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch}
|
lastForceTokenStateRefetch={this.props.lastForceTokenStateRefetch}
|
||||||
refetchTokenStateAsync={this._refetchTokenStateAsync.bind(this, token.address)}
|
refetchTokenStateAsync={this._refetchTokenStateAsync.bind(this, token.address)}
|
||||||
|
@@ -6,9 +6,9 @@ import FlatButton from 'material-ui/FlatButton';
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { Blockchain } from 'ts/blockchain';
|
import { Blockchain } from 'ts/blockchain';
|
||||||
import { EthAmountInput } from 'ts/components/inputs/eth_amount_input';
|
|
||||||
import { TokenAmountInput } from 'ts/components/inputs/token_amount_input';
|
import { TokenAmountInput } from 'ts/components/inputs/token_amount_input';
|
||||||
import { Container } from 'ts/components/ui/container';
|
import { Container } from 'ts/components/ui/container';
|
||||||
|
import { EthAmountInput } from 'ts/containers/inputs/eth_amount_input';
|
||||||
import { Dispatcher } from 'ts/redux/dispatcher';
|
import { Dispatcher } from 'ts/redux/dispatcher';
|
||||||
import { colors } from 'ts/style/colors';
|
import { colors } from 'ts/style/colors';
|
||||||
import { BlockchainCallErrs, Side, Token } from 'ts/types';
|
import { BlockchainCallErrs, Side, Token } from 'ts/types';
|
||||||
@@ -87,13 +87,8 @@ export class WrapEtherItem extends React.Component<WrapEtherItemProps, WrapEther
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
const etherBalanceInEth = Web3Wrapper.toUnitAmount(
|
|
||||||
this.props.userEtherBalanceInWei,
|
|
||||||
constants.DECIMAL_PLACES_ETH,
|
|
||||||
);
|
|
||||||
const isWrappingEth = this.props.direction === Side.Deposit;
|
const isWrappingEth = this.props.direction === Side.Deposit;
|
||||||
const topLabelText = isWrappingEth ? 'Convert ETH into WETH 1:1' : 'Convert WETH into ETH 1:1';
|
const topLabelText = isWrappingEth ? 'Convert ETH into WETH 1:1' : 'Convert WETH into ETH 1:1';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container className="flex" backgroundColor={colors.walletFocusedItemBackground} paddingTop="25px">
|
<Container className="flex" backgroundColor={colors.walletFocusedItemBackground} paddingTop="25px">
|
||||||
<div>{this._renderIsEthConversionHappeningSpinner()} </div>
|
<div>{this._renderIsEthConversionHappeningSpinner()} </div>
|
||||||
@@ -103,7 +98,6 @@ export class WrapEtherItem extends React.Component<WrapEtherItemProps, WrapEther
|
|||||||
<div style={styles.inputContainer}>
|
<div style={styles.inputContainer}>
|
||||||
{isWrappingEth ? (
|
{isWrappingEth ? (
|
||||||
<EthAmountInput
|
<EthAmountInput
|
||||||
balance={etherBalanceInEth}
|
|
||||||
amount={this.state.currentInputAmount}
|
amount={this.state.currentInputAmount}
|
||||||
hintText="0.00"
|
hintText="0.00"
|
||||||
onChange={this._onValueChange.bind(this)}
|
onChange={this._onValueChange.bind(this)}
|
||||||
|
Reference in New Issue
Block a user