Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit e76401e

Browse files
committed
Merge branch 'timeago-display' into develop
2 parents 17f5c54 + eeaaacd commit e76401e

File tree

11 files changed

+166
-10
lines changed

11 files changed

+166
-10
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"lodash": "4.17.11",
4646
"metronome-contracts": "2.0.0",
4747
"metronome-wallet-core": "2.0.1",
48-
"metronome-wallet-ui-logic": "2.0.1",
48+
"metronome-wallet-ui-logic": "2.1.0",
4949
"nedb": "1.8.0",
5050
"p-timeout": "2.0.1",
5151
"qrcode.react": "0.7.2",

public/config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ module.exports = {
1919
requiredPasswordEntropy: parseInt(process.env.REQUIRED_PASSWORD_ENTROPY || 72, 10),
2020
scanTransactionTimeout: 240000,
2121
sentryDsn: process.env.SENTRY_DSN,
22-
statePersistanceDebounce: 15000,
22+
statePersistanceDebounce: 2000,
2323
trackingId: process.env.TRACKING_ID
2424
}

src/client/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ function createClient(createStore) {
1818
window.ipcRenderer.on('ui-ready', (ev, payload) => {
1919
const debounceTime = get(payload, 'data.config.statePersistanceDebounce', 0)
2020
store.subscribe(
21-
debounce(function() {
22-
utils.forwardToMainProcess('persist-state')(store.getState())
23-
}, debounceTime)
21+
debounce(
22+
function() {
23+
utils.forwardToMainProcess('persist-state')(store.getState())
24+
},
25+
debounceTime,
26+
{ maxWait: 2 * debounceTime }
27+
)
2428
)
2529
})
2630

@@ -112,6 +116,7 @@ function createClient(createStore) {
112116
getStringEntropy,
113117
copyToClipboard,
114118
onHelpLinkClick,
119+
getAppVersion: window.getAppVersion,
115120
onInit,
116121
store
117122
}

src/components/auction/Auction.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
import styled from 'styled-components'
44
import React from 'react'
55

6-
import { DarkLayout, LoadingBar, Text, Btn, Sp } from '../common'
6+
import { DarkLayout, LastUpdated, LoadingBar, Text, Btn, Sp } from '../common'
77
import BuyMETDrawer from './BuyMETDrawer'
88
import CountDown from './CountDown'
99
import Stats from './Stats'
@@ -54,6 +54,7 @@ class Auction extends React.Component {
5454
auctionPriceUSD: PropTypes.string.isRequired,
5555
auctionStatus: PropTypes.object,
5656
buyDisabled: PropTypes.bool.isRequired,
57+
lastUpdated: PropTypes.number,
5758
title: PropTypes.string
5859
}
5960

@@ -107,6 +108,9 @@ class Auction extends React.Component {
107108
</LoadingContainer>
108109
</Sp>
109110
)}
111+
<Sp px={6}>
112+
<LastUpdated timestamp={this.props.lastUpdated} />
113+
</Sp>
110114
</DarkLayout>
111115
)
112116
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import PropTypes from 'prop-types'
2+
import TimeAgo from 'metronome-wallet-ui-logic/src/components/TimeAgo'
3+
import styled from 'styled-components'
4+
import React from 'react'
5+
6+
export const Label = styled.div`
7+
transition: color 0.5s;
8+
font-size: 1.3rem;
9+
color: ${p =>
10+
p.diff > 60
11+
? p.theme.colors.danger
12+
: p.diff > 15
13+
? p.theme.colors.warning
14+
: p.theme.colors.weak};
15+
`
16+
17+
function defaultRender({ diff, timeAgo }) {
18+
return <Label diff={diff}>Last updated {timeAgo}</Label>
19+
}
20+
21+
defaultRender.propTypes = {
22+
timeAgo: PropTypes.string,
23+
diff: PropTypes.number
24+
}
25+
26+
export default function LastUpdated({ timestamp, render }) {
27+
return (
28+
<TimeAgo
29+
updateInterval={1000}
30+
timestamp={timestamp}
31+
render={typeof render === 'function' ? render : defaultRender}
32+
/>
33+
)
34+
}
35+
36+
LastUpdated.propTypes = {
37+
timestamp: PropTypes.number,
38+
render: PropTypes.func
39+
}

src/components/common/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import TextInput, { Label } from './TextInput'
33
import ConfirmationWizard from './ConfirmationWizard'
44
import DisplayValue from './DisplayValue'
55
import AmountFields from './AmountFields'
6+
import LastUpdated from './LastUpdated'
67
import ItemFilter from './ItemFilter'
78
import DarkLayout from './DarkLayout'
89
import LoadingBar from './LoadingBar'
@@ -21,6 +22,7 @@ export {
2122
ConfirmationWizard,
2223
DisplayValue,
2324
AmountFields,
25+
LastUpdated,
2426
ItemFilter,
2527
DarkLayout,
2628
LoadingBar,

src/components/converter/Converter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
import styled from 'styled-components'
44
import React from 'react'
55

6-
import { DarkLayout, LoadingBar, Text, Btn, Sp } from '../common'
6+
import { DarkLayout, LastUpdated, LoadingBar, Text, Btn, Sp } from '../common'
77
import ConvertDrawer from './ConvertDrawer'
88
import Stats from './Stats'
99

@@ -42,6 +42,7 @@ class Converter extends React.Component {
4242
converterPriceUSD: PropTypes.string.isRequired,
4343
convertDisabled: PropTypes.bool.isRequired,
4444
converterStatus: PropTypes.object,
45+
lastUpdated: PropTypes.number,
4546
coinSymbol: PropTypes.string.isRequired
4647
}
4748

@@ -94,6 +95,9 @@ class Converter extends React.Component {
9495
</LoadingContainer>
9596
</Sp>
9697
)}
98+
<Sp px={6}>
99+
<LastUpdated timestamp={this.props.lastUpdated} />
100+
</Sp>
97101
</DarkLayout>
98102
)
99103
}

src/components/tools/Tools.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styled from 'styled-components'
55
import React from 'react'
66

77
import ConfirmModal from './ConfirmModal'
8+
import WalletStatus from './WalletStatus'
89
import {
910
ConfirmationWizard,
1011
DarkLayout,
@@ -116,6 +117,11 @@ class Tools extends React.Component {
116117
isOpen={this.state.activeModal === 'confirm-rescan'}
117118
/>
118119
</Sp>
120+
<Sp mt={5}>
121+
<hr />
122+
<h4>Wallet Information</h4>
123+
<WalletStatus />
124+
</Sp>
119125
</Sp>
120126
)
121127
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
 (0)