diff --git a/src/actions/actionCreators/Contacts.js b/src/actions/actionCreators/Contacts.js index 5de3097f2..9f37a6086 100644 --- a/src/actions/actionCreators/Contacts.js +++ b/src/actions/actionCreators/Contacts.js @@ -27,4 +27,20 @@ export function setContactTabState(tabText) { return (dispatch) => { dispatch({ type: SET_CONTACT_ETHEREUM_ADDRESS, payload: address }); }; + } + + export function updateTempWalletContacts(oldContacts, newContact) { + // let tempContacts; + // if (oldContacts.length > 0) { + // tempContacts.push(newContact) + // console.log('length is actually greater than 0'); + // console.log('old contacts', oldContacts); + // } else { + // tempContacts = []; + // tempContacts.push(newContact); + // } + // console.log('temp contact is ...', tempContacts); + return (dispatch) => { + dispatch({ type: UPDATE_WALLET_CONTACTS, payload: oldContacts }); + } } \ No newline at end of file diff --git a/src/reducers/wallet/Wallet.js b/src/reducers/wallet/Wallet.js index 32bcc54a8..8b4c026cb 100644 --- a/src/reducers/wallet/Wallet.js +++ b/src/reducers/wallet/Wallet.js @@ -18,6 +18,7 @@ import { import { SET_TEMP_CONTACT_NAME, SET_CONTACT_ETHEREUM_ADDRESS, + UPDATE_WALLET_CONTACTS, } from '../../actions/actionTypes/ContactTypes'; @@ -94,11 +95,15 @@ export default function (state = initialState, action) { case SET_TEMP_CONTACT_NAME: return { ...state, tempContactName: action.payload, - } + }; case SET_CONTACT_ETHEREUM_ADDRESS: - return { - ...state, tempContactAddress: action.payload, - } + return { + ...state, tempContactAddress: action.payload, + }; + case UPDATE_WALLET_CONTACTS: + return { + ...state, tempContactTokens: action.payload, + }; default: return state; } diff --git a/src/screens/main/menu/contacts/add/AddContact.js b/src/screens/main/menu/contacts/add/AddContact.js index fec0b2ac9..06125cbc8 100644 --- a/src/screens/main/menu/contacts/add/AddContact.js +++ b/src/screens/main/menu/contacts/add/AddContact.js @@ -11,7 +11,9 @@ import * as actions from '../../../../../actions/ActionCreator'; import LinearButton from '../../../../../components/LinearGradient/LinearButton'; import ClearButton from '../../../../../components/LinearGradient/ClearButton'; import BoxShadowCard from '../../../../../components/ShadowCards/BoxShadowCard'; -import { setContactTempName, setContactTabState, setContactEthereumAddress } from '../../../../../actions/actionCreators/Contacts'; +import { + setContactTempName, setContactTabState, setContactEthereumAddress, updateTempWalletContacts, +} from '../../../../../actions/actionCreators/Contacts'; /** @@ -43,7 +45,7 @@ class AddContact extends Component { tokenName.label = token.name; tokenName.img = token.logo.src; tokens.push(tokenName); - console.log('tokenName', tokenName); + //console.log('tokenName', tokenName); }); this.state = { @@ -115,22 +117,25 @@ class AddContact extends Component { this.setState({ contactAddressInput: '' }); } - getTokenIMG = async (token) => { - let url; + /** + * Get all the tokens the user has selected for this contact, pass that array to the action creator. + * Pass in the new token and reset the state to current list of tokens for this new contact. + */ + selectedToken = async (token) => { + let previouslySavedTokens = this.props.tempContactTokens; + previouslySavedTokens.push(token); + console.log(token); + + this.props.updateTempWalletContacts(previouslySavedTokens, token); + //old await this.setState({ tokenName: token, }); - for (let i = 0; i < this.state.tokens.length; i += 1) { - if (token === this.state.tokens[i].value) { - url = this.state.tokens[i].img; - } - } - this.setState({ tokenIMG: url }); } renderName(name) { this.props.setContactTempName(name); - this.setState({contactName: name}) + this.setState({contactName: name}) //old } renderAddress(address) { @@ -145,13 +150,7 @@ class AddContact extends Component { this.setState({ tokenImages: copyIMG }); } - - - /** - * Returns the form required to add a contact - */ render() { - return ( @@ -177,12 +176,10 @@ class AddContact extends Component { placeholder={'Ethereum Address'} onChangeText={ (address) => { return this.renderAddress(address)}} inputStyle={styles.inputAddressText} - placeholderTextColor={'#b3b3b3'} - // value={this.state.contactAddress[this.state.tokenName]} - value={this.props.tempContactAddress} + placeholderTextColor={'#b3b3b3'} + value={ this.props.tempContactAddress } /> - { return this.navigate(); }}> { - this.getTokenIMG(value); + this.selectedToken(value); }} style={pickerStyle} value={this.state.tokenName} @@ -207,7 +204,7 @@ class AddContact extends Component { this.inputRefs.picker = el; }} /> - + { - const { tempContactName, tokens, tempContactAddress } = Wallet; + const { + tempContactName, tokens, tempContactAddress, tempContactTokens, + } = Wallet; return { - tokens, tempContactName, tempContactAddress, currentContact: contacts.incompleteContactInputs, + tokens, tempContactName, tempContactAddress, tempContactTokens, currentContact: contacts.incompleteContactInputs, }; }; export default connect(mapStateToProps, { - actions, setContactTempName, setContactTabState, setContactEthereumAddress + actions, setContactTempName, setContactTabState, setContactEthereumAddress, updateTempWalletContacts, })(AddContact); \ No newline at end of file