Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function genetationJSON(res) {
- let f = [{
- item: {
- from: "____XML1",
- to: "____XML2",
- in: "____rateIn",
- out: "____rateOut",
- amount: "____reserve",
- param: 'manual',
- minamount: "____minamount"
- }
- }];
- let from = {};
- let aliases = [''];
- let reserve = {};
- for (let i in f) {
- if (aliases.indexOf(f[i].item.from) === -1) {
- aliases.push(f[i].item.from)
- }
- if (aliases.indexOf(f[i].item.to) === -1) {
- aliases.push(f[i].item.to)
- }
- const from_index = aliases.indexOf(f[i].item.from);
- const to_index = aliases.indexOf(f[i].item.to);
- reserve[to_index] = (f[i].item.amount === 0) ? undefined : f[i].item.amount;
- if (!from[from_index])
- from[from_index] = {
- to: {},
- in_min_amount: (f[i].item.minamount === 0) ? undefined : f[i].item.minamount
- };
- let rate = {
- in: (f[i].item.in === 1) ? undefined : f[i].item.in,
- out: (f[i].item.out === 1) ? undefined : f[i].item.out,
- in_min_amount: (from[from_index].in_min_amount === f[i].item.minamount) ? undefined : f[i].item.minamount
- };
- if (!rate.in_min_amount && !rate.in && !rate.out) {
- rate = 1;
- } else if (!rate.in_min_amount && (!!rate.in || !!rate.out)) {
- if (rate.in)
- rate = rate.in;
- if (rate.out)
- rate = -rate.out;
- }
- from[from_index].to[to_index] = rate;
- }
- aliases[0] = undefined;
- return {
- exchanges: {
- currencies: {
- aliases: Object.assign({}, aliases),
- amounts: reserve
- },
- from: from,
- options: ["manual"]
- }
- };
- }
Add Comment
Please, Sign In to add comment