Skip to content

Commit

Permalink
Merge branch 'chore/refactor-evm-network-typ' into feat/add-evm-netwo…
Browse files Browse the repository at this point in the history
…rk-recipients
  • Loading branch information
nicole-obrien authored Apr 30, 2024
2 parents 23cc956 + cd72ef9 commit 44fef75
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/desktop/components/NetworkCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
network.coinType,
$selectedAccount as IAccountState
)
pollEvmBalancesForAccount($selectedAccount as IAccountState)
pollEvmBalancesForAccount($activeProfile.id, $selectedAccount as IAccountState)
if ($activeProfile.type === ProfileType.Ledger) {
$networkConfigRouter.goTo(NetworkConfigRoute.ConfirmLedgerEvmAddress)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop/components/menus/TokenListMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { activeProfileId } from '@core/profile/stores'
import { showNotification } from '@auxiliary/notification'
import { IconName, Menu } from '@bloomwalletio/ui'
import { localize } from '@core/i18n'
Expand All @@ -9,7 +10,7 @@
let menu: Menu | undefined = undefined
function onSyncTokensClick(): void {
fetchEvmBalancesForAllAccounts(true)
fetchEvmBalancesForAllAccounts($activeProfileId as string, true)
showNotification({
variant: 'success',
text: localize('notifications.syncTokens.success'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
try {
await generateAndStoreEvmAddressForAccounts($activeProfile.type, coinType, account)
pollEvmBalancesForAccount(account)
pollEvmBalancesForAccount($activeProfile.id, account)
updateNetworkNameAndAddress()
} catch (error) {
handleError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
try {
await generateAndStoreEvmAddressForAccounts($activeProfile.type, network.coinType, account)
pollEvmBalancesForAccount(account)
pollEvmBalancesForAccount($activeProfile.id, account)
if ($activeProfile.type === ProfileType.Ledger) {
setSelectedChain(network)
toggleDashboardDrawer({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { updateAccountForConnectedDapps } from '@auxiliary/wallet-connect/actions'
import { pollEvmBalancesForAccount } from '@core/layer-2/actions/pollEvmBalancesForAccount'
import { activeAccounts, updateActiveProfile } from '@core/profile/stores'
import { activeAccounts, getActiveProfileId, updateActiveProfile } from '@core/profile/stores'
import { clearFilters } from '@core/utils'
import { resetSendOptionIndex } from '@core/wallet/stores'
import { get } from 'svelte/store'
import { selectedAccountIndex } from '../stores'

export function setSelectedAccount(index: number): void {
const activeProfileId = getActiveProfileId()
const account = get(activeAccounts)?.find((_account) => _account.index === index)
if (account) {
selectedAccountIndex.set(index)
updateAccountForConnectedDapps(account)
updateActiveProfile({ lastUsedAccountIndex: index })
clearFilters()
pollEvmBalancesForAccount(account)
pollEvmBalancesForAccount(activeProfileId, account)
resetSendOptionIndex()
} else {
throw new Error(`Account with ID ${index} cannot be found!`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function tryCreateAdditionalAccount(alias: string, color: string):
const coinType = getEvmNetworks()[0]?.coinType
if (coinType !== undefined) {
void generateAndStoreEvmAddressForAccounts(activeProfile.type, coinType, account)
void pollEvmBalancesForAccount(account)
void pollEvmBalancesForAccount(activeProfile.id, account)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { IAccountState } from '@core/account/interfaces'
import { getEvmNetworks } from '@core/network/stores'
import { ITokenBalance } from '@core/token'
import { setLayer2AccountBalanceForChain } from '@core/layer-2/stores'
import { activeProfileId } from '@core/profile/stores'
import { get } from 'svelte/store'

export function fetchEvmBalancesForAccount(account: IAccountState): void {
export function fetchEvmBalancesForAccount(profileId: string, account: IAccountState): void {
const evmNetworks = getEvmNetworks()
evmNetworks.forEach(async (evmNetwork) => {
try {
const tokenBalance: ITokenBalance = (await evmNetwork.getBalance(account)) ?? {}

setLayer2AccountBalanceForChain(account.index, evmNetwork.id, tokenBalance)
if (get(activeProfileId) === profileId) {
setLayer2AccountBalanceForChain(account.index, evmNetwork.id, tokenBalance)
}
} catch (error) {
console.error(error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { handleError } from '@core/error/handlers'

let pollInterval: number

export function pollEvmBalancesForAccount(account: IAccountState): void {
export function pollEvmBalancesForAccount(profileId: string, account: IAccountState): void {
try {
clearL2TokensPoll()
checkForUntrackedTokens(account)
void checkForUntrackedNfts(account)
fetchEvmBalancesForAccount(account)
fetchEvmBalancesForAccount(profileId, account)
pollInterval = window.setInterval(() => {
fetchEvmBalancesForAccount(account)
fetchEvmBalancesForAccount(profileId, account)
}, LAYER2_TOKENS_POLL_INTERVAL)
} catch (err) {
handleError(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { activeAccounts } from '@core/profile/stores'
import { checkForUntrackedTokens, fetchEvmBalancesForAccount } from '../actions'
import { checkForUntrackedNfts } from '@core/nfts/actions'

export function fetchEvmBalancesForAllAccounts(addPreviouslyUntracked?: boolean): void {
export function fetchEvmBalancesForAllAccounts(profileId: string, addPreviouslyUntracked?: boolean): void {
for (const account of get(activeAccounts)) {
try {
checkForUntrackedTokens(account, addPreviouslyUntracked)
void checkForUntrackedNfts(account)
fetchEvmBalancesForAccount(account)
fetchEvmBalancesForAccount(profileId, account)
} catch (err) {
console.error(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
incrementLoginProgress()
subscribeToWalletApiEventsForActiveProfile()
await startBackgroundSync({ syncIncomingTransactions: true })
fetchEvmBalancesForAllAccounts()
fetchEvmBalancesForAllAccounts(_activeProfile.id)
void fetchAndPersistTransactionsForAccounts(_activeProfile.id, get(activeAccounts))

// Step 8: finish login
Expand Down

0 comments on commit 44fef75

Please sign in to comment.