Skip to content

Commit

Permalink
chore: refactor for multi chain support (#2511)
Browse files Browse the repository at this point in the history
* chore: remove BASE_TOKEN_CONTRACT_ADDRESS map

* chore: rename getL1Network to getStardustNetwork

* fix: type
  • Loading branch information
Tuditi authored and jeeanribeiro committed May 22, 2024
1 parent 731e53a commit 967a4c2
Show file tree
Hide file tree
Showing 29 changed files with 53 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { requestTokensFromFaucet } from '@contexts/developer'
import { localize } from '@core/i18n'
import { getL1Network } from '@core/network'
import { getStardustNetwork } from '@core/network'
import { closePopup } from '@desktop/auxiliary/popup'
import { Error } from '@bloomwalletio/ui'
import { handleError } from '@core/error/handlers/handleError'
Expand All @@ -10,7 +10,7 @@
let isBusy = false
let error: string | undefined
const network = getL1Network()
const network = getStardustNetwork()
async function onConfirmClick(): Promise<void> {
error = undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import PopupTemplate from '../PopupTemplate.svelte'
import { IAccountState } from '@core/account'
import { getProposalStatusForMilestone } from '@contexts/governance'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
function onCancelClick(): void {
closePopup()
Expand Down Expand Up @@ -49,7 +49,7 @@
}
// TODO: User can only remove a proposal when he is not voting for it
const { currentMilestone } = getL1Network()
const { currentMilestone } = getStardustNetwork()
$: status = getProposalStatusForMilestone($currentMilestone, $selectedProposal?.milestones)
$: showAlert = status === EventStatus.Commencing || status === EventStatus.Holding
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts">
import { IconName } from '@bloomwalletio/ui'
import { localize } from '@core/i18n'
import { FAUCET_URLS, getL1Network } from '@core/network'
import { FAUCET_URLS, getStardustNetwork } from '@core/network'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import { ButtonTile } from '../../../components'
const network = getL1Network()
const network = getStardustNetwork()
function onGetTokensClick(): void {
openPopup({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import { onMount } from 'svelte'
import { ProposalStatusInfo } from './'
import { getTimeDifference, milestoneToDate } from '@core/utils'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
import { time } from '@core/app/stores'
export let proposal: IProposalWithStatus
let hasVoted = false
const currentMilestone = getL1Network().currentMilestone
const currentMilestone = getStardustNetwork().currentMilestone
$: $participationOverviewForSelectedAccount, proposal, setHasVoted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import { ProposalCard } from './'
import ProposalListMenu from './ProposalListMenu.svelte'
import { localize } from '@core/i18n'
import { getL1Network } from '@core/network'
import { getStardustNetwork } from '@core/network'
const { currentMilestone } = getL1Network()
const { currentMilestone } = getStardustNetwork()
$: proposals = getProposalsWithStatus($registeredProposalsForSelectedAccount, $currentMilestone)
let searchTerm = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { openPopup } from '@desktop/auxiliary/popup/actions'
import { PopupId } from '@desktop/auxiliary/popup'
import { localize } from '@core/i18n'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
export let onQuestionClick: (questionIndex: number) => void
export let onAnswerClick: (answerValue: number, questionIndex: number) => void
Expand All @@ -31,7 +31,7 @@
let percentages: IProposalAnswerPercentages = {}
let winnerAnswerIndex: number
const { currentMilestone } = getL1Network()
const { currentMilestone } = getStardustNetwork()
$: status = getProposalStatusForMilestone($currentMilestone, $selectedProposal?.milestones)
$: answers = [...(question?.answers ?? []), { value: 0, text: 'Abstain', additionalInfo: '' }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import { formatDate, localize } from '@core/i18n'
import { DATE_FORMAT, milestoneToDate } from '@core/utils'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
export let milestones: Record<EventStatus, number>
export let status: EventStatus
export let anchor: HTMLElement
export let placement: 'top' | 'bottom' | 'left' | 'right' = 'right'
const currentMilestone = getL1Network().currentMilestone
const currentMilestone = getStardustNetwork().currentMilestone
let eventProgress: number
switch (status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import { getTimeDifference, milestoneToDate } from '@core/utils'
import { EventStatus } from '@iota/sdk/out/types'
import { ProposalDetailsMenu, ProposalStatusPill } from '../'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
export let proposal: IProposal
const currentMilestone = getL1Network().currentMilestone
const currentMilestone = getStardustNetwork().currentMilestone
let remainingTime: string = ''
$: switch (proposal?.status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
} from '@contexts/governance/utils'
import { selectedAccount } from '@core/account/stores'
import { formatDate, localize } from '@core/i18n'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
import { activeProfile } from '@core/profile/stores'
import { formatTokenAmount } from '@core/token'
import { visibleSelectedAccountTokens } from '@core/token/stores'
Expand All @@ -23,7 +23,7 @@
milestone: number
}
const currentMilestone = getL1Network().currentMilestone
const currentMilestone = getStardustNetwork().currentMilestone
$: proposalDateData = getNextProposalDateData($currentMilestone)
function getNextProposalDateData(_currentMilestone: number): IProposalDateData | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { selectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers'
import { localize } from '@core/i18n'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
import { getBestTimeDuration, milestoneToDate } from '@core/utils'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import { ProposalQuestion } from '../../components'
Expand All @@ -43,7 +43,7 @@
let openedQuestionIndex: number = -1
let isUpdatingVotedAnswerValues: boolean = false
let lastAction: 'vote' | 'stopVote'
const currentMilestone = getL1Network().currentMilestone
const currentMilestone = getStardustNetwork().currentMilestone
$: selectedProposalOverview = $participationOverviewForSelectedAccount?.participations?.[$selectedProposal?.id]
$: trackedParticipations = Object.values(selectedProposalOverview ?? {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
} from '@contexts/governance'
import { Text, Progress, TooltipIcon } from '@bloomwalletio/ui'
import { getDecimalSeparator, localize } from '@core/i18n'
import { getL1Network } from '@core/network'
import { getStardustNetwork } from '@core/network'
import { getSignificantDigitsAndRound } from '@core/utils'
export let proposal: IProposal
export let projected: boolean = false
const QUORUM_PERCENTAGE_DECIMAL = 0.05
const currentMilestone = getL1Network().currentMilestone
const currentMilestone = getStardustNetwork().currentMilestone
$: ({ actualPercentage, projectedPercentage } = getCirculatingSupplyVotedPercentage(
$selectedParticipationEventStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ProposalQuestionListPane,
QuorumProgress,
} from '../components/proposal-details'
import { getL1Network } from '@core/network'
import { getStardustNetwork } from '@core/network'
import { getProposalWithStatus } from '@contexts/governance/utils'
let statusLoaded: boolean = false
Expand All @@ -38,7 +38,7 @@
clearSelectedParticipationEventStatus()
})
const { currentMilestone } = getL1Network()
const { currentMilestone } = getStardustNetwork()
$: proposal = getProposalWithStatus($selectedProposal, $currentMilestone)
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
NetworkType,
getEvmNetwork,
getIscChains,
getL1Network,
getStardustNetwork,
getNetwork,
isEvmNetwork,
} from '@core/network'
Expand Down Expand Up @@ -107,7 +107,7 @@
}
function getLayer1RecipientOption(accountIndexToExclude?: number): INetworkRecipientSelectorOption {
const network = getL1Network()
const network = getStardustNetwork()
return {
networkId: network.id,
name: network.name,
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/components/inputs/NetworkInput.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { IOption, SelectInput } from '@bloomwalletio/ui'
import { localize } from '@core/i18n'
import { NetworkId, getEvmNetworks, getL1Network } from '@core/network'
import { NetworkId, getEvmNetworks, getStardustNetwork } from '@core/network'
export let networkId: NetworkId | undefined
export let error: string | undefined
Expand All @@ -28,7 +28,7 @@
function getNetworkOptions(showLayer2: boolean): IOption[] {
const options: IOption[] = []
if (showLayer1) {
const l1Network = getL1Network()
const l1Network = getStardustNetwork()
options.push({ label: l1Network.name, value: l1Network.id })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { INode } from '@iota/sdk/out/types'
import { DEFAULT_NETWORK_METADATA, EMPTY_NODE } from '@core/network/constants'
import { IClientOptions, INodeInfoResponse } from '@core/network/interfaces'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
import {
checkIfOnSameNetwork,
checkNodeUrlValidity,
Expand Down Expand Up @@ -96,7 +96,7 @@
const networkName = nodeInfoResponse?.nodeInfo?.protocol.networkName
if (options.checkSameNetwork) {
const stardustNetwork = getL1Network()
const stardustNetwork = getStardustNetwork()
const isInSameNetwork = stardustNetwork?.protocol.networkName === networkName
if (!isInSameNetwork) {
formError = localize('error.node.differentNetwork')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { get } from 'svelte/store'
import { TrackedParticipationOverview } from '@iota/sdk/out/types'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
import { MILESTONE_NOT_FOUND } from '@core/network/constants'

export function calculateTotalVotesForTrackedParticipations(
trackedParticipations: TrackedParticipationOverview[]
): bigint {
const currentMilestone = get(getL1Network().currentMilestone)
const currentMilestone = get(getStardustNetwork().currentMilestone)
if (currentMilestone === MILESTONE_NOT_FOUND) {
return BigInt(0)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get } from 'svelte/store'
import { EventStatus } from '@iota/sdk/out/types'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'
import { ProposalError } from '../enums'
import { IProposal } from '../interfaces'
import { getProposalStatusForMilestone } from './getProposalStatusForMilestone'
Expand All @@ -13,7 +13,7 @@ export function createProposalFromError(
// @ts-expect-error
const isEventError = err?.error?.match(/(the requested data)|(was not found)/)?.length > 0
if (isEventError) {
const currentMilestone = get(getL1Network().currentMilestone)
const currentMilestone = get(getStardustNetwork().currentMilestone)
const status = getProposalStatusForMilestone(currentMilestone, proposal.milestones)
const isNodeOutdated = status !== EventStatus.Ended
const error = isNodeOutdated ? ProposalError.NodeOutdated : ProposalError.ResultsNotAvailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { get } from 'svelte/store'
import { registeredProposalsForSelectedAccount } from '../stores'
import { isProposalActive } from './isProposalActive'
import { getProposalWithStatus } from '@contexts/governance'
import { getL1Network } from '@core/network'
import { getStardustNetwork } from '@core/network'

export function getNumberOfActiveProposals(): number {
const proposals = get(registeredProposalsForSelectedAccount)
const currentMilestone = get(getL1Network().currentMilestone)
const currentMilestone = get(getStardustNetwork().currentMilestone)
const activeProposals = Object.values(proposals ?? {}).filter((proposal) => {
const { status } = getProposalWithStatus(proposal, currentMilestone)
return isProposalActive(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { get } from 'svelte/store'
import { IProposal, IProposalAnswerPercentages, selectedProposal } from '..'
import { AnswerStatus } from '@iota/sdk'
import { round } from '@core/utils/number'
import { getL1Network } from '@core/network/stores'
import { getStardustNetwork } from '@core/network/stores'

export function getPercentagesFromAnswerStatuses(
answerStatuses: AnswerStatus[],
Expand Down Expand Up @@ -44,7 +44,7 @@ export function getPercentagesFromAnswerStatuses(
function getProjectedVotesFromAnswerStatus(answerStatus: AnswerStatus, proposal: IProposal): number {
const { accumulated, current } = answerStatus
const endingMilestone = proposal.milestones?.ended ?? 0
const currentMilestone = get(getL1Network().currentMilestone)
const currentMilestone = get(getStardustNetwork().currentMilestone)

return Math.max(accumulated, accumulated + current * (endingMilestone - currentMilestone))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { IProposal } from '../../interfaces'
import { writable } from 'svelte/store'

jest.mock('../../../../core/network/stores/networks.store.ts', () => ({
getL1Network: jest.fn(() => {
getStardustNetwork: jest.fn(() => {
return { currentMilestone: writable(-1) }
}),
}))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IAccountState } from '@core/account/interfaces'
import { BASE_TOKEN_CONTRACT_ADDRESS } from '@core/layer-2'
import { ISC_BASE_COIN_ADDRESS } from '@core/layer-2'
import { EvmNetworkId } from '@core/network/types'
import { hasTokenBeenUntracked } from '@core/wallet/actions'
import { addAccountActivity, addPersistedTokenBalanceChange, getBalanceChanges } from '../stores'
Expand Down Expand Up @@ -31,8 +31,8 @@ export function calculateAndAddPersistedTokenBalanceChange(
}

const hasZeroStartingBalance = newBalanceChange.newBalance === '0' && newBalanceChange.oldBalance === undefined
const isShimmerErc20Token = tokenId === BASE_TOKEN_CONTRACT_ADDRESS[networkId]
if (!hidden && !hasZeroStartingBalance && !hasTokenBeenUntracked(tokenId, networkId) && !isShimmerErc20Token) {
const isBaseCoinErc20Token = tokenId === ISC_BASE_COIN_ADDRESS
if (!hidden && !hasZeroStartingBalance && !hasTokenBeenUntracked(tokenId, networkId) && !isBaseCoinErc20Token) {
const activity = generateEvmTokenBalanceChangeActivity(networkId, tokenId, newBalanceChange, account)
addAccountActivity(account.index, activity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@auxiliary/blockscout/types'
import { getOrRequestTokenFromPersistedTokens } from '@core/token/actions'
import { isNftPersisted, persistErc721Nft } from '@core/nfts/actions'
import { BASE_TOKEN_CONTRACT_ADDRESS } from '@core/layer-2/constants'
import { ISC_BASE_COIN_ADDRESS } from '@core/layer-2/constants'
import { getSmartContractDataFromBlockscoutTransaction } from './getSmartContractDataFromBlockscoutTransaction'

export async function generateEvmTokenTransferActivityFromBlockscoutTokenTransfer(
Expand Down Expand Up @@ -116,7 +116,7 @@ export async function generateEvmTokenTransferActivityFromBlockscoutTokenTransfe
transactionFee,
}

if (tokenId === BASE_TOKEN_CONTRACT_ADDRESS[networkId]) {
if (tokenId === ISC_BASE_COIN_ADDRESS) {
return {
...baseActivity,
type: EvmActivityType.CoinTransfer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IAccountState } from '@core/account/interfaces'
import { getEvmNetworks } from '@core/network/stores'
import { TokenStandard, TokenTrackingStatus } from '@core/token'
import { addNewTrackedTokenToActiveProfile, hasTokenBeenUntracked } from '@core/wallet/actions'
import { BASE_TOKEN_CONTRACT_ADDRESS } from '../constants'
import { ISC_BASE_COIN_ADDRESS } from '../constants'
import { BlockscoutApi } from '@auxiliary/blockscout/api'

export async function checkForUntrackedTokens(account: IAccountState, addPreviouslyUntracked?: boolean): Promise<void> {
Expand All @@ -21,7 +21,7 @@ export async function checkForUntrackedTokens(account: IAccountState, addPreviou
)
untrackedTokensToTrack.forEach(({ token }) => {
const { address, type, name, symbol, decimals } = token
if (address !== BASE_TOKEN_CONTRACT_ADDRESS?.[networkId]) {
if (address !== ISC_BASE_COIN_ADDRESS) {
addNewTrackedTokenToActiveProfile(
networkId,
address.toLowerCase(),
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/shared/src/lib/core/layer-2/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './accounts-contract.constant'
export * from './base-token-contract-address.constant'
export * from './contract-functions.constant'
export * from './empty-buffer.constants'
export * from './erc20-tokens-poll-interval.constant'
Expand Down
Loading

0 comments on commit 967a4c2

Please sign in to comment.