Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Prince/ Incorrect error message payment agent transfer #6627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/javascript/app/common/form_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,21 @@ const Validation = (() => {
message = localize('Should be less than [_1]', addComma(options.max, options.format_money ? getDecimalPlaces(Client.get('currency')) : undefined));
}

// Priority Validation
if ('balance' in options && isLessThanBalance(value, options)) {
is_ok = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this variable to something clearer. Like is_what_ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Carol IMO we can leave it as it is otherwise we will be needing to change the variable name in the entire project. The whole validation helper have different functions inside that use the same is_ok variable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can leave it as it is now but we should consider better variables.

message = localize('Insufficient balance.');
}

ValidatorsMap.get().number.message = message;
return is_ok;
};

const isMoreThanMax = (value, options) =>
(options.type === 'float' ? +value > +options.max : compareBigUnsignedInt(value, options.max) === 1);

const isLessThanBalance = (value,options) => options.balance < value;

const validTaxID = (value, options, field) => {
// input is valid in API regex but may not be valid for country regex
if (/^[a-zA-Z0-9]*[\w-]*$/.test(value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/app/pages/cashier/payment_agent_withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const PaymentAgentWithdraw = (() => {
$form.find('.wrapper-row-agent').find('label').append($('<span />', { text: '*', class: 'required_field_asterisk' }));
$form.find('label[for="txtAmount"]').text(`${localize('Amount in')} ${Currency.getCurrencyDisplayCode(currency)}`);
FormManager.init(form_id, [
{ selector: field_ids.txt_amount, validations: ['req', ['number', { type: 'float', decimals: Currency.getDecimalPlaces(currency), min, max }], ['custom', { func: () => +Client.get('balance') >= +$txt_amount.val(), message: localize('Insufficient balance.') }]], request_field: 'amount' },
{ selector: field_ids.txt_amount, validations: ['req', ['number', { type: 'float', decimals: Currency.getDecimalPlaces(currency), min, max, balance: Client.get('balance') }]], request_field: 'amount' },
{ selector: field_ids.txt_payment_ref, validations: [['length', { min: 0, max: 30 }], ['regular', { regex: /^[0-9A-Za-z .,'-]{0,30}$/, message: localize('Only letters, numbers, space, hyphen, period, comma, and apostrophe are allowed.') }]], request_field: 'description', value: () => $txt_payment_ref.val() ? payment_ref_prefix + $txt_payment_ref.val() : '' },

{ request_field: 'currency', value: currency },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PaymentAgentTransfer = (() => {

FormManager.init(form_id, [
{ selector: '#client_id', validations: ['req', ['regular', { regex: /^\w+\d+$/, message: localize('Please enter a valid Login ID.') }]], request_field: 'transfer_to' },
{ selector: '#amount', validations: ['req', ['number', { type: 'float', decimals: getDecimalPlaces(currency), min: pa ? pa.min_withdrawal : 10, max: max_withdrawal(balance, pa, 2000) }], ['custom', { func: () => +Client.get('balance') >= +$('#amount').val(), message: localize('Insufficient balance.') }]] },
{ selector: '#amount', validations: ['req', ['number', { type: 'float', decimals: getDecimalPlaces(currency), min: pa ? pa.min_withdrawal : 10, max: max_withdrawal(balance, pa, 2000),balance: Client.get('balance') }]] },
{ selector: '#description', validations: ['general'] },

{ request_field: 'dry_run', value: 1 },
Expand Down