Skip to content

Commit

Permalink
Multiple tokens are now being saved globally in temp storage for any …
Browse files Browse the repository at this point in the history
…given contact
  • Loading branch information
chrisfenos committed Sep 29, 2018
1 parent a7bbfe5 commit c8cd303
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
16 changes: 16 additions & 0 deletions src/actions/actionCreators/Contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
13 changes: 9 additions & 4 deletions src/reducers/wallet/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {
SET_TEMP_CONTACT_NAME,
SET_CONTACT_ETHEREUM_ADDRESS,
UPDATE_WALLET_CONTACTS,
} from '../../actions/actionTypes/ContactTypes';


Expand Down Expand Up @@ -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;
}
Expand Down
51 changes: 25 additions & 26 deletions src/screens/main/menu/contacts/add/AddContact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand All @@ -145,13 +150,7 @@ class AddContact extends Component {
this.setState({ tokenImages: copyIMG });
}



/**
* Returns the form required to add a contact
*/
render() {

return (
<SafeAreaView style={styles.safeAreaView}>
<View style={styles.mainContainer}>
Expand All @@ -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 }
/>
</View>

<View style={styles.barcodeContainer}>
<TouchableOpacity onPress={() => { return this.navigate(); }}>
<Image
Expand All @@ -199,15 +196,15 @@ class AddContact extends Component {
}}
items={this.state.tokens}
onValueChange={(value) => {
this.getTokenIMG(value);
this.selectedToken(value);
}}
style={pickerStyle}
value={this.state.tokenName}
ref={(el) => {
this.inputRefs.picker = el;
}}
/>
</View>
</View>
<TouchableOpacity
style={styles.addAnotherText}
onPress={this.addAnotherCoinAddress.bind(this)}
Expand Down Expand Up @@ -401,12 +398,14 @@ const pickerStyle = {

const mapStateToProps = ({ contacts, Wallet }) => {

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);

0 comments on commit c8cd303

Please sign in to comment.