|
| 1 | +import { withClient } from 'metronome-wallet-ui-logic/src/hocs/clientContext' |
| 2 | +import * as selectors from 'metronome-wallet-ui-logic/src/selectors' |
| 3 | +import { connect } from 'react-redux' |
| 4 | +import PropTypes from 'prop-types' |
| 5 | +import styled from 'styled-components' |
| 6 | +import React from 'react' |
| 7 | + |
| 8 | +import { Flex, Sp } from '../common' |
| 9 | +import LastUpdated, { Label } from '../common/LastUpdated' |
| 10 | + |
| 11 | +const Text = styled.div` |
| 12 | + font-size: 1.3rem; |
| 13 | + margin: 0.8rem 0; |
| 14 | + display: flex; |
| 15 | + align-items: center; |
| 16 | +` |
| 17 | + |
| 18 | +const MinedAgo = styled(Label)` |
| 19 | + margin-left: 0.8rem; |
| 20 | +` |
| 21 | + |
| 22 | +const IndicatorLed = styled.div` |
| 23 | + width: 10px; |
| 24 | + height: 10px; |
| 25 | + background-color: ${({ isOnline, isConnected, theme }) => |
| 26 | + isOnline |
| 27 | + ? isConnected |
| 28 | + ? theme.colors.success |
| 29 | + : theme.colors.danger |
| 30 | + : 'rgba(119, 132, 125, 0.68)'}; |
| 31 | + border: 1px solid white; |
| 32 | + border-radius: 10px; |
| 33 | + margin: 5px 8px 2px 1px; |
| 34 | +` |
| 35 | + |
| 36 | +function WalletStatus(props) { |
| 37 | + return ( |
| 38 | + <div> |
| 39 | + <Text>Version {props.appVersion}</Text> |
| 40 | + <Flex.Row align="center"> |
| 41 | + <Text>Connected to {props.chainName} chain</Text> |
| 42 | + <Sp px={2} /> |
| 43 | + <LastUpdated |
| 44 | + timestamp={props.bestBlockTimestamp} |
| 45 | + render={({ timeAgo, diff }) => ( |
| 46 | + <Text> |
| 47 | + Best Block {props.height} |
| 48 | + <MinedAgo diff={diff} as="span"> |
| 49 | + mined {timeAgo} |
| 50 | + </MinedAgo> |
| 51 | + </Text> |
| 52 | + )} |
| 53 | + /> |
| 54 | + </Flex.Row> |
| 55 | + <Flex.Row align="center"> |
| 56 | + <Text> |
| 57 | + <IndicatorLed |
| 58 | + isConnected={props.isIndexerConnected} |
| 59 | + isOnline={props.isOnline} |
| 60 | + /> |
| 61 | + Indexer connection |
| 62 | + </Text> |
| 63 | + <Sp px={2} /> |
| 64 | + <Text> |
| 65 | + <IndicatorLed |
| 66 | + isConnected={props.isWeb3Connected} |
| 67 | + isOnline={props.isOnline} |
| 68 | + /> |
| 69 | + Web3 connection |
| 70 | + </Text> |
| 71 | + </Flex.Row> |
| 72 | + </div> |
| 73 | + ) |
| 74 | +} |
| 75 | + |
| 76 | +WalletStatus.propTypes = { |
| 77 | + bestBlockTimestamp: PropTypes.number, |
| 78 | + isIndexerConnected: PropTypes.bool, |
| 79 | + isWeb3Connected: PropTypes.bool, |
| 80 | + appVersion: PropTypes.string.isRequired, |
| 81 | + chainName: PropTypes.string.isRequired, |
| 82 | + isOnline: PropTypes.bool, |
| 83 | + height: PropTypes.number |
| 84 | +} |
| 85 | + |
| 86 | +const mapStateToProps = (state, props) => ({ |
| 87 | + isIndexerConnected: selectors.getIndexerConnectionStatus(state), |
| 88 | + isWeb3Connected: selectors.getChainConnectionStatus(state), |
| 89 | + appVersion: props.client.getAppVersion(), |
| 90 | + chainName: selectors.getActiveChainDisplayName(state), |
| 91 | + isOnline: selectors.getIsOnline(state), |
| 92 | + ...selectors.getChainMeta(state) |
| 93 | +}) |
| 94 | + |
| 95 | +export default withClient(connect(mapStateToProps)(WalletStatus)) |
0 commit comments