<commit_before>var app = app || {};

app.abstracts = app.abstracts || {};

app.abstracts.PaymentMethod = (function() {

	'use strict';

	return {

		// The `label` attribute is the name of the cryptocurrency that will be shown in the UI.
		label: null,

		// The `code` attribute is the short-name of the currency, typically used for reference purposes.
		code: null,

		// The `settings` array will allow the end-user (merchant) to configure this cryptocurrency.
		settings: [
			// {
			// 	name: 'some-field',
			// 	label: 'Some Field (for Humans)',
			// 	type: 'text',
			// 	required: true,
			// 	validate: function(value) {
			// 		// For checking the form value for this field.
			// 		// Throw an error if the value is invalid. Like this:
			// 		throw new Error('Some field is invalid!');
			// 	}
			// }
		],

		/*
			`amount` .. A valid number
			`cb(error, paymentRequest)`:
				`error`          .. An error object if some problem occurs while generating the payment request
				`paymentRequest` .. An object containing at least the following information:
					`uri`        .. URI (e.g "bitcoin:ADDRESS?amount=AMOUNT")
					`amount`     .. The amount requested.
					`address`    .. The address to which to send the funds.
		*/
		generatePaymentRequest: function(amount, cb) {
			_.defer(function() {
				cb(new Error('This payment method has not implemented the generatePaymentRequest(amount, cb) method.'));
			});
		},

		/*
			`cb(error, rates)`:
				`error`	.. An error object if some problem occurs while generating the payment request
				`rates`	.. An object containing conversion rates for all supported currencies. E.g:
							{ 'USD': '0.0012', 'EUR': '0.00091' }
		*/
		getExchangeRates: function(cb) {
			_.defer(function() {
				cb(new Error('This payment method has not implemented the `getExchangeRates` method.'));
			});
		},

		/*
			`paymentRequest` .. A cryptocurrency payment request (e.g "bitcoin:ADDRESS?amount=AMOUNT")
			`cb(error, wasReceived)`:
				`error` .. An error object or NULL
				`wasReceived` .. TRUE or FALSE
		*/
		checkPaymentReceived: function(paymentRequest, cb) {
			_.defer(function() {
				cb(new Error('This payment method has not implemented the `checkPaymentReceived` method.'));
			});
		},

		convertAmount: function(amount, fromCurrency, cb) {

			_.defer(_.bind(function() {

				try {
					amount = new BigNumber(amount);
				} catch (error) {
					return cb(new Error('Invalid "amount". Number expected.'));
				}

				if (!_.isString(fromCurrency)) {
					return cb(new Error('Invalid "fromCurrency". String expected.'));
				}

				fromCurrency = fromCurrency.toUpperCase();

				this.getExchangeRates(function(error, rates) {

					if (error) {
						return cb(error);
					}

					if (_.isUndefined(rates[fromCurrency])) {
						return cb(new Error('Conversion rate not found for given currency: "' + fromCurrency + '"'));
					}

					var rate = rates[fromCurrency];
					amount = amount.dividedBy(rate);
					// Maximum of 8 decimal places.
					amount = amount.decimalPlaces(8);
					cb(null, amount.toString(), rate, fromCurrency);
				});
<commit_msg>Fix for monero as display currency<commit_after>var app = app || {};

app.abstracts = app.abstracts || {};

app.abstracts.PaymentMethod = (function() {

	'use strict';

	return {

		// The `label` attribute is the name of the cryptocurrency that will be shown in the UI.
		label: null,

		// The `code` attribute is the short-name of the currency, typically used for reference purposes.
		code: null,

		// The `settings` array will allow the end-user (merchant) to configure this cryptocurrency.
		settings: [
			// {
			// 	name: 'some-field',
			// 	label: 'Some Field (for Humans)',
			// 	type: 'text',
			// 	required: true,
			// 	validate: function(value) {
			// 		// For checking the form value for this field.
			// 		// Throw an error if the value is invalid. Like this:
			// 		throw new Error('Some field is invalid!');
			// 	}
			// }
		],

		/*
			`amount` .. A valid number
			`cb(error, paymentRequest)`:
				`error`          .. An error object if some problem occurs while generating the payment request
				`paymentRequest` .. An object containing at least the following information:
					`uri`        .. URI (e.g "bitcoin:ADDRESS?amount=AMOUNT")
					`amount`     .. The amount requested.
					`address`    .. The address to which to send the funds.
		*/
		generatePaymentRequest: function(amount, cb) {
			_.defer(function() {
				cb(new Error('This payment method has not implemented the generatePaymentRequest(amount, cb) method.'));
			});
		},

		/*
			`cb(error, rates)`:
				`error`	.. An error object if some problem occurs while generating the payment request
				`rates`	.. An object containing conversion rates for all supported currencies. E.g:
							{ 'USD': '0.0012', 'EUR': '0.00091' }
		*/
		getExchangeRates: function(cb) {
			_.defer(function() {
				cb(new Error('This payment method has not implemented the `getExchangeRates` method.'));
			});
		},

		/*
			`paymentRequest` .. A cryptocurrency payment request (e.g "bitcoin:ADDRESS?amount=AMOUNT")
			`cb(error, wasReceived)`:
				`error` .. An error object or NULL
				`wasReceived` .. TRUE or FALSE
		*/
		checkPaymentReceived: function(paymentRequest, cb) {
			_.defer(function() {
				cb(new Error('This payment method has not implemented the `checkPaymentReceived` method.'));
			});
		},

		convertAmount: function(amount, fromCurrency, cb) {

			_.defer(_.bind(function() {

				try {
					amount = new BigNumber(amount);
				} catch (error) {
					return cb(new Error('Invalid "amount". Number expected.'));
				}

				if (!_.isString(fromCurrency)) {
					return cb(new Error('Invalid "fromCurrency". String expected.'));
				}

				fromCurrency = fromCurrency.toUpperCase();

				var toCurrency = this.code;
				var paymentMethod = _.findWhere(app.paymentMethods, { code: fromCurrency });
				var getExchangeRates;

				if (paymentMethod) {
					getExchangeRates = _.bind(paymentMethod.getExchangeRates, paymentMethod);
				} else {
					getExchangeRates = _.bind(this.getExchangeRates, this);
				}

				getExchangeRates(function(error, rates) {

					if (error) {
						return cb(error);
					}

					var rate;

					if (paymentMethod) {
						rate = rates[toCurrency];
						amount = amount.times(rate);
					} else {
						rate = rates[fromCurrency];
						amount = amount.dividedBy(rate);
					}

					if (!rate) {
						return cb(new Error('Conversion rate not found for given currency: "' + fromCurrency + '"'));
					}

					// Maximum of 8 decimal places.
					amount = amount.decimalPlaces(8);
					cb(null, amount.toString(), rate, fromCurrency);
				});

{'fraction_non_alphanumeric': 0.1332636919862707, 'fraction_numerical': 0.003880017907774959, 'mean_word_length': 2.8539390454284073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '495803', 'n_tokens_mistral': 2497, 'n_tokens_neox': 1972, 'n_words': 614}