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

refactor: create composables for globally injected items #1278

Merged
merged 46 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1de247d
wip: add restore mnemonic keys route
SvetBorislavov Dec 4, 2024
8453a8d
feat: implement restore shared keys from mnemonic page
SvetBorislavov Dec 4, 2024
b5858e9
feat: minor wording changes
SvetBorislavov Dec 4, 2024
a70bbe4
feat: update key pairs store
SvetBorislavov Dec 4, 2024
62a48dc
fix: restore uploaded mnemonic keys
SvetBorislavov Dec 4, 2024
f473c15
fix: key pairs import
SvetBorislavov Dec 4, 2024
7607654
refactor: rename restore mnemonic keys
SvetBorislavov Dec 4, 2024
6d7ac2b
feat: add button to redirect to restore missing keys
SvetBorislavov Dec 4, 2024
6c05f0e
feat: position the restore missing keys button
SvetBorislavov Dec 4, 2024
b3ab18e
feat: change tab if no keys from recovery phrase left
SvetBorislavov Dec 4, 2024
287461e
refactor:
SvetBorislavov Dec 4, 2024
7a0631a
feat: create usePersonalPassword
SvetBorislavov Dec 4, 2024
5ff49d3
feat: use usePersonalPassword in RestoreKey
SvetBorislavov Dec 4, 2024
c7f980f
refactor: use usePersonalPassword in ImportExternalPrivateKeyModal.vue
SvetBorislavov Dec 4, 2024
88fe8d6
refactor: use usePersonalPassword in DecryptKeys
SvetBorislavov Dec 4, 2024
c772c60
feat: minor update in usePersonalPassword
SvetBorislavov Dec 4, 2024
7edd6d2
refactor: use usePersonalPassword in AutoLoginInOrganization
SvetBorislavov Dec 4, 2024
685cd0c
refactor: use usePersonalPassword in TransactionGroupProcessor
SvetBorislavov Dec 4, 2024
7dc14d0
refactor: use usePersonalPassword in FileContents
SvetBorislavov Dec 4, 2024
b31738a
refactor: use usePersonalPassword in BigFileOrganizationRequestHandler
SvetBorislavov Dec 4, 2024
a912f48
refactor: use usePersonalPassword in ConfrimTransactionRequestHandler
SvetBorislavov Dec 4, 2024
0d0458c
refactor: use usePersonalPassword in KeyPairs
SvetBorislavov Dec 4, 2024
6e77c29
refactor: use usePersonalPassword in NewPassword
SvetBorislavov Dec 4, 2024
4070fba
refactor: use usePersonalPassword in OrganizationLogin
SvetBorislavov Dec 4, 2024
bba433b
refactor: use usePersonalPassword in RestoreMissingKeys
SvetBorislavov Dec 4, 2024
9383b17
refactor: use usePersonalPassword in KeysTab
SvetBorislavov Dec 4, 2024
4729a5e
refactor: use usePersonalPassword in ProfileTab
SvetBorislavov Dec 4, 2024
8999957
refactor: use usePersonalPassword in TransactionDetails
SvetBorislavov Dec 4, 2024
dfb6f26
refactor: use usePersonalPassword in TransactionGroupDetails
SvetBorislavov Dec 4, 2024
3455cd2
chore: remove unused page
SvetBorislavov Dec 4, 2024
9dfad8e
refactor: create default dynamic layout values
SvetBorislavov Dec 4, 2024
07b0f71
chore: remove unused pages
SvetBorislavov Dec 4, 2024
b602cc2
feat: create useLoader.ts
SvetBorislavov Dec 4, 2024
3d87808
refactor: use useLoader in Header
SvetBorislavov Dec 4, 2024
cc2de92
refactor: user useLoader in UserModeSelect
SvetBorislavov Dec 4, 2024
419f356
refactor: use useLoader in GlobalAppProcesses
SvetBorislavov Dec 4, 2024
65275d5
refactor: use useLoader in OrganizationLogin
SvetBorislavov Dec 4, 2024
e591f91
refactor: use useLoader in NetworkSettings
SvetBorislavov Dec 4, 2024
ff8661b
refactor: use useLoader in Transactions
SvetBorislavov Dec 4, 2024
6522f4d
chore: remove unused util
SvetBorislavov Dec 4, 2024
bae0d46
fix: after rebase
SvetBorislavov Dec 4, 2024
e8bb352
refactor: use assertion function for personal user
SvetBorislavov Dec 4, 2024
263c747
fix: typo
SvetBorislavov Dec 4, 2024
1981901
fix: after rebase
SvetBorislavov Dec 4, 2024
b9652a4
style: remove empty space
SvetBorislavov Dec 4, 2024
af06a91
feat: remove duplication
SvetBorislavov Dec 4, 2024
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
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
<script setup lang="ts">
import type { GLOBAL_MODAL_LOADER_TYPE } from '@renderer/providers';
import { inject, onMounted, ref, watch } from 'vue';
import { onMounted, ref, watch } from 'vue';
import { MIGRATION_STARTED } from '@main/shared/constants';
import useUserStore from '@renderer/stores/storeUser';
import { useToast } from 'vue-toast-notification';
import useAutoLogin from '@renderer/composables/useAutoLogin';
import useLoader from '@renderer/composables/useLoader';
import { getUseKeychain } from '@renderer/services/safeStorageService';
import { getUsersCount, resetDataLocal } from '@renderer/services/userService';
import { getStoredClaim } from '@renderer/services/claimService';
import { GLOBAL_MODAL_LOADER_KEY } from '@renderer/providers';
import { withLoader } from '@renderer/utils';
import AutoLoginInOrganization from '@renderer/components/Organization/AutoLoginInOrganization.vue';
import AppUpdate from './components/AppUpdate.vue';
import ImportantNote from './components/ImportantNote.vue';
Expand All @@ -27,12 +21,9 @@ import BeginDataMigration from './components/BeginDataMigration.vue';
/* Stores */
const user = useUserStore();
/* Injected */
const globalModalLoaderRef = inject<GLOBAL_MODAL_LOADER_TYPE>(GLOBAL_MODAL_LOADER_KEY);
/* Composables */
const toast = useToast();
const tryAutoLogin = useAutoLogin();
const withLoader = useLoader();
/* State */
const importantNoteRef = ref<InstanceType<typeof ImportantNote> | null>(null);
Expand All @@ -58,9 +49,9 @@ const handleBeginMigrationReadyState = async (ready: boolean) => {
}
};
const handleDetectKeychainReadyState = () => {
const handleDetectKeychainReadyState = async () => {
detectKeychainReady.value = true;
withLoader(tryAutoLogin, toast, globalModalLoaderRef?.value)();
await withLoader(tryAutoLogin);
};
/* Hooks */
Expand Down
20 changes: 6 additions & 14 deletions front-end/src/renderer/components/Header.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<script setup lang="ts">
import type { Network } from '@main/shared/interfaces';
import type { GLOBAL_MODAL_LOADER_TYPE } from '@renderer/providers';
import { inject, onUpdated } from 'vue';
import { onUpdated } from 'vue';
import { CommonNetwork } from '@main/shared/enums';
import useUserStore from '@renderer/stores/storeUser';
import useNetworkStore from '@renderer/stores/storeNetwork';
import { useRouter } from 'vue-router';
import { useToast } from 'vue-toast-notification';
import useCreateTooltips from '@renderer/composables/useCreateTooltips';
import useLoader from '@renderer/composables/useLoader';
import { logout } from '@renderer/services/organization';
import { updateOrganizationCredentials } from '@renderer/services/organizationCredentials';
import { GLOBAL_MODAL_LOADER_KEY } from '@renderer/providers';
import { isUserLoggedIn, toggleAuthTokenInSessionStorage, withLoader } from '@renderer/utils';
import { isUserLoggedIn, toggleAuthTokenInSessionStorage } from '@renderer/utils';
import Logo from '@renderer/components/Logo.vue';
import LogoText from '@renderer/components/LogoText.vue';
Expand Down Expand Up @@ -53,10 +50,7 @@ const networkStore = useNetworkStore();
/* Composables */
const router = useRouter();
const createTooltips = useCreateTooltips();
const toast = useToast();
/* Injected */
const globalModalLoaderRef = inject<GLOBAL_MODAL_LOADER_TYPE>(GLOBAL_MODAL_LOADER_KEY);
const withLoader = useLoader();
/* Handlers */
const handleLogout = async () => {
Expand All @@ -77,9 +71,7 @@ const handleLogout = async () => {
};
/* Hooks */
onUpdated(() => {
createTooltips();
});
onUpdated(createTooltips);
</script>

<template>
Expand Down Expand Up @@ -124,7 +116,7 @@ onUpdated(() => {
"
class="container-icon"
data-testid="button-logout"
@click="withLoader(handleLogout, toast, globalModalLoaderRef)()"
@click="withLoader(handleLogout)"
data-bs-toggle="tooltip"
data-bs-trigger="hover"
data-bs-placement="bottom"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<script setup lang="ts">
import type { USER_PASSWORD_MODAL_TYPE } from '@renderer/providers';
import { inject, reactive, watch } from 'vue';
import { reactive, watch } from 'vue';
import { Prisma } from '@prisma/client';
import useUserStore from '@renderer/stores/storeUser';
import { useToast } from 'vue-toast-notification';
import usePersonalPassword from '@renderer/composables/usePersonalPassword';
import { generateExternalKeyPairFromString } from '@renderer/services/keyPairService';
import {
assertUserLoggedIn,
getErrorMessage,
isLoggedInOrganization,
isUserLoggedIn,
safeDuplicateUploadKey,
} from '@renderer/utils';
import { USER_PASSWORD_MODAL_KEY } from '@renderer/providers';
import AppButton from '@renderer/components/ui/AppButton.vue';
import AppModal from '@renderer/components/ui/AppModal.vue';
import AppInput from '@renderer/components/ui/AppInput.vue';
Expand All @@ -37,28 +35,19 @@ const user = useUserStore();
/* Composables */
const toast = useToast();
/* Injected */
const userPasswordModalRef = inject<USER_PASSWORD_MODAL_TYPE>(USER_PASSWORD_MODAL_KEY);
const { getPassword, passwordModalOpened } = usePersonalPassword();
/* State */
const key = reactive<{ privateKey: string; nickname?: string }>({
privateKey: '',
});
const handleImportExternalKey = async () => {
/* Verify user is logged in with password */
if (!isUserLoggedIn(user.personal)) throw new Error('User is not logged in');
const personalPassword = user.getPassword();
if (!personalPassword && !user.personal.useKeychain) {
if (!userPasswordModalRef) throw new Error('User password modal ref is not provided');
userPasswordModalRef.value?.open(
'Enter personal password',
'Private key/s will be encrypted with this password',
handleImportExternalKey,
);
return;
}
assertUserLoggedIn(user.personal);
const personalPassword = getPassword(handleImportExternalKey, {
subHeading: 'Private key/s will be encrypted with this password',
});
if (passwordModalOpened(personalPassword)) return;
try {
const keyPair: Prisma.KeyPairUncheckedCreateInput = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<script setup lang="ts">
import type { USER_PASSWORD_MODAL_TYPE } from '@renderer/providers';
import { computed, inject, ref } from 'vue';
import { computed, ref } from 'vue';
import useUserStore from '@renderer/stores/storeUser';
import { useToast } from 'vue-toast-notification';
import usePersonalPassword from '@renderer/composables/usePersonalPassword';
import { hashData } from '@renderer/services/electronUtilsService';
import { getKeysFromSecretHash, isUserLoggedIn } from '@renderer/utils';
import { USER_PASSWORD_MODAL_KEY } from '@renderer/providers';
import { getKeysFromSecretHash } from '@renderer/utils';
import DecryptKeyModal from '@renderer/components/KeyPair/ImportEncrypted/components/DecryptKeyModal.vue';
Expand All @@ -30,9 +27,7 @@ const user = useUserStore();
/* Composables */
const toast = useToast();
/* Injected */
const userPasswordModalRef = inject<USER_PASSWORD_MODAL_TYPE>(USER_PASSWORD_MODAL_KEY);
const { getPassword, passwordModalOpened } = usePersonalPassword();
/* State */
const isDecryptKeyModalShown = ref(false);
Expand Down Expand Up @@ -74,17 +69,10 @@ async function process(keyPaths: string[], words: string[] | null) {
}
/* Verify user is logged in with password */
if (!isUserLoggedIn(user.personal)) throw new Error('User is not logged in');
const personalPassword = user.getPassword();
if (!personalPassword && !user.personal.useKeychain) {
if (!userPasswordModalRef) throw new Error('User password modal ref is not provided');
userPasswordModalRef.value?.open(
'Enter personal password',
'Private key/s will be encrypted with this password',
nextKey,
);
return;
}
const personalPassword = getPassword(nextKey, {
subHeading: 'Private key/s will be encrypted with this password',
});
if (passwordModalOpened(personalPassword)) return;
await nextKey();
}
Expand Down
18 changes: 0 additions & 18 deletions front-end/src/renderer/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,6 @@ const getMenuItems = (): MenuItem[] => [
title: 'Files',
icon: 'bi bi-file-text',
},
// {
// link: '/tokens',
// title: 'Tokens',
// icon: 'bi bi-coin',
// },
// {
// link: '/smart-contracts',
// title: 'Smart Contracts',
// icon: 'bi bi-arrows-angle-contract',
// },
// {
// link: '/consensus-service',
// title: 'Consensus Service',
// icon: 'bi bi-shield-check',
// },
{
link: '/contact-list',
testid: 'button-contact-list',
Expand Down Expand Up @@ -131,9 +116,6 @@ const organizationOnly = ['/contact-list'];
:class="{ active: $route.path.startsWith('/settings') }"
><i class="bi bi-gear"></i><span>Settings</span></RouterLink
>
<!-- <RouterLink class="link-menu mt-2" to="/help"
><i class="bi bi-question-circle"></i><span>Help</span></RouterLink
> -->
</div>
</div>
</template>
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import type { Organization } from '@prisma/client';
import type { USER_PASSWORD_MODAL_TYPE } from '@renderer/providers';
import { inject, ref, watch } from 'vue';
import { ref, watch } from 'vue';
import useUserStore from '@renderer/stores/storeUser';
import { tryAutoSignIn } from '@renderer/services/organizationCredentials';
import usePersonalPassword from '@renderer/composables/usePersonalPassword';
import { USER_PASSWORD_MODAL_KEY } from '@renderer/providers';
import { tryAutoSignIn } from '@renderer/services/organizationCredentials';
import { isUserLoggedIn } from '@renderer/utils';
Expand All @@ -18,8 +17,8 @@ import AppModal from '@renderer/components/ui/AppModal.vue';
/* Stores */
const user = useUserStore();
/* Injected */
const userPasswordModalRef = inject<USER_PASSWORD_MODAL_TYPE>(USER_PASSWORD_MODAL_KEY);
/* Composables */
const { getPassword, passwordModalOpened } = usePersonalPassword();
/* State */
const checked = ref(false);
Expand Down Expand Up @@ -55,16 +54,10 @@ async function openPasswordModalIfRequired() {
if (organizationToSignIn.length === 0) return;
const personalPassword = user.getPassword();
if (!personalPassword && !user.personal.useKeychain) {
if (!userPasswordModalRef) throw new Error('User password modal ref is not provided');
userPasswordModalRef.value?.open(
null,
'Sign in to your organizations with expired token',
handleAutoLogin,
);
return;
}
const personalPassword = getPassword(handleAutoLogin, {
subHeading: 'Sign in to your organizations with expired token',
});
if (passwordModalOpened(personalPassword)) return;
await handleAutoLogin(personalPassword || null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script setup lang="ts">
import type { HederaFile } from '@prisma/client';
import type { USER_PASSWORD_MODAL_TYPE } from '@renderer/providers';
import { inject, onMounted, ref, watch } from 'vue';
import { onMounted, ref, watch } from 'vue';
import { FileContentsQuery, FileId, FileInfoQuery, Hbar, HbarUnit } from '@hashgraph/sdk';
import { DISPLAY_FILE_SIZE_LIMIT } from '@main/shared/constants';
Expand All @@ -13,22 +12,21 @@ import useNetworkStore from '@renderer/stores/storeNetwork';
import { useToast } from 'vue-toast-notification';
import { useRoute } from 'vue-router';
import useAccountId from '@renderer/composables/useAccountId';
import usePersonalPassword from '@renderer/composables/usePersonalPassword';
import { decryptPrivateKey } from '@renderer/services/keyPairService';
import { executeQuery } from '@renderer/services/transactionService';
import { add, getAll, update } from '@renderer/services/filesService';
import {
isUserLoggedIn,
assertUserLoggedIn,
isFileId,
isHederaSpecialFileId,
formatAccountId,
encodeString,
getErrorMessage,
} from '@renderer/utils';
import { USER_PASSWORD_MODAL_KEY } from '@renderer/providers';
import AppInput from '@renderer/components/ui/AppInput.vue';
import AppHbarInput from '@renderer/components/ui/AppHbarInput.vue';
import AccountIdsSelect from '@renderer/components/AccountIdsSelect.vue';
Expand All @@ -42,9 +40,7 @@ const network = useNetworkStore();
const toast = useToast();
const payerData = useAccountId();
const route = useRoute();
/* Injected */
const userPasswordModalRef = inject<USER_PASSWORD_MODAL_TYPE>(USER_PASSWORD_MODAL_KEY);
const { getPassword, passwordModalOpened } = usePersonalPassword();
/* State */
const maxQueryFee = ref<Hbar>(new Hbar(2));
Expand All @@ -55,17 +51,11 @@ const storedFiles = ref<HederaFile[]>([]);
/* Functions */
const readFile = async () => {
if (!isUserLoggedIn(user.personal)) throw new Error('User is not logged in');
const personalPassword = user.getPassword();
if (!personalPassword && !user.personal.useKeychain) {
if (!userPasswordModalRef) throw new Error('User password modal ref is not provided');
userPasswordModalRef.value?.open(
'Enter your application password',
'Enter your application password to decrypt your keys and sign the transaction',
readFile,
);
return;
}
assertUserLoggedIn(user.personal);
const personalPassword = getPassword(readFile, {
subHeading: 'Enter your application password to decrypt your keys and sign the transaction',
});
if (passwordModalOpened(personalPassword)) return;
try {
isLoading.value = true;
Expand Down Expand Up @@ -126,7 +116,7 @@ const readContent = async (privateKey: string, privateKeyType: string) => {
};
const updateLocalFileInfo = async (content: string, privateKey: string, privateKeyType: string) => {
if (!isUserLoggedIn(user.personal)) throw new Error('User is not logged in');
assertUserLoggedIn(user.personal);
try {
const fileInfoQuery = new FileInfoQuery()
Expand Down Expand Up @@ -175,9 +165,7 @@ onMounted(async () => {
fileId.value = route.query.fileId.toString();
}
if (!isUserLoggedIn(user.personal)) {
throw Error('User is not logged in');
}
assertUserLoggedIn(user.personal);
storedFiles.value = await getAll({
where: {
Expand Down
Loading
Loading