gather app utils in /src

This commit is contained in:
0xturboblitz
2024-08-29 14:03:02 +09:00
parent 8a813c577d
commit db1751b5af
6 changed files with 46 additions and 74 deletions

View File

@@ -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();

View File

@@ -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';

View File

@@ -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";

View File

@@ -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);
}
}

View File

@@ -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;
}
}