Skip to content

Commit

Permalink
gather app utils in /src
Browse files Browse the repository at this point in the history
  • Loading branch information
0xturboblitz committed Aug 29, 2024
1 parent 8a813c5 commit db1751b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 74 deletions.
3 changes: 1 addition & 2 deletions app/src/screens/NextScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { YStack, XStack, Text, Image, useWindowDimensions, Fieldset } from 'tamagui';
import { ArrowRight, Info } from '@tamagui/lucide-icons';
import { getFirstName, maskString } from '../../utils/utils';
import { getFirstName, maskString } from '../utils/utils';
import { attributeToPosition } from '../../../common/src/constants/constants';
import USER_PROFILE from '../images/user_profile.png'
import { bgGreen, borderColor, componentBgColor, textBlack, textColor1, textColor2 } from '../utils/colors';
Expand All @@ -11,7 +11,6 @@ import useUserStore from '../stores/userStore';
import useNavigationStore from '../stores/navigationStore';
import CustomButton from '../components/CustomButton';


const NextScreen: React.FC = () => {

const { height } = useWindowDimensions();
Expand Down
2 changes: 1 addition & 1 deletion app/src/utils/nfcScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NativeModules, Platform } from 'react-native';
// @ts-ignore
import PassportReader from 'react-native-passport-reader';
import { toStandardName } from '../../../common/src/utils/formatNames';
import { checkInputs } from '../../utils/utils';
import { checkInputs } from '../utils/utils';
import { PassportData } from '../../../common/src/utils/types';
import forge from 'node-forge';
import { Buffer } from 'buffer';
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/src/utils/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "ethers";
import axios from 'axios';
import groth16ExportSolidityCallData from '../../utils/snarkjs';
import groth16ExportSolidityCallData from './snarkjs';
import contractAddresses from "../../deployments/deployed_addresses.json";
import registerArtefacts from "../../deployments/artifacts/Deploy_Registry#OpenPassportRegister.json";
import sbtArtefacts from "../../deployments/artifacts/Deploy_Registry#SBT.json";
Expand Down
44 changes: 43 additions & 1 deletion app/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,46 @@ export const parseProofAndroid = (response: string) => {
},
pub_signals: pub_signals.split(',').map((n: string) => n.trim())
} as Proof;
};
};

export function getFirstName(mrz: string): string {
const names = mrz.split("<<");
const firstName = names[1].split("<")[0].trim();
const capitalized = firstName.charAt(0) + firstName.slice(1).toLowerCase();
return capitalized || "Unknown";
}

export function checkInputs(
passportNumber: string,
dateOfBirth: string,
dateOfExpiry: string,
): { success: boolean, message: string } {
// if (passportNumber.length !== 9) {
// throw new Error('Passport number must be 9 characters long');
// }
if (dateOfBirth.length !== 6) {
return {
success: false,
message: 'Complete Step 1 first'
};
}
if (dateOfExpiry.length !== 6) {
return {
success: false,
message: 'Date of expiry must be 6 characters long'
};
}

return {
success: true,
message: ''
};
}

export const maskString = (input: string): string => {
if (input.length <= 5) {
return input.charAt(0) + '*'.repeat(input.length - 1);
} else {
return input.charAt(0) + input.charAt(1) + '*'.repeat(input.length - 2);
}
}
69 changes: 0 additions & 69 deletions app/utils/utils.ts

This file was deleted.

0 comments on commit db1751b

Please sign in to comment.