Use for-of loop for iteration

This commit is contained in:
Prathamesh Musale 2024-08-14 17:01:18 +05:30
parent 4dc1387559
commit adccde9f46

View File

@ -41,18 +41,18 @@ async function processSubscribers(client: StargateClient, participants: any[], s
// Map kyc_id to participant data // Map kyc_id to participant data
const kycMap: Record<string, any> = {}; const kycMap: Record<string, any> = {};
participants.forEach((participant: any) => { participants.forEach((participant: any) => {
kycMap[participant.kyc_id] = participant; kycMap[participant.kycId] = participant;
}); });
const onboardedSubscribers: any[] = []; const onboardedSubscribers: any[] = [];
subscribers.forEach(async (subscriber) => { for (const subscriber of subscribers) {
const hashedSubscriberId = hashSubscriberId(subscriber['subscriber_id']); const hashedSubscriberId = hashSubscriberId(subscriber['subscriber_id']);
const participant = kycMap[hashedSubscriberId]; const participant = kycMap[hashedSubscriberId];
if (!participant) { if (!participant) {
return; continue;
} }
const participantAddresss = participant['cosmos_address']; const participantAddresss = participant['cosmosAddress'];
// Fetch participant's Laconic pubkey // Fetch participant's Laconic pubkey
const participantAccount = await client.getAccount(participantAddresss); const participantAccount = await client.getAccount(participantAddresss);
@ -61,13 +61,13 @@ async function processSubscribers(client: StargateClient, participants: any[], s
// Skip participant if pubkey not found // Skip participant if pubkey not found
// (account may have funds but hasn't done any tx till now) // (account may have funds but hasn't done any tx till now)
if (!participantPubkey) { if (!participantPubkey) {
return; continue;
} }
// Skip participant if an onboarding tx not found // Skip participant if an onboarding tx not found
const onboardingTxs = await client.searchTx(`message.sender='${participantAddresss}' AND message.action='/cerc.onboarding.v1.MsgOnboardParticipant'`); const onboardingTxs = await client.searchTx(`message.sender='${participantAddresss}' AND message.action='/cerc.onboarding.v1.MsgOnboardParticipant'`);
if (onboardingTxs.length === 0) { if (onboardingTxs.length === 0) {
return; continue;
} }
const latestOnboardingTx = onboardingTxs.reduce((prev, current) => { const latestOnboardingTx = onboardingTxs.reduce((prev, current) => {
@ -81,15 +81,15 @@ async function processSubscribers(client: StargateClient, participants: any[], s
'premium?': subscriber['premium?'], 'premium?': subscriber['premium?'],
created_at: subscriber['created_at'], created_at: subscriber['created_at'],
cosmos_address: participantAddresss, cosmos_address: participantAddresss,
nitro_address: participant['nitro_address'], nitro_address: participant['nitroAddress'],
role: participant['role'], role: participant['role'],
hashed_subscriber_id: participant['kyc_id'], hashed_subscriber_id: participant['kycId'],
laconic_pubkey: participantPubkey, laconic_pubkey: participantPubkey.value,
onboarding_height: latestOnboardingTx.height onboarding_height: latestOnboardingTx.height
}; };
onboardedSubscribers.push(onboardedSubscriber); onboardedSubscribers.push(onboardedSubscriber);
}); }
const writer = csvWriter.createObjectCsvWriter({ const writer = csvWriter.createObjectCsvWriter({
path: path.resolve(outputPath), path: path.resolve(outputPath),