Skip to content

Commit

Permalink
Closes #233 - Temporary contact state has been reset upon succesfful …
Browse files Browse the repository at this point in the history
…contact addition
  • Loading branch information
chrisfenos committed Sep 29, 2018
1 parent bfd83bb commit 7a0393e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/actions/actionCreators/Contacts.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import {
RESET_TEMP_CONTACT_STATE,
SET_ACTIVE_CONTACT_TAB,
UPDATE_WALLET_CONTACTS,
SET_TEMP_CONTACT_NAME,
INITIALIZE_WALLET_CONTACTS,
SET_CONTACT_ETHEREUM_ADDRESS,
INITIALIZE_CONTACT_TOKENS,
} from '../actionTypes/ContactTypes';

import {
SET_TEMPORARY_QR_ADDRESS,
} from '../actionTypes/AppConfigTypes';

export function resetTempContactState() {
return (dispatch) => {
dispatch({ type: RESET_TEMP_CONTACT_STATE, payload: '' });
};
}

export function setContactTabState(tabText) {
return (dispatch) => {
dispatch({ type: SET_ACTIVE_CONTACT_TAB, payload: tabText });
Expand Down
2 changes: 1 addition & 1 deletion src/actions/actionTypes/ContactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const UPDATE_WALLET_CONTACTS = 'UPDATE_WALLET_CONTACTS';
export const SET_TEMP_CONTACT_NAME = 'SET_TEMP_CONTACT_NAME';
export const INITIALIZE_WALLET_CONTACTS = ' INITIALIZE_WALLET_CONTACTS';
export const SET_CONTACT_ETHEREUM_ADDRESS = 'SET_CONTACT_ETHEREUM_ADDRESS';
export const INITIALIZE_CONTACT_TOKENS = 'INITIALIZE_CONTACT_TOKENS';
export const RESET_TEMP_CONTACT_STATE = 'RESET_TEMP_CONTACT_STATE';


5 changes: 5 additions & 0 deletions src/reducers/wallet/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SET_CONTACT_ETHEREUM_ADDRESS,
UPDATE_WALLET_CONTACTS,
INITIALIZE_WALLET_CONTACTS,
RESET_TEMP_CONTACT_STATE,
} from '../../actions/actionTypes/ContactTypes';


Expand Down Expand Up @@ -109,6 +110,10 @@ export default function (state = initialState, action) {
return {
...state, contacts: action.payload,
};
case RESET_TEMP_CONTACT_STATE:
return {
...state, tempContactName: null, tempContactTokens: [], tempContactAddress: null,
};
default:
return state;
}
Expand Down
37 changes: 34 additions & 3 deletions src/screens/main/menu/contacts/add/AddContact.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import LinearButton from '../../../../../components/LinearGradient/LinearButton'
import ClearButton from '../../../../../components/LinearGradient/ClearButton';
import BoxShadowCard from '../../../../../components/ShadowCards/BoxShadowCard';
import {
setContactTempName, setContactTabState, setContactEthereumAddress, updateTempWalletContacts, saveWalletContacts,
setContactTempName,
setContactTabState,
setContactEthereumAddress,
updateTempWalletContacts,
saveWalletContacts,
resetTempContactState,
} from '../../../../../actions/actionCreators/Contacts';
import Contact from '../../../../../scripts/classes/Contact';

Expand Down Expand Up @@ -95,12 +100,19 @@ class AddContact extends Component {
oldContactList.push(newContact);

const validContactName = this.checkContactName(oldContactList, currentContactName);
if (validContactName) {
const validContactAddress = this.checkContactAddress(oldContactList, currentContactName);

if (validContactName && validContactAddress) {
this.props.saveWalletContacts(oldContactList);
this.props.resetTempContactState();
} else {
console.log('contact name has been added already');
console.log('contact is invalid');
}



//clear state

//old
//this.props.completeContact(currentContactName, currentContactAddress, 'notgood');
this.setState({ contactName: '' });
Expand All @@ -126,6 +138,24 @@ class AddContact extends Component {
return true;
}

/**
* This will check if the address has already been added to another contact.
* This will also include the malicious address checks and other validation (future)
*/
checkContactAddress(contactList, proposedAddress) {
let track = 0;
let isValid = true;
contactList.forEach(contact => {
if(proposedAddress == contact.address) {
track++;
}
});
if(track > 1) {
return false
}
return true;
}

clear() {
this.setState({ contactName: '' });
this.setState({ contactAddress: {} });
Expand Down Expand Up @@ -450,4 +480,5 @@ export default connect(mapStateToProps, {
setContactEthereumAddress,
updateTempWalletContacts,
saveWalletContacts,
resetTempContactState
})(AddContact);

0 comments on commit 7a0393e

Please sign in to comment.