Refactoring

This commit is contained in:
viktor 2017-06-26 23:24:10 +03:00
parent 8dad644e9a
commit eaf322374f
258 changed files with 646 additions and 42223 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
web/node_modules
web/public/node_modules
**/*.DS_Store

View File

@ -13,16 +13,17 @@ var config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
var twilioClient = twilio(config.sendSMS.twilio.accountSIDLive, config.sendSMS.twilio.authTokenLive);
var MongoClient = mongodb.MongoClient;
var provider = require('./helpers/basicauthhttpprovider');
var web3;
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
if (config.environment == "live")
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc.live));
else if (config.environment == "dev")
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc.test));
if (config.environment == "live") {
web3 = new Web3(new provider(config.smartContract.rpc[config.environment], config.smartContract.rpc.user, config.smartContract.rpc.pass));
}
else
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc.test));
web3 = new Web3(new Web3.providers.HttpProvider(config.smartContract.rpc[config.environment]));
}
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
@ -38,16 +39,8 @@ app.twilioClient = twilioClient;
app.web3 = web3;
app.crypto = crypto;
if (config.environment == "live") {
app.contractAddress = config.smartContract.contractAddress.live;
app.contractWallet = config.smartContract.wallet.live;
} else if (config.environment == "dev") {
app.contractAddress = config.smartContract.contractAddress.test;
app.contractWallet = config.smartContract.wallet.test;
} else {
app.contractAddress = config.smartContract.contractAddress.test;
app.contractWallet = config.smartContract.wallet.test;
}
app.contractAddress = config.smartContract.contractAddress[config.environment];
app.contractWallet = config.smartContract.wallet[config.environment];
app.MongoClient = MongoClient;

View File

@ -4,100 +4,82 @@ module.exports = function (app) {
var mongodbConnectionString = app.config.mongodbConnectionString;
var randomInt = app.randomInt;
var attachToContract = app.attachToContract;
var generateError = app.generateError;
app.get('/', function(request, response) {
attachToContract(function(err, contract) {
if (err) {
console.log(err);
response.render("index", {
address: app.contractAddress
});
} else {
response.render("index", {
address: app.contractAddress
});
return;
}
response.render("index", {
address: app.contractAddress
});
});
});
app.post('/sendCodeBySMS', function(request, response) {
console.log(request.body);
var globalToken = request.body.globalToken;
if (globalToken == app.config.globalToken) {
var to = request.body.to;
var code = randomInt(100000,1000000);
twilioClient.messages.create({
body: code,
to: "+" + to,
from: app.config.sendSMS.twilio.phoneNumberLive
}, function(err, message) {
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
var to = request.body.to;
var code = randomInt(100000,1000000);
twilioClient.messages.create({
body: code,
to: "+" + to,
from: app.config.sendSMS.twilio.phoneNumberLive
}, function(err, message) {
if (err) {
console.log(err);
generateError(response, 500, "Can't send sms", err.message);
return;
}
console.log("message.sid: " + message.sid);
insertSentCodeToDB(to, code, function(err) {
if (err) {
console.log(err);
response.send({
error : {
code : 500,
title : "Can't send sms",
message : err.message
}
});
} else {
console.log("message.sid: " + message.sid);
insertSentCodeToDB(to, code, function(err) {
if (err) {
console.log(err);
response.send({
error : {
code : 500,
title : "Can't insert code to db",
message : err.message
}
});
} else {
console.log("sms code:" + code);
response.send({
success : {
code : 200,
title : "Success",
message : "SMS successfully sent"
}
});
}
});
generateError(response, 500, "Can't insert code to db", err.message);
return;
}
console.log("sms code:" + code);
response.send({
success : {
code : 200,
title : "Success",
message : "SMS successfully sent"
}
});
});
} else {
response.send({
error : {
code : 401,
title : "Unauthorized",
message : "Wrong app token"
}
});
}
});
});
function insertSentCodeToDB(phone, code, cb) {
MongoClient.connect(mongodbConnectionString, function(err, db) {
if(err) {
cb(err);
} else {
var collection = db.collection('PhoneCodes');
collection.remove({phone: phone}, function(err, result) {
if(err) {
db.close();
cb(err);
} else {
collection.insert({phone: phone, code: code}, function(err, docs) {
if(err) {
db.close();
cb(err);
} else {
db.close();
cb(null);
}
});
}
});
}
if(err) return cb(err);
var collection = db.collection('PhoneCodes');
collection.remove({phone: phone}, function(err, result) {
if (err) {
db.close();
return cb(err);
}
collection.insert({phone: phone, code: code}, function(err, docs) {
db.close();
if (err) return cb(err);
cb(null);
});
});
});
}
@ -106,75 +88,52 @@ module.exports = function (app) {
var globalToken = request.body.globalToken;
var code = request.body.code;
var phone = request.body.phone;
if (globalToken == app.config.globalToken) {
MongoClient.connect(mongodbConnectionString, function(err, db) {
if(err) {
response.send({
error : {
code : 500,
title : "Error",
message: err.message
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
MongoClient.connect(mongodbConnectionString, function(err, db) {
if (err) {
generateError(response, 500, "Error", err.message);
return;
}
var collection = db.collection('PhoneCodes');
collection.find({"code": parseInt(code), "phone": phone }, function(err, cursor) {
if (err) {
console.log(err);
generateError(response, 500, "Error", "Wrong code");
return;
}
cursor.toArray(function(err, results) {
console.log(err);
if (!results) {
generateError(response, 500, "Error", "Wrong code");
return;
}
if (results.length == 0) {
generateError(response, 500, "Error", "Wrong code");
return;
}
var hash = app.crypto.createHmac('sha256', app.config.salt)
.update(code)
.digest('hex');
console.log(hash);
console.log(results);
var result = results[0];
response.send({
success : {
code : 200,
message: hash
}
});
} else {
var collection = db.collection('PhoneCodes');
collection.find({"code": parseInt(code), "phone": phone }, function(err, cursor) {
if (err) {
console.log(err);
response.send({
error : {
code : 500,
title : "Error",
message: "Wrong code"
}
});
} else {
cursor.toArray(function(err, results) {
console.log(err);
if (!results) {
response.send({
error : {
code : 500,
title : "Error",
message: "Wrong code"
}
});
} else if (results.length > 0) {
var hash = app.crypto.createHmac('sha256', app.config.salt)
.update(code)
.digest('hex');
console.log(hash);
console.log(results);
var result = results[0];
response.send({
success : {
code : 200,
message: hash
}
});
} else {
response.send({
error : {
code : 500,
title : "Error",
message: "Wrong code"
}
});
}
db.close();
});
}
});
}
db.close();
});
});
} else {
response.send({
error : {
code : 401,
title : "Unauthorized",
message : "Wrong app token"
}
});
}
});
});
}

View File

@ -0,0 +1,146 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file httpprovider.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
"use strict";
var errors = require('web3/lib/web3/errors');
// workaround to use httpprovider in different envs
var XMLHttpRequest; // jshint ignore: line
// browser
if (typeof window !== 'undefined' && window.XMLHttpRequest) {
XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line
// node
} else {
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line
}
/**
* HttpProvider should be used to send rpc calls over http
*/
var HttpProvider = function (host, user, pass) {
this.host = host || 'http://localhost:8545';
this.authorizationHeader = 'Basic ' + (new Buffer(user + ':' + pass)).toString('base64');
this.user = user;
this.pass = pass;
};
/**
* Should be called to prepare new XMLHttpRequest
*
* @method prepareRequest
* @param {Boolean} true if request should be async
* @return {XMLHttpRequest} object
*/
HttpProvider.prototype.prepareRequest = function (async) {
var request = new XMLHttpRequest();
request.open('POST', this.host, async);
request.setRequestHeader('Content-Type','application/json');
request.setRequestHeader('Authorization', this.authorizationHeader);
return request;
};
/**
* Should be called to make sync request
*
* @method send
* @param {Object} payload
* @return {Object} result
*/
HttpProvider.prototype.send = function (payload) {
var request = this.prepareRequest(false);
try {
request.send(JSON.stringify(payload));
} catch(error) {
throw errors.InvalidConnection(this.host);
}
var result = request.responseText;
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(request.responseText);
}
return result;
};
/**
* Should be used to make async request
*
* @method sendAsync
* @param {Object} payload
* @param {Function} callback triggered on end with (err, result)
*/
HttpProvider.prototype.sendAsync = function (payload, callback) {
var request = this.prepareRequest(true);
request.onreadystatechange = function() {
if (request.readyState === 4) {
var result = request.responseText;
var error = null;
try {
result = JSON.parse(result);
} catch(e) {
error = errors.InvalidResponse(request.responseText);
}
callback(error, result);
}
};
try {
request.send(JSON.stringify(payload));
} catch(error) {
callback(errors.InvalidConnection(this.host));
}
};
/**
* Synchronously tries to make Http request
*
* @method isConnected
* @return {Boolean} returns true if request haven't failed. Otherwise false
*/
HttpProvider.prototype.isConnected = function() {
try {
this.send({
id: 9999999999,
jsonrpc: '2.0',
method: 'net_listening',
params: []
});
return true;
} catch(e) {
return false;
}
};
module.exports = HttpProvider;

