Skip to content

Commit

Permalink
Merge pull request #1852 from Giveth/prevent-duplicate-tokens-being-a…
Browse files Browse the repository at this point in the history
…dded-in-admin

prevent duplicate tokens being added in adminJS
  • Loading branch information
RamRamez authored Oct 2, 2024
2 parents 0c0aea2 + e4d210f commit 046b6e8
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/server/adminJs/tabs/tokenTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,43 @@ export const createToken = async (
organizations,
} = request.payload;
try {
if (!address || !decimals || !name || !networkId || !symbol) {
message = 'Please fill all required fields';
type = 'danger';
return {
notice: {
message,
type,
},
};
}
const duplicateAddress = await Token.createQueryBuilder('token')
.where('LOWER(token.address) = LOWER(:address)', { address })
.andWhere('token.networkId = :networkId', {
networkId: Number(networkId),
})
.getOne();

const duplicateSymbol = await Token.createQueryBuilder('token')
.where('LOWER(token.symbol) = LOWER(:symbol)', { symbol })
.andWhere('token.networkId = :networkId', {
networkId: Number(networkId),
})
.getOne();

if (duplicateSymbol || duplicateAddress) {
message = `Token ${
duplicateAddress ? 'address' : 'symbol'
} already exists!`;
type = 'danger';
return {
record: {},
notice: {
message,
type,
},
};
}
newToken = Token.create({
name,
symbol,
Expand Down

0 comments on commit 046b6e8

Please sign in to comment.