From dead04dce8b26a09cb0b451711517bcb4dea182c Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 19 Jul 2018 04:11:44 -0700 Subject: WIP for sending ether from portal (works) --- packages/website/ts/blockchain.ts | 26 ++++++++++++++ .../dialogs/eth_weth_conversion_dialog.tsx | 6 +--- .../website/ts/components/dialogs/send_dialog.tsx | 40 +++++++++++++++------- .../ts/components/inputs/eth_amount_input.tsx | 3 +- packages/website/ts/components/send_button.tsx | 14 +++++--- packages/website/ts/components/token_balances.tsx | 23 +++++++++---- .../ts/components/wallet/wrap_ether_item.tsx | 8 +---- 7 files changed, 82 insertions(+), 38 deletions(-) (limited to 'packages/website/ts') diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 88461f8a9..5d497dfb1 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -276,6 +276,32 @@ export class Blockchain { ); await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); } + public async sendAsync(toAddress: string, amountInBaseUnits: BigNumber): Promise { + 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 { utils.assert(!_.isUndefined(this._contractWrappers), 'ContractWrappers must be instantiated.'); utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); diff --git a/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx b/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx index 7b09cc92c..5f4bf8519 100644 --- a/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx +++ b/packages/website/ts/components/dialogs/eth_weth_conversion_dialog.tsx @@ -1,15 +1,13 @@ import { colors } from '@0xproject/react-shared'; import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; import Dialog from 'material-ui/Dialog'; import FlatButton from 'material-ui/FlatButton'; import * as React from 'react'; import { Blockchain } from 'ts/blockchain'; -import { EthAmountInput } from 'ts/components/inputs/eth_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 { constants } from 'ts/utils/constants'; interface EthWethConversionDialogProps { blockchain: Blockchain; @@ -78,7 +76,6 @@ export class EthWethConversionDialog extends React.Component< ? 'Convert your Ether into a tokenized, tradable form.' : "Convert your Wrapped Ether back into it's native form."; const isWrappedVersion = this.props.direction === Side.Receive; - const etherBalanceInEth = Web3Wrapper.toUnitAmount(this.props.etherBalanceInWei, constants.DECIMAL_PLACES_ETH); return (
{explanation}
@@ -106,7 +103,6 @@ export class EthWethConversionDialog extends React.Component< /> ) : ( void; onCancelled: () => void; isOpen: boolean; - token: Token; + asset: Token | 'ETH'; lastForceTokenStateRefetch: number; } @@ -58,23 +59,23 @@ export class SendDialog extends React.Component -
- -
+ const input = + this.props.asset === 'ETH' ? ( + + ) : ( + ); + return ( +
+
+ +
+ {input}
); } diff --git a/packages/website/ts/components/inputs/eth_amount_input.tsx b/packages/website/ts/components/inputs/eth_amount_input.tsx index 552d4277a..3a7905442 100644 --- a/packages/website/ts/components/inputs/eth_amount_input.tsx +++ b/packages/website/ts/components/inputs/eth_amount_input.tsx @@ -28,14 +28,13 @@ export class EthAmountInput extends React.Component = { shouldShowErrs: true, shouldShowUnderline: true, - style: { height: 63 }, }; public render(): React.ReactNode { const amount = this.props.amount ? Web3Wrapper.toUnitAmount(this.props.amount, constants.DECIMAL_PLACES_ETH) : undefined; return ( -
+
void; @@ -51,7 +51,7 @@ export class SendButton extends React.Component
@@ -67,10 +67,14 @@ export class SendButton extends React.ComponentCurrency Balance - {isTestNetwork && ( - - {isSmallScreen ? 'Faucet' : 'Request from faucet'} - - )} + {isTestNetwork && Action} + Send @@ -235,6 +232,20 @@ export class TokenBalances extends React.Component )} + + undefined} + /> + @@ -402,7 +413,7 @@ export class TokenBalances extends React.Component
{this._renderIsEthConversionHappeningSpinner()}
@@ -103,7 +98,6 @@ export class WrapEtherItem extends React.Component {isWrappingEth ? (