Sufyan

Dashboard.tsx

Sep 24th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useEffect, useState } from 'react'
  2. import { Linking } from 'react-native'
  3. import { connect } from 'react-redux'
  4. import { Screen, Container, Text, Card, Credential, Theme, Colors, Icon, SignPost, SignPostCardType } from '@kancha'
  5. import SCREENS from './Screens'
  6. import { track } from 'uPortMobile/lib/actions/metricActions'
  7. import { parseClaimItem } from 'uPortMobile/lib/utilities/parseClaims'
  8.  
  9. import { onlyLatestAttestationsWithIssuer } from 'uPortMobile/lib/selectors/attestations'
  10. const singleposts = require('../stubbs/signposts.json');
  11. interface DashboardProps {
  12.   credentials: any[]
  13.   componentId: string
  14.   openURL: (url: string, eventName: string) => void
  15. }
  16.  
  17. export const Dashboard: React.FC<DashboardProps> = props => {
  18.   const [signPosts, updateSignPosts] = useState([])
  19.   const fetchSignPosts = async () => {
  20.     // const response = await fetch(
  21.     //   'https://uport-mobile-store.s3.us-east-2.amazonaws.com/dashboard-signposts/signposts.json',
  22.     // )
  23.     // const json = await response.json()
  24.     updateSignPosts(singleposts)
  25.   }
  26.   const showSignPosts =
  27.     signPosts.length > 0 &&
  28.     props.credentials.length === 0 &&
  29.     signPosts.map((card: SignPostCardType) => {
  30.       return <SignPost key={card.id} card={card} onPress={() => props.openURL(card.url, card.id)}/>
  31.     })
  32.  
  33.   useEffect(() => {
  34.     fetchSignPosts()
  35.   }, [])
  36.  
  37.   const showCredentials = props.credentials.map(credential => {
  38.     const { claimCardHeader } = parseClaimItem(credential)
  39.  
  40.     return (
  41.       <Container key={credential.token} marginBottom>
  42.         <Credential
  43.           componentId={props.componentId}
  44.           screen={SCREENS.Credential}
  45.           verification={credential}
  46.           claimType={claimCardHeader}
  47.           issuer={credential.issuer}
  48.           noMargin
  49.         />
  50.       </Container>
  51.     )
  52.   })
  53.   return (
  54.     <Screen>
  55.       <Container padding>
  56.         {showSignPosts}
  57.         {showCredentials}
  58.       </Container>
  59.     </Screen>
  60.   )
  61. }
  62.  
  63. const mapStateToProps = (state: any) => {
  64.   return {
  65.     credentials: onlyLatestAttestationsWithIssuer(state),
  66.   }
  67. }
  68.  
  69. const mapDispatchToProps = (dispatch: any) => ({
  70.   openURL: (url: string, eventName: string) => {
  71.     dispatch(track(`Opened linked ${eventName}`))
  72.     Linking.openURL(url)
  73.   }
  74. })
  75.  
  76. export default connect(mapStateToProps, mapDispatchToProps)(Dashboard)
Add Comment
Please, Sign In to add comment