Skip to content

Commit

Permalink
Merge branch 'release/desktop-1.6.4' of https://github.com/iotaledger…
Browse files Browse the repository at this point in the history
…/firefly into release/desktop-1.6.4
  • Loading branch information
cvarley100 committed Jul 29, 2022
2 parents 29f7f1f + 505a057 commit 2e9b84a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
4 changes: 3 additions & 1 deletion packages/shared/lib/participation/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { localize } from '@core/i18n'
import { convertBech32AddressToEd25519Address } from '@lib/ed25519'
import { showAppNotification } from '@lib/notifications'
import { addError } from 'shared/lib/errors'
import { get } from 'svelte/store'
import { get, writable } from 'svelte/store'
import { getDecimalSeparator } from '../currency'
import { networkStatus } from '../networkStatus'
import { activeProfile, updateProfile } from '../profile'
Expand Down Expand Up @@ -36,6 +36,8 @@ import {
} from './types'
import { Platform } from '@lib/platform'

export const haveStakingResultsCached = writable<boolean>(null)

/**
* Determines whether an account is currently being staked or not.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { didInitialiseMigrationListeners } from './migration'
import { buildClientOptions, getDefaultClientOptions } from './network'
import { showAppNotification } from './notifications'
// PARTICIPATION
import { haveStakingResultsCached } from './participation'
import { Platform } from './platform'
import { activeProfile, updateProfile } from './profile'
import { WALLET, WalletApi } from './shell/walletApi'
Expand Down Expand Up @@ -104,6 +105,7 @@ export const resetWallet = (): void => {
isFirstManualSync.set(true)
isBackgroundSyncing.set(false)
walletSetupType.set(null)
haveStakingResultsCached.set(null)
}

// Created to help selectedAccount reactivity.
Expand Down
53 changes: 24 additions & 29 deletions packages/shared/lib/walletApiListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,49 +250,44 @@ export const initialiseListeners = (): void => {
onSuccess(response) {
const { accounts } = get(wallet)

let completeCount = 0
const totalBalance = {
balance: 0,
incoming: 0,
outgoing: 0,
}

const latestAccounts = []
const updatedAccounts = []

// 1. Iterate on all accounts;
// 2. Get latest metadata for all accounts (to compute the latest balance overview);
// 3. Only update the account for which the balance change event emitted;
// 4. Update balance overview & accounts
for (const _account of response.payload) {
getAccountMetadataWithCallback(_account.id, (metaErr, meta) => {
if (!metaErr) {
// Compute balance overview for each account
totalBalance.balance += meta.balance
totalBalance.incoming += meta.incoming
totalBalance.outgoing += meta.outgoing

aggregateAccountActivity(_account)
get(accounts).forEach((account, idx) => {
getAccountMetadataWithCallback(account?.id, (metaErr, meta) => {
if (metaErr) {
return
}

const updatedAccountInfo = formatAccountWithMetadata(_account, meta)
totalBalance.balance += meta.balance
totalBalance.incoming += meta.incoming
totalBalance.outgoing += meta.outgoing

// Keep the messages as is because they get updated through a different event
// Also, we create pairs for internal messages, so best to keep those rather than reimplementing the logic here
latestAccounts.push(updatedAccountInfo)
aggregateAccountActivity(account)
const updatedAccountInfo = formatAccountWithMetadata(account, meta)

completeCount++
updatedAccounts.push(
account?.index === updatedAccountInfo?.index
? { ...updatedAccountInfo, alias: account?.alias }
: account
)

if (completeCount === response.payload.length) {
accounts.update((_accounts) => latestAccounts.sort((a, b) => a.index - b.index))
if (idx === get(accounts).length - 1) {
accounts.update((_accounts) => updatedAccounts.sort((a, b) => a.index - b.index))

updateBalanceOverview(
totalBalance.balance,
totalBalance.incoming,
totalBalance.outgoing
)
}
updateBalanceOverview(
totalBalance.balance,
totalBalance.incoming,
totalBalance.outgoing
)
}
})
}
})
},
onError(response) {},
})
Expand Down
13 changes: 9 additions & 4 deletions packages/shared/routes/dashboard/Dashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
showAppNotification,
} from 'shared/lib/notifications'
import { stopParticipationPoll, startParticipationPoll, StakingAirdrop } from 'shared/lib/participation'
import { cacheAllStakingPeriods } from 'shared/lib/participation/staking'
import { cacheAllStakingPeriods, haveStakingResultsCached } from 'shared/lib/participation/staking'
import { pendingParticipations, resetPerformingParticipation } from 'shared/lib/participation/stores'
import { Platform } from 'shared/lib/platform'
import { closePopup, openPopup, popupState } from 'shared/lib/popup'
Expand All @@ -41,6 +41,7 @@
asyncCreateAccount,
asyncSyncAccount,
isSyncing,
isFirstSessionSync,
setSelectedAccount,
STRONGHOLD_PASSWORD_CLEAR_INTERVAL_SECS,
wallet,
Expand Down Expand Up @@ -90,9 +91,13 @@
previousPendingParticipationsLength = participations?.length ?? 0
})
$: if (!$isSyncing && $accountsLoaded) {
cacheAllStakingPeriods(StakingAirdrop.Shimmer)
cacheAllStakingPeriods(StakingAirdrop.Assembly)
$: if (!$isSyncing && !$isFirstSessionSync && $accountsLoaded) {
Promise.all([
cacheAllStakingPeriods(StakingAirdrop.Shimmer),
cacheAllStakingPeriods(StakingAirdrop.Assembly),
]).then(() => {
haveStakingResultsCached.set(true)
})
}
const viewableAccounts: Readable<WalletAccount[]> = derived(
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/routes/dashboard/wallet/Wallet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { displayNotificationForLedgerProfile, promptUserToConnectLedger } from 'shared/lib/ledger'
import { addProfileCurrencyPriceData } from 'shared/lib/market'
import { showAppNotification } from 'shared/lib/notifications'
import { haveStakingResultsCached } from 'shared/lib/participation/staking'
import { closePopup, openPopup } from 'shared/lib/popup'
import {
activeProfile,
Expand Down Expand Up @@ -388,7 +389,9 @@
</div>
{/if}
{#if $accountRoute === AccountRoute.Init}
<AccountAssets />
{#key $haveStakingResultsCached}
<AccountAssets />
{/key}
{:else if $accountRoute === AccountRoute.Send}
<Send {onSend} {onInternalTransfer} />
{:else if $accountRoute === AccountRoute.Receive}
Expand Down

0 comments on commit 2e9b84a

Please sign in to comment.