Skip to content

Commit

Permalink
Closes #228 - null values are removed from the contact state when the…
Browse files Browse the repository at this point in the history
… picker returns null values on randomly triggered event
  • Loading branch information
chrisfenos committed Sep 29, 2018
1 parent c8cd303 commit 7fa7c15
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/screens/main/menu/contacts/add/AddContact.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class AddContact extends Component {
tokenName.label = token.name;
tokenName.img = token.logo.src;
tokens.push(tokenName);
//console.log('tokenName', tokenName);
});

this.state = {
Expand Down Expand Up @@ -112,21 +111,37 @@ class AddContact extends Component {
this.setState({ tokenName: 'null' });
}

/**
* Tokens already are saved globally, this just resets the picker value
*/
addAnotherCoinAddress() {

//old
this.setState({ tokenName: 'null' });
this.setState({ contactAddressInput: '' });
}

/**
* 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.
* By default, tempContactTokens = []
* If you have added multiple tokens, you can push your new token as well
* If you have not added any, you just push a new token to an empty array.
*
* Null is returned sometimes - bug - hack fix is loop through and remove null
*/
selectedToken = async (token) => {
let arrayWithoutNullValues = [];

let previouslySavedTokens = this.props.tempContactTokens;
previouslySavedTokens.push(token);
console.log(token);

this.props.updateTempWalletContacts(previouslySavedTokens, token);

for (let i = 0; i < previouslySavedTokens.length; i++) {
console.log(previouslySavedTokens[i]);
if(previouslySavedTokens[i] !== null) {
arrayWithoutNullValues.push(previouslySavedTokens[i]);
}
}

arrayWithoutNullValues.push(token);
this.props.updateTempWalletContacts(arrayWithoutNullValues);
//old
await this.setState({
tokenName: token,
Expand Down Expand Up @@ -170,7 +185,6 @@ class AddContact extends Component {
value={this.props.tempContactName}
/>
</View>

<View style={styles.inputAddressContainer}>
<FormInput
placeholder={'Ethereum Address'}
Expand All @@ -191,15 +205,15 @@ class AddContact extends Component {
<View style={styles.pickerContainer}>
<RNPickerSelect
placeholder={{
label: 'Coin Type',
label: 'Select Token',
value: null,
}}
items={this.state.tokens}
onValueChange={(value) => {
this.selectedToken(value);
}}
style={pickerStyle}
value={this.state.tokenName}
style={ pickerStyle }
value={ this.state.tokenName }
ref={(el) => {
this.inputRefs.picker = el;
}}
Expand All @@ -209,7 +223,7 @@ class AddContact extends Component {
style={styles.addAnotherText}
onPress={this.addAnotherCoinAddress.bind(this)}
disabled={!this.state.tokenName}>
<Text style={styles.anotherText}> + Add Another Coin </Text>
<Text style={styles.anotherText}> + Add Coin </Text>
</TouchableOpacity>
</BoxShadowCard>
</View>
Expand Down

0 comments on commit 7fa7c15

Please sign in to comment.