Skip to content

Commit

Permalink
16.05.2024 изменил программу в соответствии с тем, что больше нет зад… (
Browse files Browse the repository at this point in the history
#177)

* 16.05.2024 изменил программу в соответствии с тем, что больше нет задеплоиных компаний, а только кошельки компаний.

* 17.05.2024 исправил модуль CampaignPage. Теперь программа после отсылки донатов выходит в основной список.

* 24.05.2024 внёс исправление в функцию handleLoadOneCampaign. Убрал из условий отбора компании поле deleted.

* 27.05.2024 Внёс изменения во внешний вид.Добавил внизу строчку пробела. Исправил ошибку с неправильным показом количества всего собранных компанией донатов, как в общем списке так и в форме показа отдельной компании.

* 28.05.2024 изменил файл package.json, чтобы можно было запускать и под Windows, и под Linux.
  • Loading branch information
jakogri authored Jun 4, 2024
1 parent e088490 commit d550a15
Show file tree
Hide file tree
Showing 14 changed files with 630 additions and 622 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@
"typescript": "^3.9.9"
},
"scripts": {
"start-react-windows": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"start-react": "export NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
"start-windows": "set NODE_OPTIONS=--openssl-legacy-provider && cd server && node server.js",
"start": "export NODE_OPTIONS=--openssl-legacy-provider && cd server && node server.js",
"postinstall": "npm config set legacy-peer-deps true && cd server && npm --loglevel=error install",
"install-all": "npm config set legacy-peer-deps true && npm --loglevel=error install && cd server && npm --loglevel=error install",
"build-windows": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts build && mv build/index.html build/_index.html",
"build": "export NODE_OPTIONS=--openssl-legacy-provider && react-scripts build && mv build/index.html build/_index.html",
"test-windows": "set NODE_OPTIONS=--openssl-legacy-provider && react-scripts test",
"test": "export NODE_OPTIONS=--openssl-legacy-provider && react-scripts test",
"eject": "react-scripts eject"
},
Expand Down
4 changes: 4 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ APP.post('/api/donate/adddanate', async (req, res) => {
}
});

APP.post('/api/campaign/updateWallet', async (req, res) => {
const DB = CLIENT.db(DBNAME);
serverLib.handleUpdateCampaignWallet(req, res, Sentry, DB);
});

