From b2c39ba84275548cab63203d25de2cc57e97cf6b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 7 Jun 2019 00:00:38 +0100 Subject: [PATCH] Fix AddressPickerDialog adding wrong entry to selected list case Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/dialogs/AddressPickerDialog.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/views/dialogs/AddressPickerDialog.js b/src/components/views/dialogs/AddressPickerDialog.js index 67fd197f8a..8dc348d2b0 100644 --- a/src/components/views/dialogs/AddressPickerDialog.js +++ b/src/components/views/dialogs/AddressPickerDialog.js @@ -205,7 +205,7 @@ module.exports = React.createClass({ onSelected: function(index) { const selectedList = this.state.selectedList.slice(); - selectedList.push(this.state.suggestedList[index]); + selectedList.push(this._getFilteredSuggestions()[index]); this.setState({ selectedList, suggestedList: [], @@ -526,12 +526,7 @@ module.exports = React.createClass({ }); }, - render: function() { - const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); - const DialogButtons = sdk.getComponent('views.elements.DialogButtons'); - const AddressSelector = sdk.getComponent("elements.AddressSelector"); - this.scrollElement = null; - + _getFilteredSuggestions: function() { // map addressType => set of addresses to avoid O(n*m) operation const selectedAddresses = {}; this.state.selectedList.forEach(({address, addressType}) => { @@ -540,9 +535,16 @@ module.exports = React.createClass({ }); // Filter out any addresses in the above already selected addresses (matching both type and address) - const filteredSuggestedList = this.state.suggestedList.filter(({address, addressType}) => { + return this.state.suggestedList.filter(({address, addressType}) => { return !(selectedAddresses[addressType] && selectedAddresses[addressType].has(address)); }); + }, + + render: function() { + const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog'); + const DialogButtons = sdk.getComponent('views.elements.DialogButtons'); + const AddressSelector = sdk.getComponent("elements.AddressSelector"); + this.scrollElement = null; const query = []; // create the invite list @@ -574,6 +576,8 @@ module.exports = React.createClass({ , ); + const filteredSuggestedList = this._getFilteredSuggestions(); + let error; let addressSelector; if (this.state.error) {