Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add tokens/NFTs button triggers multiple times #3824

Merged
merged 6 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/components/UI/CollectibleContracts/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useCallback } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import { TouchableOpacity, StyleSheet, View, InteractionManager, Image } from 'react-native';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -89,6 +89,8 @@ const CollectibleContracts = ({
setNftDetectionDismissed,
nftDetectionDismissed,
}) => {
const [isAddNFTEnabled, setIsAddNFTEnabled] = useState(true);

const onItemPress = useCallback(
(collectible, contractName) => {
navigation.navigate('CollectiblesDetails', { collectible, contractName });
Expand Down Expand Up @@ -130,16 +132,23 @@ const CollectibleContracts = ({
});

const goToAddCollectible = () => {
setIsAddNFTEnabled(false);
navigation.push('AddAsset', { assetType: 'collectible' });
InteractionManager.runAfterInteractions(() => {
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.WALLET_ADD_COLLECTIBLES);
setIsAddNFTEnabled(true);
});
};

const renderFooter = () => (
<View style={styles.footer} key={'collectible-contracts-footer'}>
<Text style={styles.emptyText}>{strings('wallet.no_collectibles')}</Text>
<TouchableOpacity style={styles.add} onPress={goToAddCollectible} testID={'add-collectible-button'}>
<TouchableOpacity
style={styles.add}
onPress={goToAddCollectible}
disabled={!isAddNFTEnabled}
testID={'add-collectible-button'}
>
<Text style={styles.addText}>{strings('wallet.add_collectibles')}</Text>
</TouchableOpacity>
</View>
Expand Down
13 changes: 12 additions & 1 deletion app/components/UI/Tokens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class Tokens extends PureComponent {

tokenToRemove = null;

state = {
isAddTokenEnabled: true,
};

renderEmpty = () => (
<View style={styles.emptyView}>
<Text style={styles.text}>{strings('wallet.no_tokens')}</Text>
Expand All @@ -148,7 +152,12 @@ class Tokens extends PureComponent {
renderFooter = () => (
<View style={styles.footer} key={'tokens-footer'}>
<Text style={styles.emptyText}>{strings('wallet.no_available_tokens')}</Text>
<TouchableOpacity style={styles.add} onPress={this.goToAddToken} testID={'add-token-button'}>
<TouchableOpacity
style={styles.add}
onPress={this.goToAddToken}
disabled={!this.state.isAddTokenEnabled}
testID={'add-token-button'}
>
<Text style={styles.addText}>{strings('wallet.add_tokens')}</Text>
</TouchableOpacity>
</View>
Expand Down Expand Up @@ -238,9 +247,11 @@ class Tokens extends PureComponent {
}

goToAddToken = () => {
this.setState({ isAddTokenEnabled: false });
this.props.navigation.push('AddAsset', { assetType: 'token' });
InteractionManager.runAfterInteractions(() => {
Analytics.trackEvent(ANALYTICS_EVENT_OPTS.WALLET_ADD_TOKENS);
this.setState({ isAddTokenEnabled: true });
});
};

Expand Down