Skip to content
This repository was archived by the owner on Apr 2, 2021. It is now read-only.

Commit cb9a7d0

Browse files
Merge pull request #373 from shocknet/remove-lnd-polls
Remove lnd polls
2 parents 98c92c5 + 48c8525 commit cb9a7d0

15 files changed

Lines changed: 227 additions & 763 deletions

File tree

app/components/ShockAvatar.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ interface OwnProps {
2727

2828
interface StateProps {
2929
image: string | null
30-
lastSeenApp: number | null
3130
isOwn: boolean
3231
displayName: string | null
32+
showGreenRing: boolean
3333
}
3434

3535
interface DispatchProps {}
@@ -74,10 +74,9 @@ class ShockAvatar extends React.PureComponent<Props> {
7474
const {
7575
height,
7676
image,
77-
lastSeenApp,
78-
disableOnlineRing,
7977
nameAtBottom,
8078
displayName,
79+
showGreenRing,
8180
} = this.props
8281

8382
return (
@@ -95,11 +94,7 @@ class ShockAvatar extends React.PureComponent<Props> {
9594
}
9695
}
9796
onPress={this.onPress}
98-
avatarStyle={
99-
lastSeenApp && isOnline(lastSeenApp) && !disableOnlineRing
100-
? styles.onlineRing
101-
: undefined
102-
}
97+
avatarStyle={showGreenRing ? styles.onlineRing : undefined}
10398
/>
10499
{nameAtBottom ? (
105100
<>
@@ -135,15 +130,17 @@ const makeMapStateToProps = () => {
135130
const getUser = Store.makeGetUser()
136131

137132
const f = (state: Reducers.State, ownProps: OwnProps): StateProps => {
138-
const { publicKey } = ownProps
133+
const { publicKey, disableOnlineRing } = ownProps
139134
const user = getUser(state, publicKey)
140135
const myPublicKey = Store.getMyPublicKey(state)
136+
const isOwn = user.publicKey === myPublicKey
137+
const appOnline = isOwn ? Store.isOnline(state) : isOnline(user.lastSeenApp)
141138

142139
return {
143140
image: user.avatar,
144-
lastSeenApp: user.lastSeenApp,
145-
isOwn: user.publicKey === myPublicKey,
141+
isOwn,
146142
displayName: user.displayName,
143+
showGreenRing: appOnline && !disableOnlineRing,
147144
}
148145
}
149146

app/screens/Advanced/Accordion/Transaction.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import React from 'react'
22
import { View, Text, StyleSheet, Clipboard, ToastAndroid } from 'react-native'
33
import EntypoIcons from 'react-native-vector-icons/Entypo'
4+
import * as Common from 'shock-common'
45

56
import * as CSS from '../../../res/css'
67
import TimeText from '../../../components/time-text'
7-
/**
8-
* @typedef {import('../../../services/wallet').Transaction} ITransaction
9-
*/
108

119
/**
1210
* @typedef {object} Props
13-
* @prop {ITransaction} data
11+
* @prop {Common.Schema.ChainTransaction} data
1412
*/
1513

1614
/**
@@ -55,7 +53,7 @@ const _Transaction = ({ data }) => ((
5553
</Text>
5654
<Text style={styles.textWhite}>
5755
Payment{' '}
58-
{parseInt(data.num_confirmations, 10) === 0 ? (
56+
{data.num_confirmations === 0 ? (
5957
<EntypoIcons name="clock" color="red" size={10} />
6058
) : null}
6159
</Text>

app/screens/Advanced/Accordion/index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,7 @@ const styles = StyleSheet.create({
315315
color: CSS.Colors.BLUE_DARK,
316316
fontWeight: 'bold',
317317
},
318-
// accordionMenuBtn: {
319-
// width: 45,
320-
// height: 45,
321-
// borderRadius: 100,
322-
// backgroundColor: CSS.Colors.ORANGE,
323-
// alignItems: 'center',
324-
// justifyContent: 'center',
325-
// elevation: 3,
326-
// },
318+
327319
accordionMenuBtnDark: {
328320
width: 45,
329321
height: 45,

app/screens/Advanced/index.tsx

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Big from 'big.js'
1919
import { connect } from 'react-redux'
2020
import Logger from 'react-native-file-log'
2121
import Modal from 'react-native-modalbox'
22+
import * as Common from 'shock-common'
2223

2324
import wavesBGDark from '../../assets/images/waves-bg-dark.png'
2425
import * as CSS from '../../res/css'
@@ -27,11 +28,7 @@ import Nav from '../../components/Nav'
2728
import {
2829
fetchChannels,
2930
fetchPendingChannels,
30-
fetchInvoices,
31-
fetchPayments,
3231
fetchPeers,
33-
fetchTransactions,
34-
fetchRecentTransactions,
3532
fetchHistory,
3633
} from '../../store/actions/HistoryActions'
3734
import { fetchNodeInfo } from '../../store/actions/NodeActions'
@@ -231,7 +228,6 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
231228
if (USDRate !== null) {
232229
const parsedConfirmedBalance = new Big(confirmedBalance)
233230
const parsedChannelBalance = new Big(channelBalance)
234-
//@ts-expect-error
235231
const parsedUSDRate = new Big(USDRate)
236232
const satoshiUnit = new Big(0.00000001)
237233
const confirmedBalanceUSD = parsedConfirmedBalance
@@ -701,12 +697,11 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
701697
this.setState({ modalLoading: false })
702698
}
703699

704-
transactionKeyExtractor = (
705-
transaction: import('../../services/wallet').Transaction,
706-
) => transaction.tx_hash
700+
transactionKeyExtractor = (transaction: Common.Schema.ChainTransaction) =>
701+
transaction.tx_hash
707702

708703
render() {
709-
const { node, wallet, history } = this.props
704+
const { node, wallet, history, chainTXs } = this.props
710705
const {
711706
accordions,
712707
peerURI,
@@ -887,7 +882,7 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
887882
/>
888883
<AccordionItem
889884
fetchNextPage={this.fetchNextPage('transactions')}
890-
data={history.recentTransactions}
885+
data={chainTXs}
891886
Item={Transaction}
892887
title="Transactions"
893888
open={accordions.transactions}
@@ -1000,21 +995,22 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
1000995
}
1001996
}
1002997

1003-
const mapStateToProps = ({ history, node, wallet, fees }: Store.State) => ({
1004-
history,
1005-
node,
1006-
wallet,
1007-
fees,
1008-
})
998+
const mapStateToProps = (state: Store.State) => {
999+
const { history, node, wallet, fees } = state
1000+
1001+
return {
1002+
history,
1003+
node,
1004+
wallet,
1005+
fees,
1006+
chainTXs: Store.getLatestChainTransactions(state),
1007+
}
1008+
}
10091009

10101010
const mapDispatchToProps = {
10111011
fetchChannels,
10121012
fetchPendingChannels,
1013-
fetchInvoices,
1014-
fetchPayments,
10151013
fetchPeers,
1016-
fetchTransactions,
1017-
fetchRecentTransactions,
10181014
fetchHistory,
10191015
fetchNodeInfo,
10201016
}

app/screens/WalletOverview/index.js

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
TouchableHighlight,
99
View,
1010
ImageBackground,
11-
InteractionManager,
1211
StatusBar,
1312
} from 'react-native'
1413
import Logger from 'react-native-file-log'
@@ -25,13 +24,7 @@ import wavesBGDark from '../../assets/images/waves-bg-dark.png'
2524
import ShockIcon from '../../res/icons'
2625
import btcConvert from '../../services/convertBitcoin'
2726
import * as CSS from '../../res/css'
28-
import { getUSDRate, getWalletBalance } from '../../store/actions/WalletActions'
2927
import { fetchNodeInfo } from '../../store/actions/NodeActions'
30-
import {
31-
fetchRecentTransactions,
32-
fetchRecentPayments,
33-
fetchRecentInvoices,
34-
} from '../../store/actions/HistoryActions'
3528
import { subscribeOnChats } from '../../store/actions/ChatActions'
3629
import {
3730
invoicesRefreshForced,
@@ -61,13 +54,8 @@ import { Color } from 'shock-common/dist/constants'
6154
* @prop {string|null} totalBalance
6255
* @prop {number} USDRate
6356
* @prop {boolean} testnet
64-
* @prop {() => Promise<void>} fetchRecentTransactions
65-
* @prop {() => Promise<void>} fetchRecentPayments
66-
* @prop {() => Promise<void>} fetchRecentInvoices
67-
* @prop {() => Promise<import('../../store/actions/WalletActions').WalletBalance>} getWalletBalance
6857
* @prop {() => Promise<import('../../store/actions/NodeActions').GetInfo>} fetchNodeInfo
6958
* @prop {() => Promise<Schema.Chat[]>} subscribeOnChats
70-
* @prop {() => Promise<number>} getUSDRate
7159
* @prop {{notifyDisconnect:boolean, notifyDisconnectAfterSeconds:number}} settings
7260
* @prop {() => void} forceInvoicesRefresh
7361
* @prop {boolean} isOnline
@@ -106,12 +94,6 @@ class WalletOverview extends React.PureComponent {
10694
)),
10795
}
10896

109-
/** @type {null|ReturnType<typeof setInterval>} */
110-
balanceIntervalID = null
111-
112-
/** @type {null|ReturnType<typeof setInterval>} */
113-
exchangeRateIntervalID = null
114-
11597
didFocus = { remove() {} }
11698

11799
subs = [() => {}]
@@ -122,104 +104,19 @@ class WalletOverview extends React.PureComponent {
122104
const {
123105
fetchNodeInfo,
124106
subscribeOnChats,
125-
fetchRecentTransactions,
126-
fetchRecentInvoices,
127-
navigation,
128107
forceInvoicesRefresh,
129108
forcePaymentsRefresh,
130-
getMoreFeed,
131109
forceChainTXsRefresh,
132110
} = this.props
133111

134112
forcePaymentsRefresh()
135113
forceInvoicesRefresh()
136-
getMoreFeed()
137114
forceChainTXsRefresh()
138115

139-
this.didFocus = navigation.addListener('didFocus', () => {
140-
this.balanceIntervalID = setTimeout(this.getWalletBalance, 4000)
141-
this.exchangeRateIntervalID = setTimeout(this.getUSDRate, 4000)
142-
this.recentPaymentsIntervalID = setTimeout(this.fetchRecentPayments, 4000)
143-
})
144-
145-
navigation.addListener('didBlur', () => {
146-
if (this.balanceIntervalID) {
147-
clearTimeout(this.balanceIntervalID)
148-
}
149-
150-
if (this.exchangeRateIntervalID) {
151-
clearTimeout(this.exchangeRateIntervalID)
152-
}
153-
154-
if (this.recentPaymentsIntervalID) {
155-
clearTimeout(this.recentPaymentsIntervalID)
156-
}
157-
})
158-
159116
this.startNotificationService()
160117

161118
subscribeOnChats()
162-
await Promise.all([
163-
fetchRecentInvoices(),
164-
fetchRecentTransactions(),
165-
fetchRecentPayments(),
166-
fetchNodeInfo(),
167-
])
168-
}
169-
170-
fetchRecentPayments = () =>
171-
InteractionManager.runAfterInteractions(() => {
172-
const { fetchRecentPayments } = this.props
173-
try {
174-
fetchRecentPayments()
175-
this.recentPaymentsIntervalID = setTimeout(
176-
this.fetchRecentPayments,
177-
4000,
178-
)
179-
return
180-
} catch (err) {
181-
this.recentPaymentsIntervalID = setTimeout(
182-
this.fetchRecentPayments,
183-
4000,
184-
)
185-
}
186-
})
187-
188-
getUSDRate = () =>
189-
InteractionManager.runAfterInteractions(() => {
190-
const { getUSDRate } = this.props
191-
try {
192-
getUSDRate()
193-
this.exchangeRateIntervalID = setTimeout(this.getUSDRate, 4000)
194-
return
195-
} catch (err) {
196-
this.exchangeRateIntervalID = setTimeout(this.getUSDRate, 4000)
197-
}
198-
})
199-
200-
getWalletBalance = () =>
201-
InteractionManager.runAfterInteractions(() => {
202-
const { getWalletBalance } = this.props
203-
try {
204-
getWalletBalance()
205-
this.balanceIntervalID = setTimeout(this.getWalletBalance, 4000)
206-
return
207-
} catch (err) {
208-
this.balanceIntervalID = setTimeout(this.getWalletBalance, 4000)
209-
}
210-
})
211-
212-
componentWillUnmount() {
213-
if (this.balanceIntervalID) {
214-
clearInterval(this.balanceIntervalID)
215-
}
216-
217-
if (this.exchangeRateIntervalID) {
218-
clearInterval(this.exchangeRateIntervalID)
219-
}
220-
//if (!SocketManager.socket?.connected) {
221-
// SocketManager.socket.disconnect()
222-
//}
119+
await fetchNodeInfo()
223120
}
224121

225122
onPressRequest = () => {
@@ -438,12 +335,7 @@ const mapStateToProps = state => {
438335
}
439336

440337
const mapDispatchToProps = {
441-
getUSDRate,
442-
getWalletBalance,
443-
fetchRecentTransactions,
444338
fetchNodeInfo,
445-
fetchRecentInvoices,
446-
fetchRecentPayments,
447339
subscribeOnChats,
448340
forceInvoicesRefresh: invoicesRefreshForced,
449341
forcePaymentsRefresh: paymentsRefreshForced,

0 commit comments

Comments
 (0)