• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

decentraland / marketplace / 6982743061

24 Nov 2023 03:54PM UTC coverage: 43.329% (+2.5%) from 40.865%
6982743061

Pull #2042

github

juanmahidalgo
test: fix how the lib is mocked
Pull Request #2042: feat: use squid to calculate route between two chains and tokens

2621 of 7292 branches covered (0.0%)

Branch coverage included in aggregate %.

271 of 349 new or added lines in 18 files covered. (77.65%)

1 existing line in 1 file now uncovered.

4621 of 9422 relevant lines covered (49.04%)

24.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.17
/webapp/src/components/Modals/BuyWithCryptoModal/utils.ts
1
import { ChainId, Network } from '@dcl/schemas'
2
import {
3
  ChainData,
4
  Token
5
} from 'decentraland-transactions/dist/crossChain/types'
6
import { ContractName, getContract } from 'decentraland-transactions'
7
import { getNetwork } from '@dcl/schemas/dist/dapps/chain-id'
8
import { Asset } from '../../../modules/asset/types'
9

10
export const getShouldUseMetaTx = (
1✔
11
  asset: Asset,
12
  selectedChain: ChainId,
13
  selectedTokenAddress: string,
14
  destinyChainMANA: string,
15
  connectedNetwork: Network
16
) => {
17
  return (
53✔
18
    getNetwork(asset.chainId) === Network.MATIC &&
117✔
19
    getNetwork(selectedChain) === Network.MATIC &&
20
    selectedTokenAddress.toLowerCase() === destinyChainMANA.toLowerCase() &&
21
    connectedNetwork === Network.ETHEREUM // only trigger meta tx if connected to Ethereum
22
  )
23
}
24

25
export function isToken(opt: Token | ChainData): opt is Token {
26
  return (opt as Token).decimals !== undefined
24✔
27
}
28

29
export function isChainData(opt: Token | ChainData): opt is ChainData {
NEW
30
  return (opt as ChainData).axelarChainName !== undefined
×
31
}
32

33
export function getMANAToken(chainId: ChainId) {
NEW
34
  const MANAContract = getContract(ContractName.MANAToken, chainId)
×
NEW
35
  return {
×
36
    type: 'evm' as Token['type'],
37
    chainId: chainId.toString(),
38
    address: MANAContract.address,
39
    name: MANAContract.name,
40
    symbol: 'MANA',
41
    decimals: 18,
42
    logoURI:
43
      'https://assets.coingecko.com/coins/images/878/small/decentraland-mana.png',
44
    coingeckoId: '', // not necessary
45
    subGraphId: '', // won't be used since we'll send the metatx or transaction directly
46
    subGraphOnly: false,
47
    volatility: 0, // won't be used since we'll send the metatx or transaction directly
48
    usdPrice: 0 // not necessary
49
  }
50
}
51

52
function truncateToDecimals(num: number, dec = 2) {
×
53
  const calcDec = Math.pow(10, dec)
112✔
54
  return Math.trunc(num * calcDec) / calcDec
112✔
55
}
56

57
export function formatPrice(price: string | number, token: Token): number {
58
  // Determine the number of decimals based on the USD price
59
  let decimalsToShow: number
60

61
  // Show more decimals for smaller fractions of higher-value tokens like Ethereum
62
  if (token.usdPrice && token.usdPrice < 1) {
112✔
63
    decimalsToShow = 4 // Show 4 decimals for tokens with prices less than 1 USD
56✔
64
  } else {
65
    decimalsToShow = 2 // Show 2 decimals for other tokens or higher-value fractions
56✔
66
  }
67

68
  // Format the price using toFixed to round and limit the number of decimals
69
  const formattedPrice = truncateToDecimals(
112✔
70
    typeof price === 'string' ? Number(price) : price,
112!
71
    decimalsToShow
72
  )
73

74
  return formattedPrice
112✔
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc