Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadranjbarz committed Sep 28, 2021
2 parents 68a67fc + a73e97d commit 1701fd4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 53 deletions.
14 changes: 13 additions & 1 deletion src/adapters/givethIo/givethIoAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ const getProjectInfoBySLug = async slug => {
}
`;
const result = await client.request(query, { slug });
return result.projectBySlug;
const project = result.projectBySlug;
const defaultImage =
'https://ipfs.giveth.io/ipfs/QmeVDkwp9nrDsbAxLXY9yNW853C2F4CECC7wdvEJrroTqA';
if (!project.description) {
// because description in givethio is optional but in giveth trace is required
project.description = project.title;
}
if (!project.image || /^\d+$/.test(project.image)) {
// if givethIo image is undefined or is a number (givethIo project with default image have numbers as image)
// I set the our default image for them
project.image = defaultImage;
}
return project;
} catch (e) {
logger.error('getProjectInfoBySLug error', e);
throw new errors.BadRequest('Project in givethIo with this slug not found');
Expand Down
19 changes: 4 additions & 15 deletions src/services/verifiedCampaigns/verifiedCampaigns.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ module.exports = function verifiedCampaigns() {
async create(data, params) {
const { txHash, url, slug } = data;
const projectInfo = await givethIoAdapter.getProjectInfoBySLug(slug);
const {
id: givethIoProjectId,
title,
description: givethIoDescription,
image: givethIoImage,
} = projectInfo;
const defaultImage = '/ipfs/QmeVDkwp9nrDsbAxLXY9yNW853C2F4CECC7wdvEJrroTqA';
const { id: givethIoProjectId, title, description, image } = projectInfo;
const owner = await givethIoAdapter.getUserByUserId(projectInfo.admin);
if (params.user.address.toLowerCase() !== owner.address.toLowerCase()) {
throw new errors.Forbidden('The owner of project in givethIo is not you');
Expand All @@ -27,21 +21,16 @@ module.exports = function verifiedCampaigns() {
if (campaign) {
throw new errors.BadRequest('Campaign with this givethIo projectId exists');
}
const imageIpfsPath = givethIoImage.match(/\/ipfs\/.*/);
const imageIpfsPath = image.match(/\/ipfs\/.*/);
campaign = await app.service('campaigns').create({
title,
url,
slug,
reviewerAddress: config.givethIoProjectsReviewerAddress,

// because description in givethio is optional but in giveth trace is required
description: givethIoDescription || title,
description,
verified: true,
txHash,

// if givethIo image is undefined or is a number
// (givethIo project with default image have numbers as image) I set the our default image for them
image: imageIpfsPath ? imageIpfsPath[0] : defaultImage,
image: imageIpfsPath ? imageIpfsPath[0] : image,
ownerAddress: owner.address,
givethIoProjectId,
});
Expand Down
61 changes: 24 additions & 37 deletions src/utils/tokenHelper.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,58 @@
const config = require('config');
const { ANY_TOKEN } = require('../blockchain/lib/web3Helpers');

let tokensBySymbols;
let tokensByAddress;
let tokensByForeignAddress;
const tokensBySymbols = {};
const tokensByAddress = {};
const tokensByForeignAddress = {};
const validSymbols = [];

const getWhiteListTokens = () => {
return config.get('tokenWhitelist');
};

function getTokenByAddress(address) {
if (!tokensByAddress) {
tokensByAddress = {};
getWhiteListTokens().forEach(token => {
tokensByAddress[token.address] = token;
});
tokensByAddress[ANY_TOKEN.address] = ANY_TOKEN;
}
return tokensByAddress[address];
}

function getTokenByForeignAddress(foreignAddress) {
if (!tokensByForeignAddress) {
tokensByForeignAddress = {};
getWhiteListTokens().forEach(token => {
tokensByForeignAddress[token.foreignAddress] = token;
});
tokensByForeignAddress[ANY_TOKEN.foreignAddress] = ANY_TOKEN;
}
return tokensByForeignAddress[foreignAddress];
}

function getTokenBySymbol(symbol) {
if (!tokensBySymbols) {
tokensBySymbols = {};
getWhiteListTokens().forEach(token => {
tokensBySymbols[token.symbol] = token;
});
tokensBySymbols[ANY_TOKEN.symbol] = ANY_TOKEN;
}
return tokensBySymbols[symbol] || { symbol };
}

const getValidSymbols = () => {
if (validSymbols.length) {
return validSymbols;
}
const initialize = () => {
const _tokenSymbolSet = new Set();

getWhiteListTokens().forEach(token => {
if (!validSymbols.includes(token.symbol)) {
validSymbols.push(token.symbol);
}
if (token.rateEqSymbol && !validSymbols.includes(token.rateEqSymbol)) {
validSymbols.push(token.rateEqSymbol);
tokensByForeignAddress[token.foreignAddress] = token;
tokensByAddress[token.address] = token;
tokensBySymbols[token.symbol] = token;

_tokenSymbolSet.add(token.symbol);
if (token.rateEqSymbol) {
_tokenSymbolSet.add(token.rateEqSymbol);
}
});
config.nativeCurrencyWhitelist.forEach(currency => {
if (!validSymbols.includes(currency.symbol)) {
validSymbols.push(currency.symbol);
}
_tokenSymbolSet.add(currency.symbol);
});
tokensByForeignAddress[ANY_TOKEN.foreignAddress] = ANY_TOKEN;
tokensByAddress[ANY_TOKEN.address] = ANY_TOKEN;
tokensBySymbols[ANY_TOKEN.symbol] = ANY_TOKEN;

validSymbols.push(...Array.from(_tokenSymbolSet));
};

initialize();

const getValidSymbols = () => {
return validSymbols;
};

const isSymbolInTokenWhitelist = symbol => {
return getValidSymbols().includes(symbol);
return validSymbols.includes(symbol);
};

module.exports = {
Expand Down

0 comments on commit 1701fd4

Please sign in to comment.