APP.post('/api/campaign/update', (req, res) => {
if(serverLib.authenticated(req, res, Sentry)) {
Expand Down
143 changes: 119 additions & 24 deletions server/serverLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ServerLib {
this.emailCode.set(req.body.mydata.to_email, randCode);
return(text);
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand Down Expand Up @@ -62,6 +63,7 @@ class ServerLib {
await myCollection.insertOne(ITEM);
res.send('success');
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand All @@ -74,6 +76,7 @@ class ServerLib {
await myCollection.updateOne({'_id': req.body.mydata.to_email}, {$set: {password:password}});
res.send('success');
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand Down Expand Up @@ -142,6 +145,7 @@ class ServerLib {
res.send('success');
}).catch(console.error);
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand All @@ -152,19 +156,22 @@ class ServerLib {
campaignID: req.body.mydata.campaignID.toLowerCase(),
donatorID: req.body.mydata.donatorID.toLowerCase(),
raisedAmount: req.body.mydata.raisedAmount,
tipAmount: req.body.mydata.tipAmount,
transactionHash: req.body.mydata.transactionHash,
chainId: req.body.mydata.chainId,
coinAddress: req.body.mydata.coinAddress,
blockChainOrt: req.body.mydata.blockChainOrt,
donateDate: Date.now(),
deleted: false,
checked: false
}

try {
const myCollection = await DB.collection('donations');
await myCollection.insertOne(ITEM);
await this.handleUpdateCampaignWallet(req, res, Sentry, DB);
res.send('success');
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand Down Expand Up @@ -195,22 +202,23 @@ class ServerLib {
raisedAmount: 0,
creationDate: Date.now(),
lastDonationTime: 0,
coins: req.body.mydata.coins,
addresses: req.body.mydata.addresses,
accounts: req.body.mydata.accounts,
active: false,
email: req.body.mydata.email,
countryCode: req.body.mydata.countryCode,
number: req.body.mydata.number,
telegram: req.body.mydata.telegram,
website: req.body.mydata.website,
payout_address: req.body.mydata.payout_address,
payout_chain: req.body.mydata.payout_chain,
complete:req.body.mydata.complete,
new: true
}
try {
const myCollection = await DB.collection('campaigns');
await myCollection.insertOne(ITEM);
return true
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
return false;
}
Expand All @@ -234,6 +242,7 @@ class ServerLib {
await myCollection.updateOne({'_id': req.body.mydata.address}, {$set: req.body.mydata.dataToUpdate});
res.send('success');
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand All @@ -252,6 +261,7 @@ class ServerLib {
await myCollection.updateOne({'_id': req.body.id}, {$set: {deleted:true}});
res.send('success');
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand All @@ -260,16 +270,23 @@ class ServerLib {

async handleLoadFinishedCampaigns(req, res, Sentry, DB) {
try{

let pipeline = [
{ $match: {successful: true, deleted:{ $exists : false}}},
{$sort: {raisedAmount: -1, raisedOnCoinbase: -1, _id: 1}},
{ $skip : req.body.startRec},
{ $limit:req.body.compaignsCount}
{$lookup: {from :"campaign_wallet", localField: "_id", foreignField: "campaign_id", as : "wallet"}},
{$match: {successful: true,
$or:[{deleted:{ $exists : false}}, {deleted:false}],"wallet":{ $ne : []},"active":true, complete:true}},
{$set: {wallet: {$arrayElemAt: ["$wallet.addres_base58",0]},donate_count:{$arrayElemAt: ["$wallet.donate_count",0]}}},
{$sort: {donate_count: -1, raisedOnCoinbase: -1, _id: 1}},
{$skip : req.body.startRec},
{ $limit:req.body.compaignsCount}
];
let pipeline1 = [
{ $lookup: {from :"campaign_wallet", localField: "_id", foreignField: "campaign_id", as : "wallet"}},
{ $match: {successful:true,
$or:[{deleted:{ $exists : false}}, {deleted:false}],"wallet":{ $ne : []},"active":true, complete:true}}
];
let curArr = await DB.collection('campaigns').aggregate(pipeline).toArray();
let arCount = await DB.collection('campaigns').count({successful: true, deleted:{ $exists : false }});
let result = {curArr:curArr, arCount:arCount};
let curArr1 = await DB.collection('campaigns').aggregate(pipeline1).toArray();
let result = {curArr:curArr, arCount:curArr1.length};
res.send(result);
} catch (err) {
console.log(err);
Expand All @@ -281,16 +298,25 @@ class ServerLib {
async handleLoadAllCampaigns(req, res, Sentry, DB) {
try{
let pipeline = [
{ $match: {active: true, deleted:{ $exists : false}}},
{$sort: {lastDonationTime: -1, raisedAmount: -1, raisedOnCoinbase: -1, _id: 1}},
{$lookup: {from :"campaign_wallet", localField: "_id", foreignField: "campaign_id", as : "wallet"}},
{$match: {$or:[{successful:false },{successful:{$exists : false}}],
$or:[{deleted:{ $exists : false}}, {deleted:false}],"wallet":{ $ne : []},"active":true, complete:true}},
{$set: {wallet: {$arrayElemAt: ["$wallet.addres_base58",0]},donate_count:{$sum:{$arrayElemAt: ["$wallet.donate_count",0]}}}},
{$sort: {donate_count: -1, raisedOnCoinbase: -1, _id: 1}},
{ $skip : req.body.startRec},
{ $limit: req.body.compaignsCount}
];
let pipeline1 = [
{ $lookup: {from :"campaign_wallet", localField: "_id", foreignField: "campaign_id", as : "wallet"}},
{ $match: {$or:[{successful:false },{successful:{$exists : false}}],
$or:[{deleted:{ $exists : false}}, {deleted:false}],"wallet":{ $ne : []},"active":true, complete:true}}
];
let curArr = await DB.collection('campaigns').aggregate(pipeline).toArray();
let arCount = await DB.collection('campaigns').count({active: true, deleted:{ $exists : false }});
let result = {curArr:curArr, arCount:arCount};
let curArr1 = await DB.collection('campaigns').aggregate(pipeline1).toArray();
let result = {curArr:curArr, arCount:curArr1.length};
res.send(result);
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand All @@ -310,6 +336,7 @@ class ServerLib {
res.send(result);
}
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.send("error");
}
Expand All @@ -324,6 +351,7 @@ class ServerLib {
let result = await DB.collection('donations').aggregate(pipeline).toArray();
res.send(result);
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendn("error");
}
Expand All @@ -335,7 +363,11 @@ class ServerLib {
let result = await myCollection.findOne({"key" : req.body.KEY, "deleted":{ $exists : false }});
if (result) res.send(result._id)
else res.send(req.body.KEY);
} catch (err) {Sentry.captureException(new Error(err));}
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

async handlecheckKey(req, res, Sentry, DB) {
Expand All @@ -344,7 +376,11 @@ class ServerLib {
let result = await myCollection.findOne({"key" : req.body.KEY, "deleted":{ $exists : false }});
if (result) res.send(true)
else res.send(false);
} catch (err) {Sentry.captureException(new Error(err));}
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

async handleGetCoinsList(req, res, Sentry, DB) {
Expand All @@ -353,7 +389,11 @@ class ServerLib {
let coins = await myCollection.find();//aggregate([{$group:{ _id : "$chain", coins:{$push: "$coin"}}}]);
const result = await coins.toArray();
res.send(result);
} catch (err) {Sentry.captureException(new Error(err));}
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

async handleGetTipForHeo(req, res, Sentry, DB) {
Expand All @@ -365,6 +405,7 @@ class ServerLib {
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

Expand All @@ -374,15 +415,54 @@ class ServerLib {
let chains = await myCollection.distinct("chain");
const result = await chains.toArray();
res.send(result._id);
} catch (err) {Sentry.captureException(new Error(err));}
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

async handleUpdateCampaignWallet(req, res, Sentry, DB) {
try {
const myCollection = await DB.collection('campaign_wallet');
await myCollection.updateOne({'campaign_id': req.body.mydata.campaignID, 'wallet_ort': req.body.mydata.blockChainOrt},
{$inc: {"donate_count":req.body.mydata.raisedAmount, "heo_donate":req.body.mydata.tipAmount}});
return true;
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

async handleLoadOneCampaign(req, res, Sentry, DB) {
try {
const myCollection = await DB.collection('campaigns');
let result = await myCollection.findOne({"_id" : req.body.ID, "deleted":{ $exists : false }});
const walletColection = await DB.collection('campaign_wallet');
let result = await myCollection.findOne({"_id" : req.body.ID });
let donate = await DB.collection('donations').find({campaignID: req.body.ID}).toArray();
let campaign_wallets = await walletColection.find({"campaign_id" : req.body.ID}).
project({_id:0,wallet_ort:1,addres_base58:1,addres_hex:1,coin_name:1}).toArray();
for(let i=0; i<campaign_wallets.length; i++) {
if(campaign_wallets[i].wallet_ort === 'Tron') {
campaign_wallets[i].chainId = process.env.TRON_CHAIN.toString();
campaign_wallets[i].coin_addres = process.env.TRON_TOKEN_ADRES.toString();
}
else if(campaign_wallets[i].wallet_ort === 'Etherium') {
campaign_wallets[i].chainId = process.env.CHAIN.toString();
campaign_wallets[i].coin_addres = process.env.TOKEN_ADRES.toString();
}
else campaign_wallets[i].chainId = "";
}
result.campaign_wallets = campaign_wallets;
result.totalQuantity = 0;
for(let i=0; i<donate.length; i++) result.totalQuantity += donate[i].raisedAmount;
res.send(result);
} catch (err) {Sentry.captureException(new Error(err));}
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

async handleLoadUserCampaigns(req, res, Sentry, DB) {
Expand All @@ -392,6 +472,7 @@ class ServerLib {
const result = await campaigns.toArray();
res.send(result);
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand All @@ -418,7 +499,9 @@ class ServerLib {
});

} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

Expand All @@ -429,7 +512,11 @@ class ServerLib {
try {
const myCollection = await DB.collection('fiat_payment_records');
await myCollection.insertOne(data);
} catch (err) {Sentry.captureException(new Error(err))}
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
}

//update payment record in mongodb
Expand All @@ -438,8 +525,11 @@ class ServerLib {
try{
const myCollection = await DB.collection('fiat_payment_records');
await myCollection.updateOne({'_id': recordId}, {$set: data});
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
catch (err) {Sentry.captureException(new Error(err))}
}

async authenticated(req, res, Sentry) {
Expand Down Expand Up @@ -467,7 +557,10 @@ class ServerLib {
}
}
return;
} catch (err) {Sentry.captureException(new Error(err))};
} catch (err) {
console.log(err);
Sentry.captureException(new Error(err));
}
}

async handleGetCountInPage(res, Sentry, DB) {
Expand All @@ -477,6 +570,7 @@ class ServerLib {
let fiatSettings = await fiatSettingsRAW.toArray();
res.send(fiatSettings[0].count);
} catch (err){
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand All @@ -489,6 +583,7 @@ class ServerLib {
let fiatSettings = await fiatSettingsRAW.toArray();
res.send(fiatSettings[0].count);
} catch (err){
console.log(err);
Sentry.captureException(new Error(err));
res.sendStatus(500);
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import CreateCampaign from './CreateCampaign';
import UserCampaigns from './UserCampaigns';
import EditCampaign from './EditCampaign';
import MyDonations from './MyDonations';
import WithdrawDonations from './WithdrawDonations';
import Registration from './Registration';
import Page404 from "./Page404";
import TokenSale from './TokenSale'
Expand Down Expand Up @@ -179,7 +178,6 @@ class App extends Component {
<Switch>
<Route path="/campaign" component={CampaignPage} />
<Route path="/myCampaigns" component={UserCampaigns} />
<Route path="/withdrawDonations" component={WithdrawDonations} />
<Route path="/new" component={CreateCampaign} />
<Route path="/rewards" component={MyDonations} />
<Route path="/editCampaign" component={EditCampaign} />
Expand Down
Loading

0 comments on commit d550a15

Please sign in to comment.