I have a simple Express API here.
When the user submits the chain param I want to convert the parameter to an object.
Depending on the input the object will have different values
Right now I just have a bunch of if statements stacked
Is there a better practice solution to implement this as this is quite clunky?
app.get('/gettokens/:chain/:address', async(req, res) => {
const address = req.params.address;
let chain = req.params.chain;
if (chain == 'bsc') {
chain = {
moralis: 'bsc',
coingecko: 'binance-smart-chain'
}
}
if (chain == 'eth') {
chain = {
moralis: 'eth',
coingecko: 'ethereum'
}
}
if (chain == 'avax') {
chain = {
moralis: 'avalanche',
coingecko: 'avalanche'
}
}
if (chain == 'matic') {
chain = {
moralis: 'matic',
coingecko: 'polygon-pos'
}
}