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 #355 from shocknet/refinements8
Browse files Browse the repository at this point in the history
Socket fixes
  • Loading branch information
Daniel Lugo authored Nov 6, 2020
2 parents e16901f + c355467 commit 534eef2
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 314 deletions.
43 changes: 0 additions & 43 deletions app/screens/WalletOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ import { Schema } from 'shock-common'
// @ts-expect-error
import bech32 from 'bech32'

import SocketManager from '../../services/socket'
import * as Navigation from '../../services/navigation'
import Nav from '../../components/Nav'
import wavesBG from '../../assets/images/waves-bg.png'
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 * as Wallet from '../../services/wallet'
import { getUSDRate, getWalletBalance } from '../../store/actions/WalletActions'
import { fetchNodeInfo } from '../../store/actions/NodeActions'
import {
fetchRecentTransactions,
fetchRecentPayments,
fetchRecentInvoices,
loadNewInvoice,
loadNewTransaction,
} from '../../store/actions/HistoryActions'
import { subscribeOnChats } from '../../store/actions/ChatActions'
import {
Expand Down Expand Up @@ -72,8 +68,6 @@ import { Color } from 'shock-common/dist/constants'
* @prop {() => Promise<import('../../store/actions/NodeActions').GetInfo>} fetchNodeInfo
* @prop {() => Promise<Schema.Chat[]>} subscribeOnChats
* @prop {() => Promise<number>} getUSDRate
* @prop {(invoice: Wallet.Invoice) => void} loadNewInvoice
* @prop {(transaction: Wallet.Transaction) => void} loadNewTransaction
* @prop {{notifyDisconnect:boolean, notifyDisconnectAfterSeconds:number}} settings
* @prop {() => void} forceInvoicesRefresh
* @prop {boolean} isOnline
Expand Down Expand Up @@ -124,21 +118,12 @@ class WalletOverview extends React.PureComponent {

theme = 'dark'

/**
* @param {Schema.InvoiceWhenListed} invoice
*/
loadNewInvoice = invoice => {
// @ts-expect-error
this.props.loadNewInvoice(invoice)
}

componentDidMount = async () => {
const {
fetchNodeInfo,
subscribeOnChats,
fetchRecentTransactions,
fetchRecentInvoices,
loadNewTransaction,
navigation,
forceInvoicesRefresh,
forcePaymentsRefresh,
Expand Down Expand Up @@ -173,39 +158,13 @@ class WalletOverview extends React.PureComponent {

this.startNotificationService()

if (!SocketManager.socket?.connected) {
await SocketManager.connectSocket()
}

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

SocketManager.socket.on(
'invoice:new',
/**
* @param {Schema.InvoiceWhenListed} data
*/
data => {
Logger.log('[SOCKET] New Invoice!', data)
this.loadNewInvoice(data)
},
)

SocketManager.socket.on(
'transaction:new',
/**
* @param {Wallet.Transaction} data
*/
data => {
Logger.log('[SOCKET] New Transaction!', data)
loadNewTransaction(data)
},
)
}

fetchRecentPayments = () =>
Expand Down Expand Up @@ -471,8 +430,6 @@ const mapDispatchToProps = {
fetchRecentInvoices,
fetchRecentPayments,
subscribeOnChats,
loadNewInvoice,
loadNewTransaction,
forceInvoicesRefresh: invoicesRefreshForced,
forcePaymentsRefresh: paymentsRefreshForced,
getMoreFeed,
Expand Down
1 change: 0 additions & 1 deletion app/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './encryption'
export * from './errorReporter'
export * from './navigation'
export * from './seedServer'
export * from './socket'
export * from './utils'
export * from './validators'
export * from './http'
Expand Down
204 changes: 0 additions & 204 deletions app/services/socket.js

This file was deleted.

9 changes: 1 addition & 8 deletions app/store/actions/ConnectionActions/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ import Http from 'axios'
import { RSAKeychain } from 'react-native-rsa-native'
import Logger from 'react-native-file-log'

import {
KEYS_LOADED,
keysLoaded,
SOCKET_DID_CONNECT,
SOCKET_DID_DISCONNECT,
} from './v2'
import { KEYS_LOADED, keysLoaded } from './v2'

export const ACTIONS = {
LOAD_NEW_KEYS: KEYS_LOADED,
SOCKET_DID_CONNECT,
SOCKET_DID_DISCONNECT,
}

/** @type {Promise<ExchangedKeyPair>?} */
Expand Down
16 changes: 0 additions & 16 deletions app/store/actions/ConnectionActions/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ export const keysLoaded = (keys: LoadedKeys) =>
data: keys,
} as const)

export const SOCKET_DID_CONNECT = 'socket/socketDidConnect'

export const socketDidConnect = () =>
({
type: SOCKET_DID_CONNECT,
} as const)

export const SOCKET_DID_DISCONNECT = 'socket/socketDidDisconnect'

export const socketDidDisconnect = () =>
({
type: SOCKET_DID_DISCONNECT,
} as const)

export type ConnectionAction =
| ReturnType<typeof ping>
| ReturnType<typeof keysLoaded>
| ReturnType<typeof socketDidConnect>
| ReturnType<typeof socketDidDisconnect>
Loading

0 comments on commit 534eef2

Please sign in to comment.