Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
fix(API): API.securePost callbacks version.
Browse files Browse the repository at this point in the history
  • Loading branch information
sha49 committed Feb 25, 2016
1 parent bd01de8 commit 5b1d8f3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ API.prototype.securePost = function (url, data){
return this.retry(this.request.bind(this, "POST", url, clone, true));
};

API.prototype.securePostCallbacks = function (url, data, success, error) {
this.securePost(url, data).then(success).catch(error);
};


//01000000013e095250cb35129c7dee081b8c89b4bff69f72222a25c45ba9747a704a6d0bcd010000006b4830450221009b4f6619b1499ea19494aec34c36fdeac9146b9f87f010b7ebf1eb8a1b590c6e02202f5d9b0cfa4107d586b5b370494b9932eba1411468af06e431001932c12bf245012103cf91e6b06d1a2432721559a010ee67e98f8ef0421b15cca66dc9717ac1af8d1effffffff0210270000000000001976a91402549a8a872fbe54721a899e5ac2a87daac2358088acf0ba0400000000001976a9148ee77b3dd0e33783c11a6c28473d16e9b63dc38588ac00000000
API.prototype.pushTx = function (tx, note){
Expand Down
19 changes: 10 additions & 9 deletions src/blockchain-settings-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ var WalletStore = require('./wallet-store.js');
var MyWallet = require('./wallet.js');
var API = require('./api');


function get_account_info(success, error) {
API.securePost("wallet", {method : 'get-info', format : 'json'}, function(data) {
API.securePostCallbacks("wallet", {method : 'get-info', format : 'json'}, function(data) {
typeof(success) === "function" && success(data);

}, function(data) {
Expand All @@ -27,7 +28,7 @@ function updateKV(txt, method, value, success, error, extra) {

extra = extra || '';

API.securePost("wallet"+extra, { length : (value+'').length, payload : value+'', method : method }, function(data) {
API.securePostCallbacks("wallet"+extra, { length : (value+'').length, payload : value+'', method : method }, function(data) {
WalletStore.sendEvent("msg", {type: "success", message: method + '-success: ' + data});

typeof(success) === "function" && success();
Expand Down Expand Up @@ -162,7 +163,7 @@ function setTwoFactorEmail(success, error) {
}

function setTwoFactorGoogleAuthenticator(success, error) {
API.securePost("wallet", { method : 'generate-google-secret' }, function(google_secret_url) {
API.securePostCallbacks("wallet", { method : 'generate-google-secret' }, function(google_secret_url) {
typeof(success) === "function" && success(google_secret_url);
}, function(data) {
WalletStore.sendEvent("msg", {type: "error", message: data.responseText});
Expand Down Expand Up @@ -194,7 +195,7 @@ function resendEmailConfirmation(email, success, error) {
* @param {function()} error Error callback function.
*/
function verifyEmail(code, success, error) {
API.securePost("wallet", { payload:code, length : code.length, method : 'verify-email' }, function(data) {
API.securePostCallbacks("wallet", { payload:code, length : code.length, method : 'verify-email' }, function(data) {
WalletStore.sendEvent("msg", {type: "success", message: data});
typeof(success) === "function" && success(data);
}, function(data) {
Expand All @@ -209,7 +210,7 @@ function verifyEmail(code, success, error) {
* @param {function()} error Error callback function.
*/
function verifyMobile(code, success, error) {
API.securePost("wallet", { payload:code, length : code.length, method : 'verify-sms' }, function(data) {
API.securePostCallbacks("wallet", { payload:code, length : code.length, method : 'verify-sms' }, function(data) {
WalletStore.sendEvent("msg", {type: "success", message: data});
typeof(success) === "function" && success(data);
}, function(data) {
Expand All @@ -219,7 +220,7 @@ function verifyMobile(code, success, error) {
}

function getActivityLogs(success, error) {
API.securePost("wallet", {method : 'list-logs', format : 'json'}, function(data) {
API.securePostCallbacks("wallet", {method : 'list-logs', format : 'json'}, function(data) {
typeof(success) === "function" && success(data);
}, function(data) {
var response = data.responseText || 'Error Downloading Activity Logs';
Expand All @@ -229,7 +230,7 @@ function getActivityLogs(success, error) {
}

function enableEmailNotifications(success, error) {
API.securePost("wallet", {
API.securePostCallbacks("wallet", {
method : 'update-notifications-type',
length: 1,
payload: 1
Expand All @@ -243,7 +244,7 @@ function enableEmailNotifications(success, error) {
}

function enableReceiveNotifications(success, error) {
API.securePost("wallet", {
API.securePostCallbacks("wallet", {
method : 'update-notifications-on',
length: 1,
payload: 2
Expand Down Expand Up @@ -275,7 +276,7 @@ function disableAllNotifications(success, error) {
assert(success, "Success callback required");
assert(error, "Error callback required");

API.securePost("wallet", {
API.securePostCallbacks("wallet", {
method : 'update-notifications-type',
length: 1,
payload: 0
Expand Down
8 changes: 4 additions & 4 deletions src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function didDecryptWallet(success) {
function checkWalletChecksum(payload_checksum, success, error) {
var data = {method : 'wallet.aes.json', format : 'json', checksum : payload_checksum};

API.securePost("wallet", data, function(obj) {
API.securePostCallbacks("wallet", data, function(obj) {
if (!obj.payload || obj.payload == 'Not modified') {
if (success) success();
} else if (error) error();
Expand All @@ -137,7 +137,7 @@ MyWallet.getWallet = function(success, error) {
if (WalletStore.getPayloadChecksum() && WalletStore.getPayloadChecksum().length > 0)
data.checksum = WalletStore.getPayloadChecksum();

API.securePost("wallet", data, function(obj) {
API.securePostCallbacks("wallet", data, function(obj) {
if (!obj.payload || obj.payload == 'Not modified') {
if (success) success();
return;
Expand Down Expand Up @@ -203,7 +203,7 @@ function decryptAndInitializeWallet(success, error, decrypt_success, build_hd_su
// used in the frontend
MyWallet.makePairingCode = function(success, error) {
try {
API.securePost('wallet', { method : 'pairing-encryption-password' }, function(encryption_phrase) {
API.securePostCallbacks('wallet', { method : 'pairing-encryption-password' }, function(encryption_phrase) {
var pwHex = new Buffer(WalletStore.getPassword()).toString('hex');
var encrypted = WalletCrypto.encrypt(MyWallet.wallet.sharedKey + '|' + pwHex, encryption_phrase, 10);
success('1|' + MyWallet.wallet.guid + '|' + encrypted);
Expand Down Expand Up @@ -493,7 +493,7 @@ function syncWallet (successcallback, errorcallback) {
).join('|');
}

API.securePost(
API.securePostCallbacks(
"wallet"
, data
, function(data) {
Expand Down
6 changes: 3 additions & 3 deletions tests/wallet_spec.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WalletStore = {}
WalletCrypto = {}
WalletSignup = {}
API =
securePost: () ->
securePostCallbacks: () ->

stubs = { './wallet-store': WalletStore, './wallet-crypto': WalletCrypto, './wallet-signup': WalletSignup, './api': API}

Expand All @@ -19,7 +19,7 @@ describe "Wallet", ->
callbacks = undefined

beforeEach ->

describe "makePairingCode()", ->
success = undefined
error = undefined
Expand All @@ -28,7 +28,7 @@ describe "Wallet", ->
MyWallet.wallet =
guid: 'wallet-guid'
sharedKey: 'shared-key'
spyOn(API, 'securePost').and.callFake((_a, _b, cb) -> cb('enc-phrase'))
spyOn(API, 'securePostCallbacks').and.callFake((_a, _b, cb) -> cb('enc-phrase'))
spyOn(WalletStore, 'getPassword').and.returnValue('pw')
spyOn(WalletCrypto, 'encrypt').and.callFake((d) -> "(enc:#{d})")
success = jasmine.createSpy('pairing code success')
Expand Down

0 comments on commit 5b1d8f3

Please sign in to comment.