paypro: fix parseBitcoinURI. start using bitcoin uris in tests.
This commit is contained in:
parent
283dec1f2e
commit
e0ff9ca6bd
3 changed files with 21 additions and 4 deletions
|
|
@ -86,8 +86,10 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
$rootScope.pendingPayment = null;
|
$rootScope.pendingPayment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (~address.indexOf('://')) {
|
var uri = address.indexOf('bitcoin:') === 0
|
||||||
w.createTx(address, commentText, done);
|
&& copay.Structure.parseBitcoinURI(address);
|
||||||
|
if (uri && uri.merchant) {
|
||||||
|
w.createTx(uri.merchant, commentText, done);
|
||||||
} else {
|
} else {
|
||||||
w.createTx(address, amount, commentText, done);
|
w.createTx(address, amount, commentText, done);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ var http = require('http');
|
||||||
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var preconditions = require('preconditions').singleton();
|
var preconditions = require('preconditions').singleton();
|
||||||
|
var parseBitcoinURI = require('./Structure').parseBitcoinURI;
|
||||||
|
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var bignum = bitcore.Bignum;
|
var bignum = bitcore.Bignum;
|
||||||
|
|
@ -774,6 +775,13 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
|
||||||
options = { uri: options };
|
options = { uri: options };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.uri.indexOf('bitcoin:') === 0) {
|
||||||
|
options.uri = parseBitcoinURI(options.uri).merchant;
|
||||||
|
if (!options.uri) {
|
||||||
|
return cb(new Error('No URI.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $http({
|
return $http({
|
||||||
method: options.method || 'POST',
|
method: options.method || 'POST',
|
||||||
url: options.uri || options.url,
|
url: options.uri || options.url,
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,12 @@ if (!is_browser) {
|
||||||
error: function(cb) {
|
error: function(cb) {
|
||||||
this._error = cb;
|
this._error = cb;
|
||||||
return this;
|
return this;
|
||||||
|
},
|
||||||
|
_success: function() {
|
||||||
|
;
|
||||||
|
},
|
||||||
|
_error: function(_, err) {
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (options.responseType === 'arraybuffer') {
|
if (options.responseType === 'arraybuffer') {
|
||||||
|
|
@ -44,7 +50,7 @@ if (!is_browser) {
|
||||||
options.encoding = null;
|
options.encoding = null;
|
||||||
}
|
}
|
||||||
_request(options, function(err, res, body) {
|
_request(options, function(err, res, body) {
|
||||||
if (err) return ret._error(null, null, null, options);
|
if (err) return ret._error(null, err, null, options);
|
||||||
return ret._success(body, res.statusCode, res.headers, options);
|
return ret._success(body, res.statusCode, res.headers, options);
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -62,6 +68,7 @@ function startServer(cb) {
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var bc = path.dirname(require.resolve(__dirname + '/../../bitcore/package.json'));
|
var bc = path.dirname(require.resolve(__dirname + '/../../bitcore/package.json'));
|
||||||
|
//var bc = path.dirname(require.resolve('bitcore/package.json'));
|
||||||
var example = bc + '/examples/PayPro/server.js';
|
var example = bc + '/examples/PayPro/server.js';
|
||||||
var server = require(example);
|
var server = require(example);
|
||||||
|
|
||||||
|
|
@ -206,7 +213,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
return cb(null, unspentTest, []);
|
return cb(null, unspentTest, []);
|
||||||
}, 1);
|
}, 1);
|
||||||
};
|
};
|
||||||
var address = server.uri + '/request';
|
var address = 'bitcoin:mq7se9wy2egettFxPbmn99cK8v5AFq55Lx?amount=0.11&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createTx(address, commentText, function(ntxid, ca) {
|
w.createTx(address, commentText, function(ntxid, ca) {
|
||||||
if (w.totalCopayers > 1) {
|
if (w.totalCopayers > 1) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue