Skip to content

Commit

Permalink
Redux store contract interaction function changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 committed Nov 26, 2021
1 parent 340f41a commit 3a49895
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/redux/actions/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var _= require('lodash');
export const updateIssuerInfo = () => async (dispatch) => {
try{
const issuers = new Map();
const info = await getIssuerInfo(0 ,issuers);
const totalIssuers = await Identity.methods.totalIssuer().call();
const info = await getIssuerInfo(0 , totalIssuers , issuers);
const state = Store.getState();
if(! _.isEqual(state.Issuer.info , info))
dispatch(issuerSuccess(info));
Expand All @@ -18,15 +19,14 @@ export const updateIssuerInfo = () => async (dispatch) => {
}

//get all issuers data from blockchain
const getIssuerInfo = async(num , issuers)=>{
try{
const getIssuerInfo = async(num , total , issuers)=>{
if(num < total){
const issuerData = await Identity.methods.Issuer(num).call();
issuers.set(issuerData.IssueId,issuerData.IssuerAddress);
return await getIssuerInfo(num+1 , issuers);
return await getIssuerInfo(num+1 , total ,issuers);
}
catch(err){
else
return issuers;
}
}

const issuerSuccess = info => ({
Expand Down
7 changes: 3 additions & 4 deletions src/redux/actions/issuerRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ const getRequestInfo = async()=>{
};

info.address = await Identity.methods.Owner().call();

for( let req = 0;1;req++){
try{info = await requestUtil(info , req);}
catch(err){break;}
const totalReq = await Identity.methods.issuerVerificationRequestCount().call();
for( let req = 0; req<totalReq ; req++){
info = await requestUtil(info , req);
}
return info;
}
Expand Down
36 changes: 18 additions & 18 deletions src/redux/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export const getUserInfo = async(account)=>{
}
};

const userData = await Identity.methods.UserDetail(account).call();
const issuerData = await Identity.methods.IssuerDetail(account).call();
info.identity = await getIds(0 , account , []);
info = await getRequests(0 , account , info);
const userData = await Identity.methods.UserDetail(account).call({from : account});
const issuerData = await Identity.methods.IssuerDetail(account).call({from : account});
const totalId = await Identity.methods.totalId().call({from : account});
const totalRequest = await Identity.methods.totalRequest().call({from : account});
info.identity = await getIds(0 , totalId, account , []);
info = await getRequests(0 , totalRequest, account , info);
info.registered = userData.Registered;
info.publicKey = userData.PublicKey;
info.issuer.status = issuerData.Status;
Expand All @@ -51,10 +53,10 @@ export const getUserInfo = async(account)=>{
return info;
}

const getIds = async(num , account , ids)=>{
try{
const identity = await Identity.methods.getId(num , account).call();
const getIds = async(num ,total , account , ids)=>{

if(num < total){
const identity = await Identity.methods.getId(num , account).call({from : account});
const Id = {
num : num,
name : identity.Name,
Expand All @@ -65,15 +67,14 @@ const getIds = async(num , account , ids)=>{
issuerSignature : identity.IssuerSignature
}
ids.push(Id);
return await getIds(num+1 , account , ids);
return await getIds(num+1 ,total, account , ids);
}
catch(err){
return ids;
}
else return ids;
}

const getRequests = async(num ,account , info)=>{
try{
const getRequests = async(num , total ,account , info)=>{

if(num < total){
let rqData = await Identity.methods.getRequest(num).call({from : account});
const request = {
requestNo : num,
Expand All @@ -94,11 +95,10 @@ const getRequests = async(num ,account , info)=>{
if(request.status === "0")
info.issuer.rejectedRequest.push(request);

return await getRequests(num+1 , account , info);
return await getRequests(num+1 , total, account , info);
}
catch(err){
else
return info;
}
}

export const requestIssuerAccount =
Expand Down Expand Up @@ -131,7 +131,7 @@ export const addId = (issuer , buffer , account , pbk,id) => async dispatch =>{
)
);

const Issuer_Data = await Identity.methods.UserDetail(issuer).call();
const Issuer_Data = await Identity.methods.UserDetail(issuer).call({from : account});
const encrypted_issuer_hash = ethUtil.bufferToHex(
Buffer.from(
JSON.stringify(
Expand Down

0 comments on commit 3a49895

Please sign in to comment.