More robust import #2885

This commit is contained in:
Nicolas Gotchac 2016-11-14 20:26:21 +01:00
parent 134622ea3a
commit 09ec0c1f2f

View File

@ -142,30 +142,35 @@ class Addresses extends Component {
} }
renderValidation = (content) => { renderValidation = (content) => {
let addresses; const error = {
error: 'The provided file is invalid...'
};
try { try {
addresses = JSON.parse(content); const addresses = JSON.parse(content);
} catch (e) {
return {
error: 'The provided file is invalid...'
};
}
const body = Object.values(addresses).map((address, index) => ( if (!addresses || Object.keys(addresses).length === 0) {
<Summary return error;
key={ index } }
account={ address }
name={ address.name }
noLink
/>
));
return ( const body = Object
<div> .values(addresses)
{ body } .filter((account) => account && account.address)
</div> .map((account, index) => (
); <Summary
key={ index }
account={ account }
name={ account.name }
noLink
/>
));
return (
<div>
{ body }
</div>
);
} catch (e) { return error; }
} }
onImport = (content) => { onImport = (content) => {