mirror of
https://github.com/selfxyz/self.git
synced 2026-04-27 03:01:15 -04:00
gather app utils in /src
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user