Skip to content

Commit

Permalink
Handle smart quotes when creating orders (#500)
Browse files Browse the repository at this point in the history
Fix #499
  • Loading branch information
grunch authored Apr 19, 2024
1 parent 439d043 commit 25eb7ad
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions bot/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,46 @@ const validateAdmin = async (ctx, id) => {
}
};

const processParameters = args => {
const correctedArgs = [];
let isGrouping = false;
let groupedString = '';

args.forEach((arg, _) => {
if (arg.startsWith('“') && !isGrouping) {
// Starts a new group, removing the incorrect quotation mark
groupedString = arg.substring(1);
isGrouping = true;
} else if (arg.endsWith('”') && isGrouping) {
// Closes the current group, removing the incorrect quotation mark and adding to the corrected array
groupedString += ' ' + arg.slice(0, -1);
correctedArgs.push(groupedString);
isGrouping = false;
} else if (isGrouping) {
// Continues grouping the elements
groupedString += ' ' + arg;
} else {
// Directly adds items that are outside a group
correctedArgs.push(arg);
}
});

// Handles the case when a group does not close properly
if (isGrouping) {
correctedArgs.push(groupedString);
}

return correctedArgs;
};

const validateSellOrder = async ctx => {
try {
const args = ctx.state.command.args;
let args = ctx.state.command.args;
if (args.length < 4) {
await messages.sellOrderCorrectFormatMessage(ctx);
return false;
}
args = processParameters(args);

let [amount, fiatAmount, fiatCode, paymentMethod, priceMargin] = args;

Expand Down Expand Up @@ -176,11 +209,13 @@ const validateSellOrder = async ctx => {

const validateBuyOrder = async ctx => {
try {
const args = ctx.state.command.args;
let args = ctx.state.command.args;
if (args.length < 4) {
await messages.buyOrderCorrectFormatMessage(ctx);
return false;
}
args = processParameters(args);

let [amount, fiatAmount, fiatCode, paymentMethod, priceMargin] = args;

if (priceMargin && isNaN(priceMargin)) {
Expand Down

0 comments on commit 25eb7ad

Please sign in to comment.