Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1096: Backward compatibility of Alice Bob endpoints #118

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import { createAliceBobOrder } from './utils/alice-bob/create-alice-bob-order';
import { estimateAliceBobOutput } from './utils/alice-bob/estimate-alice-bob-output';
import { getAliceBobOrderInfo } from './utils/alice-bob/get-alice-bob-order-info';
import { getAliceBobPairInfo } from './utils/alice-bob/get-alice-bob-pair-info';
import { getAliceBobPairsInfo } from './utils/alice-bob/get-alice-bob-pairs-info';
import { coinGeckoTokens } from './utils/gecko-tokens';
import { getExternalApiErrorPayload, isDefined, isNonEmptyString } from './utils/helpers';
Expand Down Expand Up @@ -149,7 +150,7 @@
await redisClient.lpush('notifications', JSON.stringify(newNotification));

res.status(200).send({ message: 'Notification added successfully' });
} catch (error: any) {

Check warning on line 153 in src/index.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

Unexpected any. Specify a different type
res.status(500).send({ error: error.message });
}
});
Expand Down Expand Up @@ -205,12 +206,13 @@
});

app.post('/api/alice-bob/create-order', async (_req, res) => {
const { amount, from, to, userId, walletAddress, cardNumber } = _req.query;
const { isWithdraw, amount, from, to, userId, walletAddress, cardNumber } = _req.query;
const booleanIsWithdraw = isWithdraw === 'true';

try {
const exchangeInfo = {
from: String(from),
to: String(to),
from: isDefined(isWithdraw) ? (booleanIsWithdraw ? 'TEZ' : 'CARDUAH') : String(from),
to: isDefined(isWithdraw) ? (booleanIsWithdraw ? 'CARDUAH' : 'TEZ') : String(to),
lendihop marked this conversation as resolved.
Show resolved Hide resolved
fromAmount: Number(amount),
userId: String(userId),
toPaymentDetails: isDefined(cardNumber) ? String(cardNumber) : String(walletAddress),
Expand Down Expand Up @@ -239,6 +241,19 @@
}
});

app.get('/api/alice-bob/get-pair-info', async (_req, res) => {
const { isWithdraw } = _req.query;

try {
const pairInfo = await getAliceBobPairInfo(isWithdraw === 'true');

res.status(200).send({ pairInfo });
} catch (error) {
const { status, data } = getExternalApiErrorPayload(error);
res.status(status).send(data);
}
});

app.get('/api/alice-bob/get-pairs-info', async (_req, res) => {
const { isWithdraw } = _req.query;

Expand Down Expand Up @@ -266,14 +281,16 @@
});

app.post('/api/alice-bob/estimate-amount', async (_req, res) => {
const { amount, from, to } = _req.query;
const { isWithdraw, amount, from, to } = _req.query;
const booleanIsWithdraw = isWithdraw === 'true';

try {
const exchangeInfo = {
from: String(from),
to: String(to),
from: isDefined(isWithdraw) ? (booleanIsWithdraw ? 'TEZ' : 'CARDUAH') : String(from),
to: isDefined(isWithdraw) ? (booleanIsWithdraw ? 'CARDUAH' : 'TEZ') : String(to),
fromAmount: Number(amount)
};

const outputAmount = await estimateAliceBobOutput(exchangeInfo);

res.status(200).send({ outputAmount });
Expand Down
15 changes: 15 additions & 0 deletions src/utils/alice-bob/get-alice-bob-pair-info.ts
lendihop marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { aliceBobApi } from '../api.sevice';
import { getAliceBobRequestHeaders } from './get-alice-bob-request-headers';
import { getAliceBobSignature } from './get-alice-bob-signature';

export const getAliceBobPairInfo = async (isWithdraw = false) => {
const pair = isWithdraw ? 'TEZ/CARDUAH' : 'CARDUAH/TEZ';

const { signature, now } = getAliceBobSignature();

const { data } = await aliceBobApi.get<{ minamount: number; maxamount: number }>('/get-pair-info/' + pair, {
headers: getAliceBobRequestHeaders(signature, now)
});

return { minAmount: data.minamount, maxAmount: data.maxamount };
};
Loading