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: profile manager #7742

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/specifications/activities/class-diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ classDiagram
class Subject {
- type: "address" | "account"
- address?: string
- account?: IAccountState
- account?: IWalletState
}
class Activity Direction {
<<Enum>>
Expand Down
6 changes: 3 additions & 3 deletions packages/desktop/components/AccountActivity.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
activityFilter,
activitySearchTerm,
queriedActivities,
selectedAccountActivities,
selectedWalletActivities,
setAsyncStatusOfAccountActivities,
} from '@core/wallet'
import { ActivityTile, Text, TextInput, TogglableButton, FontWeight } from '@ui'
Expand All @@ -22,7 +22,7 @@
$: if (searchActive && inputElement) inputElement.focus()
$: searchValue = searchActive ? searchValue.toLowerCase() : ''
$: setAsyncStatusOfAccountActivities($time)
$: if (searchActive && $selectedAccountActivities) {
$: if (searchActive && $selectedWalletActivities) {
debounce(() => {
$activitySearchTerm = searchValue
})()
Expand All @@ -46,7 +46,7 @@

$: $activityFilter, $activitySearchTerm, scrollToTop()
$: isEmptyBecauseOfFilter =
$selectedAccountActivities.filter((_activity) => !_activity.isHidden).length > 0 &&
$selectedWalletActivities.filter((_activity) => !_activity.isHidden).length > 0 &&
activityListWithTitles.length === 0

function scrollToTop(): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/components/AccountSummary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import { localize } from '@core/i18n'
import { nodeInfo } from '@core/network'
import { selectedAccountAssets } from '@core/wallet'
import { selectedWalletAssets } from '@core/wallet'
import { activeProfile } from '@core/profile'

$: fomattedNetworkName = $nodeInfo?.protocol.networkName
.split(' ')
.map((word) => word[0].toUpperCase() + word.substring(1))
.join(' ')

$: ({ baseCoin } = $selectedAccountAssets[$activeProfile?.network.id])
$: ({ baseCoin } = $selectedWalletAssets[$activeProfile?.network.id])
</script>

<account-summary class="block relative space-y-4">
Expand Down
8 changes: 4 additions & 4 deletions packages/desktop/components/AccountSwitcher.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { AccountLabel, Icon, Modal } from '@ui'
import { AccountSwitcherModal } from '@components'
import { selectedAccount } from '@core/account/stores'
import { WalletSwitcherModal } from '@components'
import { selectedWallet } from '@core/wallet/stores'
import { Icon as IconEnum } from '@auxiliary/icon'

let modal: Modal
Expand All @@ -19,12 +19,12 @@
<svelte:window on:click={onOutsideClick} />
<account-switcher>
<button type="button" on:click={onButtonClick} class="flex flex-row justify-center items-center space-x-2">
<AccountLabel account={$selectedAccount} />
<AccountLabel account={$selectedWallet} />
<icon-container class:rotate={isModalOpened}>
<Icon height="18" width="18" icon={IconEnum.ChevronDown} classes="text-gray-800 dark:text-white" />
</icon-container>
</button>
<AccountSwitcherModal bind:modal />
<WalletSwitcherModal bind:modal />
</account-switcher>

<style lang="scss">
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/components/ProposalCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { ProposalStatus } from '@contexts/governance/enums'
import { IProposal } from '@contexts/governance/interfaces'
import { participationOverviewForSelectedAccount, selectedProposalId } from '@contexts/governance/stores'
import { participationOverviewForSelectedWallet, selectedProposalId } from '@contexts/governance/stores'
import { isVotingForProposal } from '@contexts/governance/utils'

import { Icon } from '@auxiliary/icon/enums'
Expand All @@ -20,7 +20,7 @@

let hasVoted = false

$: $participationOverviewForSelectedAccount, setHasVoted()
$: $participationOverviewForSelectedWallet, setHasVoted()
$: dark = $appSettings.darkMode

function setHasVoted(): void {
Expand All @@ -37,7 +37,7 @@

<proposal-card
on:click={onProposalClick}
on:keydown={(e) => e.key === 'Enter' && onProposalClick()}

Check warning on line 40 in packages/desktop/components/ProposalCard.svelte

View workflow job for this annotation

GitHub Actions / lint

Missing return type on function
class:dark
class:ended={proposal?.status === ProposalStatus.Ended}
class="flex flex-col p-6 border border-solid border-gray-200 dark:border-transparent rounded-xl cursor-pointer h-fit shadow-elevation-1 focus:shadow-inner
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/components/Proposals.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import { localize } from '@core/i18n'

import { proposalFilter, registeredProposalsForSelectedAccount } from '@contexts/governance/stores'
import { proposalFilter, registeredProposalsForSelectedWallet } from '@contexts/governance/stores'
import { isVisibleProposal, sortProposals } from '@contexts/governance/utils'

$: proposals = Object.values($registeredProposalsForSelectedAccount)
$: proposals = Object.values($registeredProposalsForSelectedWallet)

let searchTerm = ''

Expand Down
14 changes: 7 additions & 7 deletions packages/desktop/components/ProposalsDetails.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<script lang="ts">
import { onMount } from 'svelte'
import { Button, KeyValueBox, Text, Modal, MeatballMenuButton, ButtonSize, FontWeight, MenuItem } from '@ui'
import { selectedAccount } from '@core/account'
import { selectedWallet } from '@core/wallet'
import { localize } from '@core/i18n'
import { activeProfileId } from '@core/profile'
import {
getNumberOfActiveProposals,
getNumberOfTotalProposals,
getNumberOfVotedProposals,
getNumberOfVotingProposals,
participationOverviewForSelectedAccount,
registeredProposalsForSelectedAccount,
participationOverviewForSelectedWallet,
registeredProposalsForSelectedWallet,
updateParticipationOverview,
IProposalsDetails,
} from '@contexts/governance'
Expand All @@ -25,9 +25,9 @@
votedProposals: null,
}

$: isOverviewLoaded = !!$participationOverviewForSelectedAccount
$: $registeredProposalsForSelectedAccount, $participationOverviewForSelectedAccount, updateProposalsDetails()
$: $selectedAccount, void setParticipationOverview()
$: isOverviewLoaded = !!$participationOverviewForSelectedWallet
$: $registeredProposalsForSelectedWallet, $participationOverviewForSelectedWallet, updateProposalsDetails()
$: $selectedWallet, void setParticipationOverview()

function updateProposalsDetails(): void {
if ($activeProfileId) {
Expand All @@ -42,7 +42,7 @@

async function setParticipationOverview(): Promise<void> {
if (!isOverviewLoaded || getNumberOfVotedProposals() === 0) {
await updateParticipationOverview($selectedAccount.index)
await updateParticipationOverview($selectedWallet.id)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/components/VestingSchedule.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { IVestingPayout, VestingOutputStatus } from '@contexts/vesting'
import { getFormattedTimeStamp, localize } from '@core/i18n'
import { activeProfile } from '@core/profile'
import { formatTokenAmountBestMatch, selectedAccountAssets } from '@core/wallet'
import { formatTokenAmountBestMatch, selectedWalletAssets } from '@core/wallet'
import { Pill, Text, TextType, Tooltip } from '@ui'

export let payouts: IVestingPayout[] = []
Expand All @@ -13,7 +13,7 @@

$: columnsAmount = calculateOptimalColumns(payouts.length)
$: remainingSpaces = calculateRemainingGridSpaces(payouts.length, columnsAmount)
$: baseCoin = ($selectedAccountAssets?.[$activeProfile?.network?.id] ?? {}).baseCoin
$: baseCoin = ($selectedWalletAssets?.[$activeProfile?.network?.id] ?? {}).baseCoin

const MAX_GRID_COLUMNS = 14

Expand Down Expand Up @@ -68,10 +68,10 @@
{#each payouts as payout}
{@const onMouseEnterOutput = handleHoverEvent(payout)}
{@const onMouseLeaveOutput = handleHoverEvent()}
<vesting-output

Check warning on line 71 in packages/desktop/components/VestingSchedule.svelte

View workflow job for this annotation

GitHub Actions / lint

A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event
on:mouseleave={onMouseLeaveOutput}
on:mouseenter={onMouseEnterOutput}
on:click={() => onPayoutClick(payout)}

Check warning on line 74 in packages/desktop/components/VestingSchedule.svelte

View workflow job for this annotation

GitHub Actions / lint

Missing return type on function
class:unlocked={payout.status === VestingOutputStatus.Unlocked}
/>
{/each}
Expand Down
18 changes: 9 additions & 9 deletions packages/desktop/components/VotingPower.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
import { Button, Text } from '@ui'
import { ButtonSize, FontWeight, TextType } from '@ui/enums'

import { selectedAccount } from '@core/account'
import { selectedWallet } from '@core/wallet'
import { localize } from '@core/i18n'
import { formatTokenAmountBestMatch, visibleSelectedAccountAssets } from '@core/wallet'
import { formatTokenAmountBestMatch, visibleSelectedWalletAssets } from '@core/wallet'
import { openPopup, PopupId } from '@auxiliary/popup'
import { activeProfile } from '@core/profile'

const asset = $visibleSelectedAccountAssets?.[$activeProfile?.network.id]?.baseCoin
const asset = $visibleSelectedWalletAssets?.[$activeProfile?.network.id]?.baseCoin

$: votingPower = parseInt($selectedAccount?.votingPower, 10)
$: maxVotingPower = parseInt($selectedAccount?.balances?.baseCoin?.available) + votingPower
$: votingPower = parseInt($selectedWallet?.votingPower, 10)
$: maxVotingPower = parseInt($selectedWallet?.balances?.baseCoin?.available) + votingPower
$: formattedVotingPower = formatTokenAmountBestMatch(votingPower, asset?.metadata)
$: formattedMaxVotingPower = formatTokenAmountBestMatch(maxVotingPower, asset?.metadata)
$: hasTransactionInProgress =
$selectedAccount?.hasVotingPowerTransactionInProgress ||
$selectedAccount?.hasVotingTransactionInProgress ||
$selectedAccount?.hasConsolidatingOutputsTransactionInProgress ||
$selectedAccount?.isTransferring
$selectedWallet?.hasVotingPowerTransactionInProgress ||
$selectedWallet?.hasVotingTransactionInProgress ||
$selectedWallet?.hasConsolidatingOutputsTransactionInProgress ||
$selectedWallet?.isTransferring

function onManageVotingPowerClick(): void {
openPopup({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import { AccountActionsMenu } from '@components'
import { WalletActionsMenu } from '@components'
import { Modal, MeatballMenuButton } from '@ui'

let modal: Modal
</script>

<account-actions-button class="block relative">
<MeatballMenuButton onClick={modal?.toggle} />
<AccountActionsMenu bind:modal position={{ right: '0' }} classes="mt-1.5" />
<WalletActionsMenu bind:modal position={{ right: '0' }} classes="mt-1.5" />
</account-actions-button>
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<script lang="ts">
import { OnboardingButton } from '@ui'

import { selectedAccount } from '@core/account'
import { selectedWallet } from '@core/wallet'
import { localize } from '@core/i18n'
import { resetMintTokenDetails } from '@core/wallet'

import { closePopup, openPopup, PopupId } from '@auxiliary/popup'
import { TextHintVariant } from 'shared/components/enums'

$: hasAliases = $selectedAccount.balances?.aliases.length > 0
// TODO(2.0) Should this be checking if it has accounts?
$: hasAccounts = $selectedWallet.balances?.accounts.length > 0

function onMintNativeTokenClick(): void {
resetMintTokenDetails()
if (hasAliases) {
if (hasAccounts) {
openPopup({
id: PopupId.MintNativeTokenForm,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import { onMount } from 'svelte'
import { Modal, MenuItem, MeatballMenuButton, MenuItemVariant } from '@ui'
import { selectedAccount } from '@core/account/stores'
import { selectedWallet } from '@core/wallet/stores'
import { handleError } from '@core/error/handlers'
import { localize } from '@core/i18n'
import { IProposal } from '@contexts/governance'
import { participationOverviewForSelectedAccount } from '@contexts/governance/stores'
import { participationOverviewForSelectedWallet } from '@contexts/governance/stores'
import { isVotingForSelectedProposal } from '@contexts/governance/utils'
import { Icon } from '@auxiliary/icon'
import { openPopup, PopupId } from '@auxiliary/popup'
Expand All @@ -17,8 +17,8 @@
let isVotingForProposal: boolean
let isBusy = true // starts in a busy state because data needs to be fetched before displaying selectable options

$: isTransferring = $selectedAccount?.isTransferring
$: isTransferring, $participationOverviewForSelectedAccount, void updateIsVoting() // vote/stop vote changes the isTransferring value. Relying on this requires less updates than relying on proposalsState
$: isTransferring = $selectedWallet?.isTransferring
$: isTransferring, $participationOverviewForSelectedWallet, void updateIsVoting() // vote/stop vote changes the isTransferring value. Relying on this requires less updates than relying on proposalsState
$: isBusy = isVotingForProposal === undefined

$: buttons = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<script lang="ts">
import { MenuItem, MenuItemVariant, Modal, ToggleHiddenAccountMenuItem } from '@ui'

import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { activeAccounts, activeProfile, isActiveLedgerProfile, visibleActiveAccounts } from '@core/profile/stores'
import { deleteAccount } from '@core/profile-manager/actions'
import { activeProfile, isActiveLedgerProfile } from '@core/profile/stores'

import { Icon } from '@auxiliary/icon/enums'
import { openPopup, PopupId } from '@auxiliary/popup'
import { profileManager } from '@core/profile-manager'
import { checkOrConnectLedger } from '@core/ledger'
import { showAppNotification } from '@auxiliary/notification'
import { handleError } from '@core/error/handlers'
import { NetworkId } from '@core/network/enums'
import { selectedWallet } from '@core/wallet/stores'
import { activeProfileSecretManager } from '@core/secret-manager'
import { deleteWallet } from '@core/profile'

export let modal: Modal = undefined

const showDeleteAccount =
$selectedAccount?.index === $activeAccounts?.length - 1 && $visibleActiveAccounts?.length > 1
const showDeleteAccount = true // TODO(2.0) Is there anything preventing us from deleting any account ?
// $selectedWallet?.id === $activeWallets?.length - 1 && $visibleActiveWallets?.length > 1

function onCustomiseAccountClick(): void {
openPopup({ id: PopupId.ManageAccount })
Expand All @@ -38,10 +38,13 @@
const ADDRESS_INDEX = 0
checkOrConnectLedger(() => {
try {
if ($profileManager && $selectedAccount && $isActiveLedgerProfile) {
$profileManager.generateEd25519Address($selectedAccount.index, ADDRESS_INDEX, {
internal: false,
ledgerNanoPrompt: true,
if ($activeProfileSecretManager && $selectedWallet && $isActiveLedgerProfile) {
$activeProfileSecretManager.generateEd25519Addresses({
accountIndex: ADDRESS_INDEX, // TODO(2.0) This shouldn't be named accountIndex
options: {
internal: false,
ledgerNanoPrompt: true,
}
})
showAppNotification({
type: 'info',
Expand All @@ -61,8 +64,8 @@
openPopup({
id: PopupId.DeleteAccount,
props: {
account: selectedAccount,
deleteAccount,
account: selectedWallet,
deleteWallet,
},
})
modal?.close()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
<script lang="ts">
import { Icon as IconEnum } from '@auxiliary/icon'
import { openPopup, PopupId } from '@auxiliary/popup'
import { sumBalanceForAccounts } from '@core/account'
import { selectedAccount } from '@core/account/stores'
import { sumBalanceForWallets } from '@core/wallet'
import { selectedWallet } from '@core/wallet/stores'
import { formatCurrency, localize } from '@core/i18n'
import { getMarketAmountFromAssetValue } from '@core/market/utils'
import { activeProfile, getBaseToken, visibleActiveAccounts } from '@core/profile'
import { formatTokenAmountBestMatch, selectedAccountAssets } from '@core/wallet'
import { AccountSwitcherMenuItem, FontWeight, Icon, Modal, Text, TextType } from '@ui'
import { activeProfile, getBaseToken, visibleActiveWallets } from '@core/profile'
import { formatTokenAmountBestMatch, selectedWalletAssets } from '@core/wallet'
import { WalletSwitcherMenuItem, FontWeight, Icon, Modal, Text, TextType } from '@ui'
import { tick } from 'svelte'

export let modal: Modal = undefined

$: totalBalance = sumBalanceForAccounts($visibleActiveAccounts)
$: ({ baseCoin } = $selectedAccountAssets[$activeProfile?.network.id])
$: totalBalance = sumBalanceForWallets($visibleActiveWallets)
$: ({ baseCoin } = $selectedWalletAssets[$activeProfile?.network.id])

async function scrollToSelectedAccount(): Promise<void> {
async function scrollToSelectedWallet(): Promise<void> {
await tick()
const element = document.getElementById(`account-${$selectedAccount.index}`)
const element = document.getElementById(`account-${$selectedWallet.id}`)
element?.scrollIntoView({ behavior: 'auto' })
}

function onCreateAccountClick(): void {
function oncreateWalletClick(): void {
modal?.close()
openPopup({ id: PopupId.CreateAccount })
openPopup({ id: PopupId.createWallet })
}
</script>

<Modal
bind:this={modal}
on:open={scrollToSelectedAccount}
on:open={scrollToSelectedWallet}
classes="transform -translate-x-1/2"
size="large"
position={{ top: '30px', left: '50%' }}
>
<account-list-container class="block p-4">
<account-list class="flex flex-col space-y-1 max-h-96 scrollable-y">
{#each $visibleActiveAccounts as account}
<AccountSwitcherMenuItem id="account-{account.index}" {account} onClick={modal?.close} />
{#each $visibleActiveWallets as wallet}
<WalletSwitcherMenuItem id="account-{wallet.id}" {wallet} onClick={modal?.close} />
{/each}
</account-list>
</account-list-container>
<hr />
<button
type="button"
class=" flex flex-row justify-between w-full p-8 hover:bg-gray-50 dark:hover:bg-gray-800"
on:click={onCreateAccountClick}
on:click={oncreateWalletClick}
>
<div class="flex flex-row items-center text-right space-x-4">
<Icon icon={IconEnum.Plus} height="12" width="12" classes="text-blue-500" />
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/components/modals/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as AccountActionsMenu } from './AccountActionsMenu.svelte'
export { default as AccountSwitcherModal } from './AccountSwitcherModal.svelte'
export { default as WalletActionsMenu } from './WalletActionsMenu.svelte'
export { default as WalletSwitcherModal } from './WalletSwitcherModal.svelte'
export { default as FilterModal } from './FilterModal.svelte'
export { default as VestingModal } from './VestingModal.svelte'
Loading
Loading