Skip to content

Commit

Permalink
Added the currentBalance counter
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechsimetka committed Oct 7, 2018
1 parent 022aa39 commit 8429390
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/blockchain/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const delegates = (app, liquidPledging) => {
title: delegate.name,
txHash,
totalDonated: '0',
currentBalance: '0',
donationCount: 0,
description: 'Missing Description... Added outside of UI',
});
Expand Down
2 changes: 2 additions & 0 deletions src/blockchain/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const projects = (app, liquidPledging) => {
txHash: tx.transactionHash,
pluginAddress: project.plugin,
totalDonated: '0',
currentBalance: '0',
donationCount: 0,
mined: true,
},
Expand Down Expand Up @@ -178,6 +179,7 @@ const projects = (app, liquidPledging) => {
description: 'Missing Description... Added outside of UI',
txHash,
totalDonated: '0',
currentBalance: '0',
donationCount: 0,
status: canceled ? CampaignStatus.CANCELED : CampaignStatus.ACTIVE,
mined: true,
Expand Down
3 changes: 2 additions & 1 deletion src/models/campaigns.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function createModel(app) {
projectId: { type: Schema.Types.Long, index: true, unique: true }, // we can use Long here b/c lp only stores adminId in pledges as uint64
image: { type: String, required: true },
txHash: { type: String },
totalDonated: { type: Schema.Types.BN },
totalDonated: { type: Schema.Types.BN, min: 0 },
currentBalance: { type: Schema.Types.BN, min: 0 },
donationCount: { type: Number },
peopleCount: { type: Number },
dacs: { type: [String] },
Expand Down
3 changes: 2 additions & 1 deletion src/models/dacs.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ function createModel(app) {
enum: Object.values(DacStatus),
default: DacStatus.PENDING,
},
image: { type: String }, // required: true },
image: { type: String },
txHash: { type: String, required: true },
totalDonated: { type: Schema.Types.BN, min: 0 },
currentBalance: { type: Schema.Types.BN, min: 0 },
donationCount: { type: Number },
peopleCount: { type: Number },
ownerAddress: { type: String, required: true, index: true },
Expand Down
2 changes: 1 addition & 1 deletion src/models/milestones.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Milestone(app) {
conversionRate: { type: Number, required: true },
txHash: { type: String },
pluginAddress: { type: String },
totalDonated: { type: Schema.Types.BN },
currentBalance: { type: Schema.Types.BN, min: 0 },
fullyFunded: { tupe: Boolean },
donationCount: { type: Number },
peopleCount: { type: Number },
Expand Down
12 changes: 6 additions & 6 deletions src/services/donations/updateEntityCounters.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,29 @@ const updateEntity = async (context, donation) => {
.service('donations')
.find({ paginate: false, query: donationQuery });

const { totalDonated, amountRemaining } = donations.reduce(
const { totalDonated, currentBalance } = donations.reduce(
(accumulator, d) => ({
totalDonated: accumulator.totalDonated.add(toBN(d.amount)),
amountRemaining: accumulator.amountRemaining.add(toBN(d.amountRemaining)),
currentBalance: accumulator.currentBalance.add(toBN(d.amountRemaining)),
}),
{
totalDonated: toBN(0),
amountRemaining: toBN(0),
currentBalance: toBN(0),
},
);

// NOTE: Using === to compare as both of these are strings and amounts in wei
const fullyFunded =
donation.ownerType === AdminTypes.MILESTONE && entity.maxAmount === totalDonated;
donation.ownerType === AdminTypes.MILESTONE && entity.maxAmount === currentBalance.toString();
const peopleCount = new Set(donations.map(d => d.giverAddress)).size;
const donationCount = donations.filter(
d => ![DonationStatus.PAYING, DonationStatus.PAID].includes(d.status),
).length;

await service.patch(entity._id, {
donationCount,
totalDonated: totalDonated.toString(),
amountRemaining: amountRemaining.toString(),
totalDonated,
currentBalance,
peopleCount,
fullyFunded,
});
Expand Down

0 comments on commit 8429390

Please sign in to comment.