Fix samples

This commit is contained in:
Chris Clark
2015-10-30 15:22:03 -07:00
parent 7bc242bcd0
commit f722514ecf
2 changed files with 20 additions and 11 deletions

View File

@@ -24,18 +24,22 @@ const payment = {
}
};
function quit(message) {
console.log(message);
process.exit(0);
}
function fail(message) {
console.error(message);
process.exit(1);
}
api.connect().then(() => {
console.log('Connected...');
api.preparePayment(address, payment, instructions).then(txJSON => {
return api.preparePayment(address, payment, instructions).then(prepared => {
console.log('Payment transaction prepared...');
const signedTransaction = api.sign(txJSON, secret).signedTransaction;
const {signedTransaction} = api.sign(prepared.txJSON, secret);
console.log('Payment transaction signed...');
api.submit(signedTransaction).then(response => {
console.log(response);
process.exit(0);
}).catch(error => {
console.log(error);
process.exit(1);
api.submit(signedTransaction).then(quit, fail);
});
});
});
}).catch(fail);

View File

@@ -5,7 +5,12 @@
// Enable core-js polyfills. This allows use of ES6/7 extensions listed here:
// https://github.com/zloirock/core-js/blob/fb0890f32dabe8d4d88a4350d1b268446127132e/shim.js#L1-L103
/* eslint-enable max-len */
require('babel-core/polyfill');
// In node.js env, polyfill might be already loaded (from any npm package),
// that's why we do this check.
if (!global._babelPolyfill) {
require('babel-core/polyfill');
}
const _ = require('lodash');
const EventEmitter = require('events').EventEmitter;