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

Make backup required when user has funds #1782

Merged
merged 1 commit into from
Aug 18, 2020
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
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