From f36d8ac9d49be2643bca4143b798c2a79f2c4ebd Mon Sep 17 00:00:00 2001 From: Alexandros Kalogerakis Date: Wed, 22 Jan 2025 13:57:42 +0200 Subject: [PATCH 1/3] feat: change active account on dapp login --- src/composables/accounts.ts | 23 ++++- src/popup/components/AccountCard.vue | 26 ------ src/popup/components/AccountInfo.vue | 72 +++++++++++----- .../components/AccountSelectOptionsItem.vue | 19 +++-- .../AddressBook/AddressBookList.vue | 38 ++------- .../components/FormSelectOptionsHeader.vue | 3 +- .../Modals/AccountSelectOptions.vue | 4 +- src/popup/components/PanelItem.vue | 6 +- src/popup/components/form/FormSelect.vue | 1 + src/popup/locales/en.json | 4 +- src/popup/pages/Popups/ConnectBase.vue | 83 ++++++++++++++++--- 11 files changed, 170 insertions(+), 109 deletions(-) diff --git a/src/composables/accounts.ts b/src/composables/accounts.ts index accba67eb..64b2a53f9 100644 --- a/src/composables/accounts.ts +++ b/src/composables/accounts.ts @@ -30,10 +30,10 @@ import { tg } from '@/popup/plugins/i18n'; import migrateAccountsVuexToComposable from '@/migrations/001-accounts-vuex-to-composable'; import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory'; +import { useStorageRef, useAuth, useModals } from '@/composables'; -import { useStorageRef } from './storageRef'; -import { useAuth } from './auth'; -import { useModals } from './modals'; +import AirGapIcon from '@/icons/air-gap.svg?vue-component'; +import PrivateKeyIcon from '@/icons/private-key.svg?vue-component'; const { addCallback: onAccountChange, @@ -206,6 +206,10 @@ export const useAccounts = createCustomScopedComposable(() => { return accounts.value.find((acc) => acc.globalIdx === globalIdx); } + function getAccountsSelectOptionsByProtocol(protocol: Protocol): IFormSelectOption[] { + return prepareAccountSelectOptions(accounts.value.filter((acc) => acc.protocol === protocol)); + } + /** * Access last used (or current) account of the protocol when accessing features * related to protocol different than the current account is using. @@ -311,6 +315,17 @@ export const useAccounts = createCustomScopedComposable(() => { } } + function getAccountIcon(type: AccountType) { + switch (type) { + case ACCOUNT_TYPES.airGap: + return AirGapIcon; + case ACCOUNT_TYPES.privateKey: + return PrivateKeyIcon; + default: + return null; + } + } + function resetAccounts() { mnemonic.value = ''; accountsRaw.value = []; @@ -347,6 +362,8 @@ export const useAccounts = createCustomScopedComposable(() => { getAccountByAddress, getAccountByGlobalIdx, getLastActiveProtocolAccount, + getAccountsSelectOptionsByProtocol, + getAccountIcon, onAccountChange, setActiveAccountByAddress, setActiveAccountByGlobalIdx, diff --git a/src/popup/components/AccountCard.vue b/src/popup/components/AccountCard.vue index abc09da2c..097b90bf9 100644 --- a/src/popup/components/AccountCard.vue +++ b/src/popup/components/AccountCard.vue @@ -22,14 +22,6 @@ - - @@ -41,24 +33,18 @@ import { } from 'vue'; import type { IAccount } from '@/types'; import { useBalances } from '@/composables'; -import { ACCOUNT_TYPES } from '@/constants'; import AccountInfo from './AccountInfo.vue'; import BalanceInfo from './BalanceInfo.vue'; import AccountCardTotalTokens from './AccountCardTotalTokens.vue'; import AccountCardBase, { accountCardBaseCommonProps } from './AccountCardBase.vue'; -import AirGapIcon from '../../icons/air-gap.svg?vue-component'; -import PrivateKeyIcon from '../../icons/private-key.svg?vue-component'; - export default defineComponent({ components: { AccountCardBase, AccountCardTotalTokens, AccountInfo, BalanceInfo, - AirGapIcon, - PrivateKeyIcon, }, props: { account: { type: Object as PropType, required: true }, @@ -67,21 +53,9 @@ export default defineComponent({ setup(props) { const { getAccountBalance } = useBalances(); - const accountIcon = computed(() => { - switch (props.account.type) { - case ACCOUNT_TYPES.airGap: - return AirGapIcon; - case ACCOUNT_TYPES.privateKey: - return PrivateKeyIcon; - default: - return null; - } - }); - const numericBalance = computed(() => getAccountBalance(props.account.address).toNumber()); return { - accountIcon, numericBalance, }; }, diff --git a/src/popup/components/AccountInfo.vue b/src/popup/components/AccountInfo.vue index f1fe4691b..ed6ddc51f 100644 --- a/src/popup/components/AccountInfo.vue +++ b/src/popup/components/AccountInfo.vue @@ -18,25 +18,35 @@ class="account-details" :class="{ 'list-name': isListName }" > -