Skip to content

Commit

Permalink
Done merge of screens and rearranged the identity creation on index
Browse files Browse the repository at this point in the history
  • Loading branch information
49513 - Diogo Rodrigues committed Jul 12, 2024
1 parent 5b9ec0a commit e6b177b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
15 changes: 9 additions & 6 deletions code/app/(tabs)/home/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ const HomeScreen = () => {
}
};

const handlePrivKeyModalDismiss = () => {
setPrivKeyModalVisible(false);
setModalVisible(true);
};

const handleFormSubmit = async () => {
try {
setIsSubmitting(true);
Expand Down Expand Up @@ -141,13 +136,21 @@ const HomeScreen = () => {
// Get the identity of the user
const userIdentity = await getIdentity(savedWallet.address, identityFactory);

if (!userIdentity) {
Alert.alert('Warning', `Identity for wallet: ${savedWallet.address} not found.`);
setIsSubmitting(false);
return;
}

// Create the user wallet object (ethers.Wallet)
const userWallet = getWallet(savedWallet.privateKey, provider);

// Add the key of the claim issuer that matches the institution code to the identity of the student that requested the certificate
// With this the student is allowing the institution to emit certificates on his behalf
const issuers = await trustedIR.getTrustedIssuersForClaimTopic(ethers.id(CLAIM_TOPICS_OBJ.INSTITUTION));

console.log('userIdentity', userIdentity);

for (const issuer of issuers) {
// Get contract of the issuer, by searching the issuer address in the configuration file
for (const institution of config.institutions) {
Expand Down Expand Up @@ -200,7 +203,7 @@ const HomeScreen = () => {
/>
<PrivateKeyModal
visible={privKeyModalVisible}
onDismiss={handlePrivKeyModalDismiss}
onDismiss={() => setPrivKeyModalVisible(false)}
privateKey={privateKey}
onChangePrivateKey={text => setPrivateKey(text)}
onSubmitPrivateKey={onSubmitPrivateKey}
Expand Down
6 changes: 4 additions & 2 deletions code/app/(tabs)/profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { router } from 'expo-router';
import { getValueFor, removeValueFor, save } from '@/services/storage/storage';
import useWalletConnect from '@/services/web3/wallet-connect';
import config from '@/config.json';
import SettingsModal from '@/components/SettingsModal';

const Profile = () => {
const [onSettings, setOnSettings] = useState(false);
Expand Down Expand Up @@ -61,13 +62,14 @@ const Profile = () => {

useEffect(() => {
if (address) {
getValueFor('wallet').then(wallet => {
const wallet = getValueFor('wallet').then(wallet => {
if (wallet && wallet.address === address) {
return;
}
return wallet;
});
const saveWalletAddress = async () => {
await save('wallet', JSON.stringify({ address }));
await save('wallet', JSON.stringify({ address: address, privateKey: wallet.privateKey }));
setProfile(currentProfile => ({
...currentProfile,
wallet: address,
Expand Down
4 changes: 3 additions & 1 deletion code/app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { deployIdentity } from '@/services/ethereum/scripts/identities/deploy-id
import { getContractAt } from '@/services/ethereum/scripts/utils/ethers';
import { v4 as uuidv4 } from 'uuid';
import { useRpcProvider } from '@/services/ethereum/scripts/utils/useRpcProvider';
import config from '@/config.json';

function App() {
const [loading, setLoading] = useState(true);
Expand All @@ -26,7 +27,8 @@ function App() {
if (!isAdminWallet(walletAddress.address)) {
deployUserIdentity();
}
router.replace('/profile');
setLoading(false);
return router.replace('/profile');
}
setLoading(false);
};
Expand Down
21 changes: 11 additions & 10 deletions code/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"privateKey": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
},
"identityFactory": {
"address": "0x413b1AfCa96a3df5A686d8BFBF93d30688a7f7D9",
"address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -413,7 +413,7 @@
},
"trex": {
"implementationAuthority": {
"address": "0xC66AB83418C20A65C3f8e83B3d11c8C3a6097b6F",
"address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
"abi": [
{
"type": "constructor",
Expand Down Expand Up @@ -1515,7 +1515,7 @@
]
},
"claimsTopicRegistry": {
"address": "0x12Bcb546bC60fF39F1Adfc7cE4605d5Bd6a6A876",
"address": "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -1715,7 +1715,7 @@
]
},
"trustedIssuersRegistry": {
"address": "0xaC47e91215fb80462139756f43438402998E4A3a",
"address": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -2146,7 +2146,7 @@
]
},
"identityRegistry": {
"address": "0x63fea6E447F120B8Faf85B53cdaD8348e645D80E",
"address": "0x9A676e781A523b5d0C0e43731313A708CB607508",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -2911,7 +2911,7 @@
]
},
"identityRegistryStorage": {
"address": "0x9BcC604D4381C5b0Ad12Ff3Bf32bEdE063416BC7",
"address": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -3473,7 +3473,7 @@
]
},
"modularCompliance": {
"address": "0xdFdE6B33f13de2CA1A75A6F7169f50541B14f75b",
"address": "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -3975,7 +3975,7 @@
]
},
"token": {
"address": "0xaC9fCBA56E42d5960f813B9D0387F3D3bC003338",
"address": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
"abi": [
{
"type": "event",
Expand Down Expand Up @@ -5651,9 +5651,10 @@
{
"institutionID": 3117,
"wallet": {
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"privateKey": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
},
"address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
"address": "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
"abi": [
{
"type": "constructor",
Expand Down
2 changes: 2 additions & 0 deletions code/services/ethereum/scripts/identities/getIdentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ async function getIdentity(address, identityFactory, signer = undefined) {
console.log('[!] Getting identity for wallet with address:', address);
const identity = await identityFactory.getIdentity(address);

console.log('[!] Identity:', identity);

if (identity !== ethers.ZeroAddress) {
console.log('[✓] Identity found:', identity);

Expand Down

0 comments on commit e6b177b

Please sign in to comment.