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

feat: disable or hide lock wallet button if not usable #3305

Merged
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
11 changes: 10 additions & 1 deletion src/composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export const useAuth = createCustomScopedComposable(() => {
const isAuthenticated = ref(false);
const isAuthenticating = ref(false);
const isMnemonicRestored = ref(false);
/** User skipped setting password so the test one was used */
const isUsingDefaultPassword = ref(false);
const encryptionKey = ref<CryptoKey>();

/**
Expand Down Expand Up @@ -277,6 +279,7 @@ export const useAuth = createCustomScopedComposable(() => {
return;
}

isUsingDefaultPassword.value = false;
isAuthenticating.value = true;

if (IS_MOBILE_APP) {
Expand All @@ -301,7 +304,11 @@ export const useAuth = createCustomScopedComposable(() => {
// If restoring from background failed try to use the dev mode password set
// when using "Skip" when setting password.
if (!encryptionKey.value && UNFINISHED_FEATURES && !IS_OFFSCREEN_TAB) {
await authenticateWithPassword(STUB_ACCOUNT.password).catch(() => openPasswordLoginModal());
await authenticateWithPassword(STUB_ACCOUNT.password)
.then(() => {
isUsingDefaultPassword.value = true;
})
.catch(() => openPasswordLoginModal());
}

// Finally if other attempts failed ask user for the password
Expand Down Expand Up @@ -406,6 +413,8 @@ export const useAuth = createCustomScopedComposable(() => {
return {
isAuthenticated: readonly(isAuthenticated),
isMnemonicRestored,
isMnemonicEncrypted,
isUsingDefaultPassword,
mnemonic,
mnemonicDecrypted,
mnemonicEncrypted,
Expand Down
4 changes: 4 additions & 0 deletions src/popup/components/Modals/SetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import InputPassword from '@/popup/components/InputPassword.vue';
import BtnMain from '@/popup/components/buttons/BtnMain.vue';

import LockIcon from '@/icons/secure-lock-outline.svg?vue-component';
import { useAuth } from '@/composables';

export default defineComponent({
components: {
Expand All @@ -144,6 +145,8 @@ export default defineComponent({
isRestoredWallet: Boolean,
},
setup(props) {
const { isUsingDefaultPassword } = useAuth();

const password = ref('');
const confirmPassword = ref('');

Expand All @@ -160,6 +163,7 @@ export default defineComponent({
function useDefaultPassword() {
if (UNFINISHED_FEATURES) {
props.resolve(STUB_ACCOUNT.password);
isUsingDefaultPassword.value = true;
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/popup/pages/More.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
</PanelItem>

<PanelItem
v-if="isMnemonicEncrypted || isBiometricLoginEnabled"
:title="$t('pages.secureLogin.lockWallet')"
:disabled="isUsingDefaultPassword || (!isMnemonicEncrypted && !isBiometricLoginEnabled)"
data-cy="lock-wallet"
@click="lockWallet()"
>
Expand All @@ -120,6 +122,7 @@ import {
useAddressBook,
useAeSdk,
useAuth,
useUi,
} from '@/composables';
import { AE_DEX_URL, AE_SIMPLEX_URL } from '@/protocols/aeternity/config';
import { buildAeFaucetUrl } from '@/protocols/aeternity/helpers';
Expand Down Expand Up @@ -159,7 +162,8 @@ export default defineComponent({
const { activeAccount } = useAccounts();
const { isNodeMainnet, isNodeTestnet } = useAeSdk();
const { addressBook } = useAddressBook();
const { lockWallet } = useAuth();
const { isMnemonicEncrypted, isUsingDefaultPassword, lockWallet } = useAuth();
const { isBiometricLoginEnabled } = useUi();

const isActiveAccountAe = computed(() => activeAccount.value.protocol === PROTOCOLS.aeternity);
const activeAccountFaucetUrl = computed(
Expand All @@ -180,6 +184,9 @@ export default defineComponent({
isActiveAccountAe,
isNodeMainnet,
isNodeTestnet,
isMnemonicEncrypted,
isBiometricLoginEnabled,
isUsingDefaultPassword,
};
},
});
Expand Down
Loading