Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 6fe00ff

Browse files
authored
fixes bug where app crashes on cafe deregister (#1289)
1 parent 9acf3e2 commit 6fe00ff

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

App/Containers/Cafe.tsx

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Dispatch } from 'redux'
1212
import { connect } from 'react-redux'
1313
import { NavigationScreenProps } from 'react-navigation'
1414
import { Cafe as CafeModel, CafeSessionData } from '../features/cafes/models'
15-
import Textile from '@textile/react-native-sdk'
15+
import Textile, { ICafe } from '@textile/react-native-sdk'
1616
import moment from 'moment'
1717

1818
import { RootState, RootAction } from '../Redux/Types'
@@ -94,8 +94,8 @@ const Error: TextStyle = {
9494
}
9595

9696
interface StateProps {
97-
cafe: CafeModel
98-
session: CafeSessionData
97+
cafe?: CafeModel
98+
session?: CafeSessionData
9999
}
100100

101101
interface DispatchProps {
@@ -128,14 +128,29 @@ class Cafe extends Component<Props> {
128128
render() {
129129
// Hardcoded placeholder for services UI
130130
const services = ['Backup', 'Inboxing']
131-
const { cafe, exp } = this.props.session.session
132-
const { peer, url } = cafe
133-
const date = Textile.util.timestampToDate(exp)
134-
const expirationDate = moment(date).format('MMMM Do YYYY [at] h:mm a')
135-
const refreshButtonDisabled = this.props.session.processing
136-
const cafeProcessing =
137-
this.props.cafe && this.props.cafe.state === 'deregistering'
138-
const deregisterButtonDisabled = !this.props.cafe.error && cafeProcessing
131+
let cafe: ICafe
132+
// const exp = this.props.session && this.props.session.session.exp
133+
134+
let expirationDate = ''
135+
let peer = ''
136+
let url = ''
137+
let refreshButtonDisabled = true
138+
let deregisterButtonDisabled = true
139+
if (this.props.session) {
140+
const { exp } = this.props.session.session
141+
const date = Textile.util.timestampToDate(exp)
142+
expirationDate = moment(date).format('MMMM Do YYYY [at] h:mm a')
143+
refreshButtonDisabled = this.props.session.processing
144+
cafe = this.props.session.session.cafe
145+
peer = cafe.peer
146+
url = cafe.url
147+
}
148+
if (this.props.cafe) {
149+
const cafeProcessing =
150+
this.props.cafe && this.props.cafe.state === 'deregistering'
151+
deregisterButtonDisabled = !this.props.cafe.error && cafeProcessing
152+
}
153+
139154
return (
140155
<SafeAreaView style={Container}>
141156
<Text style={URL}>{url}</Text>
@@ -152,17 +167,19 @@ class Cafe extends Component<Props> {
152167
)}
153168
ItemSeparatorComponent={RowSeparator}
154169
/>
155-
{this.props.cafe.error && (
170+
{this.props.cafe && this.props.cafe.error && (
156171
<Text style={Error}>Cafe error: {this.props.cafe.error}</Text>
157172
)}
158-
{this.props.session.error && (
173+
{this.props.session && this.props.session.error && (
159174
<Text style={Error}>
160175
Cafe session error: {this.props.session.error}
161176
</Text>
162177
)}
163-
<Text style={ExpirationDate}>
164-
Your session expires on {expirationDate}
165-
</Text>
178+
{expirationDate !== '' && (
179+
<Text style={ExpirationDate}>
180+
Your session expires on {expirationDate}
181+
</Text>
182+
)}
166183
<View style={ButtonsContainer}>
167184
<Button
168185
text="Refresh"

0 commit comments

Comments
 (0)