mirror of https://github.com/BTCPrivate/copay.git
wallet @browser working again
This commit is contained in:
parent
eff20ec49a
commit
4dcd18c42f
|
@ -2,5 +2,12 @@
|
||||||
|
|
||||||
angular.module('copay.backup').controller('BackupController',
|
angular.module('copay.backup').controller('BackupController',
|
||||||
function($scope, $rootScope, $location) {
|
function($scope, $rootScope, $location) {
|
||||||
|
|
||||||
|
|
||||||
|
if (!$rootScope.wallet.id) {
|
||||||
|
$location.path('signin');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$scope.title = 'Backup';
|
$scope.title = 'Backup';
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,15 +6,17 @@ angular.module('copay.home').controller('HomeController',
|
||||||
|
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
|
|
||||||
if (!$rootScope.peerId) {
|
if (!$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.addrs = $rootScope.publicKeyRing.getAddresses();
|
|
||||||
|
|
||||||
|
$scope.addrs = $rootScope.wallet.publicKeyRing.getAddresses();
|
||||||
$scope.selectedAddr = $scope.addrs[0];
|
$scope.selectedAddr = $scope.addrs[0];
|
||||||
|
|
||||||
$scope.newAddr = function() {
|
$scope.newAddr = function() {
|
||||||
var a = $rootScope.publicKeyRing.generateAddress();
|
var a = $rootScope.wallet.publicKeyRing.generateAddress();
|
||||||
$scope.addrs.push({ addrStr: a.toString('hex') });
|
$scope.addrs.push({ addrStr: a.toString('hex') });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,15 @@ angular.module('copay.send').controller('SendController',
|
||||||
function($scope, $rootScope, $location, Network) {
|
function($scope, $rootScope, $location, Network) {
|
||||||
$scope.title = 'Send';
|
$scope.title = 'Send';
|
||||||
|
|
||||||
if (!$rootScope.peerId) {
|
if (!$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$scope.sendTest = function() {
|
$scope.sendTest = function() {
|
||||||
var pkr = $rootScope.publicKeyRing;
|
var w = $rootScope.wallet;
|
||||||
var txp = $rootScope.txProposals;
|
var pkr = w.publicKeyRing;
|
||||||
|
var txp = w.txProposals;
|
||||||
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
var opts = {remainderOut: { address: pkr.generateAddress(true).toString() }};
|
||||||
|
|
||||||
// From @cmgustavo's wallet
|
// From @cmgustavo's wallet
|
||||||
|
@ -31,7 +32,7 @@ console.log('[send.js.29:txp:] BEFORE',txp); //TODO
|
||||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||||
'123456789',
|
'123456789',
|
||||||
unspentTest,
|
unspentTest,
|
||||||
$rootScope.privateKey,
|
w.privateKey,
|
||||||
opts
|
opts
|
||||||
);
|
);
|
||||||
console.log('[send.js.29:txp:] READY:',txp); //TODO
|
console.log('[send.js.29:txp:] READY:',txp); //TODO
|
||||||
|
|
|
@ -23,8 +23,6 @@ angular.module('copay.signin').controller('SigninController',
|
||||||
|
|
||||||
$scope.open = function(walletId) {
|
$scope.open = function(walletId) {
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
|
|
||||||
console.log('[signin.js.28:walletId:]',walletId); //TODO
|
|
||||||
if (Network.openWallet(walletId)) {
|
if (Network.openWallet(walletId)) {
|
||||||
Network.init(function() {
|
Network.init(function() {
|
||||||
$location.path('peer');
|
$location.path('peer');
|
||||||
|
|
|
@ -6,7 +6,7 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
|
|
||||||
$scope.oneAtATime = true;
|
$scope.oneAtATime = true;
|
||||||
|
|
||||||
if (!$rootScope.peerId) {
|
if (!$rootScope.wallet.id) {
|
||||||
$location.path('signin');
|
$location.path('signin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,5 +23,5 @@ angular.module('copay.transactions').controller('TransactionsController',
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
$scope.txsoutput = $rootScope.txProposals.txps;
|
$scope.txsoutput = $rootScope.wallet.txProposals.txps;
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,47 +21,52 @@ Wallet.prototype._startInterface = function(config) {
|
||||||
this.storage = new Storage(config.storage);
|
this.storage = new Storage(config.storage);
|
||||||
this.network = new Network(config.network);
|
this.network = new Network(config.network);
|
||||||
this.blockchain = new Blockchain(config.blockchain);
|
this.blockchain = new Blockchain(config.blockchain);
|
||||||
|
|
||||||
|
this.networkName = config.networkName;
|
||||||
|
this.requiredCopayers = config.requiredCopayers;
|
||||||
|
this.totalCopayers = config.totalCopayers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype._createNew = function(config, opts) {
|
Wallet.prototype.create = function(opts) {
|
||||||
|
|
||||||
this.id = opts.id || Wallet.getRandomId();
|
this.id = opts.id || Wallet.getRandomId();
|
||||||
console.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID'));
|
console.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID'));
|
||||||
|
|
||||||
this.privateKey = new copay.PrivateKey({
|
this.privateKey = new copay.PrivateKey({
|
||||||
networkName: config.networkName
|
networkName: this.networkName
|
||||||
});
|
});
|
||||||
console.log('\t### PrivateKey Initialized');
|
console.log('\t### PrivateKey Initialized');
|
||||||
|
|
||||||
this.publicKeyRing = opts.publicKeyRing || new copay.PublicKeyRing({
|
this.publicKeyRing = new copay.PublicKeyRing({
|
||||||
id: this.id,
|
walletId: this.id,
|
||||||
requiredCopayers: opts.requiredCopayers || config.wallet.requiredCopayers,
|
requiredCopayers: opts.requiredCopayers || this.requiredCopayers,
|
||||||
totalCopayers: opts.totalCopayers || config.wallet.totalCopayers,
|
totalCopayers: opts.totalCopayers || this.totalCopayers,
|
||||||
networkName: config.networkName,
|
networkName: this.networkName,
|
||||||
});
|
});
|
||||||
this.publicKeyRing.addCopayer(this.privateKey.getBIP32().extendedPublicKeyString());
|
|
||||||
console.log('\t### PublicKeyRing Initialized WalletID: ' + this.publicKeyRing.id);
|
|
||||||
|
|
||||||
this.txProposals = opts.txProposals || new copay.TxProposals({
|
this.publicKeyRing.addCopayer(this.privateKey.getBIP32().extendedPublicKeyString());
|
||||||
|
console.log('\t### PublicKeyRing Initialized WalletID: ' + this.publicKeyRing.walletId);
|
||||||
|
|
||||||
|
this.txProposals = new copay.TxProposals({
|
||||||
walletId: this.id,
|
walletId: this.id,
|
||||||
publicKeyRing: this.publicKeyRing,
|
publicKeyRing: this.publicKeyRing,
|
||||||
networkName: config.networkName,
|
networkName: this.networkName,
|
||||||
});
|
});
|
||||||
console.log('\t### TxProposals Initialized');
|
console.log('\t### TxProposals Initialized');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype._checkLoad = function(config, walletId) {
|
Wallet.prototype._checkLoad = function(walletId) {
|
||||||
return (
|
return (
|
||||||
this.storage.get(this.id, 'publicKeyRing') &&
|
this.storage.get(walletId, 'publicKeyRing') &&
|
||||||
this.storage.get(this.id, 'txProposals') &&
|
this.storage.get(walletId, 'txProposals') &&
|
||||||
this.storage.get(this.id, 'privateKey')
|
this.storage.get(walletId, 'privateKey')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallet.prototype._load = function(config, walletId) {
|
Wallet.prototype.load = function(walletId) {
|
||||||
if (! this._checkLoad(config,walletId)) return;
|
if (! this._checkLoad(walletId)) return;
|
||||||
|
|
||||||
|
|
||||||
this.id = walletId;
|
this.id = walletId;
|
||||||
|
@ -106,10 +111,7 @@ Wallet.prototype.sendTxProposals = function(recipients) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
||||||
console.log('### SENDING publicKeyRing TO:', recipients||'All');
|
console.log('### SENDING publicKeyRing TO:', recipients||'All', this.publicKeyRing.toObj());
|
||||||
|
|
||||||
console.log('[Wallet.js.100]', this.publicKeyRing.toObj()); //TODO
|
|
||||||
|
|
||||||
|
|
||||||
this.network.send(recipients, {
|
this.network.send(recipients, {
|
||||||
type: 'publicKeyRing',
|
type: 'publicKeyRing',
|
||||||
|
@ -124,19 +126,6 @@ console.log('[Wallet.js.100]', this.publicKeyRing.toObj()); //TODO
|
||||||
// this.storage.remove('peerData');
|
// this.storage.remove('peerData');
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// CONSTRUCTORS
|
|
||||||
Wallet.read = function(config, walletId) {
|
|
||||||
var w = new Wallet(config);
|
|
||||||
w._load(config, walletId);
|
|
||||||
return w;
|
|
||||||
};
|
|
||||||
|
|
||||||
Wallet.create = function(config, opts) {
|
|
||||||
var w = new Wallet(config);
|
|
||||||
w._createNew(config, opts);
|
|
||||||
|
|
||||||
return w;
|
|
||||||
};
|
|
||||||
|
|
||||||
Wallet.getRandomId = function() {
|
Wallet.getRandomId = function() {
|
||||||
var r = buffertools.toHex(coinUtil.generateNonce());
|
var r = buffertools.toHex(coinUtil.generateNonce());
|
||||||
|
@ -153,7 +142,8 @@ var WalletFactory = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.create = function(config, opts) {
|
WalletFactory.prototype.create = function(config, opts) {
|
||||||
var w = new Wallet.create(config, opts);
|
var w = new Wallet(config);
|
||||||
|
w.create(opts);
|
||||||
w.store();
|
w.store();
|
||||||
this.addWalletId(w.id);
|
this.addWalletId(w.id);
|
||||||
return w;
|
return w;
|
||||||
|
|
|
@ -220,6 +220,8 @@ Network.prototype.start = function(openCallback) {
|
||||||
|
|
||||||
Network.prototype._sendToOne = function(peerId, data, cb) {
|
Network.prototype._sendToOne = function(peerId, data, cb) {
|
||||||
if (peerId !== this.peerId) {
|
if (peerId !== this.peerId) {
|
||||||
|
console.log('[WebRTC.js.222:peerId:]',peerId, data); //TODO
|
||||||
|
|
||||||
var conns = this.peer.connections[peerId];
|
var conns = this.peer.connections[peerId];
|
||||||
|
|
||||||
if (conns) {
|
if (conns) {
|
||||||
|
@ -240,10 +242,12 @@ Network.prototype._sendToOne = function(peerId, data, cb) {
|
||||||
Network.prototype.send = function(peerIds, data, cb) {
|
Network.prototype.send = function(peerIds, data, cb) {
|
||||||
var self=this;
|
var self=this;
|
||||||
|
|
||||||
|
console.log('[WebRTC.js.242:peerIds:]',peerIds); //TODO
|
||||||
if (!peerIds) {
|
if (!peerIds) {
|
||||||
peerIds = this.connectedPeers;
|
peerIds = this.connectedPeers;
|
||||||
data.isBroadcast = 1;
|
data.isBroadcast = 1;
|
||||||
}
|
}
|
||||||
|
console.log('[WebRTC.js.246:peerIds:]',peerIds, data); //TODO
|
||||||
|
|
||||||
if (Array.isArray(peerIds)) {
|
if (Array.isArray(peerIds)) {
|
||||||
var l = peerIds.length;
|
var l = peerIds.length;
|
||||||
|
|
|
@ -39,16 +39,16 @@ angular.module('copay.network')
|
||||||
|
|
||||||
// TODO -> probably not in network.js
|
// TODO -> probably not in network.js
|
||||||
var createWallet = function(walletId) {
|
var createWallet = function(walletId) {
|
||||||
console.log('[network.js.41:walletId:]',walletId); //TODO
|
var w = $rootScope.wallet || new copay.Wallet(config);
|
||||||
var w = new copay.Wallet.create(config, {id: walletId});
|
w.create({id: walletId});
|
||||||
w.store();
|
w.store();
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
console.log('createWallet ENDED'); //TODO
|
console.log('createWallet ENDED'); //TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
var openWallet = function (walletId) {
|
var openWallet = function (walletId) {
|
||||||
|
var w = $rootScope.wallet || new copay.Wallet(config);
|
||||||
var w = new copay.Wallet.read(config, walletId);
|
w.load(walletId);
|
||||||
if (w && w.publicKeyRing && w.privateKey) {
|
if (w && w.publicKeyRing && w.privateKey) {
|
||||||
console.log('### WALLET OPENED:', w.walletId);
|
console.log('### WALLET OPENED:', w.walletId);
|
||||||
$rootScope.wallet = w;
|
$rootScope.wallet = w;
|
||||||
|
@ -58,13 +58,14 @@ console.log('[network.js.41:walletId:]',walletId); //TODO
|
||||||
|
|
||||||
var closeWallet = function() {
|
var closeWallet = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.store();
|
if (w && w.id)
|
||||||
|
w.store();
|
||||||
|
|
||||||
console.log('### CLOSING WALLET');
|
console.log('### CLOSING WALLET');
|
||||||
delete $rootScope['wallet'];
|
delete $rootScope['wallet'];
|
||||||
};
|
};
|
||||||
|
|
||||||
var _checkWallet = function(walletId, allowChange) {
|
var _checkWallet = function(walletId) {
|
||||||
console.log('[network.js.79:_checkWallet:]',walletId); //TODO
|
console.log('[network.js.79:_checkWallet:]',walletId); //TODO
|
||||||
|
|
||||||
if ($rootScope.wallet && $rootScope.wallet.id === walletId)
|
if ($rootScope.wallet && $rootScope.wallet.id === walletId)
|
||||||
|
@ -73,7 +74,6 @@ console.log('[network.js.41:walletId:]',walletId); //TODO
|
||||||
if ($rootScope.wallet && $rootScope.wallet.id && $rootScope.wallet.id !== walletId) {
|
if ($rootScope.wallet && $rootScope.wallet.id && $rootScope.wallet.id !== walletId) {
|
||||||
throw new Error('message to wrong walletID');
|
throw new Error('message to wrong walletID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!openWallet(walletId)) {
|
if (!openWallet(walletId)) {
|
||||||
createWallet(walletId);
|
createWallet(walletId);
|
||||||
|
|
Loading…
Reference in New Issue