Guest User

Untitled

a guest
Nov 21st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. function genetationJSON(res) {
  2.  
  3.  
  4. let f = [{
  5. item: {
  6. from: "____XML1",
  7. to: "____XML2",
  8. in: "____rateIn",
  9. out: "____rateOut",
  10. amount: "____reserve",
  11. param: 'manual',
  12. minamount: "____minamount"
  13. }
  14. }];
  15.  
  16. let from = {};
  17. let aliases = [''];
  18. let reserve = {};
  19. for (let i in f) {
  20. if (aliases.indexOf(f[i].item.from) === -1) {
  21. aliases.push(f[i].item.from)
  22. }
  23. if (aliases.indexOf(f[i].item.to) === -1) {
  24. aliases.push(f[i].item.to)
  25. }
  26. const from_index = aliases.indexOf(f[i].item.from);
  27. const to_index = aliases.indexOf(f[i].item.to);
  28. reserve[to_index] = (f[i].item.amount === 0) ? undefined : f[i].item.amount;
  29. if (!from[from_index])
  30. from[from_index] = {
  31. to: {},
  32. in_min_amount: (f[i].item.minamount === 0) ? undefined : f[i].item.minamount
  33. };
  34.  
  35. let rate = {
  36. in: (f[i].item.in === 1) ? undefined : f[i].item.in,
  37. out: (f[i].item.out === 1) ? undefined : f[i].item.out,
  38. in_min_amount: (from[from_index].in_min_amount === f[i].item.minamount) ? undefined : f[i].item.minamount
  39. };
  40.  
  41. if (!rate.in_min_amount && !rate.in && !rate.out) {
  42. rate = 1;
  43. } else if (!rate.in_min_amount && (!!rate.in || !!rate.out)) {
  44. if (rate.in)
  45. rate = rate.in;
  46. if (rate.out)
  47. rate = -rate.out;
  48. }
  49.  
  50. from[from_index].to[to_index] = rate;
  51. }
  52. aliases[0] = undefined;
  53. return {
  54. exchanges: {
  55. currencies: {
  56. aliases: Object.assign({}, aliases),
  57. amounts: reserve
  58. },
  59. from: from,
  60. options: ["manual"]
  61. }
  62. };
  63. }
Add Comment
Please, Sign In to add comment