settings: it works

This commit is contained in:
Manuel Araoz 2014-09-04 16:13:30 -03:00
commit 3effa3d0b1
2 changed files with 33 additions and 19 deletions

View file

@ -112,6 +112,21 @@ Wallet.builderOpts = {
feeSat: undefined, feeSat: undefined,
}; };
/**
* @desc static list with persisted properties of a wallet.
* These are the properties that get stored/read from localstorage
*/
Wallet.PERSISTED_PROPERTIES = [
'opts',
'settings',
'publicKeyRing',
'txProposals',
'privateKey',
'addressBook',
'backupOffered',
'lastTimestamp',
];
/** /**
* @desc Retrieve a random id for the wallet * @desc Retrieve a random id for the wallet
* @TODO: Discuss changing to a UUID * @TODO: Discuss changing to a UUID
@ -175,6 +190,7 @@ Wallet.prototype._onIndexes = function(senderId, data) {
Wallet.prototype.changeSettings = function(settings) { Wallet.prototype.changeSettings = function(settings) {
console.log(settings); console.log(settings);
this.settings = settings; this.settings = settings;
this.store();
}; };
/** /**
@ -818,6 +834,8 @@ Wallet.prototype.toObj = function() {
addressBook: this.addressBook, addressBook: this.addressBook,
lastTimestamp: this.lastTimestamp, lastTimestamp: this.lastTimestamp,
}; };
console.dir(walletObj);
console.trace();
return walletObj; return walletObj;
}; };

View file

@ -83,10 +83,10 @@ WalletFactory.prototype.fromObj = function(obj, skipFields) {
obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay; obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay;
// this is only used if private key or public key ring is skipped // this is only used if private key or public key ring is skipped
obj.opts.networkName = this.networkName; obj.opts.networkName = this.networkName;
skipFields = skipFields || []; skipFields = skipFields || [];
skipFields.forEach(function(k){ skipFields.forEach(function(k) {
if (obj[k]) { if (obj[k]) {
delete obj[k]; delete obj[k];
} else } else
@ -146,13 +146,9 @@ WalletFactory.prototype.read = function(walletId, skipFields) {
var s = this.storage; var s = this.storage;
obj.id = walletId; obj.id = walletId;
obj.opts = s.get(walletId, 'opts'); _.each(Wallet.PERSISTED_PROPERTIES, function(value) {
obj.publicKeyRing = s.get(walletId, 'publicKeyRing'); obj[value] = s.get(walletId, value);
obj.txProposals = s.get(walletId, 'txProposals'); });
obj.privateKey = s.get(walletId, 'privateKey');
obj.addressBook = s.get(walletId, 'addressBook');
obj.backupOffered = s.get(walletId, 'backupOffered');
obj.lastTimestamp = s.get(walletId, 'lastTimestamp');
var w = this.fromObj(obj, skipFields); var w = this.fromObj(obj, skipFields);
return w; return w;
@ -185,7 +181,7 @@ WalletFactory.prototype.create = function(opts) {
networkName: this.networkName, networkName: this.networkName,
}; };
if (opts.privateKeyHex && opts.privateKeyHex.length>1) { if (opts.privateKeyHex && opts.privateKeyHex.length > 1) {
privOpts.extendedPrivateKeyString = opts.privateKeyHex; privOpts.extendedPrivateKeyString = opts.privateKeyHex;
} }
@ -243,9 +239,9 @@ WalletFactory.prototype._checkVersion = function(inVersion) {
//We only check for major version differences //We only check for major version differences
if (thisV0 < inV0) { if (thisV0 < inV0) {
throw new Error('Major difference in software versions' + throw new Error('Major difference in software versions' +
'. Received:' + inVersion + '. Received:' + inVersion +
'. Current version:' + this.version + '. Current version:' + this.version +
'. Aborting.'); '. Aborting.');
} }
}; };
@ -343,7 +339,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
networkName: this.networkName, networkName: this.networkName,
}; };
if (privateHex && privateHex.length>1) { if (privateHex && privateHex.length > 1) {
privOpts.extendedPrivateKeyString = privateHex; privOpts.extendedPrivateKeyString = privateHex;
} }
@ -354,7 +350,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
copayerId: privateKey.getId(), copayerId: privateKey.getId(),
privkey: privateKey.getIdPriv(), privkey: privateKey.getIdPriv(),
key: privateKey.getIdKey(), key: privateKey.getIdKey(),
secretNumber : s.secretNumber, secretNumber: s.secretNumber,
}; };
self.network.cleanUp(); self.network.cleanUp();
@ -369,7 +365,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
}); });
self.network.start(opts, function() { self.network.start(opts, function() {
self.network.greet(s.pubKey,opts.secretNumber); self.network.greet(s.pubKey, opts.secretNumber);
self.network.on('data', function(sender, data) { self.network.on('data', function(sender, data) {
if (data.type === 'walletId') { if (data.type === 'walletId') {
if (data.networkName !== self.networkName) { if (data.networkName !== self.networkName) {