Skip to content

Commit

Permalink
Version 1.0 - Ninki Wallet
Browse files Browse the repository at this point in the history
Client side Javascript files used in the Chrome app
  • Loading branch information
Administrator committed Dec 6, 2014
1 parent 4cccea7 commit 6162b0f
Show file tree
Hide file tree
Showing 5 changed files with 3,717 additions and 3,922 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"jquery-browserify": "*",
"crypto-js": "3.1.2-3",
"bitcoinjs-lib": "0.2.0",
"openpgp": "0.6.1"
"openpgp": "0.6.1",
"sjcl": "1.0.1",
"sanitizer" : "0.1.2",
"pretty-date" : "0.2.0"
}
}
179 changes: 116 additions & 63 deletions src/ninki-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,21 @@ API.post = function (url, postData, callback) {

function lpost(url, postData, callback) {

//https://ninkip2p.com

var sessionToken = $('#API-Token').val();

//
$.ajax({
url: "https://localhost:1111" + url,
url: "https://api.ninkip2p.com:443" + url,
type: "POST",
data: JSON.stringify(postData),
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: { 'api-token': sessionToken },
success: function (data) {


data = sanitizer.sanitize(data);


var jdata = JSON.parse(data);



if (jdata.error) {
return callback(true, jdata.message);
}
Expand All @@ -76,41 +70,47 @@ function lpost(url, postData, callback) {
return callback(false, JSON.stringify(jdata));
},
fail: function (data, textStatus) {

data = sanitizer.sanitize(data);
textStatus = sanitizer.sanitize(textStatus);

return callback(true, {
textStatus: textStatus,
data: data
});
},
error: function (data) {

console.log(data);

if (data.status == 403) {
//session has been lost

}
else if (data.status == 401) {

// if (!window.cordova) {
// if (chrome) {
// if (chrome.runtime) {
// if (chrome.runtime.reload) {
// chrome.runtime.reload()
// } else {
// location.reload();
// }
// } else {
// location.reload();
// }
// //return callback(true, data.statusText);
// } else {
// location.reload();
// }
// } else {
//
// }
} else if (data.status == 401) {

if (!window.cordova) {
if (chrome) {
if (chrome.runtime) {
if (chrome.runtime.reload) {
chrome.runtime.reload()
} else {
location.reload();
}
} else {
location.reload();
}
//return callback(true, data.statusText);
} else {
location.reload();
}
} else {

}


} else {

data.responseText = sanitizer.sanitize(data.responseText);

return callback(true, data.responseText);
}

Expand Down Expand Up @@ -316,6 +316,21 @@ API.getUnconfirmedBalance = function (guid, sharedid, callback) {
});
}

//function for increased performance on login
API.getAccountData = function (guid, sharedid, callback) {
var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getaccountdata", postData, function (err, dataStr) {
return callback(err, dataStr);
});
}

API.getUserData = function (guid, sharedid, callback) {
var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getuserdata", postData, function (err, dataStr) {
return callback(err, dataStr);
});
}


//gets the username associated with the wallet
API.getNickname = function (guid, sharedid, callback) {
Expand Down Expand Up @@ -345,9 +360,12 @@ API.getUnspentOutputs = function (guid, sharedid, callback) {

var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getunspentoutputs", postData, function (err, response) {
var data1 = response;
var data2 = JSON.parse(data1);
return callback(err, data2.Message);
if (!err) {
var data = JSON.parse(response);
return callback(err, data.Message);
} else {
return callback(err, response);
}
});
}

Expand All @@ -356,17 +374,25 @@ API.getCoinProfile = function (guid, sharedid, callback) {

var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getcoinprofile", postData, function (err, response) {
var data = JSON.parse(response);
return callback(err, data);
if (!err) {
var data = JSON.parse(response);
return callback(err, data);
} else {
return callback(err, response);
}
});
}

