From df9096df80e371bab5b3169bbed33cb5cdccc7b4 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Tue, 9 May 2017 12:55:35 +0200 Subject: [PATCH] Fix Multisig wallet settings (#5560) * Improve add/remove owner in Wallet (use changeOwner) * fix linting --- .../modals/WalletSettings/walletSettings.js | 46 +++++++++++++++--- .../WalletSettings/walletSettingsStore.js | 47 +++++++++++++++---- 2 files changed, 78 insertions(+), 15 deletions(-) diff --git a/js/src/modals/WalletSettings/walletSettings.js b/js/src/modals/WalletSettings/walletSettings.js index 359dca697..1984e6213 100644 --- a/js/src/modals/WalletSettings/walletSettings.js +++ b/js/src/modals/WalletSettings/walletSettings.js @@ -246,8 +246,6 @@ class WalletSettings extends Component { } renderChange (change) { - const { accountsInfo } = this.props; - switch (change.type) { case 'dailylimit': return ( @@ -278,14 +276,50 @@ class WalletSettings extends Component { id='walletSettings.ownersChange.details' defaultMessage=' from {from} to {to} ' values={ { - from: change.initial.toNumber(), - to: change.value.toNumber() + from: { change.initial.toNumber() }, + to: { change.value.toNumber() } } } /> ); + case 'change_owner': + return ( +
+
+ +
+
+ + } + text + value={ change.value.from } + /> + + } + text + value={ change.value.to } + /> +
+
+ ); + case 'add_owner': return (
@@ -298,8 +332,8 @@ class WalletSettings extends Component {
@@ -317,8 +351,8 @@ class WalletSettings extends Component {
diff --git a/js/src/modals/WalletSettings/walletSettingsStore.js b/js/src/modals/WalletSettings/walletSettingsStore.js index b4ae8fc9a..d31ec9eb2 100644 --- a/js/src/modals/WalletSettings/walletSettingsStore.js +++ b/js/src/modals/WalletSettings/walletSettingsStore.js @@ -78,12 +78,16 @@ export default class WalletSettingsStore { const changes = data.map((datum) => { const [ type, valueStr ] = datum.split(';'); - let value = valueStr; + let value; - // Only addresses start with `0x`, the others - // are BigNumbers - if (!/^0x/.test(valueStr)) { - value = new BigNumber(valueStr, 16); + if (/^#BN#/.test(valueStr)) { + value = new BigNumber(valueStr.replace(/^#BN#/, ''), 16); + } else { + try { + value = JSON.parse(valueStr); + } catch (e) { + value = valueStr; + } } return { type, value }; @@ -104,8 +108,8 @@ export default class WalletSettingsStore { const { type, value } = change; const valueStr = (value && typeof value.plus === 'function') - ? value.toString(16) - : value; + ? '#BN#' + value.toString(16) + : JSON.stringify(value); return [ type, @@ -147,14 +151,26 @@ export default class WalletSettingsStore { const ownersToRemove = prevOwners.filter((owner) => !nextOwners.includes(owner)); const ownersToAdd = nextOwners.filter((owner) => !prevOwners.includes(owner)); - ownersToRemove.forEach((owner) => { + const ownersChangeCount = Math.min(ownersToRemove.length, ownersToAdd.length); + + for (let i = 0; i < ownersChangeCount; i++) { + changes.push({ + type: 'change_owner', + value: { + from: ownersToRemove[i], + to: ownersToAdd[i] + } + }); + } + + ownersToRemove.slice(ownersChangeCount).forEach((owner) => { changes.push({ type: 'remove_owner', value: owner }); }); - ownersToAdd.forEach((owner) => { + ownersToAdd.slice(ownersChangeCount).forEach((owner) => { changes.push({ type: 'add_owner', value: owner @@ -182,6 +198,12 @@ export default class WalletSettingsStore { this.wallet.require = value; break; + case 'change_owner': + this.wallet.owners = this.wallet.owners + .filter((owner) => owner !== value.from) + .concat(value.to); + break; + case 'remove_owner': this.wallet.owners = this.wallet.owners.filter((owner) => owner !== value); break; @@ -309,6 +331,13 @@ export default class WalletSettingsStore { }; } + if (change.type === 'change_owner') { + return { + method: walletInstance.changeOwner, + values: [ change.value.from, change.value.to ] + }; + } + if (change.type === 'remove_owner') { return { method: walletInstance.removeOwner,