var priceObj; var cur; var check_shapeshift = false;//checking ShapeShift var shape_cur = {}; //rates ShapeShift var html = ''; var data; var procent_tier_bonus; //var serv_api = '//funcoin.io/'; var serv_api = ''; var crypto_array = { 'BTC': { tochn: 8, crypto: 1 }, 'ETH': { tochn: 6,//д.б. "6" crypto: 1 }, 'SBD': { tochn: 4, crypto: 1 }, 'BTS': { tochn: 5, crypto: 1 }, /* 'DASH': { tochn: 8, crypto: 0 }, 'DAO': { tochn: 16, crypto: 0 }, 'DGD': { tochn: 8,//д.б. "9" crypto: 1 }, 'DOGE': { tochn: 8, crypto: 0 }, 'LTC': { tochn: 8, crypto: 1 }, 'MUSE': { tochn: 4, crypto: 1 }, 'PPC': { tochn: 8, crypto: 1 },*/ }; // Selector $('#buy_form_rq_currency').change( function () { calcPrice(1); }); // Amount Input $('#buy_form_rq_amount').on('input', function () { calcPrice(1); }); $('#buy_form_rq_received').on('input', function () { calcPrice(2); }); // Calculation function calcPrice(forward) { if (cur != null) cur = $('#buy_form_rq_currency').val().toLowerCase(); else cur = 'btc'; //console.log(cur); if (forward == 1) var amount = $('#buy_form_rq_amount').val(); else var amount = $('#buy_form_rq_received').val(); if (cur != "none" && amount >= 0) { priceObj = JSON.parse($('#buy_form_price_matrix').val()); var price = priceObj[cur]; //console.log(cur); check_shapeshift = false; if (!price) { var price = shape_cur[cur]['rate']; //console.log("max: "+shape_cur[cur]['max']); //console.log("min: "+shape_cur[cur]['min']); check_shapeshift = true } // var price = shape_cur[cur]; //console.log('price=' + price); $('#buy_form_rq_price').text(price); /* var toch_big_8 = [ 'BTC',//8 'SBD',//4 'BTS',//5 'DASH',//8 'DAO',//16 'DGD',//9 'DOGE',//8 'LTC',//8 'MUSE',//4 'PPC'//8 ]; var toch_big_6 = [ 'ETH', ];*/ //console.log('cur='+cur); /* if (toch_big_8.in_array(cur.toUpperCase()) || shape_cur[cur]) { var tochn = 8; } else if (toch_big_6.in_array(cur.toUpperCase()) || shape_cur[cur]) { var tochn = 6; } else var tochn = 2;*/ if (cur.toUpperCase() in crypto_array) { var tochn = crypto_array[cur.toUpperCase()]['tochn'] } else { var tochn = 8; } //(crypto_array.toUpperCase().in_array(cur.toUpperCase())) //console.log(tochn); if (forward == 1) { var total = amount / price * (1 + procent_tier_bonus); var tier_bonus = total - amount / price; $('#buy_form_rq_received').val(total.toFixed(4)); $('#bonus_tier').html(tier_bonus.toFixed(4)); } else { var total = amount * price / (1 + procent_tier_bonus); var tier_bonus = amount - amount / (1 + procent_tier_bonus); $('#buy_form_rq_amount').val(total.toFixed(tochn)); $('#bonus_tier').html(tier_bonus.toFixed(4)); } $('#buy_form_res_price').html('( ' + price.toFixed(tochn) + ' ' + cur.toUpperCase() + ' / FUNC ) '); } } function MakeSelectShape() { html = ''; if (indicator != 0) $("#buy_form_rq_currency").append(html); } function getRate(coin_full, coin_short, coin_original) { $.get('https://shapeshift.io/marketinfo/' + coin_short + '_btc', {}, function (response) { if (response.rate) { if (coin_short !== 'xrp' && coin_short !== 'bts') { shape_cur[coin_full]['name'] = coin_original; shape_cur[coin_full]['short'] = coin_short; // shape_cur[coin_full]['rate'] = priceObj['btc'] / response.rate * 1; shape_cur[coin_full]['max'] = response.limit * 1; shape_cur[coin_full]['min'] = response.minimum * 1; shape_cur[coin_full]['fee'] = response.minerFee * 1; } } else shape_cur[coin_full] = false; } ); } $(function () { // Bo READY function $.post( serv_api + "api/index.php", { method: 'getPrices' }, function (res) { $('#buy_form_price_matrix').val(res); calcPrice(1); getShiftCoins(); var te = 9; $(document).ajaxStop(function () { //last ajax call stopped if (te === 9) MakeSelectShape(); te = 1; }); } ); // get Recent $.post( serv_api + "php/stat_api.php", { method: 'recent_buy', num: 18 }, function (res) { //console.log(res); $('#recent_orders').html(res); } ); // Get_Tokens Info $.post( serv_api + "api/index.php", { method: 'stat_tokens_info', }, function (res) { res = JSON.parse(res); $('.stat_tokens_bought').html(res.bought); $('.stat_tokens_left').html(res.left); } ); function getShiftCoins() { $.get( "https://shapeshift.io/getcoins", {}, function (data) { for (var key in data) { if (data[key]['status'] == 'available' && data[key]['name'].toLowerCase() != 'bitcoin') { //html += ''; shape_cur[data[key]['name'].toLowerCase()] = {}; getRate(data[key]['name'].toLowerCase(), data[key]['symbol'].toLowerCase(), data[key]['name']); } else { //console.log(data[key]['name'].toLowerCase()); } } } ); } }); $(document).ready(function () { // BACK stage $('#back_stage').click(function () { setTimeout(function () { $('#first_stage').fadeIn() }, 300); $('#second_stage').fadeOut(300);//style.display='block'; }); function is_number(x) { if (x * 1 == x) return true; return false; } $('#buy_form_rq_amount').on('input', function () { var amount = $(this).val(); if ((!is_number(amount)) || (!amount)) { $('#buy_form_rq_amount').addClass('un_valid'); return false; } ; $('#buy_form_rq_amount').removeClass('un_valid'); }); $('#buy_form_rq_account').on('input', function () { var account = $('#buy_form_rq_account').val(); if (!account) { $('#buy_form_rq_account').addClass('un_valid'); return false; } ; $('#buy_form_rq_account').removeClass('un_valid'); }); // Second stage $('#next_stage').click(function () { var amount = $('#buy_form_rq_amount').val() * 1; if ((!is_number(amount)) || (!amount)) { $('#buy_form_rq_amount').addClass('un_valid'); return false; } ; var min_btsr = 100; var current_btsr = $('#buy_form_rq_received').val(); //console.log(current_btsr); if (current_btsr < min_btsr || isNaN(current_btsr)) { $('#btsr_min').addClass('btsr_min'); return false; } //console.log(current_btsr); //console.log(amount); //console.log(check_shapeshift); //console.log("===================="); if (check_shapeshift == true) { if (amount > shape_cur[cur]['max']) { $('#btsr_min').removeClass('btsr_min'); $('#shape_shift_min').addClass('btsr_min'); $('#shape_shift_min').html("Maximum amount for automatic exchange: " + shape_cur[cur]['max'] + " " + cur.toUpperCase()); return false; } if (amount < shape_cur[cur]['min']) { $('#btsr_min').removeClass('btsr_min'); $('#shape_shift_min').addClass('btsr_min'); $('#shape_shift_min').html("Minimum amount for automatic exchange: " + shape_cur[cur]['min'] + " " + cur.toUpperCase()); return false; } } $('#buy_form_rq_amount').removeClass('un_valid'); $('#btsr_min').removeClass('btsr_min'); $('#shape_shift_min').removeClass('btsr_min'); setTimeout(function () { $('#second_stage').fadeIn() }, 300); $('#first_stage').fadeOut(300);//style.display='block'; }); // Third stage $('#send_stage').click(function () { var account = $('#buy_form_rq_account').val(); if (!account) { $('#buy_form_rq_account').addClass('un_valid'); return false; } $('#buy_form_rq_account').removeClass('un_valid'); //if (crypto_array.in_array($('#buy_form_rq_currency').val().toUpperCase())) { if ((cur.toUpperCase() in crypto_array) && (crypto_array[$('#buy_form_rq_currency').val().toUpperCase()]['crypto'] == 1)) { var method = 'order'; $('.notification_for_user').css('display', 'block'); } else if (check_shapeshift) { var method = 'order_shape'; $('.notification_for_user').css('display', 'none'); } else { var method = 'fiat_order'; $('.notification_for_user').css('display', 'none'); } data = { 'method': method, 'json': true, 'capcha': $('#buy_form').serializeArray()[0]['value'], 'currency': $('#buy_form_rq_currency').val(), 'account': $('#buy_form_rq_account').val(), 'amount': $('#buy_form_rq_amount').val(), 'price': $('#buy_form_rq_price').text(), 'email': $('#buy_form_rq_email').val(), 'deposit': $('#buy_form_rq_memo').val(), //this is field MEMO 'promo': $('#buy_form_rq_promo').val(), }; setTimeout(function () { $('#third_stage').fadeIn() }, 300); $('#second_stage').fadeOut(300); if (method === 'order_shape') { $('#response_shapeshift').css('display', 'block'); pay_button_clicked(); $('.status-window').animate({ height: '154px' }, 500, 'easeInOutExpo'); } else { $.post(serv_api + 'api/index.php', data, function (response) { if (response.error) { $('#response_fiat').css('display', 'block'); $('#response_fiat').html('