API.getPrice = function (ccy, callback) {
API.getPrice = function (guid, ccy, callback) {

var postData = { ccy: ccy };
return lpost("/api/1/u/getPrice", postData, function (err, response) {
var data = JSON.parse(response);
return callback(err, data);
var postData = { guid: guid, ccy: ccy };
return lpost("/api/1/u/getprice", postData, function (err, response) {
if (!err) {
var data = JSON.parse(response);
return callback(err, data);
} else {
return callback(err, response);
}
});
}

Expand All @@ -375,44 +401,57 @@ API.getPendingUserRequests = function (guid, sharedid, callback) {
//these are requests made by me to other people
var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getpendinguserrequests", postData, function (err, data) {
var friends = JSON.parse(data);

return callback(err, friends);
if (!err) {
var friends = JSON.parse(data);
return callback(err, friends);
} else {
return callback(err, data);
}
});
}

API.getFriendRequests = function (guid, sharedid, callback) {

var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getfriendrequests", postData, function (err, dataStr) {
var jdata = JSON.parse(dataStr);
return callback(err, jdata);
if (!err) {
var jdata = JSON.parse(dataStr);
return callback(err, jdata);
} else {
return callback(err, dataStr);
}
});
}

API.getUserPacket = function (guid, sharedid, callback) {

var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getuserpacket", postData, function (err, dataStr) {

var jdata = JSON.parse(dataStr);
return callback(err, jdata);
if (!err) {
var jdata = JSON.parse(dataStr);
return callback(err, jdata);
} else {
return callback(err, dataStr);
}
});
}

API.isNetworkExist = function (guid, sharedid, username, callback) {
var postData = { guid: guid, sharedid: sharedid, username: username };
lpost("/api/1/u/doesnetworkexist", postData, function (err, result) {
var exists = JSON.parse(result);
return callback(err, exists);

if (!err) {
var exists = JSON.parse(result);
return callback(err, exists);
} else {
return callback(err, result);
}
});

}

API.rejectFriendRequest = function (guid, sharedid, username, callback) {
var postData = { guid: guid, sharedid: sharedid, username: username };
lpost("/api/1/u/rejectfriend", params, function (err, result) {
lpost("/api/1/u/rejectfriend", postData, function (err, result) {
return callback(err, result);
});
}
Expand All @@ -423,9 +462,12 @@ API.getTransactionRecords = function (guid, sharedid, callback) {

lpost("/api/1/u/gettransactionrecords", postData, function (err, transactions) {

var jtran = JSON.parse(transactions);

return callback(err, jtran);
if (!err) {
var jtran = JSON.parse(transactions);
return callback(err, jtran);
} else {
return callback(err, transactions);
}

});

Expand All @@ -437,9 +479,13 @@ API.getInvoiceList = function (guid, sharedid, callback) {

lpost("/api/1/u/getinvoicestopay", postData, function (err, invoices) {

var jtran = JSON.parse(invoices);
if (!err) {
var jtran = JSON.parse(invoices);

return callback(err, jtran);
return callback(err, jtran);
} else {
return callback(err, invoices);
}

});

Expand All @@ -451,9 +497,12 @@ API.getInvoiceByUserList = function (guid, sharedid, callback) {

lpost("/api/1/u/getinvoicesbyuser", postData, function (err, invoices) {

var jtran = JSON.parse(invoices);

return callback(err, jtran);
if (!err) {
var jtran = JSON.parse(invoices);
return callback(err, jtran);
} else {
return callback(err, invoices);
}

});

Expand Down Expand Up @@ -483,7 +532,7 @@ API.registerDevice = function (guid, deviceName, deviceId, deviceModel, devicePI
}

API.getDeviceKey = function (guid, devicePIN, regToken, callback) {
var postData = { guid: guid, devicePIN: devicePIN, regToken: regToken};
var postData = { guid: guid, devicePIN: devicePIN, regToken: regToken };
return lpost("/api/1/u/getdevicekey", postData, function (err, dataStr) {
return callback(err, dataStr);
});
Expand Down Expand Up @@ -516,8 +565,12 @@ API.createDevice = function (guid, sharedid, deviceName, callback) {
API.getDevices = function (guid, sharedid, callback) {
var postData = { guid: guid, sharedid: sharedid };
return lpost("/api/1/u/getdevices", postData, function (err, dataStr) {
var jdevs = JSON.parse(dataStr);
return callback(err, jdevs);
if (!err) {
var jdevs = JSON.parse(dataStr);
return callback(err, jdevs);
} else {
return callback(err, dataStr);
}
});
}

Expand Down
Loading

0 comments on commit 6162b0f

Please sign in to comment.