mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #1369 from isocolsky/rename_backup
Added copayer nickname to backup name
This commit is contained in:
commit
c9ccc4f085
|
@ -632,6 +632,14 @@ Wallet.prototype.getMyCopayerIdPriv = function() {
|
|||
return this.privateKey.getIdPriv(); //copayer idpriv is hex of a private key
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Get my own nickname
|
||||
* @return {string} copayer nickname
|
||||
*/
|
||||
Wallet.prototype.getMyCopayerNickname = function() {
|
||||
return this.publicKeyRing.nicknameForCopayer(this.getMyCopayerId());
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Returns the secret value for other users to join this wallet
|
||||
* @return {string} my own pubkey, base58 encoded
|
||||
|
|
|
@ -9,14 +9,17 @@ BackupService.prototype.getName = function(wallet) {
|
|||
return (wallet.name ? (wallet.name + '-') : '') + wallet.id;
|
||||
};
|
||||
|
||||
BackupService.prototype.getCopayer = function(wallet) {
|
||||
return wallet.totalCopayers > 1 ? wallet.getMyCopayerNickname() : '';
|
||||
};
|
||||
|
||||
BackupService.prototype.download = function(wallet) {
|
||||
var ew = wallet.toEncryptedObj();
|
||||
var partial = !wallet.publicKeyRing.isComplete();
|
||||
var walletName = this.getName(wallet) + (partial ? '-Partial' : '');
|
||||
var filename = walletName + '-keybackup.json.aes';
|
||||
var walletName = this.getName(wallet);
|
||||
var copayerName = this.getCopayer(wallet);
|
||||
var filename = (copayerName ? copayerName + '-' : '') + walletName + '-keybackup.json.aes';
|
||||
|
||||
var notify = partial ? 'Partial backup created' : 'Backup created';
|
||||
this.notifications.success(notify, 'Encrypted backup file saved.');
|
||||
this.notifications.success('Backup created', 'Encrypted backup file saved.');
|
||||
var blob = new Blob([ew], {
|
||||
type: 'text/plain;charset=utf-8'
|
||||
});
|
||||
|
@ -32,9 +35,8 @@ BackupService.prototype.download = function(wallet) {
|
|||
// throw an email intent if we are in the mobile version
|
||||
if (window.cordova) {
|
||||
var name = wallet.name ? wallet.name + ' ' : '';
|
||||
var partial = partial ? 'Partial ' : '';
|
||||
return window.plugin.email.open({
|
||||
subject: 'Copay - ' + name + 'Wallet ' + partial + 'Backup',
|
||||
subject: 'Copay - ' + name + 'Wallet ' + 'Backup',
|
||||
body: 'Here is the encrypted backup of the wallet ' + wallet.id,
|
||||
attachments: ['base64:' + filename + '//' + btoa(ew)]
|
||||
});
|
||||
|
|
|
@ -23,6 +23,7 @@ var FakeWallet = function() {
|
|||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||
};
|
||||
this.name = 'myTESTwullet';
|
||||
this.nickname = 'myNickname';
|
||||
this.addressBook = {
|
||||
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ': {
|
||||
label: 'John',
|
||||
|
@ -86,6 +87,10 @@ FakeWallet.prototype.getAddressesInfo = function() {
|
|||
|
||||
FakeWallet.prototype.subscribeToAddresses = function() {};
|
||||
|
||||
FakeWallet.prototype.getMyCopayerNickname = function() {
|
||||
return this.nickname;
|
||||
};
|
||||
|
||||
FakeWallet.prototype.isShared = function() {
|
||||
return this.totalCopayers > 1;
|
||||
}
|
||||
|
|
|
@ -1221,6 +1221,15 @@ describe('Wallet model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#getMyCopayerNickname', function() {
|
||||
it('should call publicKeyRing.nicknameForCopayer', function() {
|
||||
var w = cachedCreateW2();
|
||||
w.publicKeyRing.nicknameForCopayer = sinon.spy();
|
||||
w.getMyCopayerNickname();
|
||||
w.publicKeyRing.nicknameForCopayer.calledOnce.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#netStart', function() {
|
||||
it('should call Network.start', function() {
|
||||
var w = cachedCreateW2();
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
var sinon = require('sinon');
|
||||
|
||||
// Replace saveAs plugin
|
||||
saveAsLastCall = null;
|
||||
saveAs = function(o) {
|
||||
saveAsLastCall = o;
|
||||
saveAs = function(blob, filename) {
|
||||
saveAsLastCall = {
|
||||
blob: blob,
|
||||
filename: filename
|
||||
};
|
||||
};
|
||||
|
||||
var startServer = require('../../mocks/FakePayProServer');
|
||||
|
@ -44,14 +46,30 @@ describe("Unit: Controllers", function() {
|
|||
$scope: scope,
|
||||
$modal: {},
|
||||
});
|
||||
saveAsLastCall = null;
|
||||
}));
|
||||
|
||||
it('Backup controller #download', function() {
|
||||
scope.wallet.setEnc('1234567');
|
||||
expect(saveAsLastCall).equal(null);
|
||||
scope.downloadBackup();
|
||||
expect(saveAsLastCall.size).equal(7);
|
||||
expect(saveAsLastCall.type).equal('text/plain;charset=utf-8');
|
||||
expect(saveAsLastCall.blob.size).equal(7);
|
||||
expect(saveAsLastCall.blob.type).equal('text/plain;charset=utf-8');
|
||||
});
|
||||
|
||||
it('Backup controller should name backup correctly for multiple copayers', function() {
|
||||
scope.wallet.setEnc('1234567');
|
||||
expect(saveAsLastCall).equal(null);
|
||||
scope.downloadBackup();
|
||||
expect(saveAsLastCall.filename).equal('myNickname-myTESTwullet-testID-keybackup.json.aes');
|
||||
});
|
||||
|
||||
it('Backup controller should name backup correctly for 1-1 wallet', function() {
|
||||
scope.wallet.setEnc('1234567');
|
||||
expect(saveAsLastCall).equal(null);
|
||||
scope.wallet.totalCopayers = 1;
|
||||
scope.downloadBackup();
|
||||
expect(saveAsLastCall.filename).equal('myTESTwullet-testID-keybackup.json.aes');
|
||||
});
|
||||
|
||||
it('Backup controller #delete', function() {
|
||||
|
|
Loading…
Reference in New Issue