View File

@ -1,7 +1,18 @@
module.exports = function (app) {
app.randomInt = randomInt;
app.generateError = generateError;
function randomInt (low, high) {
return Math.floor(Math.random() * (high - low) + low);
}
function generateError (response, code, title, message) {
response.send({
error : {
code : code,
title : title,
message : message
}
});
}
};

View File

@ -1,5 +1,6 @@
module.exports = function (app) {
var web3 = app.web3;
var generateError = app.generateError;
var contract;
app.attachToContract = attachToContract;
@ -8,187 +9,165 @@ module.exports = function (app) {
function attachToContract(cb) {
if(!web3.isConnected()) {
if (cb) {
cb({code: 200, title: "Error", message: "check RPC"}, null);
}
} else {
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[1];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
var MyContract = web3.eth.contract(contractABI);
contract = MyContract.at(app.contractAddress);
if (cb) {
cb(null, contract);
}
if (cb) cb({code: 200, title: "Error", message: "check RPC"}, null);
return;
}
console.log(web3.eth.accounts);
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log("web3.eth.defaultAccount:");
console.log(web3.eth.defaultAccount);
var MyContract = web3.eth.contract(contractABI);
contract = MyContract.at(app.contractAddress);
if (cb) cb(null, contract);
}
function newPhoneToAddr(wallet, phone, cb) {
if(!web3.isConnected()) {
cb({code: 500, title: "Error", message: "check RPC"}, null);
} else {
contract.newPhoneToAddr.sendTransaction(wallet, phone, {gas: 100000, from: web3.eth.defaultAccount}, function(err, result) {
cb(err, result);
});
if (cb) cb({code: 500, title: "Error", message: "check RPC"}, null);
return;
}
contract.newPhoneToAddr.sendTransaction(wallet, phone, {gas: 100000, from: web3.eth.defaultAccount}, function(err, result) {
cb(err, result);
});
}
app.post('/newPhoneToAddr', function(request, response) {
var globalToken = request.body.globalToken;
if (globalToken == app.config.globalToken) {
var phone = parseInt(request.body.phone);
var wallet = request.body.wallet;
var code = request.body.code;
console.log(wallet);
console.log(request.body.wallet);
var isHex = /^0x[0-9A-Fa-f]{40}$/i.test(wallet);
if (isHex) {
contract.getPaymentByAddress.call(wallet, function(err, val) {
console.log("err:");
console.log(err);
console.log("val:");
console.log(val);
if (val > 0) {
contract.getPaymentDataByAddress.call(wallet, function(err, paymentData) {
console.log("err:");
console.log(err);
console.log("paymentData:");
console.log(paymentData);
var hash = app.crypto.createHmac('sha256', app.config.salt)
.update(code)
.digest('hex');
console.log("hash:");
console.log(hash);
//var hashBuf = new Buffer(hash, 'binary').toString('hex');
//console.log("hashBuf:");
//console.log(hashBuf.toString());
console.log(paymentData.substring(2) + " == " + hash);
if (paymentData.substring(2) == hash) {
newPhoneToAddr(wallet, phone, function(err, result) {
console.log(err);
console.log(result);
response.send({
success : {
code : 200,
title : "Success",
message : "Phone successfully joined"
}
});
});
} else {
response.send({
error : {
code : 1000,
title : "Warning",
message : "Sent message doesn't match with the one displayed on the page"
}
});
}
});
} else {
response.send({
error : {
code : 1000,
title : "Warning",
message : "Payment wasn't sent yet"
}
});
}
});
} else {
response.send({
error : {
code : 500,
title : "Error",
message : "Not valid address"
}
});
}
} else {
response.send({
error : {
code : 401,
title : "Unauthorized",
message : "Wrong app token"
}
});
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
});
app.post('/getPhoneByAddress', function(request, response) {
var globalToken = request.body.globalToken;
if (globalToken == app.config.globalToken) {
var wallet = request.body.wallet;
var isHex = /^0x[0-9A-Fa-f]{40}$/i.test(wallet)
if (isHex) {
var phone = parseInt(request.body.phone);
var wallet = request.body.wallet;
var code = request.body.code;
console.log(wallet);
console.log(request.body.wallet);
var isHex = /^0x[0-9A-Fa-f]{40}$/i.test(wallet);
var phone = contract.getPhoneByAddress.call(wallet, function(err, obj) {
console.log("err:");
if (!isHex) {
generateError(response, 500, "Error", "Not valid address");
return;
}
if (!contract) {
generateError(response, 500, "Error", "RPC doesn't work");
return;
}
contract.getPaymentByAddress.call(wallet, function(err, val) {
console.log("err:");
console.log(err);
console.log("val:");
console.log(val);
if (val <= 0) {
generateError(response, 1000, "Warning", "Payment wasn't sent yet");
return;
}
contract.getPaymentDataByAddress.call(wallet, function(err, paymentData) {
console.log("err:");
console.log(err);
console.log("paymentData:");
console.log(paymentData);
var hash = app.crypto.createHmac('sha256', app.config.salt)
.update(code)
.digest('hex');
console.log("hash:");
console.log(hash);
//var hashBuf = new Buffer(hash, 'binary').toString('hex');
//console.log("hashBuf:");
//console.log(hashBuf.toString());
console.log(paymentData.substring(2) + " == " + hash);
if (paymentData.substring(2) != hash) {
generateError(response, 1000, "Warning", "Sent message doesn't match with the one displayed on the page");
return;
}
newPhoneToAddr(wallet, phone, function(err, result) {
console.log(err);
console.log("obj:");
console.log(obj);
console.log(result);
response.send({
success : {
code : 200,
title : "Success",
message : "Phone successfully joined",
phone: obj
message : "Phone successfully joined"
}
});
});
} else {
response.send({
error : {
code : 500,
title : "Error",
message : "Not valid address"
}
});
}
} else {
});
});
});
app.post('/getPhoneByAddress', function(request, response) {
var globalToken = request.body.globalToken;
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
var wallet = request.body.wallet;
var isHex = /^0x[0-9A-Fa-f]{40}$/i.test(wallet);
if (!isHex) {
generateError(response, 500, "Error", "Not valid address");
return;
}
if (!contract) {
generateError(response, 500, "Error", "RPC doesn't work");
return;
}
var phone = contract.getPhoneByAddress.call(wallet, function(err, obj) {
console.log("err:");
console.log(err);
console.log("obj:");
console.log(obj);
response.send({
error : {
code : 401,
title : "Unauthorized",
message : "Wrong app token"
success : {
code : 200,
title : "Success",
message : "Phone successfully joined",
phone: obj
}
});
}
});
});
app.post('/getAddressByPhone', function(request, response) {
var globalToken = request.body.globalToken;
if (globalToken == app.config.globalToken) {
if (globalToken != app.config.globalToken) {
generateError(response, 401, "Unauthorized", "Wrong app token");
return;
}
if (!contract) {
generateError(response, 500, "Error", "RPC doesn't work");
return;
}
var phone = parseInt(request.body.phone);
var address = contract.phones.call(phone, function(err, address) {
console.log(address);
response.send({
success : {
code : 200,
title : "Success",
message : "Phone successfully joined",
addr: address
}
});
});
} else {
var phone = parseInt(request.body.phone);
var address = contract.phones.call(phone, function(err, address) {
console.log(address);
response.send({
error : {
code : 401,
title : "Unauthorized",
message : "Wrong app token"
success : {
code : 200,
title : "Success",
message : "Phone successfully joined",
addr: address
}
});
}
});
});
};

View File

@ -85,7 +85,7 @@
line-height: 17px;
width: 100%;
}
.inputContainer {
div.inputContainer {
margin-bottom: 5px;
width: 540px;
}
@ -93,7 +93,7 @@
margin-bottom: 10px;
width: 400;
}
.POPInput {
input.POPInput {
font-family: 'Open Sans', sans-serif;
height: 56px;
width: 400px;
@ -103,7 +103,7 @@
padding-left: 50px;
margin-right: 20px;
}
.POPInput:focus {
input.POPInput:focus {
outline: none;
/*outline-color: rgb(87,196,223);
outline-width: 2px;*/
@ -111,22 +111,22 @@
padding-left: 48px;
border: 2px solid rgb(87,196,223) !important;
}
.POPInput.POPInputPhone {
input.POPInput.POPInputPhone {
background: white url("/img/inputPhone.png") no-repeat left 15px center;
}
.POPInput.POPInputSMS {
input.POPInput.POPInputSMS {
background: white url("/img/inputSMS.png") no-repeat left 15px center;
}
.POPInput.POPInputWallet {
input.POPInput.POPInputWallet {
background: white url("/img/inputWallet.png") no-repeat left 15px center;
}
.POPInput.POPInputPhone:focus {
input.POPInput.POPInputPhone:focus {
background: white url("/img/inputPhone.png") no-repeat left 13px center;
}
.POPInput.POPInputSMS:focus {
input.POPInput.POPInputSMS:focus {
background: white url("/img/inputSMS.png") no-repeat left 13px center;
}
.POPInput.POPInputWallet:focus {
input.POPInput.POPInputWallet:focus {
background: white url("/img/inputWallet.png") no-repeat left 13px center;
}
.POPTitle2 {
@ -220,14 +220,14 @@
#step3CopyTable {
display: inline-block;
}
.copyTable {
table.copyTable {
border: none;
font-size: 14px;
font-weight: 600;
margin-top: 20px;
margin-bottom: 20px;
}
.copyTable.nomargin {
table.copyTable.nomargin {
margin-top: 0px;
margin-bottom: 0px;
}
@ -257,7 +257,7 @@
transition: .2s ease-out;
background: rgb(115, 196, 217) url("/img/copy.png") no-repeat center center !important;
}
.copyTableCellWalletValue1 {
td.copyTableCellWalletValue1 {
background: rgb(156,224,236);
color: rgb(48,142,162);
/*padding: 15px;*/

View File

@ -65,7 +65,7 @@ body {
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
opacity: 0;
position: absolute;
background-image: url(../images/loader.png);
background-image: url(../img/loader.png);
}
.loader-i_left-bottom {
-moz-animation: loader 12s linear 4s infinite forwards;

29
web/public/gulpfile.js Executable file
View File

@ -0,0 +1,29 @@
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
const sassGlob = require('gulp-sass-glob');
const autoprefixer = require('gulp-autoprefixer');
const uglifycss = require('gulp-uglifycss');
const include = require('gulp-include');
const addsrc = require('gulp-add-src');
const order = require('gulp-order');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
gulp.task('javascript', function() {
return gulp.src('javascripts/application/*.js')
.pipe(addsrc('javascripts/vendor/index.js'))
.pipe(order([
"javascripts/vendor/index.js",
"javascripts/application/*.js"
], {base: '.'}))
.pipe(include())
.pipe(concat('application.js'))
.pipe(uglify())
.pipe(gulp.dest('javascripts'));
});
gulp.task('watch', function() {
gulp.watch('javascripts/application/*.js', ['javascript']);
});

View File

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,26 @@
function addPhoneToWallet(phone, wallet, code, changeStepNumber, cb) {
$.post("/newPhoneToAddr", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"phone": phone,
"wallet": wallet,
"code": code
}, function( data ) {
cb();
if (data.success) {
changeStepNumber(+1, null);
} else if (data.error.code == 1000) {
swal({
title: "Warning",
text: data.error.message,
type: "warning"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}

View File

@ -0,0 +1,27 @@
function getAddressByPhone(phone, changeStepNumber, cb) {
$.post("/getAddressByPhone", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"phone": phone
}, function( data ) {
cb();
if (data.success) {
if (data.success.addr != "0x0000000000000000000000000000000000000000") {
POPInputWallet.val(data.success.addr);
changeStepNumber(null, 4);
} else {
swal({
title: "Warning",
text: "This phone wasn't set for any wallet yet",
type: "warning"
});
}
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}

View File

@ -0,0 +1,28 @@
function getPhoneByAddress(wallet, changeStepNumber, cb) {
$.post("/getPhoneByAddress", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"wallet": wallet
}, function( data ) {
cb();
if (data.success) {
if (data.success.phone != 0) {
POPInputPhone.val(data.success.phone);
changeStepNumber(null, 4);
} else {
swal({
title: "Warning",
text: "Phone wasn't set for this wallet yet",
type: "warning"
});
}
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}

View File

@ -60,7 +60,7 @@ $(document).ready(function() {
POPInputWallet.val(wallet);
changeStepNumber(null, 5);
walletRadioCheck();
getPhoneByAddress(function(err, output) {
getPhoneByAddress(POPInputWallet.val(), changeStepNumber, function(err, output) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
if (!err) {
@ -202,21 +202,36 @@ $(document).ready(function() {
loader.removeClass('hide');
switch(curStepNum) {
case 1:
sendCodeBySMS(visibleInput.val());
sendCodeBySMS(visibleInput.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
break;
case 2:
verifyCodeFromSMS();
verifyCodeFromSMS(POPInputSMS.val(), POPInputPhone.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
break;
case 3:
addPhoneToWallet();
addPhoneToWallet(POPInputPhone.val(), POPInputWallet.val(), POPInputSMS.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
break;
case 5:
{
var radioVal = $('input[name=radioCheck]:checked').val();
if (radioVal == "wallet") {
getPhoneByAddress();
getPhoneByAddress(POPInputWallet.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
} else {
getAddressByPhone();
getAddressByPhone(POPInputPhone.val(), changeStepNumber, function() {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
});
}
}
break;
@ -227,23 +242,18 @@ $(document).ready(function() {
}
break;
}
} else {
visibleInput.focus();
}
} else visibleInput.focus();
}
function changeStepNumber(addition, absolute) {
console.log(hashToAddress);
var newStepVal = 0;
if (addition)
newStepVal = parseInt(stepNum.val()) + addition;
else
newStepVal = absolute;
if (addition) newStepVal = parseInt(stepNum.val()) + addition;
else newStepVal = absolute;
stepNum.val(newStepVal);
var newStepNum = parseInt(stepNum.val());
stepLabel.text("Step " + newStepNum);
//POPInput.val("");
switch(newStepNum) {
case 1:
{
@ -309,7 +319,7 @@ $(document).ready(function() {
$("#hashCopy").attr("data-clipboard-text", hashToAddress);
});
clientCopyHash.on( "aftercopy", function( event ) {
Materialize.toast('message copied to buffer', 3000, 'rounded');
Materialize.toast('message copied to buffer', 3000, 'rounded');
});
});
@ -439,145 +449,4 @@ $(document).ready(function() {
break;
}
}
function sendCodeBySMS(phone) {
$.post("/sendCodeBySMS", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"to": phone
}, function( data ) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
console.log( data );
if (data.success) {
changeStepNumber(+1, null);
token.val(data.success.code);
swal({
title: "Success",
text: "Code successfully sent by SMS",
type: "success"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}
function verifyCodeFromSMS() {
$.post("/verifyCodeFromSMS", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"code": POPInputSMS.val(),
"phone": POPInputPhone.val()
}, function( data ) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
console.log( data );
if (data.success) {
hashToAddress = data.success.message;
console.log(hashToAddress);
changeStepNumber(+1, null);
token.val(data.success.code);
swal({
title: "Success",
text: "Code successfully verified",
type: "success"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}
function addPhoneToWallet() {
$.post("/newPhoneToAddr", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"phone": POPInputPhone.val(),
"wallet": POPInputWallet.val(),
"code": POPInputSMS.val()
}, function( data ) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
if (data.success) {
changeStepNumber(+1, null);
} else if (data.error.code == 1000) {
swal({
title: "Warning",
text: data.error.message,
type: "warning"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}
function getPhoneByAddress() {
$.post("/getPhoneByAddress", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"wallet": POPInputWallet.val()
}, function( data ) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
if (data.success) {
if (data.success.phone != 0) {
POPInputPhone.val(data.success.phone);
changeStepNumber(null, 4);
} else {
swal({
title: "Warning",
text: "Phone wasn't set for this wallet yet",
type: "warning"
});
}
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}
function getAddressByPhone() {
$.post("/getAddressByPhone", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"phone": POPInputPhone.val()
}, function( data ) {
middleMainContainerInner.fadeIn(500);
loader.addClass('hide');
if (data.success) {
if (data.success.addr != "0x0000000000000000000000000000000000000000") {
POPInputWallet.val(data.success.addr);
changeStepNumber(null, 4);
} else {
swal({
title: "Warning",
text: "This phone wasn't set for any wallet yet",
type: "warning"
});
}
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}
});

View File

@ -0,0 +1,23 @@
function sendCodeBySMS(phone, changeStepNumber, cb) {
$.post("/sendCodeBySMS", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"to": phone
}, function( data ) {
console.log( data );
if (data.success) {
changeStepNumber(+1, null);
token.val(data.success.code);
swal({
title: "Success",
text: "Code successfully sent by SMS",
type: "success"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}

View File

@ -0,0 +1,27 @@
function verifyCodeFromSMS(code, phone, changeStepNumber, cb) {
$.post("/verifyCodeFromSMS", {
"globalToken": "cba2c691-47df-41e7-bc97-a0818103ed14",
"code": code,
"phone": phone
}, function( data ) {
cb();
console.log( data );
if (data.success) {
hashToAddress = data.success.message;
console.log(hashToAddress);
changeStepNumber(+1, null);
token.val(data.success.code);
swal({
title: "Success",
text: "Code successfully verified",
type: "success"
});
} else {
swal({
title: "Error",
text: data.error.message,
type: "error"
});
}
});
}

View File

@ -0,0 +1,4 @@
//=require ZeroClipboard.js
//=require jquery.min.js
//=require materialize.min.js
//=require sweetalert.min.js

View File

@ -1,61 +0,0 @@
function getAddressByPhone(cb) {
var phoneToAddress = PhoneToAddress.deployed();
var phone = document.getElementById("POPInputPhone").value;
phoneToAddress.getAddressByPhone.call(phone, {from: account}).then(function(value) {
console.log(value);
cb(null, value);
}).catch(function(e) {
console.log(e);
console.log("Error getting phone; see log.");
cb(e, null);
});
};
function getPhoneByAddress(cb) {
var phoneToAddress = PhoneToAddress.deployed();
var addr = document.getElementById("POPInputWallet").value;
phoneToAddress.getPhoneByAddress.call(addr, {from: account}).then(function(value) {
console.log(value);
cb(null, value);
}).catch(function(e) {
console.log(e);
console.log("Error getting address; see log.");
cb(e, null);
});
};
function joinPhoneToAddress(cb) {
var phoneToAddress = PhoneToAddress.deployed();
var phone = parseInt(document.getElementById("POPInputPhone").value);
var addr = document.getElementById("POPInputWallet").value;
console.log(phone);
console.log(addr);
console.log("Initiating transaction... (please wait)");
phoneToAddress.getPhoneByAddress.call(addr, {from: account}).then(function(value) {
console.log("Phone for address: ");
console.log(value);
if (value != 0) {
console.log("Phone was already set before for this wallet");
cb(null, false);
} else {
phoneToAddress.newPhoneToAddr(addr, phone, {from: account}).then(function() {
console.log("Transaction completed!");
cb(null, true);
}).catch(function(e) {
console.log(e);
console.log("Error in joining phone; see log.");
cb(e, false);
});
}
}).catch(function(e) {
console.log(e);
console.log("Error getting address; see log.");
cb(e, false);
});
};

Some files were not shown because too many files have changed in this diff Show More