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

Commit

Permalink
Merge pull request #373 from shocknet/remove-lnd-polls
Browse files Browse the repository at this point in the history
Remove lnd polls
  • Loading branch information
shocknet-justin authored Nov 11, 2020
2 parents 98c92c5 + 48c8525 commit cb9a7d0
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 763 deletions.
19 changes: 8 additions & 11 deletions app/components/ShockAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ interface OwnProps {

interface StateProps {
image: string | null
lastSeenApp: number | null
isOwn: boolean
displayName: string | null
showGreenRing: boolean
}

interface DispatchProps {}
Expand Down Expand Up @@ -74,10 +74,9 @@ class ShockAvatar extends React.PureComponent<Props> {
const {
height,
image,
lastSeenApp,
disableOnlineRing,
nameAtBottom,
displayName,
showGreenRing,
} = this.props

return (
Expand All @@ -95,11 +94,7 @@ class ShockAvatar extends React.PureComponent<Props> {
}
}
onPress={this.onPress}
avatarStyle={
lastSeenApp && isOnline(lastSeenApp) && !disableOnlineRing
? styles.onlineRing
: undefined
}
avatarStyle={showGreenRing ? styles.onlineRing : undefined}
/>
{nameAtBottom ? (
<>
Expand Down Expand Up @@ -135,15 +130,17 @@ const makeMapStateToProps = () => {
const getUser = Store.makeGetUser()

const f = (state: Reducers.State, ownProps: OwnProps): StateProps => {
const { publicKey } = ownProps
const { publicKey, disableOnlineRing } = ownProps
const user = getUser(state, publicKey)
const myPublicKey = Store.getMyPublicKey(state)
const isOwn = user.publicKey === myPublicKey
const appOnline = isOwn ? Store.isOnline(state) : isOnline(user.lastSeenApp)

return {
image: user.avatar,
lastSeenApp: user.lastSeenApp,
isOwn: user.publicKey === myPublicKey,
isOwn,
displayName: user.displayName,
showGreenRing: appOnline && !disableOnlineRing,
}
}

Expand Down
8 changes: 3 additions & 5 deletions app/screens/Advanced/Accordion/Transaction.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import React from 'react'
import { View, Text, StyleSheet, Clipboard, ToastAndroid } from 'react-native'
import EntypoIcons from 'react-native-vector-icons/Entypo'
import * as Common from 'shock-common'

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

/**
* @typedef {object} Props
* @prop {ITransaction} data
* @prop {Common.Schema.ChainTransaction} data
*/

/**
Expand Down Expand Up @@ -55,7 +53,7 @@ const _Transaction = ({ data }) => ((
</Text>
<Text style={styles.textWhite}>
Payment{' '}
{parseInt(data.num_confirmations, 10) === 0 ? (
{data.num_confirmations === 0 ? (
<EntypoIcons name="clock" color="red" size={10} />
) : null}
</Text>
Expand Down
10 changes: 1 addition & 9 deletions app/screens/Advanced/Accordion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,7 @@ const styles = StyleSheet.create({
color: CSS.Colors.BLUE_DARK,
fontWeight: 'bold',
},
// accordionMenuBtn: {
// width: 45,
// height: 45,
// borderRadius: 100,
// backgroundColor: CSS.Colors.ORANGE,
// alignItems: 'center',
// justifyContent: 'center',
// elevation: 3,
// },

accordionMenuBtnDark: {
width: 45,
height: 45,
Expand Down
36 changes: 16 additions & 20 deletions app/screens/Advanced/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Big from 'big.js'
import { connect } from 'react-redux'
import Logger from 'react-native-file-log'
import Modal from 'react-native-modalbox'
import * as Common from 'shock-common'

import wavesBGDark from '../../assets/images/waves-bg-dark.png'
import * as CSS from '../../res/css'
Expand All @@ -27,11 +28,7 @@ import Nav from '../../components/Nav'
import {
fetchChannels,
fetchPendingChannels,
fetchInvoices,
fetchPayments,
fetchPeers,
fetchTransactions,
fetchRecentTransactions,
fetchHistory,
} from '../../store/actions/HistoryActions'
import { fetchNodeInfo } from '../../store/actions/NodeActions'
Expand Down Expand Up @@ -231,7 +228,6 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
if (USDRate !== null) {
const parsedConfirmedBalance = new Big(confirmedBalance)
const parsedChannelBalance = new Big(channelBalance)
//@ts-expect-error
const parsedUSDRate = new Big(USDRate)
const satoshiUnit = new Big(0.00000001)
const confirmedBalanceUSD = parsedConfirmedBalance
Expand Down Expand Up @@ -701,12 +697,11 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
this.setState({ modalLoading: false })
}

transactionKeyExtractor = (
transaction: import('../../services/wallet').Transaction,
) => transaction.tx_hash
transactionKeyExtractor = (transaction: Common.Schema.ChainTransaction) =>
transaction.tx_hash

render() {
const { node, wallet, history } = this.props
const { node, wallet, history, chainTXs } = this.props
const {
accordions,
peerURI,
Expand Down Expand Up @@ -887,7 +882,7 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
/>
<AccordionItem
fetchNextPage={this.fetchNextPage('transactions')}
data={history.recentTransactions}
data={chainTXs}
Item={Transaction}
title="Transactions"
open={accordions.transactions}
Expand Down Expand Up @@ -1000,21 +995,22 @@ class AdvancedScreen extends React.PureComponent<Props, State> {
}
}

const mapStateToProps = ({ history, node, wallet, fees }: Store.State) => ({
history,
node,
wallet,
fees,
})
const mapStateToProps = (state: Store.State) => {
const { history, node, wallet, fees } = state

return {
history,
node,
wallet,
fees,
chainTXs: Store.getLatestChainTransactions(state),
}
}

const mapDispatchToProps = {
fetchChannels,
fetchPendingChannels,
fetchInvoices,
fetchPayments,
fetchPeers,
fetchTransactions,
fetchRecentTransactions,
fetchHistory,
fetchNodeInfo,
}
Expand Down
110 changes: 1 addition & 109 deletions app/screens/WalletOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
TouchableHighlight,
View,
ImageBackground,
InteractionManager,
StatusBar,
} from 'react-native'
import Logger from 'react-native-file-log'
Expand All @@ -25,13 +24,7 @@ import wavesBGDark from '../../assets/images/waves-bg-dark.png'
import ShockIcon from '../../res/icons'
import btcConvert from '../../services/convertBitcoin'
import * as CSS from '../../res/css'
import { getUSDRate, getWalletBalance } from '../../store/actions/WalletActions'
import { fetchNodeInfo } from '../../store/actions/NodeActions'
import {
fetchRecentTransactions,
fetchRecentPayments,
fetchRecentInvoices,
} from '../../store/actions/HistoryActions'
import { subscribeOnChats } from '../../store/actions/ChatActions'
import {
invoicesRefreshForced,
Expand Down Expand Up @@ -61,13 +54,8 @@ import { Color } from 'shock-common/dist/constants'
* @prop {string|null} totalBalance
* @prop {number} USDRate
* @prop {boolean} testnet
* @prop {() => Promise<void>} fetchRecentTransactions
* @prop {() => Promise<void>} fetchRecentPayments
* @prop {() => Promise<void>} fetchRecentInvoices
* @prop {() => Promise<import('../../store/actions/WalletActions').WalletBalance>} getWalletBalance
* @prop {() => Promise<import('../../store/actions/NodeActions').GetInfo>} fetchNodeInfo
* @prop {() => Promise<Schema.Chat[]>} subscribeOnChats
* @prop {() => Promise<number>} getUSDRate
* @prop {{notifyDisconnect:boolean, notifyDisconnectAfterSeconds:number}} settings
* @prop {() => void} forceInvoicesRefresh
* @prop {boolean} isOnline
Expand Down Expand Up @@ -106,12 +94,6 @@ class WalletOverview extends React.PureComponent {
)),
}

/** @type {null|ReturnType<typeof setInterval>} */
balanceIntervalID = null

/** @type {null|ReturnType<typeof setInterval>} */
exchangeRateIntervalID = null

didFocus = { remove() {} }

subs = [() => {}]
Expand All @@ -122,104 +104,19 @@ class WalletOverview extends React.PureComponent {
const {
fetchNodeInfo,
subscribeOnChats,
fetchRecentTransactions,
fetchRecentInvoices,
navigation,
forceInvoicesRefresh,
forcePaymentsRefresh,
getMoreFeed,
forceChainTXsRefresh,
} = this.props

forcePaymentsRefresh()
forceInvoicesRefresh()
getMoreFeed()
forceChainTXsRefresh()

this.didFocus = navigation.addListener('didFocus', () => {
this.balanceIntervalID = setTimeout(this.getWalletBalance, 4000)
this.exchangeRateIntervalID = setTimeout(this.getUSDRate, 4000)
this.recentPaymentsIntervalID = setTimeout(this.fetchRecentPayments, 4000)
})

navigation.addListener('didBlur', () => {
if (this.balanceIntervalID) {
clearTimeout(this.balanceIntervalID)
}

if (this.exchangeRateIntervalID) {
clearTimeout(this.exchangeRateIntervalID)
}

if (this.recentPaymentsIntervalID) {
clearTimeout(this.recentPaymentsIntervalID)
}
})

this.startNotificationService()

subscribeOnChats()
await Promise.all([
fetchRecentInvoices(),
fetchRecentTransactions(),
fetchRecentPayments(),
fetchNodeInfo(),
])
}

fetchRecentPayments = () =>
InteractionManager.runAfterInteractions(() => {
const { fetchRecentPayments } = this.props
try {
fetchRecentPayments()
this.recentPaymentsIntervalID = setTimeout(
this.fetchRecentPayments,
4000,
)
return
} catch (err) {
this.recentPaymentsIntervalID = setTimeout(
this.fetchRecentPayments,
4000,
)
}
})

getUSDRate = () =>
InteractionManager.runAfterInteractions(() => {
const { getUSDRate } = this.props
try {
getUSDRate()
this.exchangeRateIntervalID = setTimeout(this.getUSDRate, 4000)
return
} catch (err) {
this.exchangeRateIntervalID = setTimeout(this.getUSDRate, 4000)
}
})

getWalletBalance = () =>
InteractionManager.runAfterInteractions(() => {
const { getWalletBalance } = this.props
try {
getWalletBalance()
this.balanceIntervalID = setTimeout(this.getWalletBalance, 4000)
return
} catch (err) {
this.balanceIntervalID = setTimeout(this.getWalletBalance, 4000)
}
})

componentWillUnmount() {
if (this.balanceIntervalID) {
clearInterval(this.balanceIntervalID)
}

if (this.exchangeRateIntervalID) {
clearInterval(this.exchangeRateIntervalID)
}
//if (!SocketManager.socket?.connected) {
// SocketManager.socket.disconnect()
//}
await fetchNodeInfo()
}

onPressRequest = () => {
Expand Down Expand Up @@ -438,12 +335,7 @@ const mapStateToProps = state => {
}

const mapDispatchToProps = {
getUSDRate,
getWalletBalance,
fetchRecentTransactions,
fetchNodeInfo,
fetchRecentInvoices,
fetchRecentPayments,
subscribeOnChats,
forceInvoicesRefresh: invoicesRefreshForced,
forcePaymentsRefresh: paymentsRefreshForced,
Expand Down
Loading

0 comments on commit cb9a7d0

Please sign in to comment.