Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #84 from rsksmart/develop
Browse files Browse the repository at this point in the history
Holder app v0.1.1
  • Loading branch information
ilanolkies authored Oct 18, 2020
2 parents ed88621 + 9271523 commit 4015a11
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/IdentityApp/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Identity Holder Wallet

The holder wallet is used to store declarative detials and credentials of it's users. Built in React Native it can be packaged for both IOS and Android, however, Android is the only officially supported platform.
The holder wallet is used to store declarative details and credentials of it's users. Built in React Native it can be packaged for both IOS and Android, however, Android is the only officially supported platform.

## Setting up a local Android Environment

Expand Down
2 changes: 1 addition & 1 deletion apps/IdentityApp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "IdentityApp",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
2 changes: 1 addition & 1 deletion apps/IdentityApp/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"DATA_VAULT_ENDPOINT": "http://ec2-3-131-142-122.us-east-2.compute.amazonaws.com:5102",
"RSK_NODE": "https://did.testnet.rsk.co:4444",
"CONVEY_URL": "http://ec2-3-131-142-122.us-east-2.compute.amazonaws.com:5104",
"CONVEY_DID": "did:ethr:rsk:testnet:0xff80e2096CbE429A3915ADF0983C66c729059cAB"
"CONVEY_DID": "did:ethr:rsk:testnet:0xFF80e2096CBE429A3915Adf0983C66c729059CAB"
}
57 changes: 45 additions & 12 deletions apps/IdentityApp/src/features/restore/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export const restoreProfileFromDataVault = (did: string) => async (dispatch: Dis
const details = Array.isArray(response) ? response[response.length - 1] : response;
const declarativeDetails = JSON.parse(details.content);

const callback = (err: Error) => {
const callback = (err: Error | undefined) => {
if (err) {
console.log(err);
console.log('declarative details callback error', err);
dispatch(resetRestoreProcess());
return dispatch(errorRestore('Error from DataVault'));
}
Expand All @@ -75,18 +75,51 @@ export const restoreProfileFromDataVault = (did: string) => async (dispatch: Dis
});
};

export const restoreCredentialsFromDataVault = () => async (dispatch: Dispatch<any>) => {
interface IDVItem {
cid: string;
content: string;
}

/**
* RestoreCredentialLoop
* Helper function that takes an array of DataVault Credential Objects and adds them one at a time to the reducer.
* @param jwtResponseArray Array of DataVault Items
* @param finalCallback Callback function to be called at the end.
*/
const restoredCredentialLoop = (
jwtResponseArray: IDVItem[],
finalCallback: (err?: Error) => void,
) => (dispatch: Dispatch<any>) => {
const receiveCredentialRif = receiveCredentialFactory(agent);
getFromDataVault(dataVaultKeys.CREDENTIALS)
.then(credentials => {
credentials.map((item: any) => dispatch(receiveCredentialRif(JSON.parse(item.content))));
const callback = (err: Error | undefined) => {
if (err) {
return finalCallback(err);
}

// run it again if there are more credentials:
jwtResponseArray.length !== 1
? dispatch(restoredCredentialLoop(jwtResponseArray.slice(1), finalCallback))
: finalCallback();
};

dispatch(receiveCredentialRif(JSON.parse(jwtResponseArray[0].content), callback));
};

/**
* Get Credentials from the DataVault
*/
export const restoreCredentialsFromDataVault = () => async (dispatch: Dispatch<any>) => {
getFromDataVault(dataVaultKeys.CREDENTIALS).then(credentials => {
const callback = (err?: Error | undefined) => {
if (err) {
dispatch(resetRestoreProcess());
return dispatch(errorRestore('Error Restoring Credentials'));
}

dispatch(receiveRestore());
RootNavigation.navigate('SignupFlow', { screen: 'PinCreate' });
})
.catch(err => {
console.log(err);
dispatch(resetRestoreProcess());
return dispatch(errorNoIdentity());
});
};

credentials.length === 0 ? callback() : dispatch(restoredCredentialLoop(credentials, callback));
});
};

0 comments on commit 4015a11

Please sign in to comment.