Daniel Ternyak b493a0c968 Offline Send (#276)
* offline-send mvp

* cleanup unneeded imports

* - create pollOfflineStatus action, action creator, interface

* expand UnlockHeader when collapse-button is clicked, instead of div

* kick-off pollOfflineStatus upon SendTransaction mount.

* Create sagas for polling offline status

* remove comment

* - create CONFIG_FORCE_OFFLINE action, action creator, interface

* Adjust OfflineToggle terms to "Force Online/Offline", and understand when forced offline and when really offline.

* - Assume offline in SendTransaction when either offline or forcedOffline

* - handle forceOffline action in reducer
- adjust state type / provide default state for forceOffline in config reducer

* adjust test to pass with different key name

* fix incorrect import

* - allow size to be specified in offline toggle

* - Decode and display nonce in confirmation modal

* - set default nonces when forced offline and have online connectivity based on transaction count
- pass nonce to generateCompleteTransaction
- refactor componentDidUpdate

* Allow optional nonce to be passed to generateCompleteTransaction

* - create stripHexPrefix function

* - cleanup sagas

* move getParam into helper util

* update address on component update

* - show spinner while transaction is being signed
- reset state when wallet instance changes (new wallet instantiated via UnlockHeader)

* center-align offline message

* Adjust force offline/online button text

* - validate nonces when offline
- only estimate gas when online
- don't show send tx button when offline

* - break generateCompleteTransactionFromRawTransaction into multiple functions.
- support offline generation in generateCompleteTransaction (and generateCompleteTransactionFromRawTransaction). Balance checking is now only done when not offline to support offline generation.

* Create Help component (to be used as a tooltip)

* Disable hardware wallets when offline.

* Hide Send Entire Balance when balance is falsy

* Show help icon in nonce field.

* - show helper instructions on how to broadcast when user is offline after generating a tx
- hardcoded gas limits when offline
- refactors

* create isPositiveInteger helper function

* fix nonce validation

* really fix nonce validation (specifically the input highlighting)

* remove stray // @flow's

* remove offline tab nav

* remove unused action arg

* address PR comments
2017-10-10 22:04:49 -07:00

119 lines
3.5 KiB
TypeScript

import { TFetchCCRates } from 'actions/rates';
import { Identicon } from 'components/ui';
import { NetworkConfig } from 'config/data';
import { Ether } from 'libs/units';
import { IWallet } from 'libs/wallet';
import React from 'react';
import translate from 'translations';
import { formatNumber } from 'utils/formatters';
import './AccountInfo.scss';
interface Props {
balance: Ether;
wallet: IWallet;
network: NetworkConfig;
fetchCCRates: TFetchCCRates;
}
interface State {
showLongBalance: boolean;
address: string;
}
export default class AccountInfo extends React.Component<Props, State> {
public state = {
showLongBalance: false,
address: ''
};
public async setAddressFromWallet() {
const address = await this.props.wallet.getAddress();
if (address !== this.state.address) {
this.setState({ address });
}
}
public componentDidMount() {
this.props.fetchCCRates();
this.setAddressFromWallet();
}
public componentDidUpdate() {
this.setAddressFromWallet();
}
// TODO: don't use any;
public toggleShowLongBalance = (e: any) => {
e.preventDefault();
this.setState(state => {
return {
showLongBalance: !state.showLongBalance
};
});
};
public render() {
const { network, balance } = this.props;
const { blockExplorer, tokenExplorer } = network;
const { address } = this.state;
return (
<div className="AccountInfo">
<div className="AccountInfo-section">
<h5 className="AccountInfo-section-header">
{translate('sidebar_AccountAddr')}
</h5>
<div className="AccountInfo-address">
<div className="AccountInfo-address-icon">
<Identicon address={address} size="100%" />
</div>
<div className="AccountInfo-address-addr">{address}</div>
</div>
</div>
<div className="AccountInfo-section">
<h5 className="AccountInfo-section-header">
{translate('sidebar_AccountBal')}
</h5>
<ul className="AccountInfo-list">
<li className="AccountInfo-list-item">
<span
className="AccountInfo-list-item-clickable mono wrap"
onClick={this.toggleShowLongBalance}
>
{this.state.showLongBalance
? balance ? balance.toString() : '???'
: balance ? formatNumber(balance.amount) : '???'}
</span>
{` ${network.name}`}
</li>
</ul>
</div>
{(!!blockExplorer || !!tokenExplorer) && (
<div className="AccountInfo-section">
<h5 className="AccountInfo-section-header">
{translate('sidebar_TransHistory')}
</h5>
<ul className="AccountInfo-list">
{!!blockExplorer && (
<li className="AccountInfo-list-item">
<a href={blockExplorer.address(address)} target="_blank">
{`${network.name} (${blockExplorer.name})`}
</a>
</li>
)}
{!!tokenExplorer && (
<li className="AccountInfo-list-item">
<a href={tokenExplorer.address(address)} target="_blank">
{`Tokens (${tokenExplorer.name})`}
</a>
</li>
)}
</ul>
</div>
)}
</div>
);
}
}