diff --git a/app/src/screens/NextScreen.tsx b/app/src/screens/NextScreen.tsx index 152c5209..b3822de1 100644 --- a/app/src/screens/NextScreen.tsx +++ b/app/src/screens/NextScreen.tsx @@ -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'; @@ -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(); diff --git a/app/src/utils/nfcScanner.ts b/app/src/utils/nfcScanner.ts index 32347e5d..d416032d 100644 --- a/app/src/utils/nfcScanner.ts +++ b/app/src/utils/nfcScanner.ts @@ -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'; diff --git a/app/utils/snarkjs.ts b/app/src/utils/snarkjs.ts similarity index 100% rename from app/utils/snarkjs.ts rename to app/src/utils/snarkjs.ts diff --git a/app/src/utils/transactions.ts b/app/src/utils/transactions.ts index 720e9684..db6d0dd0 100644 --- a/app/src/utils/transactions.ts +++ b/app/src/utils/transactions.ts @@ -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"; diff --git a/app/src/utils/utils.ts b/app/src/utils/utils.ts index 64fc6621..9023ffdf 100644 --- a/app/src/utils/utils.ts +++ b/app/src/utils/utils.ts @@ -81,4 +81,46 @@ export const parseProofAndroid = (response: string) => { }, pub_signals: pub_signals.split(',').map((n: string) => n.trim()) } as Proof; -}; \ No newline at end of file +}; + +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); + } +} \ No newline at end of file diff --git a/app/utils/utils.ts b/app/utils/utils.ts deleted file mode 100644 index d80d8533..00000000 --- a/app/utils/utils.ts +++ /dev/null @@ -1,69 +0,0 @@ -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 formatDuration(durationInMs: number) { - const durationInSeconds = durationInMs / 1000; - const minutes = Math.floor((durationInSeconds % 3600) / 60); - const seconds = Math.floor(durationInSeconds % 60); - - if (minutes > 0) { - return `${minutes}m ${seconds}s`; - } else if (seconds > 0) { - return `${seconds}s`; - } else { - return `${durationInMs}ms`; - } -} -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); - } -} - -export const getTx = (input: string | null): string => { - if (!input) return ''; - const transaction = input.split(' ').filter(word => word.startsWith('0x')).join(' '); - return transaction; -} - -export const shortenTxHash = (input: string | null): string => { - if (!input) return ''; - if (input.length > 9) { - return input.substring(0, 25) + '\u2026'; - } else { - return input; - } -}