Skip to content

Commit

Permalink
Develop (#20)
Browse files Browse the repository at this point in the history
* feat: add reward convertation #15 (#16)

* chore: remove unused

* 1.3.0

* feat: do not lower rewards after gem chops (#19)

* fix: price calcilation

* hotfix: class/model names in forks (#22)

* Fix forks (#23)

* hotfix: class/model names in forks

* feat: update deps, migrate to new fork manager

* hotfix: models

Co-authored-by: Igor Tkachenko <[email protected]>
  • Loading branch information
IvanBlacky and b1acksun authored Jul 21, 2020
1 parent 439f25f commit b007a1a
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 426 deletions.
287 changes: 136 additions & 151 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "GPL-3.0",
"dependencies": {
"bytebuffer": "^5.0.1",
"cyberway-core-service": "^3.58.4",
"cyberway-core-service": "^3.59.3",
"cyberwayjs": "^20.0.0-beta7",
"eosjs-ecc": "latest",
"mongodb": "^3.2.7",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/Community.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Community extends BasicService {

await this.registerForkChanges({
type: 'create',
Model: CommunityModel,
Model: Community,
documentId: newCommunity._id,
});
}
Expand Down Expand Up @@ -53,7 +53,7 @@ class Community extends BasicService {

await this.registerForkChanges({
type: 'update',
Model: CommunityModel,
Model: Community,
documentId: previousModel._id,
data: {
$set: {
Expand Down
12 changes: 11 additions & 1 deletion src/controllers/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,27 @@ class Gallery extends Service {
async handleMosaicState(state) {
const { tracery } = state;

const collectionEnd = state.collection_end_date + 'Z';

let displayReward;
if (new Date(collectionEnd) > Date.now()) {
displayReward = state.reward;
}

const previousModel = await Mosaic.findOneAndUpdate(
{
tracery,
},
{
$set: {
tracery,
collectionEnd: state.collection_end_date + 'Z',
collectionEnd,
gemCount: state.gem_count,
shares: state.shares,
damnShares: state.damn_shares,
reward: state.reward,
banned: state.banned,
displayReward,
},
}
);
Expand All @@ -169,6 +177,8 @@ class Gallery extends Service {
damnShares: previousModel.damnShares,
reward: previousModel.reward,
banned: previousModel.banned,
// do not change display reward if it hasn't been changed
displayReward: displayReward ? previousModel.displayReward : undefined,
},
},
});
Expand Down
18 changes: 17 additions & 1 deletion src/controllers/connector/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Gallery extends BasicController {
$project: {
topCount: 1,
reward: 1,
displayReward: 1,
collectionEnd: 1,
tracery: 1,
_id: 0,
Expand All @@ -71,7 +72,7 @@ class Gallery extends BasicController {
for (const mosaic of mosaics) {
if (userId) {
const gems = await Gem.find(
{ 'contentId.userId': userId, tracery: mosaic.tracery, isClaimable: true },
{ 'contentId.userId': userId, tracery: mosaic.tracery },
{ reward: 1 },
{ lean: true }
);
Expand All @@ -97,6 +98,21 @@ class Gallery extends BasicController {
};
}
}

const [rewardAmount, symbol] = mosaic.reward.split(' ');

if (parseFloat(rewardAmount) && this.pointsPrices) {
const cmn = parseFloat(rewardAmount / this.pointsPrices.prices[symbol]).toFixed(4);

// TODO get from price feed
const usd = parseFloat(cmn * env.COMMUN_PRICE).toFixed(2);

mosaic.convertedReward = {
cmn,
usd,
};
}

mosaic.isClosed = Date.now() - mosaic.collectionEnd >= 0;
mosaic.contentId = traceryContentIdMap.get(mosaic.tracery);
}
Expand Down
55 changes: 0 additions & 55 deletions src/models/Fork.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/models/Mosaic.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module.exports = MongoDB.makeModel(
reward: {
type: String,
},
displayReward: {
type: String,
},
banned: {
type: Boolean,
},
Expand Down
215 changes: 0 additions & 215 deletions src/services/Fork.js

This file was deleted.

0 comments on commit b007a1a

Please sign in to comment.