2014-06-02 14:00:24 -07:00
|
|
|
/*
|
|
|
|
** copay-shell integration
|
|
|
|
*/
|
|
|
|
(function() {
|
|
|
|
/*
|
|
|
|
** This is a monkey patch for when Copay is running from
|
|
|
|
** within Copay-Shell (atom-shell). Since the renderer (the frontend)
|
|
|
|
** receives context from Node.js, we get a `module.exports` contruct
|
|
|
|
** available to us. Because of this, some libs (specifically Moment.js)
|
|
|
|
** attempt to assume their CommonJS form and bind to this. This causes
|
|
|
|
** there to be no references in the window to these libs, so let's trick
|
|
|
|
** the renderer into thinking that we are _not_ in a CommonJS environment.
|
|
|
|
*/
|
|
|
|
if (typeof module !== 'undefined') module = { exports: null };
|
|
|
|
|
|
|
|
// are we running in copay shell?
|
2014-06-03 07:50:37 -07:00
|
|
|
if (window.process && process.type === 'renderer') {
|
|
|
|
window.cshell = initCopayShellBindings();
|
|
|
|
}
|
2014-06-02 14:00:24 -07:00
|
|
|
|
|
|
|
function controller(name) {
|
|
|
|
return angular.element(
|
|
|
|
document.querySelectorAll(
|
|
|
|
'[ng-controller="' + name + '"], [data-ng-controller="' + name + '"]'
|
|
|
|
)
|
|
|
|
).scope();
|
|
|
|
};
|
|
|
|
|
2014-06-03 08:55:48 -07:00
|
|
|
function needsWalletLogin(ipc) {
|
|
|
|
ipc.send('alert', 'info', 'Please select a wallet.');
|
|
|
|
};
|
|
|
|
|
2014-06-02 14:00:24 -07:00
|
|
|
function initCopayShellBindings() {
|
|
|
|
|
|
|
|
var ipc = require('ipc');
|
|
|
|
|
|
|
|
ipc.on('address:create', function(data) {
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('AddressesController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
location.href = '#/addresses';
|
|
|
|
ctrl.newAddr();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('transactions:send', function(data) {
|
2014-06-03 08:55:48 -07:00
|
|
|
var ctrl = controller('SendController');
|
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
2014-06-02 14:00:24 -07:00
|
|
|
location.href = '#/send';
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('transactions:all', function(data) {
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('TransactionsController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
location.href = '#/transactions';
|
|
|
|
ctrl.show();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('transactions:pending', function(data) {
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('TransactionsController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
location.href = '#/transactions';
|
|
|
|
ctrl.show(true);
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('backup:download', function(data) {
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('BackupController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
location.href = '#/backup';
|
|
|
|
ctrl.download();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('backup:email', function(data) {
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('BackupController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
location.href = '#/backup';
|
|
|
|
ctrl.email();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
2014-06-03 07:50:37 -07:00
|
|
|
return ipc;
|
|
|
|
|
2014-06-02 14:00:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|