Skip to content

Commit

Permalink
fix: fix bad badge color when one timeout occur
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Froment <sfroment42@gmail.com>

123

Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Jan 24, 2019
1 parent 072a7da commit ff47785
Show file tree
Hide file tree
Showing 20 changed files with 625 additions and 620 deletions.
30 changes: 20 additions & 10 deletions client/react-native/common/components/Library/Header.js
Expand Up @@ -6,7 +6,6 @@ import { padding, borderBottom, paddingBottom } from '../../styles'
import { isRTL } from '../../i18n'
import RelayContext from '../../relay/RelayContext'
import Icon from './Icon'
// import multiaddr from 'multiaddr'

const [defaultTextColor, defaultBackColor] = [colors.black, colors.white]

Expand All @@ -23,6 +22,7 @@ class StateBadge extends PureComponent {
listenInterfaceAddrs: [],
timeouted: false,
requestTimeout: 1000,
color: colors.black,
}

this.fetchListenAddrs()
Expand All @@ -47,21 +47,25 @@ class StateBadge extends PureComponent {
})
.catch((err) => reject(err))
.finally(() => clearTimeout(timer))
}).then((listenAddrs) => setTimeout(caller, watchTime))
})
.catch((err) => console.log('GetListenAddrsFailed with', err))
.finally(() => setTimeout(caller, watchTime))
}

fetchListenAddrs = () => {
const { context } = this.props
this.reqTimeoutOrRetry(this.fetchListenAddrs, context.queries.GetListenAddrs.fetch, (e) => this.setState({ listenAddrs: e.addrs }))
this.reqTimeoutOrRetry(this.fetchListenAddrs, context.queries.GetListenAddrs.fetch,
(e) => this.setState({ listenAddrs: e.addrs, timeouted: false }, this.setColor)
)
}

fetchListenInterfaceAddrs = () => {
const { context } = this.props
this.reqTimeoutOrRetry(this.fetchListenInterfaceAddrs, context.queries.GetListenInterfaceAddrs.fetch, (e) => this.setState({ listenInterfaceAddrs: e.addrs }))
this.reqTimeoutOrRetry(this.fetchListenInterfaceAddrs, context.queries.GetListenInterfaceAddrs.fetch,
(e) => this.setState({ listenInterfaceAddrs: e.addrs, timeouted: false }, this.setColor))
}

render () {
setColor = () => {
const { listenAddrs, listenInterfaceAddrs, timeouted } = this.state
let color = colors.black

Expand All @@ -72,8 +76,6 @@ class StateBadge extends PureComponent {
try {
const splited = v.split('/')
if (splited[1] === 'ip4' && splited[2] !== '127.0.0.1') {
// const addr = multiaddr(v).nodeAddress()
// if (addr.address !== '127.0.0.1') {
color = colors.green
}
} catch (e) {
Expand All @@ -86,6 +88,11 @@ class StateBadge extends PureComponent {
if (timeouted) {
color = colors.red
}
this.setState({ color })
}

render () {
const { color } = this.state

return (<Icon style={{ color }} name={'material-checkbox-blank-circle'} />)
}
Expand Down Expand Up @@ -169,9 +176,12 @@ export default class Header extends PureComponent {
middle
size={5}
>
<RelayContext.Consumer>
{context => <StateBadge context={context} />}
</RelayContext.Consumer>
{navigation.state.routeName === 'chats/list'
? <RelayContext.Consumer>
{context => <StateBadge context={context} />}
</RelayContext.Consumer>
: null
}
{title}
</Text>
{rightBtn ? <View>{rightBtn}</View> : null}
Expand Down
13 changes: 6 additions & 7 deletions client/react-native/common/components/Screens/Chats/List.js
@@ -1,7 +1,4 @@
import { withNamespaces } from 'react-i18next'
import I18n from 'i18next'
import React, { PureComponent } from 'react'

import { Avatar, EmptyList, Flex, Header, Screen, Text, Icon } from '../../Library'
import { BertyP2pKindInputKind } from '../../../graphql/enums.gen'
import { Pagination, QueryReducer, RelayContext } from '../../../relay'
Expand All @@ -12,7 +9,6 @@ import { parseEmbedded } from '../../../helpers/json'
import { conversation as utils } from '../../../utils'
import { withNamespaces } from 'react-i18next'
import I18n from 'i18next'
import RelayContext from '../../../relay/RelayContext'

class StateBadge extends PureComponent {
constructor (props) {
Expand All @@ -25,10 +21,14 @@ class StateBadge extends PureComponent {
this.getPing()
}

componentWillUnmount () {
clearInterval(this.state.setint)
}

getPing = () => {
const { other, context } = this.props
other.contact.devices.forEach(element => {
context.queries.GetTagInfo.fetch({ str: element.contactId })
context.queries.Libp2PPing.fetch({ str: element.contactId })
.then(
(e) => {
console.log('fetch ret', e)
Expand All @@ -39,7 +39,7 @@ class StateBadge extends PureComponent {
}
}
).catch(
(e) => console.error('err', e)
(e) => console.warn('err', e)
)
})
}
Expand All @@ -49,7 +49,6 @@ class StateBadge extends PureComponent {
}
}


const Message = withNamespaces()(({ data, t, ...props }) => {
switch (data.kind) {
case BertyP2pKindInputKind.ConversationNewMessage:
Expand Down
20 changes: 0 additions & 20 deletions client/react-native/common/graphql/queries/GetTagInfo.js

This file was deleted.

15 changes: 15 additions & 0 deletions client/react-native/common/graphql/queries/Libp2PPing.js
@@ -0,0 +1,15 @@
import { fetchQuery, graphql } from 'react-relay'

const query = graphql`
query Libp2PPingQuery($str: String!) {
Libp2PPing(str: $str) {
ret
}
}
`

export default context => ({
graphql: query,
fetch: async variables =>
(await fetchQuery(context.environment, query, variables)).Libp2PPing,
})
2 changes: 1 addition & 1 deletion client/react-native/common/graphql/queries/index.js
@@ -1,4 +1,4 @@
export GetTagInfo from './GetTagInfo'
export Libp2PPing from './Libp2PPing'
export GetListenAddrs from './GetListenAddrs'
export GetListenInterfaceAddrs from './GetListenInterfaceAddrs'
export ConversationList from './ConversationList'
Expand Down
11 changes: 4 additions & 7 deletions client/react-native/common/relay/environment.js
Expand Up @@ -79,13 +79,7 @@ const setupMiddlewares = async ({ getIp, getPort }) => [
retryMiddleware({
allowMutations: true,
fetchTimeout: 5000,
retryDelays: (attempt) => {
console.log(attempt)
if (attempt === 5) {
return false
}
return 3000
},
retryDelays: attempt => Math.pow(2, attempt + 4) * 100,
beforeRetry: async ({
forceRetry,
abort,
Expand All @@ -94,6 +88,9 @@ const setupMiddlewares = async ({ getIp, getPort }) => [
lastError,
req,
}) => {
if (attempt > 5) {
abort()
}
req.fetchOpts.url = `http://${await getIp()}:${await getPort()}/query`

// eslint-disable-next-line
Expand Down
8 changes: 4 additions & 4 deletions client/react-native/common/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions core/api/client/jsonclient/berty.node.service.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions core/api/node/graphql/gqlgen.gen.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff47785

Please sign in to comment.