Skip to content

Commit

Permalink
Make backup required when user has funds (#1782)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimenta authored Aug 18, 2020
1 parent 5048cfb commit 3c9e448
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
35 changes: 22 additions & 13 deletions app/components/Views/AccountBackupStep1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ActionModal from '../../UI/ActionModal';
import SeedphraseModal from '../../UI/SeedphraseModal';
import { getOnboardingNavbarOptions } from '../../UI/Navbar';
import scaling from '../../../util/scaling';
import Engine from '../../../core/Engine';

const explain_backup_seedphrase = require('../../../images/explain-backup-seedphrase.png'); // eslint-disable-line
const warning_skip_backup = require('../../../images/warning.png'); // eslint-disable-line
Expand Down Expand Up @@ -155,9 +156,13 @@ const AccountBackupStep1 = props => {
const [showRemindLaterModal, setRemindLaterModal] = useState(false);
const [showWhatIsSeedphraseModal, setWhatIsSeedphraseModal] = useState(false);
const [skipCheckbox, setToggleSkipCheckbox] = useState(false);
const [hasFunds, setHasFunds] = useState(false);

useEffect(
() => {
// Check if user has funds
if (Engine.hasFunds()) setHasFunds(true);

// Disable back press
const hardwareBackPress = () => true;

Expand All @@ -177,6 +182,8 @@ const AccountBackupStep1 = props => {
};

const showRemindLater = () => {
if (hasFunds) return;

setRemindLaterModal(true);
};

Expand Down Expand Up @@ -245,20 +252,22 @@ const AccountBackupStep1 = props => {
</View>
</View>
<View style={styles.buttonWrapper}>
<View style={styles.remindLaterContainer}>
<TouchableOpacity
style={styles.remindLaterButton}
onPress={showRemindLater}
hitSlop={{ top: 10, left: 10, bottom: 10, right: 10 }}
>
<Text style={styles.remindLaterText}>
{strings('account_backup_step_1.remind_me_later')}
{!hasFunds && (
<View style={styles.remindLaterContainer}>
<TouchableOpacity
style={styles.remindLaterButton}
onPress={showRemindLater}
hitSlop={{ top: 10, left: 10, bottom: 10, right: 10 }}
>
<Text style={styles.remindLaterText}>
{strings('account_backup_step_1.remind_me_later')}
</Text>
</TouchableOpacity>
<Text style={styles.remindLaterSubText}>
{strings('account_backup_step_1.remind_me_later_subtext')}
</Text>
</TouchableOpacity>
<Text style={styles.remindLaterSubText}>
{strings('account_backup_step_1.remind_me_later_subtext')}
</Text>
</View>
</View>
)}
<View style={styles.ctaContainer}>
<StyledButton
containerStyle={styles.button}
Expand Down
30 changes: 30 additions & 0 deletions app/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,33 @@ class Engine {
return total;
};

/**
* Returns true or false whether the user has funds or not
*/
hasFunds = () => {
try {
const {
engine: { backgroundState }
} = store.getState();
const collectibles = backgroundState.AssetsController.collectibles;
const tokens = backgroundState.AssetsController.tokens;
const tokenBalances = backgroundState.TokenBalancesController.contractBalances;

let tokenFound = false;
tokens.forEach(token => {
if (tokenBalances[token.address] && !tokenBalances[token.address].isZero()) {
tokenFound = true;
}
});

const fiatBalance = this.getTotalFiatAccountBalance();

return fiatBalance > 0 || tokenFound || collectibles.length > 0;
} catch (e) {
Logger.log('Error while getting user funds', e);
}
};

resetState = async () => {
// Whenever we are gonna start a new wallet
// either imported or created, we need to
Expand Down Expand Up @@ -428,6 +455,9 @@ export default {
getTotalFiatAccountBalance() {
return instance.getTotalFiatAccountBalance();
},
hasFunds() {
return instance.hasFunds();
},
resetState() {
return instance.resetState();
},
Expand Down

0 comments on commit 3c9e448

Please sign in to comment.