Skip to content

Commit

Permalink
Merge branch 'develop' into chore/update-notarize
Browse files Browse the repository at this point in the history
  • Loading branch information
rajivshah3 committed Jan 9, 2024
2 parents 45ab111 + b3f64f7 commit c0e20f7
Show file tree
Hide file tree
Showing 94 changed files with 3,844 additions and 3,098 deletions.
6 changes: 6 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ singleQuote: true
tabWidth: 4
trailingComma: es5
useTabs: false
plugins:
- prettier-plugin-svelte
overrides:
- files: '*.svelte'
options:
parser: 'svelte'
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"check-types:shared": "cd packages/shared && tsc --project tsconfig.base.json --pretty --noEmit",
"docs:start": "cd docs/ && retype start",
"format": "yarn format:write",
"format:check": "prettier -c \"**/*.{ts,js,json,scss,css,svelte}\"",
"format:write": "prettier -w \"**/*.{ts,js,json,scss,css,svelte}\"",
"format:check": "prettier --plugin prettier-plugin-svelte -c \"**/*.{ts,js,json,scss,css,svelte}\"",
"format:write": "prettier --plugin prettier-plugin-svelte -w \"**/*.{ts,js,json,scss,css,svelte}\"",
"lint": "yarn lint:fix",
"lint:check": "eslint . --cache",
"lint:fix": "eslint . --cache --fix",
Expand Down
15 changes: 14 additions & 1 deletion packages/desktop/components/modals/AccountActionsMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { selectedAccount } from '@core/account/stores'
import { localize } from '@core/i18n'
import { activeAccounts, isActiveLedgerProfile, visibleActiveAccounts } from '@core/profile/stores'
import { activeAccounts, activeProfile, isActiveLedgerProfile, visibleActiveAccounts } from '@core/profile/stores'
import { deleteAccount } from '@core/profile-manager/actions'
import { Icon } from '@auxiliary/icon/enums'
Expand All @@ -12,6 +12,7 @@
import { checkOrConnectLedger } from '@core/ledger'
import { showAppNotification } from '@auxiliary/notification'
import { handleError } from '@core/error/handlers'
import { NetworkId } from '@core/network/enums'
export let modal: Modal = undefined
Expand All @@ -28,6 +29,11 @@
modal?.close()
}
function onViewAddressHistoryClick(): void {
openPopup({ id: PopupId.AddressHistory })
modal?.close()
}
function onVerifyAddressClick(): void {
const ADDRESS_INDEX = 0
checkOrConnectLedger(() => {
Expand Down Expand Up @@ -66,6 +72,13 @@
<Modal bind:this={modal} {...$$restProps}>
<account-actions-menu class="flex flex-col">
<MenuItem icon={Icon.Doc} title={localize('actions.viewBalanceBreakdown')} onClick={onViewBalanceClick} />
{#if $activeProfile?.network?.id === NetworkId.Iota || $activeProfile?.network?.id === NetworkId.IotaAlphanet}
<MenuItem
icon={Icon.Timer}
title={localize('actions.viewAddressHistory')}
onClick={onViewAddressHistoryClick}
/>
{/if}
<MenuItem icon={Icon.Customize} title={localize('actions.customizeAcount')} onClick={onCustomiseAccountClick} />
{#if $isActiveLedgerProfile}
<MenuItem
Expand Down
47 changes: 26 additions & 21 deletions packages/desktop/components/popups/ActivityDetailsPopup.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
<script lang="ts">
import { PopupId, closePopup, openPopup } from '@auxiliary/popup'
import { openUrlInBrowser } from '@core/app'
import { localize } from '@core/i18n'
import { ExplorerEndpoint } from '@core/network'
import { getOfficialExplorerUrl } from '@core/network/utils'
import {
Text,
Button,
FontWeight,
TextType,
BasicActivityDetails,
AliasActivityDetails,
FoundryActivityDetails,
GovernanceActivityDetails,
NftActivityDetails,
ConsolidationActivityDetails,
ActivityInformation,
} from 'shared/components'
import { openUrlInBrowser } from '@core/app'
import { activeProfile, checkActiveProfileAuth } from '@core/profile'
import { setClipboard, truncateString } from '@core/utils'
import {
ActivityAsyncStatus,
ActivityDirection,
Expand All @@ -23,13 +14,21 @@
rejectActivity,
selectedAccountActivities,
} from '@core/wallet'
import { activeProfile, checkActiveProfileAuth } from '@core/profile'
import { setClipboard } from '@core/utils'
import { truncateString } from '@core/utils'
import { closePopup, openPopup, PopupId } from '@auxiliary/popup'
import { onMount } from 'svelte'
import { ExplorerEndpoint } from '@core/network'
import {
ActivityInformation,
AliasActivityDetails,
BasicActivityDetails,
Button,
ConsolidationActivityDetails,
FontWeight,
FoundryActivityDetails,
GovernanceActivityDetails,
NftActivityDetails,
Text,
TextType,
} from 'shared/components'
import { TextHintVariant } from 'shared/components/enums'
import { onMount } from 'svelte'
export let activityId: string
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
Expand All @@ -45,7 +44,13 @@
activity?.asyncData?.asyncStatus === ActivityAsyncStatus.Unclaimed
function onExplorerClick(): void {
openUrlInBrowser(`${explorerUrl}/${ExplorerEndpoint.Transaction}/${activity?.transactionId}`)
let url: string
if (activity?.type === ActivityType.Vesting) {
url = `${explorerUrl}/${ExplorerEndpoint.Output}/${activity?.outputId}`
} else {
url = `${explorerUrl}/${ExplorerEndpoint.Transaction}/${activity?.transactionId}`
}
openUrlInBrowser(url)
}
function onTransactionIdClick(): void {
Expand Down
202 changes: 202 additions & 0 deletions packages/desktop/components/popups/AddressHistoryPopup.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<script lang="ts">
import { selectedAccount } from '@core/account'
import { handleError } from '@core/error/handlers/handleError'
import { localize } from '@core/i18n'
import { CHRONICLE_ADDRESS_HISTORY_ROUTE, CHRONICLE_URLS } from '@core/network/constants/chronicle-urls.constant'
import { fetchWithTimeout } from '@core/nfts'
import { checkActiveProfileAuth, getActiveProfile, updateAccountPersistedDataOnActiveProfile } from '@core/profile'
import { getProfileManager } from '@core/profile-manager/stores'
import { setClipboard, truncateString } from '@core/utils'
import { AccountAddress } from '@iota/sdk/out/types'
import VirtualList from '@sveltejs/svelte-virtual-list'
import { Button, FontWeight, KeyValueBox, Spinner, Text, TextType } from 'shared/components'
import { onMount } from 'svelte'
interface AddressHistory {
address: string
items: [
{
milestoneIndex: number
milestoneTimestamp: number
outputId: string
isSpent: boolean
}
]
}
const activeProfile = getActiveProfile()
const ADDRESS_GAP_LIMIT = 20
let knownAddresses: AccountAddress[] = []
$: accountIndex = $selectedAccount?.index
$: network = activeProfile?.network?.id
let searchURL: string
let searchAddressStartIndex = 0
let currentSearchGap = 0
let isBusy = false
function onCopyClick(): void {
const addresses = knownAddresses.map((address) => address.address).join(',')
setClipboard(addresses)
}
onMount(() => {
knownAddresses = $selectedAccount?.knownAddresses
if (!knownAddresses?.length) {
isBusy = true
$selectedAccount
.addresses()
.then((_knownAddresses) => {
knownAddresses = sortAddresses(_knownAddresses)
updateAccountPersistedDataOnActiveProfile(accountIndex, { knownAddresses })
isBusy = false
})
.finally(() => {
isBusy = false
})
}
if (CHRONICLE_URLS[network] && CHRONICLE_URLS[network].length > 0) {
const chronicleRoot = CHRONICLE_URLS[network][0]
searchURL = `${chronicleRoot}${CHRONICLE_ADDRESS_HISTORY_ROUTE}`
} else {
throw new Error(localize('popups.addressHistory.errorNoChronicle'))
}
})
async function isAddressWithHistory(address: string): Promise<boolean> {
try {
const response = await fetchWithTimeout(`${searchURL}${address}`, 3, { method: 'GET' })
const addressHistory: AddressHistory = await response.json()
return addressHistory?.items?.length > 0
} catch (err) {
throw new Error(localize('popups.addressHistory.errorFailedFetch'))
}
}
async function generateNextUnknownAddress(): Promise<[string, number]> {
let nextUnknownAddress: string
try {
do {
nextUnknownAddress = await getProfileManager().generateEd25519Address(
accountIndex,
searchAddressStartIndex
)
searchAddressStartIndex++
} while (knownAddresses.map((accountAddress) => accountAddress.address).includes(nextUnknownAddress))
} catch (err) {
throw new Error(localize('popups.addressHistory.errorFailedGenerate'))
}
return [nextUnknownAddress, searchAddressStartIndex - 1]
}
async function search(): Promise<void> {
currentSearchGap = 0
const tmpKnownAddresses = [...knownAddresses]
while (currentSearchGap < ADDRESS_GAP_LIMIT) {
const [nextAddressToCheck, addressIndex] = await generateNextUnknownAddress()
if (!nextAddressToCheck) {
isBusy = false
break
}
const hasHistory = await isAddressWithHistory(nextAddressToCheck)
if (hasHistory) {
const accountAddress: AccountAddress = {
address: nextAddressToCheck,
keyIndex: addressIndex,
internal: false,
used: true,
}
tmpKnownAddresses.push(accountAddress)
} else {
currentSearchGap++
}
}
knownAddresses = sortAddresses(tmpKnownAddresses)
updateAccountPersistedDataOnActiveProfile(accountIndex, { knownAddresses })
}
async function handleSearchClick(): Promise<void> {
isBusy = true
try {
await checkActiveProfileAuth(search, { stronghold: true, ledger: true })
} catch (err) {
handleError(err)
} finally {
isBusy = false
}
}
function sortAddresses(addresses: AccountAddress[] = []): AccountAddress[] {
return addresses.sort((a, b) => a.keyIndex - b.keyIndex)
}
</script>

<div class="flex flex-col space-y-6">
<Text type={TextType.h3} fontWeight={FontWeight.semibold} lineHeight="6">
{localize('popups.addressHistory.title')}
</Text>
{#if knownAddresses}
{#if knownAddresses.length > 0}
<div class="w-full flex-col space-y-2 virtual-list-wrapper">
<VirtualList items={knownAddresses} let:item>
<div class="mb-1">
<KeyValueBox
isCopyable
classes="flex items-center w-full py-4"
keyText={truncateString(item?.address, 15, 15)}
valueText={localize('popups.addressHistory.indexAndType', {
values: {
index: item.keyIndex,
internal: item.internal,
},
})}
copyValue={item.address}
backgroundColor="gray-50"
darkBackgroundColor="gray-900"
/>
</div>
</VirtualList>
</div>
{:else}
<Text secondary classes="text-center">-</Text>
{/if}
{:else}
<div class="flex items-center justify-center">
<Spinner />
</div>
{/if}
</div>
<div class="flex flex-row flex-nowrap w-full space-x-4 mt-6">
<div class="flex w-full justify-center pt-8 space-x-4">
<Button outline classes="w-1/2" onClick={onCopyClick}>{localize('actions.copy')}</Button>
<Button
classes="w-1/2"
onClick={handleSearchClick}
disabled={isBusy}
{isBusy}
busyMessage={localize('actions.searching')}>{localize('actions.search')}</Button
>
</div>
</div>

<style lang="scss">
.virtual-list-wrapper :global(svelte-virtual-list-viewport) {
margin-right: -1rem !important;
flex: auto;
overflow-y: scroll;
padding-right: 1.5rem !important;
min-height: 52px;
max-height: 300px;
}
.virtual-list-wrapper :global(svelte-virtual-list-contents) {
margin-right: -1rem !important;
}
</style>
18 changes: 16 additions & 2 deletions packages/desktop/components/popups/LedgerAppGuidePopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import { LedgerAppName, ledgerAppName } from '@core/ledger'
import { localize } from '@core/i18n'
import { IllustrationEnum } from '@auxiliary/illustration'
import { Icon } from '@auxiliary/icon'
let stepIndex = 0
const stepAnimations = [
const stepIlustrations = [
IllustrationEnum.LedgerLiveUpdatedDesktop,
IllustrationEnum.LedgerConnected2Desktop,
$ledgerAppName === LedgerAppName.Shimmer
Expand All @@ -16,6 +17,14 @@
IllustrationEnum.LedgerCloseLiveDesktop,
]
const stepIconWithIlustrations = [
undefined,
undefined,
undefined,
$ledgerAppName === LedgerAppName.Shimmer ? Icon.Shimmer : Icon.Iota,
undefined,
]
function changeIndex(increment: number): void {
stepIndex += increment
}
Expand All @@ -29,7 +38,12 @@
{localize('popups.ledgerAppGuide.title', { values: { legacy: $ledgerAppName } })}
</Text>
<div class="w-full flex flex-row flex-wrap">
<LedgerAnimation illustration={stepAnimations[stepIndex]} classes="illustration-wrapper" bgClasses="top-6" />
<LedgerAnimation
illustration={stepIlustrations[stepIndex]}
iconNetwork={stepIconWithIlustrations[stepIndex]}
classes="illustration-wrapper"
bgClasses="top-6"
/>
<div class="w-full text-center my-9 px-10">
<Text secondary>
{localize(`popups.ledgerAppGuide.steps.${stepIndex}`, { values: { legacy: $ledgerAppName } })}
Expand Down
Loading

0 comments on commit c0e20f7

Please sign in to comment.