Skip to content

Commit

Permalink
Reading Uruguay's codes
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Oct 5, 2021
1 parent 448ea3c commit 7ffaafe
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 9 deletions.
116 changes: 116 additions & 0 deletions app/components/DCCUYCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React, {Component} from 'react';
import { View, Image, Button, FlatList, TouchableOpacity } from 'react-native';
import { Text, Divider } from 'react-native-elements';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';

import { CardStyles as styles } from '../themes/CardStyles'

import Moment from 'moment';


export default class DCCYUCard extends Component {

showQR = (card) => {
this.props.navigation.navigate({name: 'QRShow', params: {
qr: card.rawQR,
title: this.formatPerson(),
detail: this.formatCI(),
signedBy: this.formatSignedBy()
}
});
}

cert = () => {
return this.props.detail.cert ? this.props.detail.cert : this.props.detail;
}

formatCI = () => {
return this.cert().data.DocumentType + ": " + this.cert().data.DocumentNumber;
}

formatExpiresOn = () => {
if (this.cert().exp === undefined || this.cert().exp === "") return "";
return Moment(this.cert().exp*1000).format('MMM DD, YYYY')
}

formatPerson = () => {
if (this.cert().data.Name)
return this.cert().data.Name;
else
return "Unkown";
}

formatSignedBy = () => {
let line = "Signed by ";
if (this.cert().iss)
line += this.cert().iss;
else
line += this.props.detail.pub_key.toLowerCase();

if (this.cert().iat) {
line += " on " + Moment(this.cert().iat * 1000).format('MMM DD, YYYY')
}

return line;
}

renderCard = () => {
return (
<View style={[styles.card, {backgroundColor:this.props.colors.primary}]}>
<View style={{flexDirection:'row', justifyContent:'space-between', alignItems:'center'}}>
<Text style={styles.notes}>{Moment(this.props.detail.scanDate).format('MMM DD, hh:mma')} - Vaccination</Text>
<FontAwesome5 style={styles.button} name={'trash'} onPress={() => this.props.removeItem(this.props.detail.signature)} solid/>
</View>

<View style={styles.row}>
<Text style={styles.title}>{this.formatPerson()}</Text>
</View>

<View style={styles.row}>
<Text style={styles.notes}>{this.formatCI()}</Text>
</View>

<Divider style={[styles.divisor, {borderBottomColor:this.props.colors.cardText}]} />

<FlatList
listKey={this.props.detail.signature+"v"}
data={this.cert().data.VaccinationInfo.Doses}
keyExtractor={item => (this.props.detail.signature+item.Date)}
renderItem={({item}) => {
return (
<View style={styles.groupLine}>

<View>
<Text style={styles.notes}>Shot {item.Number}/{this.cert().data.VaccinationInfo.Doses.length}: {Moment(item.Date).format('MMM DD, YYYY')}</Text>
</View>

<View>
<Text style={styles.notes}>Brand: {item.Vaccine}</Text>
</View>
<Divider style={[styles.divisor, {borderBottomColor:this.props.colors.cardText}]} />
</View>
)
}} />

<View style={{flexDirection:'row', alignItems: 'center', paddingRight: 10}}>
<FontAwesome5 style={styles.icon} name={'check-circle'} solid/>
<Text style={styles.notes}>{this.formatSignedBy()}</Text>
</View>

<View style={{flexDirection:'row', alignItems: 'center'}}>
<FontAwesome5 style={styles.icon} name={'clock'} solid/>
<Text style={styles.notes}>Valid until: {this.formatExpiresOn()}</Text>
</View>
</View>
);
}


render() {
return this.props.pressable ?
( <TouchableOpacity onPress={() => this.showQR(this.props.detail)}>
{this.renderCard()}
</TouchableOpacity>
) : this.renderCard();
}
}
5 changes: 5 additions & 0 deletions app/screens/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import StatusCard from './../components/StatusCard';
import PassKeyCard from './../components/PassKeyCard';
import SHCCard from './../components/SHCCard';
import DCCCard from './../components/DCCCard';
import DCCUYCard from './../components/DCCUYCard';

import { listCards, removeCard } from './../utils/StorageManager';

Expand Down Expand Up @@ -118,6 +119,10 @@ function Entry({ navigation }) {
return <View style={styles.listItem}><SHCCard detail={item} colors={colors} navigation={navigation} removeItem={removeItem} pressable/></View>
if (item.format === "DCC" && item.type === "DCC")
return <View style={styles.listItem}><DCCCard detail={item} colors={colors} navigation={navigation} removeItem={removeItem} pressable/></View>
if (item.format === "DCC" && item.type === "UY")
return <View style={styles.listItem}><DCCUYCard detail={item} colors={colors} navigation={navigation} removeItem={removeItem} pressable/></View>


}} />
</View>
</SafeAreaView>
Expand Down
2 changes: 2 additions & 0 deletions app/screens/QRResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import StatusCard from './../components/StatusCard';
import PassKeyCard from './../components/PassKeyCard';
import SHCCard from './../components/SHCCard';
import DCCCard from './../components/DCCCard';
import DCCUYCard from './../components/DCCUYCard';

import { removeCard } from './../utils/StorageManager';

Expand Down Expand Up @@ -54,6 +55,7 @@ function QRResult({ navigation, route }) {
{ qr.type === "COWIN" && <CowinCard detail={qr} colors={colors} removeItem={removeItem} /> }
{ qr.type === "FHIRBundle" && <SHCCard detail={qr} colors={colors} removeItem={removeItem} /> }
{ qr.type === "DCC" && <DCCCard detail={qr} colors={colors} removeItem={removeItem} /> }
{ qr.type === "UY" && <DCCUYCard detail={qr} colors={colors} removeItem={removeItem} /> }
</View>
<TouchableOpacity
style={[styles.button, {backgroundColor: colors.primary}]}
Expand Down
4 changes: 3 additions & 1 deletion app/utils/ImportDCC.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ const importDCC = async (certificateData) => {
}
let signature = debugInfo.value[3];

let cardType = payload.nam ? "DCC" : "UY"

let baseCard = {
format: "DCC",
type: "DCC",
type: cardType,
pub_key: keyId,
signature: signature,
scanDate: new Date().toJSON(),
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@cto.af/textdecoder": "*",
"@pathcheck/cred-sdk": "^0.0.6",
"@pathcheck/dcc-sdk": "^0.0.20",
"@pathcheck/dcc-sdk": "^0.0.21",
"@pathcheck/divoc-sdk": "^0.1.1",
"@pathcheck/shc-sdk": "^0.0.3",
"@react-native-async-storage/async-storage": "^1.15.4",
Expand Down

0 comments on commit 7ffaafe

Please sign in to comment.