@stellar-expert/ui-framework 1.16.5 → 1.16.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,15 @@
1
1
  import {toStroops, fromStroops} from '@stellar-expert/formatter'
2
+ import {AssetDescriptor} from '@stellar-expert/asset-descriptor'
2
3
 
3
4
  /**
4
5
  * Calculate available balance for a given account balance trustline
5
6
  * @param {AccountResponse} account
6
7
  * @param {Horizon.BalanceLine} balance
7
8
  * @param {Number} [additionalReserves]
9
+ * @param {Number} [decimals=7]
8
10
  * @return {String}
9
11
  */
10
- export function calculateAvailableBalance(account, balance, additionalReserves = null) {
12
+ export function calculateAvailableBalance(account, balance, additionalReserves = null, decimals = 7) {
11
13
  let available = toStroops(balance.balance) - toStroops(balance.selling_liabilities || 0)
12
14
  if (balance.asset_type === 'native') {
13
15
  const reserves = 2 + account.subentry_count + account.num_sponsoring - account.num_sponsored
@@ -15,7 +17,7 @@ export function calculateAvailableBalance(account, balance, additionalReserves =
15
17
  //TODO: fetch base_reserve from the Horizon
16
18
  }
17
19
  if (additionalReserves !== null) {
18
- available = available - toStroops(additionalReserves)
20
+ available = available - toStroops(additionalReserves, decimals)
19
21
  }
20
- return fromStroops(available)
22
+ return fromStroops(available, decimals)
21
23
  }
package/asset/amount.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import React from 'react'
2
- import {formatWithPrecision, formatWithAutoPrecision, stripTrailingZeros, fromStroops} from '@stellar-expert/formatter'
2
+ import {formatWithPrecision, formatWithAutoPrecision, fromStroops} from '@stellar-expert/formatter'
3
3
  import {AssetDescriptor, isAssetValid, isValidPoolId} from '@stellar-expert/asset-descriptor'
4
+ import {useAssetMeta} from './asset-meta-hooks'
4
5
  import {AssetLink} from './asset-link'
5
6
 
6
7
  /**
@@ -15,11 +16,12 @@ import {AssetLink} from './asset-link'
15
16
  * @constructor
16
17
  */
17
18
  export const Amount = React.memo(function Amount({amount, asset, decimals, adjust, round, issuer, icon}) {
19
+ const meta = useAssetMeta(asset)
18
20
  if (amount === undefined || amount === null)
19
21
  return null
20
22
  if (adjust === true) {
21
23
  try {
22
- amount = fromStroops(amount)
24
+ amount = fromStroops(amount, meta?.decimals ?? 7)
23
25
  } catch (e) {
24
26
  console.error(e)
25
27
  return null
@@ -47,7 +49,9 @@ export const Amount = React.memo(function Amount({amount, asset, decimals, adjus
47
49
  return <span className="amount nowrap condensed">
48
50
  {amount}
49
51
  {!!asset && <>
50
- {' '}{isAssetValid(asset) || isValidPoolId(asset) ? <AssetLink asset={asset} icon={icon} issuer={issuer}/> : asset.toString()}
52
+ {' '}{isAssetValid(asset) || isValidPoolId(asset) ?
53
+ <AssetLink asset={asset} icon={icon} issuer={issuer}/> :
54
+ asset.toString()}
51
55
  </>}
52
56
  </span>
53
57
  })
@@ -24,7 +24,10 @@ import {getCurrentStellarNetwork} from '../state/stellar-network-hooks'
24
24
  const cache = new InMemoryClientCache()
25
25
 
26
26
  const loader = new ExplorerBatchInfoLoader(batch => {
27
- return fetchExplorerApi(getCurrentStellarNetwork() + '/asset/meta' + stringifyQuery({asset: batch, origin: window.location.origin}))
27
+ return fetchExplorerApi(getCurrentStellarNetwork() + '/asset/meta' + stringifyQuery({
28
+ asset: batch,
29
+ origin: window.location.origin
30
+ }))
28
31
  }, entry => {
29
32
  cache.set(entry.name, entry)
30
33
  return {
@@ -56,7 +59,11 @@ function normalizeAssetName(asset) {
56
59
  * @return {AssetMeta}
57
60
  */
58
61
  export function useAssetMeta(asset) {
59
- asset = normalizeAssetName(asset)
62
+ try {
63
+ asset = normalizeAssetName(asset)
64
+ } catch (e) {
65
+ asset = null
66
+ }
60
67
  const [assetInfo, setAssetInfo] = useState(retrieveFromCache(asset))
61
68
  useEffect(() => {
62
69
  if (!asset)
@@ -68,7 +75,11 @@ export function useAssetMeta(asset) {
68
75
  let unloaded = false
69
76
  //load from the server
70
77
  loader.loadEntry(asset)
71
- .then(a => !unloaded && setAssetInfo(a))
78
+ .then(a => {
79
+ if (unloaded)
80
+ return
81
+ setAssetInfo(a)
82
+ })
72
83
  return () => {
73
84
  unloaded = true
74
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-expert/ui-framework",
3
- "version": "1.16.5",
3
+ "version": "1.16.6",
4
4
  "description": "StellarExpert shared UI components library",
5
5
  "main": "index.js",
6
6
  "module": "./index.js",
@@ -16,11 +16,11 @@
16
16
  "peerDependencies": {
17
17
  "@stellar/stellar-base": "^14.0.0",
18
18
  "@stellar/stellar-sdk": "^14.0.0",
19
- "@stellar-expert/asset-descriptor": "^1.4.0",
19
+ "@stellar-expert/asset-descriptor": "^1.5.0",
20
20
  "@stellar-expert/claimable-balance-utils": "^1.4.1",
21
21
  "@stellar-expert/client-cache": "^1.1.0",
22
22
  "@stellar-expert/contract-wasm-interface-parser": "^3.2.0",
23
- "@stellar-expert/formatter": "^2.5.0",
23
+ "@stellar-expert/formatter": "^3.0.0",
24
24
  "@stellar-expert/navigation": "^1.1.0",
25
25
  "@stellar-expert/tx-meta-effects-parser": "^8.3.3",
26
26
  "classnames": ">=2",