Skip to content

Commit

Permalink
rename L2 to EVM
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkNerdi committed Apr 30, 2024
1 parent 66c07d0 commit ab588b7
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 98 deletions.
4 changes: 2 additions & 2 deletions packages/desktop/components/NetworkCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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 { generateAndStoreEvmAddressForAccounts, pollEvmBalancesForAccount } from '@core/layer-2/actions'
import { LedgerAppName } from '@core/ledger'
import { ExplorerEndpoint, Network, NetworkNamespace, getDefaultExplorerUrl, setSelectedChain } from '@core/network'
import { ProfileType } from '@core/profile'
Expand Down Expand Up @@ -67,7 +67,7 @@
network.coinType,
$selectedAccount as IAccountState
)
pollL2BalanceForAccount($activeProfile.id, $selectedAccount as IAccountState)
pollEvmBalancesForAccount($selectedAccount as IAccountState)
if ($activeProfile.type === ProfileType.Ledger) {
$networkConfigRouter.goTo(NetworkConfigRoute.ConfirmLedgerEvmAddress)
}
Expand Down
5 changes: 2 additions & 3 deletions packages/desktop/components/menus/TokenListMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<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'
import { loadTokensForAllAccountBalances } from '@core/token/actions'
import { PopupId, closePopup, openPopup } from '../../lib/auxiliary/popup'
import { fetchL2BalanceForAllAccounts } from '@core/layer-2'
import { fetchEvmBalancesForAllAccounts } from '@core/layer-2'
let menu: Menu | undefined = undefined
function onSyncTokensClick(): void {
fetchL2BalanceForAllAccounts($activeProfileId as string, true)
fetchEvmBalancesForAllAccounts(true)
showNotification({
variant: 'success',
text: localize('notifications.syncTokens.success'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { selectedAccount } from '@core/account/stores'
import { setClipboard } from '@core/utils'
import { getActiveNetworkId, getNetwork, NetworkId, NetworkNamespace } from '@core/network'
import { generateAndStoreEvmAddressForAccounts, pollL2BalanceForAccount } from '@core/layer-2/actions'
import { activeProfile, activeProfileId } from '@core/profile/stores'
import { generateAndStoreEvmAddressForAccounts, pollEvmBalancesForAccount } from '@core/layer-2/actions'
import { activeProfile } from '@core/profile/stores'
import { checkActiveProfileAuth } from '@core/profile/actions'
import { LedgerAppName } from '@core/ledger'
import PopupTemplate from '../PopupTemplate.svelte'
Expand Down Expand Up @@ -42,7 +42,7 @@
try {
await generateAndStoreEvmAddressForAccounts($activeProfile.type, coinType, account)
pollL2BalanceForAccount($activeProfileId as string, account)
pollEvmBalancesForAccount(account)
updateNetworkNameAndAddress()
} catch (error) {
handleError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { AvatarGroup, Copyable, Text } from '@bloomwalletio/ui'
import { FormattedBalance } from '@components'
import { formatCurrency, localize } from '@core/i18n'
import { generateAndStoreEvmAddressForAccounts, pollL2BalanceForAccount } from '@core/layer-2/actions'
import { generateAndStoreEvmAddressForAccounts, pollEvmBalancesForAccount } from '@core/layer-2/actions'
import { LedgerAppName } from '@core/ledger'
import { Network, NetworkNamespace, setSelectedChain } from '@core/network'
import { MimeType, Nft } from '@core/nfts'
Expand Down Expand Up @@ -89,7 +89,7 @@
try {
await generateAndStoreEvmAddressForAccounts($activeProfile.type, network.coinType, account)
pollL2BalanceForAccount($activeProfile.id, account)
pollEvmBalancesForAccount(account)
if ($activeProfile.type === ProfileType.Ledger) {
setSelectedChain(network)
toggleDashboardDrawer({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { updateAccountForConnectedDapps } from '@auxiliary/wallet-connect/actions'
import { pollL2BalanceForAccount } from '@core/layer-2/actions/pollL2BalanceForAccount'
import { activeAccounts, getActiveProfileId, updateActiveProfile } from '@core/profile/stores'
import { pollEvmBalancesForAccount } from '@core/layer-2/actions/pollEvmBalancesForAccount'
import { activeAccounts, 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()
pollL2BalanceForAccount(activeProfileId, account)
pollEvmBalancesForAccount(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 @@ -6,7 +6,7 @@ import { createNewAccount } from './createNewAccount'
import { setSelectedAccount } from './setSelectedAccount'
import { getActiveProfile } from '@core/profile/stores'
import { ProfileType } from '@core/profile'
import { generateAndStoreEvmAddressForAccounts, pollL2BalanceForAccount } from '@core/layer-2/actions'
import { generateAndStoreEvmAddressForAccounts, pollEvmBalancesForAccount } from '@core/layer-2/actions'
import { getEvmNetworks } from '@core/network/stores'
import { IError } from '@core/error/interfaces'

Expand All @@ -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 pollL2BalanceForAccount(activeProfile.id, account)
void pollEvmBalancesForAccount(account)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IAccountState } from '@core/account/interfaces'
import { getEvmNetworks } from '@core/network/stores'
import { ITokenBalance } from '@core/token'
import { setLayer2AccountBalanceForChain } from '@core/layer-2/stores'

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

setLayer2AccountBalanceForChain(account.index, evmNetwork.id, tokenBalance)
} catch (error) {
console.error(error)
}
})
}

This file was deleted.

4 changes: 2 additions & 2 deletions packages/shared/src/lib/core/layer-2/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ export * from './buildUnwrapAssetParameters'
export * from './buildUnwrapAssetTargetAddress'
export * from './canAccountMakeEvmTransaction'
export * from './checkForUntrackedTokens'
export * from './fetchL2BalanceForAccount'
export * from './fetchEvmBalancesForAccount'
export * from './getGasFeeForLayer1ToLayer2Transaction'
export * from './generateAndStoreEvmAddressForAccounts'
export * from './getIscTransferSmartContractData'
export * from './getLayer2MetadataForTransfer'
export * from './getLayer2NetworkFromAddress'
export * from './getNetworkFromAddress'
export * from './pollL2BalanceForAccount'
export * from './pollEvmBalancesForAccount'
export * from './setGasFee'
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { IAccountState } from '@core/account/interfaces'
import { checkForUntrackedNfts } from '@core/nfts/actions'
import { LAYER2_TOKENS_POLL_INTERVAL } from '../constants'
import { checkForUntrackedTokens, fetchL2BalanceForAccount } from '.'
import { checkForUntrackedTokens, fetchEvmBalancesForAccount } from '.'
import { handleError } from '@core/error/handlers'

let pollInterval: number

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

export function fetchL2BalanceForAllAccounts(profileId: string, addPreviouslyUntracked?: boolean): void {
export function fetchEvmBalancesForAllAccounts(addPreviouslyUntracked?: boolean): void {
for (const account of get(activeAccounts)) {
try {
checkForUntrackedTokens(account, addPreviouslyUntracked)
void checkForUntrackedNfts(account)
fetchL2BalanceForAccount(profileId, account)
fetchEvmBalancesForAccount(account)
} catch (err) {
console.error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/lib/core/layer-2/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export * from './buildEvmTransactionDataForToken'
export * from './calculateEstimatedGasFeeFromTransactionData'
export * from './calculateMaxGasFeeFromTransactionData'
export * from './fetchIscAssetsForAccount'
export * from './fetchL2BalanceForAllAccounts'
export * from './fetchEvmBalancesForAllAccounts'
export * from './getAmountFromEvmTransactionValue'
export * from './getEvmTokenMetadata'
export * from './getErc20TransferSmartContractData'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { generateAndStoreActivitiesForAllAccounts } from '@core/activity/actions
import { Platform } from '@core/app/classes'
import { AppContext } from '@core/app/enums'
import { handleError } from '@core/error/handlers'
import { fetchL2BalanceForAllAccounts } from '@core/layer-2/utils'
import { fetchEvmBalancesForAllAccounts } from '@core/layer-2/utils'
import { pollLedgerDeviceState } from '@core/ledger/actions'
import { pollMarketPrices } from '@core/market/actions'
import { loadNftsForActiveProfile } from '@core/nfts/actions'
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
incrementLoginProgress()
subscribeToWalletApiEventsForActiveProfile()
await startBackgroundSync({ syncIncomingTransactions: true })
fetchL2BalanceForAllAccounts(id)
fetchEvmBalancesForAllAccounts()
void fetchAndPersistTransactionsForAccounts(_activeProfile.id, get(activeAccounts))

// Step 8: finish login
Expand Down

0 comments on commit ab588b7

Please sign in to comment.