Skip to content

Commit

Permalink
chore: update profile auth for evm address generation (#2268)
Browse files Browse the repository at this point in the history
* update profile auth on networkcard

* update profile auth on receive address popup

* update profile auth on network summary

* remove checkActiveProfileAuth

* remove unused prop

* chore: cosmetics

* rename checkActiveProfileAuthAsync -> checkActiveProfileAuth

---------

Co-authored-by: Tuditi <[email protected]>
Co-authored-by: Tuditi <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent e6b6acb commit bc23fd8
Show file tree
Hide file tree
Showing 31 changed files with 196 additions and 202 deletions.
65 changes: 38 additions & 27 deletions packages/desktop/components/NetworkCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { IAccountState } from '@core/account'
import { selectedAccount } from '@core/account/stores'
import { openUrlInBrowser } from '@core/app'
import { handleError } from '@core/error/handlers'
import { localize } from '@core/i18n'
import { generateAndStoreEvmAddressForAccounts, pollL2BalanceForAccount } from '@core/layer-2/actions'
import { LedgerAppName } from '@core/ledger'
Expand All @@ -26,58 +27,68 @@
import { NetworkConfigRoute, networkConfigRouter } from '@views/dashboard/drawers'
import { onMount } from 'svelte'
export let network: INetwork = undefined
export let chain: IChain = undefined
export let network: INetwork | undefined = undefined
export let chain: IChain | undefined = undefined
export let onCardClick: UiEventFunction
export let onQrCodeIconClick: UiEventFunction
let configuration: IIscpChainConfiguration = undefined
let configuration: IIscpChainConfiguration | undefined = undefined
let networkId: NetworkId | undefined
let name = ''
let address = ''
let address: string | undefined = undefined
let status: NetworkHealth
$: $networkStatus, $chainStatuses, $selectedAccount, setNetworkCardData()
$: explorer = getDefaultExplorerUrl(networkId, ExplorerEndpoint.Address)
$: explorer = networkId ? getDefaultExplorerUrl(networkId, ExplorerEndpoint.Address) : undefined
function onExplorerClick(address: string): void {
function onExplorerClick(): void {
if (!explorer || !address) {
return
}
const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` })
openUrlInBrowser(url?.href)
}
function setNetworkCardData(): void {
const account = $selectedAccount as IAccountState
if (network) {
networkId = network.getMetadata().id
name = network.getMetadata().name
address = $selectedAccount.depositAddress
address = account.depositAddress
status = $networkStatus.health
} else if (chain) {
configuration = chain.getConfiguration() as IIscpChainConfiguration
networkId = configuration.id
name = configuration.name
address = $selectedAccount.evmAddresses[configuration.coinType]
address = account.evmAddresses[configuration.coinType]
status = chain.getStatus().health
}
}
function onGenerateAddressClick(): void {
setSelectedChain(chain)
if (chain) {
checkActiveProfileAuth(
async () => {
await generateAndStoreEvmAddressForAccounts(
$activeProfile.type,
configuration.coinType,
$selectedAccount as IAccountState
)
pollL2BalanceForAccount($activeProfile.id, $selectedAccount as IAccountState)
if ($activeProfile.type === ProfileType.Ledger) {
$networkConfigRouter.goTo(NetworkConfigRoute.ConfirmLedgerEvmAddress)
}
},
{},
LedgerAppName.Ethereum
async function onGenerateAddressClick(): Promise<void> {
if (!chain) {
return
}
try {
await checkActiveProfileAuth(LedgerAppName.Ethereum)
} catch {
return
}
try {
setSelectedChain(chain)
await generateAndStoreEvmAddressForAccounts(
$activeProfile.type,
configuration.coinType,
$selectedAccount as IAccountState
)
pollL2BalanceForAccount($activeProfile.id, $selectedAccount as IAccountState)
if ($activeProfile.type === ProfileType.Ledger) {
$networkConfigRouter.goTo(NetworkConfigRoute.ConfirmLedgerEvmAddress)
}
} catch (error) {
handleError(error)
}
}
Expand Down Expand Up @@ -118,12 +129,12 @@
{/if}
</div>
<div class="flex flex-row space-x-1">
{#if explorer.baseUrl && address}
{#if explorer?.baseUrl && address}
<IconButton
size="sm"
icon={IconName.Globe}
tooltip={localize('general.viewOnExplorer')}
on:click={() => onExplorerClick(address)}
on:click={onExplorerClick}
/>
{/if}
{#if address}
Expand Down
42 changes: 23 additions & 19 deletions packages/desktop/components/menus/AccountActionsMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { IAccountState } from '@core/account'
import { setNextSelectedAccount } from '@core/account/actions'
import { selectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers'
import { localize } from '@core/i18n'
import { deleteAccount } from '@core/profile-manager/actions'
import { checkActiveProfileAuth, updateActiveAccountPersistedData } from '@core/profile/actions'
Expand All @@ -11,6 +12,8 @@
let menu: Menu | undefined = undefined
$: account = $selectedAccount as IAccountState
function onSyncAccountsClick(): void {
openPopup({ id: PopupId.SyncAccounts })
menu?.close()
Expand All @@ -27,19 +30,15 @@
}
function onShowAccountClick(): void {
if ($selectedAccount) {
updateActiveAccountPersistedData($selectedAccount.index, { hidden: false })
menu?.close()
}
updateActiveAccountPersistedData(account.index, { hidden: false })
menu?.close()
}
function onHideAccountClick(): void {
if ($nonHiddenActiveAccounts.length > 1) {
if ($selectedAccount) {
updateActiveAccountPersistedData($selectedAccount.index, { hidden: true })
if (!$activeProfile.showHiddenAccounts) {
setNextSelectedAccount()
}
updateActiveAccountPersistedData(account.index, { hidden: true })
if (!$activeProfile.showHiddenAccounts) {
setNextSelectedAccount()
}
} else {
console.error('Not enough accounts visible: ', $nonHiddenActiveAccounts.length)
Expand All @@ -52,17 +51,22 @@
id: PopupId.Confirmation,
props: {
variant: 'danger',
title: localize('popups.deleteAccount.title', { values: { name: $selectedAccount?.name } }),
title: localize('popups.deleteAccount.title', { values: { name: account.name } }),
alert: { variant: 'warning', text: localize('popups.deleteAccount.hint') },
confirmText: localize('actions.delete'),
onConfirm: async () => {
await checkActiveProfileAuth(
async () => {
await deleteAccount($selectedAccount?.index)
closePopup()
},
{ stronghold: true }
)
try {
await checkActiveProfileAuth()
} catch {
return
}
try {
await deleteAccount(account.index)
closePopup()
} catch (error) {
handleError(error)
}
},
},
})
Expand Down Expand Up @@ -112,9 +116,9 @@
}
}
$: setItems(
$selectedAccount,
account,
$nonHiddenActiveAccounts,
$selectedAccount?.index === $activeAccounts?.length - 1 && $visibleActiveAccounts?.length > 1
account.index === $activeAccounts?.length - 1 && $visibleActiveAccounts?.length > 1
)
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { localize } from '@core/i18n'
import { isEvmChain } from '@core/network'
import { IIrc27Nft, Nft, isNftLocked } from '@core/nfts'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { activeProfile, updateActiveProfile } from '@core/profile/stores'
import { CollectiblesRoute, collectiblesRouter } from '@core/router'
import { burnNft } from '@core/wallet'
Expand Down Expand Up @@ -46,8 +46,8 @@
confirmText: localize('actions.burn'),
onConfirm: async () => {
try {
await checkActiveProfileAuthAsync()
} catch (error) {
await checkActiveProfileAuth()
} catch {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { processAndAddToActivities } from '@core/activity/actions'
import { handleError } from '@core/error/handlers/handleError'
import { localize } from '@core/i18n'
import { checkActiveProfileAuthAsync, getBaseToken } from '@core/profile/actions'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { EMPTY_HEX_ID, sendPreparedTransaction } from '@core/wallet'
import {
AliasOutputBuilderParams,
Expand Down Expand Up @@ -46,7 +46,7 @@
async function onConfirmClick(): Promise<void> {
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch (error) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { selectedAccount } from '@core/account/stores'
import { getStorageDepositFromOutput } from '@core/activity/utils/helper'
import { localize } from '@core/i18n'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { consolidateOutputs } from '@core/wallet/actions/consolidateOutputs'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { CommonOutput, OutputType, UnlockCondition, UnlockConditionType } from '@iota/sdk/out/types'
Expand Down Expand Up @@ -115,7 +115,7 @@
confirmText: localize('popups.minimizeStorageDeposit.confirmButton'),
onConfirm: async () => {
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch (err) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Alert, Table } from '@bloomwalletio/ui'
import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { ITokenWithBalance, formatTokenAmountBestMatch } from '@core/token'
import { burnToken } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
Expand All @@ -22,7 +22,7 @@
async function onBurnTokenClick(): Promise<void> {
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch (err) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { tryCreateAdditionalAccount, validateAccountName } from '@core/account/actions'
import { handleError } from '@core/error/handlers/handleError'
import { localize } from '@core/i18n'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { getTrimmedLength } from '@core/utils'
import { closePopup } from '@desktop/auxiliary/popup'
import PopupTemplate from '../PopupTemplate.svelte'
Expand Down Expand Up @@ -36,7 +36,7 @@
}
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch (error) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import { openUrlInBrowser } from '@core/app'
import { StardustActivityType } from '@core/activity'
import { BASE_TOKEN_ID } from '@core/token/constants'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { LedgerAppName } from '@core/ledger'
import { DappVerification, RpcMethod } from '@auxiliary/wallet-connect/enums'
import { LegacyTransaction } from '@ethereumjs/tx'
Expand Down Expand Up @@ -119,7 +119,7 @@
async function onConfirmClick(): Promise<void> {
try {
await checkActiveProfileAuthAsync(LedgerAppName.Ethereum)
await checkActiveProfileAuth(LedgerAppName.Ethereum)
} catch (error) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { selectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers'
import { localize } from '@core/i18n'
import { checkActiveProfileAuthAsync } from '@core/profile/actions'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { activeProfile } from '@core/profile/stores'
import { visibleSelectedAccountTokens } from '@core/token/stores'
import { PopupId, closePopup, openPopup, popupState } from '@desktop/auxiliary/popup'
Expand Down Expand Up @@ -44,7 +44,7 @@
}
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { selectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers/handleError'
import { localize } from '@core/i18n'
import { getBaseToken, checkActiveProfileAuthAsync } from '@core/profile/actions'
import { getBaseToken, checkActiveProfileAuth } from '@core/profile/actions'
import { mintNativeToken, mintTokenDetails, buildFoundryOutputBuilderParams, IMintTokenDetails } from '@core/wallet'
import { closePopup, openPopup, PopupId } from '@desktop/auxiliary/popup'
import { IIrc30Metadata, TokenStandard, formatTokenAmountPrecise } from '@core/token'
Expand Down Expand Up @@ -58,7 +58,7 @@
async function onConfirmClick(): Promise<void> {
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch (error) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { localize } from '@core/i18n'
import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts'
import { getClient } from '@core/profile-manager'
import { checkActiveProfileAuthAsync, getBaseToken } from '@core/profile/actions'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { buildNftOutputBuilderParams, mintNftCollection, mintNftCollectionDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
Expand Down Expand Up @@ -55,7 +55,7 @@
async function onConfirmClick(): Promise<void> {
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch (err) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { localize } from '@core/i18n'
import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts'
import { getClient } from '@core/profile-manager'
import { checkActiveProfileAuthAsync, getBaseToken } from '@core/profile/actions'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { buildNftOutputBuilderParams, mintNft, mintNftDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
Expand Down Expand Up @@ -72,7 +72,7 @@
async function onConfirmClick(): Promise<void> {
try {
await checkActiveProfileAuthAsync()
await checkActiveProfileAuth()
} catch (err) {
return
}
Expand Down
Loading

0 comments on commit bc23fd8

Please sign in to comment.