diff --git a/src/views/Wallet/views/AccountSend/components/PendingTransactions.js b/src/views/Wallet/views/AccountSend/components/PendingTransactions.js deleted file mode 100644 index a8f8c17e..00000000 --- a/src/views/Wallet/views/AccountSend/components/PendingTransactions.js +++ /dev/null @@ -1,95 +0,0 @@ -/* @flow */ - - -import React from 'react'; -import ColorHash from 'color-hash'; -import { H2 } from 'components/Heading'; -import ScaleText from 'react-scale-text'; - -import { findAccountTokens } from 'reducers/TokensReducer'; - -import type { Coin } from 'reducers/LocalStorageReducer'; -import type { Token } from 'reducers/TokensReducer'; -import type { Props as BaseProps } from '../Container'; - -type Props = { - pending: $PropertyType<$ElementType, 'pending'>, - tokens: $PropertyType<$ElementType, 'tokens'>, - network: Coin -} - -type Style = { - +color: string, - +background: string, - +borderColor: string -} - -const PendingTransactions = (props: Props) => { - const pending = props.pending.filter(tx => !tx.rejected); - if (pending.length < 1) return null; - - const tokens: Array = props.tokens; - - const bgColorFactory = new ColorHash({ lightness: 0.7 }); - const textColorFactory = new ColorHash(); - - const pendingTxs: React$Element = pending.map((tx, i) => { - let iconColor: Style; - let symbol: string; - let name: string; - const isSmartContractTx: boolean = tx.currency !== props.network.symbol; - if (isSmartContractTx) { - const token: ?Token = tokens.find(t => t.symbol === tx.currency); - if (!token) { - iconColor = { - color: '#ffffff', - background: '#000000', - borderColor: '#000000', - }; - symbol = 'Unknown'; - name = 'Unknown'; - } else { - const bgColor: string = bgColorFactory.hex(token.name); - iconColor = { - color: textColorFactory.hex(token.name), - background: bgColor, - borderColor: bgColor, - }; - symbol = token.symbol.toUpperCase(); - name = token.name; - } - } else { - iconColor = { - color: textColorFactory.hex(tx.network), - background: bgColorFactory.hex(tx.network), - borderColor: bgColorFactory.hex(tx.network), - }; - symbol = props.network.symbol; - name = props.network.name; - } - - return ( -
-
-
-

{ symbol }

-
-
-
- { name } -
-
{ isSmartContractTx ? tx.amount : tx.total } { symbol }
-
- ); - }); - - - return ( -
-

Pending transactions

- { pendingTxs } -
- ); -}; - -export default PendingTransactions; \ No newline at end of file diff --git a/src/views/Wallet/views/AccountSend/components/PendingTransactions/index.js b/src/views/Wallet/views/AccountSend/components/PendingTransactions/index.js new file mode 100644 index 00000000..5399332e --- /dev/null +++ b/src/views/Wallet/views/AccountSend/components/PendingTransactions/index.js @@ -0,0 +1,165 @@ +/* @flow */ +import React, { Component } from 'react'; +import styled from 'styled-components'; +import colors from 'config/colors'; +import ColorHash from 'color-hash'; +import { H2 } from 'components/Heading'; +import Link from 'components/Link'; +import ScaleText from 'react-scale-text'; + +import type { Coin } from 'reducers/LocalStorageReducer'; +import type { Token } from 'reducers/TokensReducer'; +import type { Props as BaseProps } from '../Container'; + +type Props = { + pending: $PropertyType<$ElementType, 'pending'>, + tokens: $PropertyType<$ElementType, 'tokens'>, + network: Coin +} + +type Style = { + +color: string, + +background: string, + +borderColor: string +} + +const Wrapper = styled.div` + border-top: 1px solid ${colors.DIVIDER}; +`; + +const TransactionWrapper = styled.div` + border-bottom: 1px solid ${colors.DIVIDER}; + padding: 14px 48px; + display: flex; + flex-direction: row; + align-items: center; + + &:last-child { + border-bottom: 0px; + } +`; + +const TransactionIcon = styled.div` + padding: 6px; + margin-right: 10px; + width: 36px; + height: 36px; + border-radius: 50%; + line-height: 30px; + text-transform: uppercase; + user-select: none; + text-align: center; + color: ${props => props.color}; + background: ${props => props.background}; + border-color: ${props => props.borderColor}; +`; + +const P = styled.p``; + +const TransactionName = styled.div` + flex: 1; +`; + +const TransactionAmount = styled.div``; + +class PendingTransactions extends Component { + getPendingTransactions() { + return this.props.pending.filter(tx => !tx.rejected); + } + + getTransactionIconColors(tx: any) { + let iconColors = { }; + const bgColorFactory = new ColorHash({ lightness: 0.7 }); + const textColorFactory = new ColorHash(); + + const isSmartContractTx = tx.currency !== this.props.network.symbol; + + if (isSmartContractTx) { + const token: ?Token = this.findTransactionToken(tx.currency); + + if (!token) { + iconColors = { + color: '#ffffff', + background: '#000000', + borderColor: '#000000', + }; + } else { + const bgColor: string = bgColorFactory.hex(token.name); + iconColors = { + color: textColorFactory.hex(token.name), + background: bgColor, + borderColor: bgColor, + }; + } + } else { + iconColors = { + color: textColorFactory.hex(tx.network), + background: bgColorFactory.hex(tx.network), + borderColor: bgColorFactory.hex(tx.network), + }; + } + + return iconColors; + } + + getTransactionSymbol(tx: any) { + let { symbol } = this.props.network; + const isSmartContractTx = tx.currency !== this.props.network.symbol; + if (isSmartContractTx) { + const token: ?Token = this.findTransactionToken(tx.currency); + symbol = token ? token.symbol.toUpperCase() : 'Unknown'; + } + return symbol; + } + + getTransactionName(tx: any) { + let { name } = this.props.network; + const isSmartContractTx = tx.currency !== this.props.network.symbol; + if (isSmartContractTx) { + const token: ?Token = this.findTransactionToken(tx.currency); + name = token ? token.symbol.toUpperCase() : 'Unknown'; + } + return name; + } + + findTransactionToken(transactionCurrency: string) { + return this.props.tokens.find(t => t.symbol === transactionCurrency); + } + + render() { + return ( + +

Pending transactions

+ {this.getPendingTransactions().map(tx => ( + + this.getTransactionIconColors(tx).color} + background={() => this.getTransactionIconColors(tx).background} + borderColor={() => this.getTransactionIconColors(tx).borderColor} + > + +

{this.getTransactionSymbol(tx)}

+
+
+ + + + {this.getTransactionName(tx)} + + + + + {tx.currency !== this.props.network.symbol ? tx.amount : tx.total} {this.getTransactionSymbol(tx)} + +
+ ))} +
+ ); + } +} + +export default PendingTransactions;