Skip to content

Commit

Permalink
enhancement: ethereum coin price (#2668)
Browse files Browse the repository at this point in the history
* enhancement: ethereum coin price

* fix types

---------

Co-authored-by: Mark Nardi <[email protected]>
  • Loading branch information
nicole-obrien and MarkNerdi authored Jun 27, 2024
1 parent ee0fa9e commit c1fe076
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script lang="ts">
import { Text } from '@bloomwalletio/ui'
import { formatCurrency } from '@core/i18n'
import { getFiatValueFromTokenAmount, getMarketPriceForToken } from '@core/market/actions'
import { SupportedStardustNetworkId, TokenSupply, getActiveNetworkId } from '@core/network'
import { BASE_TOKEN_SUPPLY_FOR_NETWORK } from '@core/network'
import { activeProfile } from '@core/profile/stores'
import { BASE_TOKEN_ID, ITokenWithBalance, formatTokenAmount } from '@core/token'
import { truncateString } from '@core/utils'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import { TokenAvatar, NetworkAvatar, NetworkTypePill } from '@ui'
import { Text } from '@bloomwalletio/ui'
import { activeProfile } from '@core/profile/stores'
import { NetworkAvatar, NetworkTypePill, TokenAvatar } from '@ui'
import TokenStandardPill from './TokenStandardPill.svelte'
export let token: ITokenWithBalance
Expand All @@ -17,18 +17,7 @@
return '-'
}
let tokenSupply: TokenSupply | '0'
switch (getActiveNetworkId()) {
case SupportedStardustNetworkId.Iota:
tokenSupply = TokenSupply.Iota
break
case SupportedStardustNetworkId.Shimmer:
case SupportedStardustNetworkId.Testnet:
tokenSupply = TokenSupply.Shimmer
break
default:
tokenSupply = '0'
}
const tokenSupply: bigint | undefined = BASE_TOKEN_SUPPLY_FOR_NETWORK[token.networkId]
const marketPrice = tokenSupply ? getFiatValueFromTokenAmount(BigInt(tokenSupply), token) : undefined
return marketPrice ? formatCurrency(marketPrice, $activeProfile.settings.marketCurrency, true) : '-'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function getAndUpdateMarketPrices(): Promise<void> {
)

const marketPricesResponse = await CoinGeckoApi.getSimplePrices(
[MarketCoinId.Iota, MarketCoinId.Shimmer, ...storedTokenIds],
[MarketCoinId.Iota, MarketCoinId.Shimmer, MarketCoinId.Ethereum, ...storedTokenIds],
Object.values(MarketCurrency)
)
updateMarketCoinPrices(marketPricesResponse)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SupportedIscNetworkId } from '@core/network/constants/supported-network-id.constant'
import { SupportedIscNetworkId, SupportedL1EvmNetworkId } from '@core/network/constants/supported-network-id.constant'
import { MILLISECONDS_PER_SECOND, sleep } from '@core/utils'
import { get } from 'svelte/store'
import { CoinGeckoApi } from '../apis'
Expand All @@ -9,6 +9,7 @@ import { coinGeckoTokensMetadata } from '../stores/'
const NETWORK_FROM_PLATFORM: { [key in CoinGeckoNetworkId]: string } = {
[CoinGeckoNetworkId.IotaEvm]: SupportedIscNetworkId.IotaEvm,
[CoinGeckoNetworkId.ShimmerEvm]: SupportedIscNetworkId.ShimmerEvm,
[CoinGeckoNetworkId.Ethereum]: SupportedL1EvmNetworkId.Ethereum,
}

export async function getAndUpdateTokensMetadataFromCoinGecko(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum CoinGeckoNetworkId {
IotaEvm = 'iota-evm',
ShimmerEvm = 'shimmer_evm',
Ethereum = 'ethereum',
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum MarketCoinId {
Iota = 'iota',
Shimmer = 'shimmer',
Ethereum = 'ethereum',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NetworkId } from '../types'
import { SupportedNetworkId } from './supported-network-id.constant'

export const BASE_TOKEN_SUPPLY_FOR_NETWORK: Readonly<{ [id in NetworkId]: bigint }> = {
[SupportedNetworkId.Iota]: BigInt('4600000000000000'),
[SupportedNetworkId.Shimmer]: BigInt('1813620509061365'),
[SupportedNetworkId.IotaTestnet]: BigInt('4600000000000000'),
[SupportedNetworkId.Testnet]: BigInt('1450896407249092'),
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const IOTA_TESTNET_EVM_BASE_TOKEN: IBaseToken = {

export const EVM_BASE_TOKEN: IBaseToken = {
standard: TokenStandard.BaseToken,
name: 'Ether',
name: 'Ethereum',
tickerSymbol: 'ETH',
unit: 'ETH',
decimals: 18,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/lib/core/network/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* break the dependency flow. It MUST be exported first!
*/
export * from './average-block-time-in-seconds.constant'
export * from './base-token-supply-for-network.constant'
export * from './confirmation-threshold.constant'
export * from './default-coin-type.constant'
export * from './default-bech32-hrp.constant'
Expand Down

0 comments on commit c1fe076

Please sign in to comment.