Skip to content

Commit

Permalink
prevent duplicate tokens being added in adminJS
Browse files Browse the repository at this point in the history
  • Loading branch information
RamRamez committed Oct 2, 2024
1 parent 0415865 commit b125c2a
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 @@ -130,6 +130,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 b125c2a

Please sign in to comment.