From 3f2a5202b244eaf013639934c603f1ac9eec6aaf Mon Sep 17 00:00:00 2001 From: Ralfs Date: Sat, 10 Apr 2021 01:40:55 +0300 Subject: [PATCH] Heroku --- src/utils.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 0b3acfb..5257932 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -17,14 +17,18 @@ const twilioClient = new Twilio(config.twilioSid, config.twilioToken); export const validateMarginAccount = (client: MangoClient, connection: Connection, dexProgramId: PublicKey, alert: any) => { return new Promise(async (resolve, reject) => { - const mangoGroupPk = new PublicKey(alert.mangoGroupPk); - const marginAccountPk = new PublicKey(alert.marginAccountPk); - const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk); - const marginAccount = await client.getMarginAccount(connection, marginAccountPk, dexProgramId); - if (!mangoGroup || !marginAccount) { + try { + const mangoGroupPk = new PublicKey(alert.mangoGroupPk); + const marginAccountPk = new PublicKey(alert.marginAccountPk); + const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk); + const marginAccount = await client.getMarginAccount(connection, marginAccountPk, dexProgramId); + if (!mangoGroup || !marginAccount) { + reject(new UserError('Invalid margin account or mango group')); + } else { + resolve(); + } + } catch (e) { reject(new UserError('Invalid margin account or mango group')); - } else { - resolve(); } }); }