Skip to content

Commit

Permalink
Merge branch 'develop' into fix/avoid-nft-send-crash
Browse files Browse the repository at this point in the history
  • Loading branch information
begonaalvarezd authored Oct 11, 2023
2 parents 248a8cf + 5a390e8 commit 3e545fa
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 28 deletions.
36 changes: 35 additions & 1 deletion packages/desktop/components/modals/AccountActionsMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { activeAccounts, visibleActiveAccounts } from '@core/profile/stores'
import { activeAccounts, isActiveLedgerProfile, visibleActiveAccounts } from '@core/profile/stores'
import { deleteAccount } from '@core/profile-manager/actions'
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'
export let modal: Modal = undefined
Expand All @@ -24,6 +28,29 @@
modal?.close()
}
function onVerifyAddressClick(): void {
const ADDRESS_INDEX = 0
checkOrConnectLedger(() => {
try {
if ($profileManager && $selectedAccount && $isActiveLedgerProfile) {
$profileManager.generateEd25519Address($selectedAccount.index, ADDRESS_INDEX, {
internal: false,
ledgerNanoPrompt: true,
})
showAppNotification({
type: 'info',
message: localize('general.verifyLedgerDepositAddress'),
})
}
} catch (err) {
handleError(err)
} finally {
modal?.close()
}
return Promise.resolve()
})
}
function onDeleteAccountClick(): void {
openPopup({
id: PopupId.DeleteAccount,
Expand All @@ -40,6 +67,13 @@
<account-actions-menu class="flex flex-col">
<MenuItem icon={Icon.Doc} title={localize('actions.viewBalanceBreakdown')} onClick={onViewBalanceClick} />
<MenuItem icon={Icon.Customize} title={localize('actions.customizeAcount')} onClick={onCustomiseAccountClick} />
{#if $isActiveLedgerProfile}
<MenuItem
icon={Icon.Ledger}
title={localize('actions.verifyDepositAddress')}
onClick={onVerifyAddressClick}
/>
{/if}
<ToggleHiddenAccountMenuItem onClick={modal?.close} />
<hr />
{#if showDeleteAccount}
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/components/SubjectBox.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<script lang="ts">
import { localize } from '@core/i18n'
import { Subject } from '@core/wallet'
import { Subject, SubjectType } from '@core/wallet'
import { Box, AddressBox, Text, AccountLabel, TextType, FontWeight } from 'shared/components'
export let subject: Subject | null = null
</script>

{#if subject?.type === 'account'}
{#if subject?.type === SubjectType.Account}
<Box row clearBackground clearPadding classes="justify-center">
<AccountLabel account={subject?.account} />
</Box>
{:else if subject?.type === 'address'}
{:else if subject?.type === SubjectType.Address}
<AddressBox clearBackground clearPadding isCopyable address={subject?.address} />
{:else}
<Box row clearBackground clearPadding classes="justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
on:click={onReceiveClick}
>
<Text type="h5" fontWeight={FontWeight.semibold} classes="text-left">{localize('general.receiveFunds')}</Text>
<inner-box class="w-full flex flex-col items-center space-y-6 pt-7 pb-6">
<inner-box class="w-full flex flex-col items-center space-y-6 py-4">
<QR data={receiveAddress} />
<AddressBox
bind:this={addressBoxElement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NewTransactionDetails,
NewTransactionType,
Subject,
SubjectType,
getAssetById,
getUnitFromTokenMetadata,
selectedAccountAssets,
Expand Down Expand Up @@ -58,7 +59,7 @@ function parseSendConfirmationOperation(searchParams: URLSearchParams): NewTrans
throw new InvalidAddressError()
}

const recipient: Subject = { type: 'address', address }
const recipient: Subject = { type: SubjectType.Address, address }

const assetId = searchParams.get(SendOperationParameter.AssetId)
assetId && validateAssetId(assetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getAssetById,
NewTransactionType,
getUnitFromTokenMetadata,
SubjectType,
} from '@core/wallet'
import { openPopup, PopupId } from '@auxiliary/popup'
import { get } from 'svelte/store'
Expand Down Expand Up @@ -51,7 +52,7 @@ function parseSendFormOperation(searchParams: URLSearchParams): NewTransactionDe
const rawAmount = getRawAmountFromSearchParam(searchParams)
const metadata = searchParams.get(SendOperationParameter.Metadata)
const tag = searchParams.get(SendOperationParameter.Tag)
const recipient: Subject = address ? { type: 'address', address } : undefined
const recipient: Subject = address ? { type: SubjectType.Address, address } : undefined

return {
type: NewTransactionType.TokenTransfer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
setNewTransactionDetails,
NewTransactionType,
NewTokenTransactionDetails,
SubjectType,
} from '@core/wallet'
import { logAndNotifyError } from '@core/error/actions'

Expand Down Expand Up @@ -66,7 +67,7 @@ async function claimShimmerRewardsForShimmerClaimingAccount(

const newTransactionDetails: NewTokenTransactionDetails = {
recipient: {
type: 'address',
type: SubjectType.Address,
address: recipientAddress,
},
type: NewTransactionType.TokenTransfer,
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/lib/core/account/utils/getBoundAccount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IAccount, UnableToGetBoundAccountError } from '@core/account'
import { WalletRsError } from '@core/error'
import { createAccount, getAccount, profileManager as _profileManager } from '@core/profile-manager'

export async function getBoundAccount(
Expand All @@ -16,7 +15,8 @@ export async function getBoundAccount(
const account = await getAccount(accountIndex ?? 0, profileManager)
return account
} catch (err) {
if (err?.type === WalletRsError?.AccountNotFound && createAccountsIfNotFound) {
// TODO: Update error type when sdk Error enum has been updated
if (err?.type === 'wallet' && createAccountsIfNotFound) {
for (let indexToCreateAccount = 0; indexToCreateAccount < accountIndex; indexToCreateAccount++) {
const account = await createAccount({}, profileManager)
if (account?.getMetadata()?.index === accountIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function buildProfileManagerOptionsFromProfileData(
): Promise<ProfileManagerOptions> {
const { id, type, network } = profileData
const storagePath = await getStorageDirectoryOfProfile(id)
const coinType = network?.coinType ?? network ? COIN_TYPE[network?.id] ?? 1 : 1
const coinType = network?.coinType ? network?.coinType : network ? COIN_TYPE[network?.id] ?? 1 : 1
const useDefaultClientOptions =
!profileData?.clientOptions ||
!profileData?.clientOptions?.nodes ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
pollLedgerNanoStatus()
}

setSelectedAccount(lastUsedAccountIndex ?? get(activeAccounts)?.[0]?.index ?? null)
let initialSelectedAccountindex = get(activeAccounts)?.[0]?.index
if (
lastUsedAccountIndex &&
get(activeAccounts)?.find((_account) => _account.index === lastUsedAccountIndex)
) {
initialSelectedAccountindex = lastUsedAccountIndex
}
setSelectedAccount(initialSelectedAccountindex)
lastActiveAt.set(new Date())
loggedIn.set(true)
setTimeout(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/lib/core/wallet/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './verified-status.enum'
export * from './return-strategy.enum'
export * from './inclusion-state.enum'
export * from './irc27-version.enum'
export * from './subject.enum'
4 changes: 4 additions & 0 deletions packages/shared/lib/core/wallet/enums/subject.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum SubjectType {
Account = 'account',
Address = 'address',
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAccountState } from '@core/account'
import { SubjectType } from '../enums'

export interface IAccountSubject {
type: 'account'
type: SubjectType.Account
account: IAccountState
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { SubjectType } from '../enums'

export interface IAddressSubject {
type: 'address'
type: SubjectType.Address
address: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isValidIrc30Token } from '@core/token'

import { selectedAccount } from '../../account/stores/selected-account.store'
import { Activity } from '../types/activity.type'
import { ActivityType } from '../enums'
import { ActivityType, SubjectType } from '../enums'
import { ActivityFilter } from '../interfaces/activity-filter.interface'
import { getAssetFromPersistedAssets, getFormattedAmountFromActivity } from '../utils'
import { isVisibleActivity } from '../utils/isVisibleActivity'
Expand Down Expand Up @@ -78,9 +78,9 @@ function getFieldsToSearchFromActivity(activity: Activity): string[] {
fieldsToSearch.push(getFormattedAmountFromActivity(activity, false)?.toLowerCase())
}

if (activity.subject?.type === 'account') {
if (activity.subject?.type === SubjectType.Account) {
fieldsToSearch.push(activity.subject?.account?.name)
} else if (activity.subject?.type === 'address') {
} else if (activity.subject?.type === SubjectType.Address) {
fieldsToSearch.push(activity.subject?.address)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parseLayer2Metadata, getDestinationNetworkFromAddress } from '@core/layer-2/utils'
import { Layer2Metadata } from '@core/layer-2/types'
import { SenderInfo } from '../../../types'
import { SubjectType } from '@core/wallet/enums'

export function getLayer2ActivityInformation(
metadata: string,
Expand All @@ -14,7 +15,7 @@ export function getLayer2ActivityInformation(
try {
parsedLayer2Metadata = parseLayer2Metadata(metadata)
destinationNetwork = getDestinationNetworkFromAddress(
sendingInfo.subject?.type === 'address' ? sendingInfo.subject.address : undefined
sendingInfo.subject?.type === SubjectType.Address ? sendingInfo.subject.address : undefined
)
} catch (_err) {
parsedLayer2Metadata = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { localize } from '@core/i18n'
import { getLayer2NetworkFromAddress } from '@core/layer-2/utils'
import { truncateString } from '@core/utils'
import { ActivityType } from '@core/wallet/enums'
import { ActivityType, SubjectType } from '@core/wallet/enums'
import type { Activity, Subject } from '@core/wallet/types'

export function getSubjectFromActivity(activity: Activity): Subject {
if (activity.parsedLayer2Metadata) {
return {
...activity.subject,
...(activity.subject?.type === 'address' && {
...(activity.subject?.type === SubjectType.Address && {
address: activity.parsedLayer2Metadata?.ethereumAddress,
}),
}
} else if (activity.subject?.type === 'address') {
} else if (activity.subject?.type === SubjectType.Address) {
const network = getLayer2NetworkFromAddress(activity.subject.address)
return { ...activity.subject, address: network ?? activity.subject.address }
} else {
Expand All @@ -27,9 +27,9 @@ export function getSubjectLocaleFromActivity(activity: Activity): string {
return localize('general.shimmerGenesis')
} else if (activity.type === ActivityType.Vesting) {
return localize('general.stardustGenesis')
} else if (subject?.type === 'account') {
} else if (subject?.type === SubjectType.Account) {
return truncateString(subject?.account?.name, 13, 0)
} else if (subject?.type === 'address') {
} else if (subject?.type === SubjectType.Address) {
const address = activity?.parsedLayer2Metadata?.ethereumAddress ?? subject?.address
const network = getLayer2NetworkFromAddress(address)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { findActiveAccountWithAddress } from '@core/profile'
import { Subject } from '../types'
import { SubjectType } from '../enums'

export function getSubjectFromAddress(address: string): Subject {
const account = findActiveAccountWithAddress(address)
if (account) {
return { type: 'account', account: account }
return { type: SubjectType.Account, account: account }
} else {
return { type: 'address', address }
return { type: SubjectType.Address, address }
}
}
3 changes: 2 additions & 1 deletion packages/shared/lib/core/wallet/utils/isSubjectInternal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SubjectType } from '../enums'
import { Subject } from '../types'

export function isSubjectInternal(subject: Subject | undefined): boolean {
return subject?.type === 'account'
return subject?.type === SubjectType.Account
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Subject } from '@core/wallet/types'
import { CommonOutput } from '@iota/sdk/out/types'
import { getSenderFromOutput } from '../outputs/getSenderFromOutput'
import { SubjectType } from '@core/wallet/enums'

export function getSenderFromTransaction(
isIncoming: boolean,
Expand All @@ -10,6 +11,6 @@ export function getSenderFromTransaction(
if (isIncoming) {
return getSenderFromOutput(output)
} else {
return { type: 'address', address: accountAddress }
return { type: SubjectType.Address, address: accountAddress }
}
}
4 changes: 3 additions & 1 deletion packages/shared/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@
"viewDownloads" : "View downloads",
"viewStatus": "View status",
"viewBalanceBreakdown": "View balance breakdown",
"verifyDepositAddress": "Verify deposit address",
"showHiddenAccounts": "Show hidden wallets",
"confirm": "Confirm",
"hideNetworkStatistics": "Hide network statistics",
Expand Down Expand Up @@ -1664,7 +1665,8 @@
"jwt": "JSON web token",
"internalTransaction": "Internal transaction",
"coinType":"Coin type",
"custom": "Custom"
"custom": "Custom",
"verifyLedgerDepositAddress": "Please check the ledger device and verify that the deposit address matches the one displayed on the ledger device"
},
"filters":{
"title": "Filters",
Expand Down

0 comments on commit 3e545fa

Please sign in to comment.