Moar await
This commit is contained in:
parent
60ed697460
commit
960dcb55de
@ -16,30 +16,32 @@ module.exports = async function(robot, kredits) {
|
|||||||
const walletTransactionCount = await kredits.provider.getTransactionCount(kredits.signer.address);
|
const walletTransactionCount = await kredits.provider.getTransactionCount(kredits.signer.address);
|
||||||
let nonce = walletTransactionCount;
|
let nonce = walletTransactionCount;
|
||||||
|
|
||||||
function createContributionFor(displayName, meeting) {
|
async function createContributionFor (displayName, meeting) {
|
||||||
|
const contributor = await getContributorByZoomDisplayName(displayName);
|
||||||
|
|
||||||
return getContributorByZoomDisplayName(displayName)
|
if (!contributor) {
|
||||||
.then(contributor => {
|
robot.logger.info(`[hubot-kredits] Contributor not found: Zoom display name: ${displayName}`);
|
||||||
if (!contributor) {
|
messageRoom(`I tried to add a contribution for zoom user ${displayName}, but did not find a matching contributor profile.`);
|
||||||
robot.logger.error(`[hubot-kredits] Contributor not found: Zoom display name: ${displayName}`);
|
return Promise.resolve();
|
||||||
messageRoom(`I tried to add a contribution for zoom user ${displayName}, but did not find a matching contributor profile.`);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
const contribution = {
|
|
||||||
contributorId: contributor.id,
|
|
||||||
contributorIpfsHash: contributor.ipfsHash,
|
|
||||||
amount: kreditsContributionAmount,
|
|
||||||
kind: kreditsContributionKind,
|
|
||||||
description: 'Team/Community Call',
|
|
||||||
date: meeting.end_time.split('T')[0],
|
|
||||||
time: meeting.end_time.split('T')[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
return Contribution.add(contribution, { nonce: nonce++ })
|
const contribution = {
|
||||||
.catch(error => {
|
contributorId: contributor.id,
|
||||||
robot.logger.error(`[hubot-kredits] Adding contribution failed:`, error);
|
contributorIpfsHash: contributor.ipfsHash,
|
||||||
});
|
amount: kreditsContributionAmount,
|
||||||
|
kind: kreditsContributionKind,
|
||||||
|
description: 'Team/Community Call',
|
||||||
|
date: meeting.end_time.split('T')[0],
|
||||||
|
time: meeting.end_time.split('T')[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return Contribution.add(contribution, { nonce: nonce++ })
|
||||||
|
.then(tx => {
|
||||||
|
robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
|
||||||
})
|
})
|
||||||
|
.catch(error => {
|
||||||
|
robot.logger.error(`[hubot-kredits] Adding contribution for Zoom call failed:`, error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContributorByZoomDisplayName(displayName) {
|
function getContributorByZoomDisplayName(displayName) {
|
||||||
@ -72,13 +74,11 @@ module.exports = async function(robot, kredits) {
|
|||||||
robot.logger.info(`[hubot-kredits] Ignoring zoom call ${data.uuid} (duration: ${meetingDetails.duration}, participants_count: ${meetingDetails.participants_count})`);
|
robot.logger.info(`[hubot-kredits] Ignoring zoom call ${data.uuid} (duration: ${meetingDetails.duration}, participants_count: ${meetingDetails.participants_count})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const names = Array.from(new Set(participants.map(p => p.name)));
|
const names = Array.from(new Set(participants.map(p => p.name)));
|
||||||
for(const displayName of names) {
|
|
||||||
const tx = createContributionFor(displayName, meetingDetails)
|
for (const displayName of names) {
|
||||||
// if the contributor is not found we do not get a transaction object here
|
await createContributionFor(displayName, meetingDetails);
|
||||||
if (tx) {
|
|
||||||
robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user