Skip to content

Commit

Permalink
chore: rename EvmNetworkType
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi committed Apr 30, 2024
1 parent ce322b0 commit a24b72c
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { DrawerTemplate } from '@components'
import { EvmNetworkType, IscChain, selectedChain } from '@core/network'
import { NetworkType, IscChain, selectedChain } from '@core/network'
import { Router } from '@core/router'
import { NetworkConfigRoute } from '../'
import { EvmChainInformation, IscChainInformation } from './components'
Expand All @@ -12,9 +12,9 @@

<DrawerTemplate title={evmNetwork?.name} {drawerRouter}>
<div class="w-full h-full px-6">
{#if evmNetwork?.type === EvmNetworkType.Isc}
{#if evmNetwork?.type === NetworkType.Isc}
<IscChainInformation {evmNetwork} />
{:else if evmNetwork?.type === EvmNetworkType.PureEvm}
{:else if evmNetwork?.type === NetworkType.Evm}
<EvmChainInformation />
{/if}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { localize } from '@core/i18n'
import {
MAX_NETWORK_NAME_LENGTH,
EvmNetworkType,
NetworkType,
IIscChainConfiguration,
ETHEREUM_COIN_TYPE,
EvmNetworkId,
Expand All @@ -26,7 +26,7 @@
$: submitDisabled = !iscNetwork.name || !iscNetwork.aliasAddress || !iscNetwork.rpcEndpoint
const iscNetwork: IIscChainConfiguration = {
type: EvmNetworkType.Isc,
type: NetworkType.Isc,
id: '' as EvmNetworkId,
namespace: NetworkNamespace.Evm,
chainId: '' as ChainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
[sendFlowType]: {
token: selectedToken,
},
sourceNetworkId: selectedToken?.networkId,
})
$sendFlowRouter.next()
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/components/pills/NetworkTypePill.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { EvmNetworkType, NetworkId, getActiveNetworkId, getEvmNetwork } from '@core/network'
import { NetworkType, NetworkId, getActiveNetworkId, getEvmNetwork } from '@core/network'
import { Pill, Tooltip } from '@bloomwalletio/ui'
import { localize } from '@core/i18n'
Expand All @@ -12,16 +12,16 @@
{@const chainType = getEvmNetwork(networkId)?.type}
<network-type-pill bind:this={anchor} class="h-fit">
<Pill color="cyan" compact>
{chainType === EvmNetworkType.PureEvm ? 'EVM' : chainType === EvmNetworkType.Isc ? 'ISC' : undefined}
{chainType === NetworkType.Evm ? 'EVM' : chainType === NetworkType.Isc ? 'ISC' : undefined}
</Pill>
</network-type-pill>
<Tooltip
{anchor}
placement="top"
event="hover"
text={chainType === EvmNetworkType.PureEvm
text={chainType === NetworkType.Evm
? 'Ethereum'
: chainType === EvmNetworkType.Isc
: chainType === NetworkType.Isc
? 'IOTA Smart Contracts'
: localize('views.dashboard.network.undefined')}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IEvmNetwork, IscChain, getIscChains } from '@core/network'
import { IscChain, getIscChains } from '@core/network'

export function getNetworkFromAddress(networkAddress: string | undefined): IEvmNetwork | undefined {
const evmNetwork = getIscChains().find((evmNetwork) => (evmNetwork as IscChain).aliasAddress === networkAddress)
export function getNetworkFromAddress(networkAddress: string | undefined): IscChain | undefined {
const evmNetwork = getIscChains().find(({ aliasAddress }) => aliasAddress === networkAddress)
return evmNetwork
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ function getNftDataForTransaction(
const transferredAsset = { type: AssetType.Nft, nft } as TransferredAsset
switch (nft.standard) {
case NftStandard.Irc27:
return getIscTransferSmartContractData(recipientAddress, transferredAsset, evmNetwork as IscChain)
return getIscTransferSmartContractData(
recipientAddress,
transferredAsset,
evmNetwork as unknown as IscChain
)
case NftStandard.Erc721: {
return getErc721TransferSmartContractData(originAddress, recipientAddress, nft, evmNetwork)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ function getTokenDataForTransaction(
const isBaseCoin = token.standard === TokenStandard.BaseToken
const assetType = isBaseCoin ? AssetType.BaseCoin : AssetType.Token
const transferredAsset = { type: assetType, token, amount } as TransferredAsset
return getIscTransferSmartContractData(recipientAddress, transferredAsset, evmNetwork as IscChain)
return getIscTransferSmartContractData(
recipientAddress,
transferredAsset,
evmNetwork as unknown as IscChain
)
}
case TokenStandard.Erc20:
return getErc20TransferSmartContractData(recipientAddress, token, amount, evmNetwork)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { calculateAndAddPersistedTokenBalanceChange, calculateAndAddPersistedNft
import { ISC_MAGIC_CONTRACT_ADDRESS } from '@core/layer-2/constants'
import { ContractType } from '@core/layer-2/enums'
import { getSmartContractHexName, evmAddressToAgentId, getAgentBalanceParameters } from '@core/layer-2/helpers'
import { IEvmNetwork, IscChain } from '@core/network'
import { IscChain } from '@core/network'
import { isIrc27Nft, getNftsFromNftIds } from '@core/nfts'
import {
updateAllAccountNftsForAccount,
Expand Down Expand Up @@ -38,10 +38,10 @@ export async function fetchIscAssetsForAccount(
return l2Balance
}

async function getL2NativeTokenBalancesForAddress(evmAddress: string, iscChain: IEvmNetwork): Promise<ITokenBalance> {
async function getL2NativeTokenBalancesForAddress(evmAddress: string, iscChain: IscChain): Promise<ITokenBalance> {
const accountsCoreContract = getSmartContractHexName('accounts')
const getBalanceFunc = getSmartContractHexName('balance')
const agentID = evmAddressToAgentId(evmAddress, (iscChain as IscChain).aliasAddress)
const agentID = evmAddressToAgentId(evmAddress, iscChain.aliasAddress)
const parameters = getAgentBalanceParameters(agentID)
try {
const contract = iscChain.getContract(ContractType.IscMagic, ISC_MAGIC_CONTRACT_ADDRESS)
Expand All @@ -60,12 +60,12 @@ async function getL2NativeTokenBalancesForAddress(evmAddress: string, iscChain:
async function fetchL2Irc27Nfts(
profileId: string,
evmAddress: string,
iscChain: IEvmNetwork,
iscChain: IscChain,
account: IAccountState
): Promise<void> {
const accountsCoreContract = getSmartContractHexName('accounts')
const getBalanceFunc = getSmartContractHexName('accountNFTs')
const agentID = evmAddressToAgentId(evmAddress, (iscChain as IscChain).aliasAddress)
const agentID = evmAddressToAgentId(evmAddress, iscChain.aliasAddress)
const parameters = getAgentBalanceParameters(agentID)
try {
const contract = iscChain.getContract(ContractType.IscMagic, ISC_MAGIC_CONTRACT_ADDRESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EVM_CONTRACT_ABIS } from '@core/layer-2/constants'
import { ContractType } from '@core/layer-2/enums'
import { Contract } from '@core/layer-2/types'

import { EvmNetworkType, NetworkHealth, NetworkNamespace, ChainId } from '../enums'
import { NetworkHealth, NetworkNamespace, ChainId } from '../enums'
import { IBlock, IEvmNetwork, IBaseEvmNetworkConfiguration } from '../interfaces'
import { CoinType } from '@iota/sdk/out/types'
import { EvmNetworkId, Web3Provider } from '../types'
Expand All @@ -20,13 +20,12 @@ import { Converter } from '@core/utils'
import { getActiveProfile } from '@core/profile/stores'
import { IError } from '@core/error/interfaces'

export class BaseEvmNetwork implements IEvmNetwork {
export class BaseEvmNetwork implements Omit<IEvmNetwork, 'type'> {
public readonly provider: Web3Provider

public readonly id: EvmNetworkId
public readonly namespace: NetworkNamespace.Evm
public readonly chainId: ChainId
public readonly type: EvmNetworkType
public readonly coinType: CoinType
public readonly name: string
public readonly baseToken: IBaseToken
Expand All @@ -40,7 +39,6 @@ export class BaseEvmNetwork implements IEvmNetwork {
id,
namespace,
chainId,
type,
coinType,
baseToken,
name,
Expand All @@ -54,7 +52,6 @@ export class BaseEvmNetwork implements IEvmNetwork {
this.id = id
this.namespace = namespace
this.chainId = chainId
this.type = type
this.coinType = coinType
this.baseToken = baseToken
this.name = name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { IPureEvmNetworkConfiguration } from '../interfaces'
import { NetworkType } from '../enums'
import { IEvmNetwork, IPureEvmNetworkConfiguration } from '../interfaces'
import { BaseEvmNetwork } from './base-evm-network.class'

export class EvmNetwork extends BaseEvmNetwork {
export class EvmNetwork extends BaseEvmNetwork implements IEvmNetwork {
public readonly type = NetworkType.Evm

constructor(chainConfiguration: IPureEvmNetworkConfiguration) {
try {
super(chainConfiguration)
} catch (err) {
console.error(err)
throw new Error('Failed to construct isc Chain!')
}
super(chainConfiguration)
}
}
24 changes: 10 additions & 14 deletions packages/shared/src/lib/core/network/classes/isc-chain.class.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import { IIscChainConfiguration, IIscChainMetadata } from '../interfaces'
import { IIscChain, IIscChainConfiguration, IIscChainMetadata } from '../interfaces'
import { Converter } from '@core/utils'
import { BaseEvmNetwork } from './base-evm-network.class'
import { IAccountState } from '@core/account/interfaces'
import { ITokenBalance } from '@core/token/interfaces'
import { fetchIscAssetsForAccount } from '@core/layer-2/utils'
import { getActiveProfileId } from '@core/profile/stores'
import { NetworkType } from '@core/network/enums'

export class IscChain extends BaseEvmNetwork {
export class IscChain extends BaseEvmNetwork implements IIscChain {
private readonly _chainApi: string
private _metadata: IIscChainMetadata | undefined

public readonly explorerUrl: string | undefined
public readonly apiEndpoint: string
public readonly aliasAddress: string
public readonly type = NetworkType.Isc

constructor(chainConfiguration: IIscChainConfiguration) {
try {
const { rpcEndpoint, aliasAddress, apiEndpoint } = chainConfiguration
const _rpcEndpoint = new URL(`v1/chains/${aliasAddress}/evm`, rpcEndpoint).href
const { rpcEndpoint, aliasAddress, apiEndpoint } = chainConfiguration
const _rpcEndpoint = new URL(`v1/chains/${aliasAddress}/evm`, rpcEndpoint).href

super({ ...chainConfiguration, rpcEndpoint: _rpcEndpoint })
super({ ...chainConfiguration, rpcEndpoint: _rpcEndpoint })

this.aliasAddress = aliasAddress
this.apiEndpoint = apiEndpoint

this._chainApi = new URL(`v1/chains/${aliasAddress}`, apiEndpoint).href
} catch (err) {
console.error(err)
throw new Error('Failed to construct isc Chain!')
}
this.aliasAddress = aliasAddress
this.apiEndpoint = apiEndpoint
this._chainApi = new URL(`v1/chains/${aliasAddress}`, apiEndpoint).href
}

getMetadata(): Promise<IIscChainMetadata> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get, writable } from 'svelte/store'
import { activeProfile, updateActiveProfile } from '@core/profile/stores'
import { NetworkHealth, NetworkNamespace } from '../enums'
import { NetworkHealth, NetworkNamespace, NetworkType } from '../enums'
import { IIscChainConfiguration, IProtocol, IStardustNetwork, IStardustNetworkMetadata } from '../interfaces'
import { EvmNetworkId, StardustNetworkId } from '../types'

Expand All @@ -21,8 +21,9 @@ export class StardustNetwork implements IStardustNetwork {
public readonly bech32Hrp: string
public readonly protocol: IProtocol
public readonly baseToken: IBaseToken
public iscChains: IscChain[]
public readonly type = NetworkType.Stardust

public iscChains: IscChain[]
public health = writable(NetworkHealth.Operational)
public currentMilestone = writable(-1)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EvmNetworkType, NetworkNamespace, ChainId } from '../enums'
import { NetworkType, NetworkNamespace, ChainId } from '../enums'
import { IIscChainConfiguration } from '../interfaces'
import { StardustNetworkId } from '../types'
import { SHIMMER_BASE_TOKEN } from './default-base-token.constant'
Expand All @@ -8,7 +8,7 @@ import { SupportedIscNetworkId, SupportedNetworkId, SupportedStardustNetworkId }
export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetworkId]?: IIscChainConfiguration }> = {
[SupportedStardustNetworkId.Shimmer]: {
id: SupportedIscNetworkId.ShimmerEvm,
type: EvmNetworkType.Isc,
type: NetworkType.Isc,
name: 'Shimmer EVM',
chainId: ChainId.ShimmerEvm,
namespace: NetworkNamespace.Evm,
Expand All @@ -21,7 +21,7 @@ export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetwor
},
[SupportedStardustNetworkId.Testnet]: {
id: SupportedIscNetworkId.TestnetEvm,
type: EvmNetworkType.Isc,
type: NetworkType.Isc,
name: 'Testnet EVM',
chainId: ChainId.TestnetEvm,
namespace: NetworkNamespace.Evm,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId, EvmNetworkType, NetworkNamespace } from '../enums'
import { ChainId, NetworkType, NetworkNamespace } from '../enums'
import { IPureEvmNetworkConfiguration } from '../interfaces'
import { EvmNetworkId } from '../types'
import { DEFAULT_COIN_TYPE } from './default-coin-type.constant'
Expand All @@ -10,7 +10,7 @@ export const DEFAULT_L1_EVM_NETWORK_CONFIGURATION: Readonly<{
[key in EvmNetworkId]: IPureEvmNetworkConfiguration
}> = {
[SupportedL1EvmNetworkId.Ethereum]: {
type: EvmNetworkType.PureEvm,
type: NetworkType.Evm,
name: 'Ethereum',
baseToken: EVM_BASE_TOKEN,
id: SupportedL1EvmNetworkId.Ethereum,
Expand All @@ -21,7 +21,7 @@ export const DEFAULT_L1_EVM_NETWORK_CONFIGURATION: Readonly<{
rpcEndpoint: 'https://ethereum-rpc.publicnode.com',
},
[SupportedL1EvmNetworkId.Sepolia]: {
type: EvmNetworkType.PureEvm,
type: NetworkType.Evm,
name: 'Sepolia Testnet',
baseToken: EVM_BASE_TOKEN,
id: SupportedL1EvmNetworkId.Sepolia,
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/shared/src/lib/core/network/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * from './chain-id.enum'
export * from './evm-network-type.enum'
export * from './explorer-api-endpoint.enum'
export * from './explorer-endpoint.enum'
export * from './network-health.enum'
export * from './network-namespace.enum'
export * from './network-type.enum'
export * from './stardust-network-name.enum'
export * from './token-supply.enum'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum NetworkType {
Stardust = 'stardust',
Isc = 'iscp',
Evm = 'evm',
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { CoinType } from '@iota/sdk/out/types'
import { EvmNetworkType, NetworkNamespace, ChainId } from '../enums'
import { NetworkType, NetworkNamespace, ChainId } from '../enums'
import { EvmNetworkId } from '../types'
import { IBaseToken } from '@core/token/interfaces'

export interface IIscChainConfiguration extends IBaseEvmNetworkConfiguration {
type: EvmNetworkType.Isc
type: NetworkType.Isc
aliasAddress: string
apiEndpoint: string
}

export interface IPureEvmNetworkConfiguration extends IBaseEvmNetworkConfiguration {
type: EvmNetworkType.PureEvm
type: NetworkType.Evm
}

export interface IBaseEvmNetworkConfiguration {
id: EvmNetworkId
namespace: NetworkNamespace.Evm
chainId: ChainId
baseToken: IBaseToken
type: EvmNetworkType
type: NetworkType
coinType: CoinType
name: string
explorerUrl?: string
Expand Down
Loading

0 comments on commit a24b72c

Please sign in to comment.